(
annotations: ToolAnnotations | undefined,
address: ToolAddress,
args: unknown,
policy: EffectivePolicy,
handler: ElicitationHandler,
)
| 6278 | }; |
| 6279 | |
| 6280 | const enforceApproval = ( |
| 6281 | annotations: ToolAnnotations | undefined, |
| 6282 | address: ToolAddress, |
| 6283 | args: unknown, |
| 6284 | policy: EffectivePolicy, |
| 6285 | handler: ElicitationHandler, |
| 6286 | ) => |
| 6287 | Effect.gen(function* () { |
| 6288 | if (!approvalRequired(annotations, policy)) return; |
| 6289 | const policyForcesApproval = policy.action === "require_approval"; |
| 6290 | const message = annotations?.approvalDescription |
| 6291 | ? annotations.approvalDescription |
| 6292 | : policyForcesApproval && policy.pattern |
| 6293 | ? `Approve ${address}? (matched policy: ${policy.pattern})` |
| 6294 | : `Approve ${address}?`; |
| 6295 | const request = FormElicitation.make({ |
| 6296 | message: `${message}\n\nArguments:\n${approvalArgumentPreview(args)}`, |
| 6297 | requestedSchema: { type: "object", properties: {} }, |
| 6298 | }); |
| 6299 | const response = yield* handler({ address, args, request, source: "policy" }); |
| 6300 | if (response.action !== "accept") { |
| 6301 | return yield* new ElicitationDeclinedError({ |
| 6302 | address, |
| 6303 | action: response.action, |
| 6304 | }); |
| 6305 | } |
| 6306 | }); |
| 6307 | |
| 6308 | // ------------------------------------------------------------------ |
| 6309 | // execute — the invoke path. |
no test coverage detected