(
annotations: ToolAnnotations | undefined,
address: ToolAddress,
args: unknown,
policy: EffectivePolicy,
handler: ElicitationHandler,
)
| 3548 | }; |
| 3549 | |
| 3550 | const enforceApproval = ( |
| 3551 | annotations: ToolAnnotations | undefined, |
| 3552 | address: ToolAddress, |
| 3553 | args: unknown, |
| 3554 | policy: EffectivePolicy, |
| 3555 | handler: ElicitationHandler, |
| 3556 | ) => |
| 3557 | Effect.gen(function* () { |
| 3558 | if (!approvalRequired(annotations, policy)) return; |
| 3559 | const policyForcesApproval = policy.action === "require_approval"; |
| 3560 | const message = annotations?.approvalDescription |
| 3561 | ? annotations.approvalDescription |
| 3562 | : policyForcesApproval && policy.pattern |
| 3563 | ? `Approve ${address}? (matched policy: ${policy.pattern})` |
| 3564 | : `Approve ${address}?`; |
| 3565 | const request = FormElicitation.make({ |
| 3566 | message: `${message}\n\nArguments:\n${approvalArgumentPreview(args)}`, |
| 3567 | requestedSchema: { type: "object", properties: {} }, |
| 3568 | }); |
| 3569 | const response = yield* handler({ address, args, request }); |
| 3570 | if (response.action !== "accept") { |
| 3571 | return yield* new ElicitationDeclinedError({ |
| 3572 | address, |
| 3573 | action: response.action, |
| 3574 | }); |
| 3575 | } |
| 3576 | }); |
| 3577 | |
| 3578 | // ------------------------------------------------------------------ |
| 3579 | // execute — the invoke path. |
no test coverage detected