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

Function enforceApproval

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

Source from the content-addressed store, hash-verified

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.

Callers 1

executeFunction · 0.85

Calls 3

approvalRequiredFunction · 0.85
approvalArgumentPreviewFunction · 0.85
handlerFunction · 0.50

Tested by

no test coverage detected