MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / enforceApproval

Function enforceApproval

packages/core/sdk/src/executor.ts:4221–4247  ·  view source on GitHub ↗
(
      annotations: ToolAnnotations | undefined,
      address: ToolAddress,
      args: unknown,
      policy: EffectivePolicy,
      handler: ElicitationHandler,
    )

Source from the content-addressed store, hash-verified

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.

Callers 1

executeFunction · 0.85

Calls 3

approvalRequiredFunction · 0.85
approvalArgumentPreviewFunction · 0.85
handlerFunction · 0.50

Tested by

no test coverage detected