(
annotations: ToolAnnotations | undefined,
address: ToolAddress,
args: unknown,
policy: EffectivePolicy,
handler: ElicitationHandler,
)
| 6370 | }; |
| 6371 | |
| 6372 | const enforceApproval = ( |
| 6373 | annotations: ToolAnnotations | undefined, |
| 6374 | address: ToolAddress, |
| 6375 | args: unknown, |
| 6376 | policy: EffectivePolicy, |
| 6377 | handler: ElicitationHandler, |
| 6378 | ) => |
| 6379 | Effect.gen(function* () { |
| 6380 | if (!approvalRequired(annotations, policy)) return; |
| 6381 | const policyForcesApproval = policy.action === "require_approval"; |
| 6382 | const message = annotations?.approvalDescription |
| 6383 | ? annotations.approvalDescription |
| 6384 | : policyForcesApproval && policy.pattern |
| 6385 | ? `Approve ${address}? (matched policy: ${policy.pattern})` |
| 6386 | : `Approve ${address}?`; |
| 6387 | const request = FormElicitation.make({ |
| 6388 | message: `${message}\n\nArguments:\n${approvalArgumentPreview(args)}`, |
| 6389 | requestedSchema: { type: "object", properties: {} }, |
| 6390 | }); |
| 6391 | const response = yield* handler({ address, args, request, source: "policy" }); |
| 6392 | if (response.action !== "accept") { |
| 6393 | return yield* new ElicitationDeclinedError({ |
| 6394 | address, |
| 6395 | action: response.action, |
| 6396 | }); |
| 6397 | } |
| 6398 | }); |
| 6399 | |
| 6400 | // ------------------------------------------------------------------ |
| 6401 | // execute — the invoke path. |
no test coverage detected