(
annotations: ToolAnnotations | undefined,
address: ToolAddress,
args: unknown,
policy: EffectivePolicy,
handler: ElicitationHandler,
)
| 6158 | }; |
| 6159 | |
| 6160 | const enforceApproval = ( |
| 6161 | annotations: ToolAnnotations | undefined, |
| 6162 | address: ToolAddress, |
| 6163 | args: unknown, |
| 6164 | policy: EffectivePolicy, |
| 6165 | handler: ElicitationHandler, |
| 6166 | ) => |
| 6167 | Effect.gen(function* () { |
| 6168 | if (!approvalRequired(annotations, policy)) return; |
| 6169 | const policyForcesApproval = policy.action === "require_approval"; |
| 6170 | const message = annotations?.approvalDescription |
| 6171 | ? annotations.approvalDescription |
| 6172 | : policyForcesApproval && policy.pattern |
| 6173 | ? `Approve ${address}? (matched policy: ${policy.pattern})` |
| 6174 | : `Approve ${address}?`; |
| 6175 | const request = FormElicitation.make({ |
| 6176 | message: `${message}\n\nArguments:\n${approvalArgumentPreview(args)}`, |
| 6177 | requestedSchema: { type: "object", properties: {} }, |
| 6178 | }); |
| 6179 | const response = yield* handler({ address, args, request }); |
| 6180 | if (response.action !== "accept") { |
| 6181 | return yield* new ElicitationDeclinedError({ |
| 6182 | address, |
| 6183 | action: response.action, |
| 6184 | }); |
| 6185 | } |
| 6186 | }); |
| 6187 | |
| 6188 | // ------------------------------------------------------------------ |
| 6189 | // execute — the invoke path. |
no test coverage detected