(
annotations: ToolAnnotations | undefined,
address: ToolAddress,
args: unknown,
policy: EffectivePolicy,
handler: ElicitationHandler,
)
| 4193 | }; |
| 4194 | |
| 4195 | const enforceApproval = ( |
| 4196 | annotations: ToolAnnotations | undefined, |
| 4197 | address: ToolAddress, |
| 4198 | args: unknown, |
| 4199 | policy: EffectivePolicy, |
| 4200 | handler: ElicitationHandler, |
| 4201 | ) => |
| 4202 | Effect.gen(function* () { |
| 4203 | if (!approvalRequired(annotations, policy)) return; |
| 4204 | const policyForcesApproval = policy.action === "require_approval"; |
| 4205 | const message = annotations?.approvalDescription |
| 4206 | ? annotations.approvalDescription |
| 4207 | : policyForcesApproval && policy.pattern |
| 4208 | ? `Approve ${address}? (matched policy: ${policy.pattern})` |
| 4209 | : `Approve ${address}?`; |
| 4210 | const request = FormElicitation.make({ |
| 4211 | message: `${message}\n\nArguments:\n${approvalArgumentPreview(args)}`, |
| 4212 | requestedSchema: { type: "object", properties: {} }, |
| 4213 | }); |
| 4214 | const response = yield* handler({ address, args, request }); |
| 4215 | if (response.action !== "accept") { |
| 4216 | return yield* new ElicitationDeclinedError({ |
| 4217 | address, |
| 4218 | action: response.action, |
| 4219 | }); |
| 4220 | } |
| 4221 | }); |
| 4222 | |
| 4223 | // ------------------------------------------------------------------ |
| 4224 | // execute — the invoke path. |
no test coverage detected