feat(agent): add permission controls for chat agents (#313)

* feat(agent): add permission controls for chat agents

* refactor(agent): extract shared agent permission helpers

Consolidate the duplicated role-hierarchy logic into
packages/core/src/agent/permissions.ts:

- getRoleLevel(): numeric level for a team role (fail closed at 0)
- getAgentRequiredLevel(): required level for an agent permission
  (defaults to reviewer/1)
- getAllowedAgentRoles(): inclusive role set for filtering

The typed Record over TeamMemberRole makes the mapping exhaustive,
so adding a new role fails compilation until all sites are updated.
Used by ChatService.startOrContinueChat, AssetService comment
mentions, getAgentChatContextActivity, AgentService.listAgents, and
TeamService.getTeamMembers, replacing four inline copies of the
hierarchy and the allowed-roles conditionals.

Also fix the API permission-denial test to mock HTTPException(403)
and assert a 403 response instead of a generic Error/500, matching
real authzService behavior.

* test(agent): fix flaky comment DAG tests by spacing ULID id generation

ULID ids have 1ms timestamp granularity; back-to-back comment creates
frequently land in the same millisecond, in which case Prisma ULIDs sort
by their random suffix instead of creation order. The DAG spine in
initializeAgentSessionActivity chains top-level comments by id, so a
shuffled order produces paths that omit preceding comments, making the
path-to-root assertions flaky (~80% of full-file runs locally).

Add a 2ms sleep between consecutive comment creates in the affected
tests, guaranteeing strictly increasing ULID timestamps. A 2ms delay is
sufficient because the next create always fires at least 2ms after the
previous ULID was generated. Production is unaffected: real comments
arrive seconds apart via separate requests.
This commit is contained in:
Yiling-J
2026-08-16 11:16:14 +08:00
committed by GitHub
parent 6d4f62d6f6
commit cb1c1c502b
26 changed files with 1066 additions and 122 deletions
+119
View File
@@ -421,4 +421,123 @@ describe('AgentService', () => {
expect(result).toBeNull()
})
})
describe('agent permissions', () => {
test('createAgent with custom permission and updateAgentPermission', async () => {
const db = prisma
const svc = new AgentService()
const { team, provider, model } = await setupTestData(db)
const agent = await svc.createAgent({
teamId: team.id,
name: 'Owner Only Agent',
type: 'chat',
enabled: true,
thinkingLevel: 'off',
permission: 'owner',
providerId: provider.id,
modelId: model.id,
})
expect(agent?.permission).toBe('owner')
const updated = await svc.updateAgentPermission(agent!.id, 'editor')
expect(updated.permission).toBe('editor')
const updatedViaUpdateAgent = await svc.updateAgent({
agentId: agent!.id,
name: 'Owner Only Agent Updated',
type: 'chat',
enabled: true,
thinkingLevel: 'off',
permission: 'reviewer',
providerId: provider.id,
modelId: model.id,
})
expect(updatedViaUpdateAgent.permission).toBe('reviewer')
})
test('listAgents filters chat agents by requester role when userId is provided', async () => {
const db = prisma
const svc = new AgentService()
const { team, provider, model } = await setupTestData(db)
// Create 3 chat agents with different permissions
const reviewerAgent = await svc.createAgent({
teamId: team.id,
name: 'All Users Agent',
type: 'chat',
enabled: true,
thinkingLevel: 'off',
permission: 'reviewer',
providerId: provider.id,
modelId: model.id,
})
const editorAgent = await svc.createAgent({
teamId: team.id,
name: 'Editor Agent',
type: 'chat',
enabled: true,
thinkingLevel: 'off',
permission: 'editor',
providerId: provider.id,
modelId: model.id,
})
const ownerAgent = await svc.createAgent({
teamId: team.id,
name: 'Owner Agent',
type: 'chat',
enabled: true,
thinkingLevel: 'off',
permission: 'owner',
providerId: provider.id,
modelId: model.id,
})
// Create 3 test users with different roles in the team
const reviewerUser = await db.user.create({
data: { name: 'Reviewer User', email: 'rev@shumai.ai' },
})
await db.teamMember.create({
data: { teamId: team.id, userId: reviewerUser.id, role: 'reviewer' },
})
const editorUser = await db.user.create({
data: { name: 'Editor User', email: 'ed@shumai.ai' },
})
await db.teamMember.create({
data: { teamId: team.id, userId: editorUser.id, role: 'editor' },
})
const ownerUser = await db.user.create({
data: { name: 'Owner User', email: 'own@shumai.ai' },
})
await db.teamMember.create({
data: { teamId: team.id, userId: ownerUser.id, role: 'owner' },
})
// Reviewer should only see reviewerAgent
const reviewerList = await svc.listAgents({ teamId: team.id, userId: reviewerUser.id })
const reviewerAgentIds = reviewerList.map((a) => a.id)
expect(reviewerAgentIds).toContain(reviewerAgent!.id)
expect(reviewerAgentIds).not.toContain(editorAgent!.id)
expect(reviewerAgentIds).not.toContain(ownerAgent!.id)
// Editor should see reviewerAgent and editorAgent
const editorList = await svc.listAgents({ teamId: team.id, userId: editorUser.id })
const editorAgentIds = editorList.map((a) => a.id)
expect(editorAgentIds).toContain(reviewerAgent!.id)
expect(editorAgentIds).toContain(editorAgent!.id)
expect(editorAgentIds).not.toContain(ownerAgent!.id)
// Owner should see all agents
const ownerList = await svc.listAgents({ teamId: team.id, userId: ownerUser.id })
const ownerAgentIds = ownerList.map((a) => a.id)
expect(ownerAgentIds).toContain(reviewerAgent!.id)
expect(ownerAgentIds).toContain(editorAgent!.id)
expect(ownerAgentIds).toContain(ownerAgent!.id)
})
})
})
+55
View File
@@ -14,6 +14,7 @@ import {
import '@shumai/db/src/prisma-json-types'
import { s3Service } from '@shumai/core/src/s3/s3'
import { getAvatarUrl } from '@shumai/core/src/user/avatar'
import { getAllowedAgentRoles } from './permissions'
import AdmZip from 'adm-zip'
import * as fs from 'fs'
import * as path from 'path'
@@ -114,6 +115,7 @@ export class AgentService {
name,
type,
enabled,
permission,
avatar,
providerId,
modelId,
@@ -179,6 +181,7 @@ export class AgentService {
teamId,
type,
enabled: enabled ?? true,
permission: permission || 'reviewer',
providerId: providerId || null,
modelId: modelId || null,
soul,
@@ -224,6 +227,7 @@ export class AgentService {
name,
type,
enabled,
permission,
avatar,
providerId,
modelId,
@@ -300,6 +304,7 @@ export class AgentService {
data: {
type,
enabled: enabled ?? true,
...(permission ? { permission } : {}),
providerId: providerId || null,
modelId: modelId || null,
soul,
@@ -327,6 +332,29 @@ export class AgentService {
})
}
async updateAgentPermission(agentId: string, permission: 'owner' | 'editor' | 'reviewer') {
const existing = await this.prismaClient.agent.findUnique({
where: { id: agentId },
})
if (!existing) throw new Error('agent not found')
return this.prismaClient.agent.update({
where: { id: agentId },
data: { permission },
include: {
user: true,
provider: true,
modelRef: true,
skills: {
include: {
skill: true,
},
},
mcpServers: true,
},
})
}
async getAgent(params: { agentId: string }) {
return this.prismaClient.agent.findUnique({
where: { id: params.agentId },
@@ -349,9 +377,36 @@ export class AgentService {
}
async listAgents(params: ListAgentsParams) {
const allowedRoles = params.userId
? getAllowedAgentRoles(
(
await this.prismaClient.teamMember.findUnique({
where: {
teamIdUserId: {
teamId: params.teamId,
userId: params.userId,
},
},
select: { role: true },
})
)?.role,
)
: null
return this.prismaClient.agent.findMany({
where: {
teamId: params.teamId,
...(allowedRoles
? {
OR: [
{ type: { not: 'chat' } },
{
type: 'chat',
permission: { in: allowedRoles },
},
],
}
: {}),
},
orderBy: {
id: 'desc',
@@ -0,0 +1,43 @@
import { describe, it, expect } from 'vitest'
import { getRoleLevel, getAgentRequiredLevel, getAllowedAgentRoles } from './permissions'
describe('agent permission helpers', () => {
describe('getRoleLevel', () => {
it('maps each role to its level', () => {
expect(getRoleLevel('reviewer')).toBe(1)
expect(getRoleLevel('editor')).toBe(2)
expect(getRoleLevel('owner')).toBe(3)
})
it('resolves missing roles to 0 (fail closed)', () => {
expect(getRoleLevel(null)).toBe(0)
expect(getRoleLevel(undefined)).toBe(0)
})
})
describe('getAgentRequiredLevel', () => {
it('maps each permission to its required level', () => {
expect(getAgentRequiredLevel('reviewer')).toBe(1)
expect(getAgentRequiredLevel('editor')).toBe(2)
expect(getAgentRequiredLevel('owner')).toBe(3)
})
it('defaults missing permissions to reviewer level (1)', () => {
expect(getAgentRequiredLevel(null)).toBe(1)
expect(getAgentRequiredLevel(undefined)).toBe(1)
})
})
describe('getAllowedAgentRoles', () => {
it('returns inclusive role sets per hierarchy', () => {
expect(getAllowedAgentRoles('owner')).toEqual(['reviewer', 'editor', 'owner'])
expect(getAllowedAgentRoles('editor')).toEqual(['reviewer', 'editor'])
expect(getAllowedAgentRoles('reviewer')).toEqual(['reviewer'])
})
it('defaults missing roles to reviewer only', () => {
expect(getAllowedAgentRoles(null)).toEqual(['reviewer'])
expect(getAllowedAgentRoles(undefined)).toEqual(['reviewer'])
})
})
})
+44
View File
@@ -0,0 +1,44 @@
import type { TeamMemberRole } from '@shumai/db'
/**
* Numeric levels for the team role hierarchy used by agent permissions.
* The record is typed exhaustively over `TeamMemberRole`, so adding a new
* role to the enum will fail compilation until it is handled here.
*/
const ROLE_LEVELS: Record<TeamMemberRole, number> = {
reviewer: 1,
editor: 2,
owner: 3,
}
/**
* Numeric level of a team role for agent-permission comparisons.
* Unknown or missing roles resolve to 0, which is below every agent
* permission, so lookups fail closed.
*/
export function getRoleLevel(role: TeamMemberRole | null | undefined): number {
if (!role) return 0
return ROLE_LEVELS[role] ?? 0
}
/**
* Minimum role level required to use an agent with the given permission.
* Unknown or missing permissions resolve to 1 (reviewer), the most
* permissive default.
*/
export function getAgentRequiredLevel(permission: TeamMemberRole | null | undefined): number {
if (!permission) return 1
return ROLE_LEVELS[permission] ?? 1
}
/**
* Roles allowed to use agents, following the inclusive role hierarchy:
* owner sees owner+editor+reviewer agents, editor sees editor+reviewer,
* reviewer (or any unknown/missing role) sees reviewer agents only.
*/
export function getAllowedAgentRoles(role: TeamMemberRole | null | undefined): TeamMemberRole[] {
const level = getRoleLevel(role)
if (level >= 3) return ['reviewer', 'editor', 'owner']
if (level === 2) return ['reviewer', 'editor']
return ['reviewer']
}
+70 -19
View File
@@ -41,6 +41,13 @@ describe('AssetService', () => {
const team = await prisma.team.create({
data: { name: 'TestTeam_Asset_' + Date.now() },
})
await prisma.teamMember.create({
data: {
teamId: team.id,
userId: user.id,
role: 'owner',
},
})
const project = await prisma.project.create({
data: { name: 'TestProject_Asset', teamId: team.id },
})
@@ -734,15 +741,6 @@ describe('AssetService', () => {
attachmentIds: [],
})
// 2. Add user as a team member with owner role (team owner)
await prisma.teamMember.create({
data: {
teamId: project.teamId,
userId: user.id,
role: 'owner',
},
})
// Create another user
const otherUser = await prisma.user.create({
data: {
@@ -813,16 +811,7 @@ describe('AssetService', () => {
it('deleteComment cleans up S3 attachment files and database records', async () => {
const { user, project, assets } = await setupBasicAssets()
// 1. Add user as team owner
await prisma.teamMember.create({
data: {
teamId: project.teamId,
userId: user.id,
role: 'owner',
},
})
// 2. Create StorageKey and Asset for attachment
// 1. Create StorageKey and Asset for attachment
const storageKey = await prisma.storageKey.create({
data: {
key: 'attachments/test-attachment-file.png',
@@ -1245,6 +1234,68 @@ describe('AssetService', () => {
expect(p3b?.agent?.userId).toBe(user.id)
})
it('silently skips triggering agent workflow when comment creator lacks permission', async () => {
const { project } = await setupBasicAssets()
const file = await prisma.asset.create({
data: {
name: 'perm-file',
type: AssetType.file,
projectId: project.id,
status: 'uploaded',
},
})
// Create owner-only bot agent
const ownerBotUser = await prisma.user.create({
data: {
name: 'Owner Bot Agent',
type: 'agent',
email: `owner-bot-${Date.now()}@shumai.ai`,
},
})
const ownerAgent = await prisma.agent.create({
data: {
id: ownerBotUser.id,
teamId: project.teamId,
type: 'chat',
permission: 'owner',
config: { provider: 'p', model: 'm' },
},
})
// Create a reviewer user
const reviewerUser = await prisma.user.create({
data: {
name: 'Reviewer Member',
email: `rev-comment-${Date.now()}@shumai.ai`,
password: 'pw',
},
})
await prisma.teamMember.create({
data: { teamId: project.teamId, userId: reviewerUser.id, role: 'reviewer' },
})
// Reviewer mentions owner-only agent
const comment = await assetService.createComment({
assetId: file.id,
userId: reviewerUser.id,
message: `Hello <@${ownerAgent.id}>`,
attachmentIds: [],
})
// Comment was saved successfully
expect(comment.id).toBeDefined()
// But no workflow task was created for ownerAgent
const tasks = await prisma.workflowTask.findMany({
where: {
assetId: file.id,
payload: { path: ['agent', 'userCommentId'], equals: comment.id },
},
})
expect(tasks.length).toBe(0)
})
it('updates asset order correctly', async () => {
const { user, project } = await setupBasicAssets()
+41 -16
View File
@@ -26,6 +26,7 @@ import { dedupeSymlinksToTarget } from './symlink'
import { watermarkService } from '@shumai/core/src/watermark/watermark'
import { generateKeyBetween } from 'jittered-fractional-indexing'
import { getAvatarUrl } from '@shumai/core/src/user/avatar'
import { getAgentRequiredLevel, getRoleLevel } from '@shumai/core/src/agent/permissions'
type AssetWithIncludes = Prisma.AssetGetPayload<{
include: {
@@ -1377,30 +1378,49 @@ export class AssetService {
const mentionedAgentIds = new Set(botMentionMatches.map((match) => match[1]))
const handledAgentIds = new Set<string>()
const member = a.project?.team
? await tx.teamMember.findUnique({
where: {
teamIdUserId: {
teamId: a.project.team.id,
userId: req.userId,
},
},
select: { role: true },
})
: null
const userLevel = getRoleLevel(member?.role)
if (parentComment && a.project) {
const rootSessionId = parentComment.sessionId
const isRootAgent = !!rootSessionId || parentComment.creator?.type === 'agent'
const rootAgentId = parentComment.creatorId
if (isRootAgent && rootAgentId && mentionedAgentIds.has(rootAgentId)) {
await tx.workflowTask.create({
data: {
assetId: a.id,
type: 'chat',
status: 'pending',
teamId: a.project.team.id,
projectId: a.project.id,
payload: {
const rootAgent = await tx.agent.findUnique({ where: { id: rootAgentId } })
const requiredLevel = getAgentRequiredLevel(rootAgent?.permission)
if (userLevel >= requiredLevel) {
await tx.workflowTask.create({
data: {
assetId: a.id,
type: 'chat',
status: 'pending',
teamId: a.project.team.id,
projectId: a.project.id,
agent: {
userCommentId: comment.id,
agentId: rootAgentId,
sessionId: rootSessionId || undefined,
userId: req.userId,
payload: {
projectId: a.project.id,
agent: {
userCommentId: comment.id,
agentId: rootAgentId,
sessionId: rootSessionId || undefined,
userId: req.userId,
},
},
},
},
})
})
}
handledAgentIds.add(rootAgentId)
}
}
@@ -1414,7 +1434,12 @@ export class AssetService {
foundAgent = true
} else {
const agent = await tx.agent.findUnique({ where: { id: agentId } })
if (agent) foundAgent = true
if (agent) {
const requiredLevel = getAgentRequiredLevel(agent.permission)
if (userLevel >= requiredLevel) {
foundAgent = true
}
}
}
if (foundAgent && a.project) {
+58
View File
@@ -255,6 +255,61 @@ describe('ChatService', () => {
expect(taskPayload?.agent?.imageUrls).toContain('doc_s3_key')
})
it('should enforce agent permissions in startOrContinueChat', async () => {
const { team, project } = await setupBasicData()
// Create an owner-only agent
const ownerAgentUser = await prisma.user.create({
data: {
name: 'Owner Agent User',
email: `owner-agent-${Date.now()}@shumai.ai`,
type: 'agent',
},
})
const ownerAgent = await prisma.agent.create({
data: {
id: ownerAgentUser.id,
teamId: team.id,
type: 'chat',
permission: 'owner',
config: { provider: 'p', model: 'm' },
},
})
// Create an editor user and a reviewer user
const editorUser = await prisma.user.create({
data: { name: 'Editor User', email: `ed-${Date.now()}@shumai.ai`, password: 'pw' },
})
await prisma.teamMember.create({
data: { teamId: team.id, userId: editorUser.id, role: 'editor' },
})
const reviewerUser = await prisma.user.create({
data: { name: 'Reviewer User', email: `rev-${Date.now()}@shumai.ai`, password: 'pw' },
})
await prisma.teamMember.create({
data: { teamId: team.id, userId: reviewerUser.id, role: 'reviewer' },
})
// Editor trying to chat with owner-only agent should fail
await expect(
chatService.startOrContinueChat(editorUser, team.id, {
agentId: ownerAgent.id,
textPrompt: 'test',
projectId: project.id,
}),
).rejects.toThrow('Permission denied')
// Reviewer trying to chat with owner-only agent should fail
await expect(
chatService.startOrContinueChat(reviewerUser, team.id, {
agentId: ownerAgent.id,
textPrompt: 'test',
projectId: project.id,
}),
).rejects.toThrow('Permission denied')
})
it('should list sessions of a user and only return chat type sessions', async () => {
const { user, team, project } = await setupBasicData()
@@ -688,6 +743,9 @@ describe('ChatService', () => {
const otherUser = await prisma.user.create({
data: { name: 'Other User', email: `other-${Date.now()}@example.com`, password: 'pw' },
})
await prisma.teamMember.create({
data: { teamId: team.id, userId: otherUser.id, role: 'reviewer' },
})
const { sessionId } = await chatService.startOrContinueChat(otherUser, team.id, {
agentId: 'test-agent-id',
textPrompt: 'hello',
+26 -1
View File
@@ -6,6 +6,7 @@ import type { ChatRequest, ChatSessionInfo, ChatMessage } from '@shumai/dtos'
import type { SessionTreeEntry } from '@earendil-works/pi-agent-core'
import { workflowService } from '@shumai/workflow-core'
import { agentService } from '@shumai/core/src/agent/agent'
import { getAgentRequiredLevel, getRoleLevel } from '@shumai/core/src/agent/permissions'
type User = Prisma.UserGetPayload<Record<string, never>>
@@ -281,7 +282,10 @@ export class ChatService {
let activeSessionId = passedSessionId
// Ensure AI agent configuration exists
const agent = await tx.agent.findUnique({ where: { id: agentId } })
const agent = await tx.agent.findUnique({
where: { id: agentId },
include: { user: true },
})
if (!agent) {
throw new Error(`Agent with ID "${agentId}" not found`)
}
@@ -289,6 +293,27 @@ export class ChatService {
throw new Error(`Agent does not belong to the specified team`)
}
// Check user's permission to use this agent
const member = await tx.teamMember.findUnique({
where: {
teamIdUserId: {
teamId,
userId: user.id,
},
},
})
if (!member) {
throw new Error('User is not a member of the team')
}
const userLevel = getRoleLevel(member.role)
const requiredLevel = getAgentRequiredLevel(agent.permission)
if (userLevel < requiredLevel) {
throw new Error(
`Permission denied: Insufficient role to use agent "${agent.user.name}". Minimum required role is "${agent.permission}".`,
)
}
if (activeSessionId) {
const sessionExists = await tx.agentSession.findUnique({
where: { id: activeSessionId },
+109
View File
@@ -184,6 +184,115 @@ describe('TeamService', () => {
expect(allMembers).toHaveLength(2)
})
it('should filter included agents by agent permission and requester role', async () => {
const owner = await prisma.user.create({
data: { name: 'Owner', email: `owner-${Date.now()}@example.com`, password: 'pw' },
})
const team = await teamService.createTeam(owner, { name: 'Permission Team' })
const editor = await prisma.user.create({
data: { name: 'Editor', email: `editor-${Date.now()}@example.com`, password: 'pw' },
})
await prisma.teamMember.create({
data: { teamId: team.id, userId: editor.id, role: 'editor' },
})
const reviewer = await prisma.user.create({
data: { name: 'Reviewer', email: `reviewer-${Date.now()}@example.com`, password: 'pw' },
})
await prisma.teamMember.create({
data: { teamId: team.id, userId: reviewer.id, role: 'reviewer' },
})
// Create 3 agents with different permissions
const botReviewer = await prisma.user.create({
data: {
name: 'Bot All Users',
email: `bot-rev-${Date.now()}@shumai.ai`,
type: 'agent',
agent: {
create: {
teamId: team.id,
type: 'chat',
permission: 'reviewer',
enabled: true,
config: { provider: 'p', model: 'm' },
},
},
},
})
await teamService.joinTeam({ teamId: team.id, userId: botReviewer.id })
const botEditor = await prisma.user.create({
data: {
name: 'Bot Editor Only',
email: `bot-ed-${Date.now()}@shumai.ai`,
type: 'agent',
agent: {
create: {
teamId: team.id,
type: 'chat',
permission: 'editor',
enabled: true,
config: { provider: 'p', model: 'm' },
},
},
},
})
await teamService.joinTeam({ teamId: team.id, userId: botEditor.id })
const botOwner = await prisma.user.create({
data: {
name: 'Bot Owner Only',
email: `bot-own-${Date.now()}@shumai.ai`,
type: 'agent',
agent: {
create: {
teamId: team.id,
type: 'chat',
permission: 'owner',
enabled: true,
config: { provider: 'p', model: 'm' },
},
},
},
})
await teamService.joinTeam({ teamId: team.id, userId: botOwner.id })
// Reviewer should only see botReviewer among agents
const reviewerMembers = await teamService.getTeamMembers({
teamId: team.id,
userId: reviewer.id,
includeAgents: true,
})
const reviewerAgentIds = reviewerMembers.filter((m) => m.type === 'agent').map((m) => m.id)
expect(reviewerAgentIds).toEqual([botReviewer.id])
// Editor should see botReviewer and botEditor
const editorMembers = await teamService.getTeamMembers({
teamId: team.id,
userId: editor.id,
includeAgents: true,
})
const editorAgentIds = editorMembers.filter((m) => m.type === 'agent').map((m) => m.id)
expect(editorAgentIds).toHaveLength(2)
expect(editorAgentIds).toContain(botReviewer.id)
expect(editorAgentIds).toContain(botEditor.id)
expect(editorAgentIds).not.toContain(botOwner.id)
// Owner should see all 3 agents
const ownerMembers = await teamService.getTeamMembers({
teamId: team.id,
userId: owner.id,
includeAgents: true,
})
const ownerAgentIds = ownerMembers.filter((m) => m.type === 'agent').map((m) => m.id)
expect(ownerAgentIds).toHaveLength(3)
expect(ownerAgentIds).toContain(botReviewer.id)
expect(ownerAgentIds).toContain(botEditor.id)
expect(ownerAgentIds).toContain(botOwner.id)
})
it('should filter members for project-scoped members', async () => {
const owner = await prisma.user.create({
data: { name: 'Owner', email: `owner-${Date.now()}@example.com`, password: 'pw' },
+4
View File
@@ -5,6 +5,7 @@ import { ProviderService, providerService } from '@shumai/core/src/provider/prov
import { notificationService } from '@shumai/core/src/notification/notification'
import { getAvatarUrl } from '@shumai/core/src/user/avatar'
import { HTTPException } from 'hono/http-exception'
import { getAllowedAgentRoles } from '@shumai/core/src/agent/permissions'
import {
ServiceCreateTeamRequest,
ServiceGetUserTeamsRequest,
@@ -188,6 +189,8 @@ export class TeamService {
throw new HTTPException(403, { message: 'Requester is not a team member' })
}
const allowedAgentRoles = getAllowedAgentRoles(requester.role)
const members = await prisma.teamMember.findMany({
where: {
teamId: req.teamId,
@@ -201,6 +204,7 @@ export class TeamService {
agent: {
type: 'chat',
enabled: true,
permission: { in: allowedAgentRoles },
},
},
],