@@ -8,6 +8,7 @@ import type { AgentCapabilities, AgentSkill } from '@/lib/a2a/types'
88import { checkHybridAuth } from '@/lib/auth/hybrid'
99import { getRedisClient } from '@/lib/core/config/redis'
1010import { loadWorkflowFromNormalizedTables } from '@/lib/workflows/persistence/utils'
11+ import { checkWorkspaceAccess } from '@/lib/workspaces/permissions/utils'
1112
1213const logger = createLogger ( 'A2AAgentCardAPI' )
1314
@@ -95,6 +96,11 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<Ro
9596 return NextResponse . json ( { error : 'Agent not found' } , { status : 404 } )
9697 }
9798
99+ const workspaceAccess = await checkWorkspaceAccess ( existingAgent . workspaceId , auth . userId )
100+ if ( ! workspaceAccess . canWrite ) {
101+ return NextResponse . json ( { error : 'Forbidden' } , { status : 403 } )
102+ }
103+
98104 const body = await request . json ( )
99105
100106 if (
@@ -160,6 +166,11 @@ export async function DELETE(request: NextRequest, { params }: { params: Promise
160166 return NextResponse . json ( { error : 'Agent not found' } , { status : 404 } )
161167 }
162168
169+ const workspaceAccess = await checkWorkspaceAccess ( existingAgent . workspaceId , auth . userId )
170+ if ( ! workspaceAccess . canWrite ) {
171+ return NextResponse . json ( { error : 'Forbidden' } , { status : 403 } )
172+ }
173+
163174 await db . delete ( a2aAgent ) . where ( eq ( a2aAgent . id , agentId ) )
164175
165176 logger . info ( `Deleted A2A agent: ${ agentId } ` )
@@ -194,6 +205,11 @@ export async function POST(request: NextRequest, { params }: { params: Promise<R
194205 return NextResponse . json ( { error : 'Agent not found' } , { status : 404 } )
195206 }
196207
208+ const workspaceAccess = await checkWorkspaceAccess ( existingAgent . workspaceId , auth . userId )
209+ if ( ! workspaceAccess . canWrite ) {
210+ return NextResponse . json ( { error : 'Forbidden' } , { status : 403 } )
211+ }
212+
197213 const body = await request . json ( )
198214 const action = body . action as 'publish' | 'unpublish' | 'refresh'
199215
0 commit comments