(
annotations: ToolAnnotations | undefined,
address: ToolAddress,
args: unknown,
policy: EffectivePolicy,
handler: ElicitationHandler,
)
| 5657 | }; |
| 5658 | |
| 5659 | const enforceApproval = ( |
| 5660 | annotations: ToolAnnotations | undefined, |
| 5661 | address: ToolAddress, |
| 5662 | args: unknown, |
| 5663 | policy: EffectivePolicy, |
| 5664 | handler: ElicitationHandler, |
| 5665 | ) => |
| 5666 | Effect.gen(function* () { |
| 5667 | if (!approvalRequired(annotations, policy)) return; |
| 5668 | const policyForcesApproval = policy.action === "require_approval"; |
| 5669 | const message = annotations?.approvalDescription |
| 5670 | ? annotations.approvalDescription |
| 5671 | : policyForcesApproval && policy.pattern |
| 5672 | ? `Approve ${address}? (matched policy: ${policy.pattern})` |
| 5673 | : `Approve ${address}?`; |
| 5674 | const request = FormElicitation.make({ |
| 5675 | message: `${message}\n\nArguments:\n${approvalArgumentPreview(args)}`, |
| 5676 | requestedSchema: { type: "object", properties: {} }, |
| 5677 | }); |
| 5678 | const response = yield* handler({ address, args, request }); |
| 5679 | if (response.action !== "accept") { |
| 5680 | return yield* new ElicitationDeclinedError({ |
| 5681 | address, |
| 5682 | action: response.action, |
| 5683 | }); |
| 5684 | } |
| 5685 | }); |
| 5686 | |
| 5687 | // ------------------------------------------------------------------ |
| 5688 | // execute — the invoke path. |
no test coverage detected