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

Function enforceApproval

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

Source from the content-addressed store, hash-verified

4927 };
4928
4929 const enforceApproval = (
4930 annotations: ToolAnnotations | undefined,
4931 address: ToolAddress,
4932 args: unknown,
4933 policy: EffectivePolicy,
4934 handler: ElicitationHandler,
4935 ) =>
4936 Effect.gen(function* () {
4937 if (!approvalRequired(annotations, policy)) return;
4938 const policyForcesApproval = policy.action === "require_approval";
4939 const message = annotations?.approvalDescription
4940 ? annotations.approvalDescription
4941 : policyForcesApproval && policy.pattern
4942 ? `Approve ${address}? (matched policy: ${policy.pattern})`
4943 : `Approve ${address}?`;
4944 const request = FormElicitation.make({
4945 message: `${message}\n\nArguments:\n${approvalArgumentPreview(args)}`,
4946 requestedSchema: { type: "object", properties: {} },
4947 });
4948 const response = yield* handler({ address, args, request });
4949 if (response.action !== "accept") {
4950 return yield* new ElicitationDeclinedError({
4951 address,
4952 action: response.action,
4953 });
4954 }
4955 });
4956
4957 // ------------------------------------------------------------------
4958 // 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