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

Function enforceApproval

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

Source from the content-addressed store, hash-verified

4649 };
4650
4651 const enforceApproval = (
4652 annotations: ToolAnnotations | undefined,
4653 address: ToolAddress,
4654 args: unknown,
4655 policy: EffectivePolicy,
4656 handler: ElicitationHandler,
4657 ) =>
4658 Effect.gen(function* () {
4659 if (!approvalRequired(annotations, policy)) return;
4660 const policyForcesApproval = policy.action === "require_approval";
4661 const message = annotations?.approvalDescription
4662 ? annotations.approvalDescription
4663 : policyForcesApproval && policy.pattern
4664 ? `Approve ${address}? (matched policy: ${policy.pattern})`
4665 : `Approve ${address}?`;
4666 const request = FormElicitation.make({
4667 message: `${message}\n\nArguments:\n${approvalArgumentPreview(args)}`,
4668 requestedSchema: { type: "object", properties: {} },
4669 });
4670 const response = yield* handler({ address, args, request });
4671 if (response.action !== "accept") {
4672 return yield* new ElicitationDeclinedError({
4673 address,
4674 action: response.action,
4675 });
4676 }
4677 });
4678
4679 // ------------------------------------------------------------------
4680 // 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