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

Function enforceApproval

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

Source from the content-addressed store, hash-verified

4106 };
4107
4108 const enforceApproval = (
4109 annotations: ToolAnnotations | undefined,
4110 address: ToolAddress,
4111 args: unknown,
4112 policy: EffectivePolicy,
4113 handler: ElicitationHandler,
4114 ) =>
4115 Effect.gen(function* () {
4116 if (!approvalRequired(annotations, policy)) return;
4117 const policyForcesApproval = policy.action === "require_approval";
4118 const message = annotations?.approvalDescription
4119 ? annotations.approvalDescription
4120 : policyForcesApproval && policy.pattern
4121 ? `Approve ${address}? (matched policy: ${policy.pattern})`
4122 : `Approve ${address}?`;
4123 const request = FormElicitation.make({
4124 message: `${message}\n\nArguments:\n${approvalArgumentPreview(args)}`,
4125 requestedSchema: { type: "object", properties: {} },
4126 });
4127 const response = yield* handler({ address, args, request });
4128 if (response.action !== "accept") {
4129 return yield* new ElicitationDeclinedError({
4130 address,
4131 action: response.action,
4132 });
4133 }
4134 });
4135
4136 // ------------------------------------------------------------------
4137 // 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