(
annotations: ToolAnnotations | undefined,
address: ToolAddress,
args: unknown,
policy: EffectivePolicy,
handler: ElicitationHandler,
)
| 3564 | }; |
| 3565 | |
| 3566 | const enforceApproval = ( |
| 3567 | annotations: ToolAnnotations | undefined, |
| 3568 | address: ToolAddress, |
| 3569 | args: unknown, |
| 3570 | policy: EffectivePolicy, |
| 3571 | handler: ElicitationHandler, |
| 3572 | ) => |
| 3573 | Effect.gen(function* () { |
| 3574 | if (!approvalRequired(annotations, policy)) return; |
| 3575 | const policyForcesApproval = policy.action === "require_approval"; |
| 3576 | const message = annotations?.approvalDescription |
| 3577 | ? annotations.approvalDescription |
| 3578 | : policyForcesApproval && policy.pattern |
| 3579 | ? `Approve ${address}? (matched policy: ${policy.pattern})` |
| 3580 | : `Approve ${address}?`; |
| 3581 | const request = FormElicitation.make({ |
| 3582 | message: `${message}\n\nArguments:\n${approvalArgumentPreview(args)}`, |
| 3583 | requestedSchema: { type: "object", properties: {} }, |
| 3584 | }); |
| 3585 | const response = yield* handler({ address, args, request }); |
| 3586 | if (response.action !== "accept") { |
| 3587 | return yield* new ElicitationDeclinedError({ |
| 3588 | address, |
| 3589 | action: response.action, |
| 3590 | }); |
| 3591 | } |
| 3592 | }); |
| 3593 | |
| 3594 | // ------------------------------------------------------------------ |
| 3595 | // execute — the invoke path. |
no test coverage detected