(
annotations: ToolAnnotations | undefined,
address: ToolAddress,
args: unknown,
policy: EffectivePolicy,
handler: ElicitationHandler,
)
| 3647 | }; |
| 3648 | |
| 3649 | const enforceApproval = ( |
| 3650 | annotations: ToolAnnotations | undefined, |
| 3651 | address: ToolAddress, |
| 3652 | args: unknown, |
| 3653 | policy: EffectivePolicy, |
| 3654 | handler: ElicitationHandler, |
| 3655 | ) => |
| 3656 | Effect.gen(function* () { |
| 3657 | if (!approvalRequired(annotations, policy)) return; |
| 3658 | const policyForcesApproval = policy.action === "require_approval"; |
| 3659 | const message = annotations?.approvalDescription |
| 3660 | ? annotations.approvalDescription |
| 3661 | : policyForcesApproval && policy.pattern |
| 3662 | ? `Approve ${address}? (matched policy: ${policy.pattern})` |
| 3663 | : `Approve ${address}?`; |
| 3664 | const request = FormElicitation.make({ |
| 3665 | message: `${message}\n\nArguments:\n${approvalArgumentPreview(args)}`, |
| 3666 | requestedSchema: { type: "object", properties: {} }, |
| 3667 | }); |
| 3668 | const response = yield* handler({ address, args, request }); |
| 3669 | if (response.action !== "accept") { |
| 3670 | return yield* new ElicitationDeclinedError({ |
| 3671 | address, |
| 3672 | action: response.action, |
| 3673 | }); |
| 3674 | } |
| 3675 | }); |
| 3676 | |
| 3677 | // ------------------------------------------------------------------ |
| 3678 | // execute — the invoke path. |
no test coverage detected