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

Function enforceApproval

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

Source from the content-addressed store, hash-verified

4265 };
4266
4267 const enforceApproval = (
4268 annotations: ToolAnnotations | undefined,
4269 address: ToolAddress,
4270 args: unknown,
4271 policy: EffectivePolicy,
4272 handler: ElicitationHandler,
4273 ) =>
4274 Effect.gen(function* () {
4275 if (!approvalRequired(annotations, policy)) return;
4276 const policyForcesApproval = policy.action === "require_approval";
4277 const message = annotations?.approvalDescription
4278 ? annotations.approvalDescription
4279 : policyForcesApproval && policy.pattern
4280 ? `Approve ${address}? (matched policy: ${policy.pattern})`
4281 : `Approve ${address}?`;
4282 const request = FormElicitation.make({
4283 message: `${message}\n\nArguments:\n${approvalArgumentPreview(args)}`,
4284 requestedSchema: { type: "object", properties: {} },
4285 });
4286 const response = yield* handler({ address, args, request });
4287 if (response.action !== "accept") {
4288 return yield* new ElicitationDeclinedError({
4289 address,
4290 action: response.action,
4291 });
4292 }
4293 });
4294
4295 // ------------------------------------------------------------------
4296 // 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