(
annotations: ToolAnnotations | undefined,
address: ToolAddress,
args: unknown,
policy: EffectivePolicy,
handler: ElicitationHandler,
)
| 4219 | }; |
| 4220 | |
| 4221 | const enforceApproval = ( |
| 4222 | annotations: ToolAnnotations | undefined, |
| 4223 | address: ToolAddress, |
| 4224 | args: unknown, |
| 4225 | policy: EffectivePolicy, |
| 4226 | handler: ElicitationHandler, |
| 4227 | ) => |
| 4228 | Effect.gen(function* () { |
| 4229 | if (!approvalRequired(annotations, policy)) return; |
| 4230 | const policyForcesApproval = policy.action === "require_approval"; |
| 4231 | const message = annotations?.approvalDescription |
| 4232 | ? annotations.approvalDescription |
| 4233 | : policyForcesApproval && policy.pattern |
| 4234 | ? `Approve ${address}? (matched policy: ${policy.pattern})` |
| 4235 | : `Approve ${address}?`; |
| 4236 | const request = FormElicitation.make({ |
| 4237 | message: `${message}\n\nArguments:\n${approvalArgumentPreview(args)}`, |
| 4238 | requestedSchema: { type: "object", properties: {} }, |
| 4239 | }); |
| 4240 | const response = yield* handler({ address, args, request }); |
| 4241 | if (response.action !== "accept") { |
| 4242 | return yield* new ElicitationDeclinedError({ |
| 4243 | address, |
| 4244 | action: response.action, |
| 4245 | }); |
| 4246 | } |
| 4247 | }); |
| 4248 | |
| 4249 | // ------------------------------------------------------------------ |
| 4250 | // execute — the invoke path. |
no test coverage detected