@@ -63,8 +63,7 @@ export function approveCapability(
6363 use : [ sessionMiddleware ] ,
6464 metadata : {
6565 openapi : {
66- description :
67- "Approve or deny a pending agent registration or capability request." ,
66+ description : "Approve or deny a pending agent registration or capability request." ,
6867 } ,
6968 } ,
7069 } ,
@@ -123,19 +122,16 @@ export function approveCapability(
123122 let deviceApprovalRequests : ApprovalRequest [ ] = [ ] ;
124123 if ( approvalRequest ) {
125124 deviceApprovalRequests =
126- approvalRequest . method === "device_authorization"
127- ? [ approvalRequest ]
128- : [ ] ;
125+ approvalRequest . method === "device_authorization" ? [ approvalRequest ] : [ ] ;
129126 } else {
130- deviceApprovalRequests =
131- await ctx . context . adapter . findMany < ApprovalRequest > ( {
132- model : TABLE . approval ,
133- where : [
134- { field : "agentId" , value : agentId } ,
135- { field : "status" , value : "pending" } ,
136- { field : "method" , value : "device_authorization" } ,
137- ] ,
138- } ) ;
127+ deviceApprovalRequests = await ctx . context . adapter . findMany < ApprovalRequest > ( {
128+ model : TABLE . approval ,
129+ where : [
130+ { field : "agentId" , value : agentId } ,
131+ { field : "status" , value : "pending" } ,
132+ { field : "method" , value : "device_authorization" } ,
133+ ] ,
134+ } ) ;
139135 }
140136
141137 // Check expiry on any resolved approval request
@@ -147,41 +143,33 @@ export function approveCapability(
147143 }
148144
149145 // Verify user_code for device_authorization approvals (approve only — deny is safe)
150- const hasDeviceApproval = deviceApprovalRequests . some (
151- ( r ) => r . userCodeHash ,
152- ) ;
146+ const hasDeviceApproval = deviceApprovalRequests . some ( ( r ) => r . userCodeHash ) ;
153147 if ( action === "approve" && hasDeviceApproval ) {
154148 if ( ! userCode ) {
155149 throw agentError ( "BAD_REQUEST" , ERR . INVALID_USER_CODE ) ;
156150 }
157151 const normalized = normalizeUserCode ( userCode ) ;
158152 const submittedHash = await hashToken ( normalized ) ;
159- const matched = deviceApprovalRequests . some (
160- ( r ) => r . userCodeHash === submittedHash ,
161- ) ;
153+ const matched = deviceApprovalRequests . some ( ( r ) => r . userCodeHash === submittedHash ) ;
162154 if ( ! matched ) {
163155 throw agentError ( "FORBIDDEN" , ERR . INVALID_USER_CODE ) ;
164156 }
165157 }
166158
167- const allGrants =
168- await ctx . context . adapter . findMany < AgentCapabilityGrant > ( {
169- model : TABLE . grant ,
170- where : [ { field : "agentId" , value : agentId } ] ,
171- } ) ;
159+ const allGrants = await ctx . context . adapter . findMany < AgentCapabilityGrant > ( {
160+ model : TABLE . grant ,
161+ where : [ { field : "agentId" , value : agentId } ] ,
162+ } ) ;
172163
173164 // ── Claim: autonomous agent ownership transfer ──
174165 if ( isClaim ) {
175166 const now = new Date ( ) ;
176167
177168 if ( action === "deny" ) {
178- const resolved = await resolvePendingApprovalRequests (
179- ctx . context . adapter ,
180- {
181- agentId,
182- status : "denied" ,
183- } ,
184- ) ;
169+ const resolved = await resolvePendingApprovalRequests ( ctx . context . adapter , {
170+ agentId,
171+ status : "denied" ,
172+ } ) ;
185173 void deliverApprovalNotifications ( resolved , {
186174 agent_id : agentId ,
187175 status : "denied" ,
@@ -245,9 +233,7 @@ export function approveCapability(
245233 ) ;
246234 }
247235
248- const activeCaps = allGrants
249- . filter ( ( g ) => g . status === "active" )
250- . map ( ( g ) => g . capability ) ;
236+ const activeCaps = allGrants . filter ( ( g ) => g . status === "active" ) . map ( ( g ) => g . capability ) ;
251237
252238 await opts . onAutonomousAgentClaimed ?.( {
253239 ctx,
@@ -258,13 +244,10 @@ export function approveCapability(
258244 capabilities : activeCaps ,
259245 } ) ;
260246
261- const resolved = await resolvePendingApprovalRequests (
262- ctx . context . adapter ,
263- {
264- agentId,
265- status : "approved" ,
266- } ,
267- ) ;
247+ const resolved = await resolvePendingApprovalRequests ( ctx . context . adapter , {
248+ agentId,
249+ status : "approved" ,
250+ } ) ;
268251 void deliverApprovalNotifications ( resolved , {
269252 agent_id : agentId ,
270253 status : "approved" ,
@@ -286,10 +269,7 @@ export function approveCapability(
286269 status : "approved" ,
287270 agentId,
288271 claimed : true ,
289- agent_capability_grants : formatGrantsResponse (
290- allGrants ,
291- opts . capabilities ,
292- ) ,
272+ agent_capability_grants : formatGrantsResponse ( allGrants , opts . capabilities ) ,
293273 } ) ;
294274 }
295275
@@ -298,10 +278,7 @@ export function approveCapability(
298278 const agentIsPending = agent . status === "pending" ;
299279
300280 if ( pendingGrants . length === 0 && ! agentIsPending ) {
301- throw agentError (
302- "PRECONDITION_FAILED" ,
303- ERR . CAPABILITY_REQUEST_ALREADY_RESOLVED ,
304- ) ;
281+ throw agentError ( "PRECONDITION_FAILED" , ERR . CAPABILITY_REQUEST_ALREADY_RESOLVED ) ;
305282 }
306283
307284 if ( action === "deny" ) {
@@ -334,13 +311,10 @@ export function approveCapability(
334311 ? `User denied the authorization request: ${ denyReason } `
335312 : "User denied the authorization request." ;
336313
337- const resolved = await resolvePendingApprovalRequests (
338- ctx . context . adapter ,
339- {
340- agentId,
341- status : "denied" ,
342- } ,
343- ) ;
314+ const resolved = await resolvePendingApprovalRequests ( ctx . context . adapter , {
315+ agentId,
316+ status : "denied" ,
317+ } ) ;
344318
345319 void deliverApprovalNotifications ( resolved , {
346320 agent_id : agentId ,
@@ -417,9 +391,7 @@ export function approveCapability(
417391 // Per-capability overrides can still escalate to webauthn
418392 if ( ! requiresWebAuthn ) {
419393 const capDefs = opts . capabilities ?? [ ] ;
420- const capDefMap = new Map < string , Capability > (
421- capDefs . map ( ( c ) => [ c . name , c ] ) ,
422- ) ;
394+ const capDefMap = new Map < string , Capability > ( capDefs . map ( ( c ) => [ c . name , c ] ) ) ;
423395 requiresWebAuthn = capabilities . some ( ( capId ) => {
424396 const def = capDefMap . get ( capId ) ;
425397 return def ?. approvalStrength === "webauthn" ;
@@ -449,10 +421,7 @@ export function approveCapability(
449421 }
450422
451423 if ( ! webauthnResponse ) {
452- const { options } = await generateApprovalChallenge (
453- opts . proofOfPresence ,
454- passkeys ,
455- ) ;
424+ const { options } = await generateApprovalChallenge ( opts . proofOfPresence , passkeys ) ;
456425
457426 challengeCache . set ( session . user . id , agentId , options . challenge ) ;
458427
@@ -467,10 +436,7 @@ export function approveCapability(
467436 ) ;
468437 }
469438
470- const expectedChallenge = challengeCache . consume (
471- session . user . id ,
472- agentId ,
473- ) ;
439+ const expectedChallenge = challengeCache . consume ( session . user . id , agentId ) ;
474440
475441 if ( ! expectedChallenge ) {
476442 throw agentError (
@@ -480,11 +446,8 @@ export function approveCapability(
480446 ) ;
481447 }
482448
483- const assertionResponse =
484- webauthnResponse as unknown as AuthenticationResponseJSON ;
485- const matchingPasskey = passkeys . find (
486- ( pk ) => pk . credentialID === assertionResponse . id ,
487- ) ;
449+ const assertionResponse = webauthnResponse as unknown as AuthenticationResponseJSON ;
450+ const matchingPasskey = passkeys . find ( ( pk ) => pk . credentialID === assertionResponse . id ) ;
488451
489452 if ( ! matchingPasskey ) {
490453 throw agentError (
@@ -529,10 +492,7 @@ export function approveCapability(
529492 }
530493
531494 if ( opts . blockedCapabilities . length > 0 ) {
532- const blocked = findBlockedCapabilities (
533- [ ...approvedCapIds ] ,
534- opts . blockedCapabilities ,
535- ) ;
495+ const blocked = findBlockedCapabilities ( [ ...approvedCapIds ] , opts . blockedCapabilities ) ;
536496 if ( blocked . length > 0 ) {
537497 throw agentError (
538498 "BAD_REQUEST" ,
@@ -542,10 +502,7 @@ export function approveCapability(
542502 }
543503 }
544504
545- const activeGrantsByCapability = new Map <
546- string ,
547- AgentCapabilityGrant [ ]
548- > ( ) ;
505+ const activeGrantsByCapability = new Map < string , AgentCapabilityGrant [ ] > ( ) ;
549506 for ( const g of allGrants ) {
550507 if ( g . status !== "active" ) continue ;
551508 const list = activeGrantsByCapability . get ( g . capability ) ?? [ ] ;
@@ -556,8 +513,7 @@ export function approveCapability(
556513
557514 for ( const grant of pendingGrants ) {
558515 if ( approvedCapIds . has ( grant . capability ) ) {
559- const existingActive =
560- activeGrantsByCapability . get ( grant . capability ) ?? [ ] ;
516+ const existingActive = activeGrantsByCapability . get ( grant . capability ) ?? [ ] ;
561517 const alreadyCovered = existingActive . some ( ( ag ) =>
562518 constraintsCover ( ag . constraints , grant . constraints ) ,
563519 ) ;
@@ -601,13 +557,10 @@ export function approveCapability(
601557 }
602558 }
603559
604- const resolved = await resolvePendingApprovalRequests (
605- ctx . context . adapter ,
606- {
607- agentId,
608- status : added . length > 0 || agentIsPending ? "approved" : "denied" ,
609- } ,
610- ) ;
560+ const resolved = await resolvePendingApprovalRequests ( ctx . context . adapter , {
561+ agentId,
562+ status : added . length > 0 || agentIsPending ? "approved" : "denied" ,
563+ } ) ;
611564
612565 void deliverApprovalNotifications ( resolved , {
613566 agent_id : agentId ,
0 commit comments