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

Function enforceApproval

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

Source from the content-addressed store, hash-verified

5657 };
5658
5659 const enforceApproval = (
5660 annotations: ToolAnnotations | undefined,
5661 address: ToolAddress,
5662 args: unknown,
5663 policy: EffectivePolicy,
5664 handler: ElicitationHandler,
5665 ) =>
5666 Effect.gen(function* () {
5667 if (!approvalRequired(annotations, policy)) return;
5668 const policyForcesApproval = policy.action === "require_approval";
5669 const message = annotations?.approvalDescription
5670 ? annotations.approvalDescription
5671 : policyForcesApproval && policy.pattern
5672 ? `Approve ${address}? (matched policy: ${policy.pattern})`
5673 : `Approve ${address}?`;
5674 const request = FormElicitation.make({
5675 message: `${message}\n\nArguments:\n${approvalArgumentPreview(args)}`,
5676 requestedSchema: { type: "object", properties: {} },
5677 });
5678 const response = yield* handler({ address, args, request });
5679 if (response.action !== "accept") {
5680 return yield* new ElicitationDeclinedError({
5681 address,
5682 action: response.action,
5683 });
5684 }
5685 });
5686
5687 // ------------------------------------------------------------------
5688 // 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