MCPcopy Create free account
hub / github.com/TanStack/ai / resolveApproval

Function resolveApproval

packages/ai-sandbox/src/approvals.ts:56–74  ·  view source on GitHub ↗
(input: ResolveApprovalInput)

Source from the content-addressed store, hash-verified

54
55/** Resolve a harness permission request against policy + client approvals. */
56export function resolveApproval(input: ResolveApprovalInput): ApprovalOutcome {
57 const base =
58 input.command !== undefined
59 ? evaluateCommand(input.command, input.policy, input.scripts)
60 : input.capability !== undefined
61 ? (input.policy?.capabilities?.[input.capability] ??
62 input.policy?.default ??
63 'ask')
64 : (input.policy?.default ?? 'ask')
65
66 if (base === 'allow') return { decision: 'allow', needsApproval: false }
67 if (base === 'deny') return { decision: 'deny', needsApproval: false }
68
69 // base === 'ask' — consult the client's decision.
70 const granted = input.approvals?.get(input.id)
71 if (granted === true) return { decision: 'allow', needsApproval: false }
72 if (granted === false) return { decision: 'deny', needsApproval: false }
73 return { decision: 'deny', needsApproval: true }
74}
75
76/** Build the AG-UI `approval-requested` CUSTOM event for a harness action. */
77export function buildApprovalRequestedEvent(input: {

Callers 2

approvals.test.tsFile · 0.90

Calls 2

evaluateCommandFunction · 0.90
getMethod · 0.65

Tested by

no test coverage detected