bridgePermissionCallbacks.ts
1 import type { PermissionUpdate } from '../utils/permissions/PermissionUpdateSchema.js' 2 3 type BridgePermissionResponse = { 4 behavior: 'allow' | 'deny' 5 updatedInput?: Record<string, unknown> 6 updatedPermissions?: PermissionUpdate[] 7 message?: string 8 } 9 10 type BridgePermissionCallbacks = { 11 sendRequest( 12 requestId: string, 13 toolName: string, 14 input: Record<string, unknown>, 15 toolUseId: string, 16 description: string, 17 permissionSuggestions?: PermissionUpdate[], 18 blockedPath?: string, 19 ): void 20 sendResponse(requestId: string, response: BridgePermissionResponse): void 21 /** Cancel a pending control_request so the web app can dismiss its prompt. */ 22 cancelRequest(requestId: string): void 23 onResponse( 24 requestId: string, 25 handler: (response: BridgePermissionResponse) => void, 26 ): () => void // returns unsubscribe 27 } 28 29 /** Type predicate for validating a parsed control_response payload 30 * as a BridgePermissionResponse. Checks the required `behavior` 31 * discriminant rather than using an unsafe `as` cast. */ 32 function isBridgePermissionResponse( 33 value: unknown, 34 ): value is BridgePermissionResponse { 35 if (!value || typeof value !== 'object') return false 36 return ( 37 'behavior' in value && 38 (value.behavior === 'allow' || value.behavior === 'deny') 39 ) 40 } 41 42 export { isBridgePermissionResponse } 43 export type { BridgePermissionCallbacks, BridgePermissionResponse }