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

Function enforceApproval

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

Source from the content-addressed store, hash-verified

3564 };
3565
3566 const enforceApproval = (
3567 annotations: ToolAnnotations | undefined,
3568 address: ToolAddress,
3569 args: unknown,
3570 policy: EffectivePolicy,
3571 handler: ElicitationHandler,
3572 ) =>
3573 Effect.gen(function* () {
3574 if (!approvalRequired(annotations, policy)) return;
3575 const policyForcesApproval = policy.action === "require_approval";
3576 const message = annotations?.approvalDescription
3577 ? annotations.approvalDescription
3578 : policyForcesApproval && policy.pattern
3579 ? `Approve ${address}? (matched policy: ${policy.pattern})`
3580 : `Approve ${address}?`;
3581 const request = FormElicitation.make({
3582 message: `${message}\n\nArguments:\n${approvalArgumentPreview(args)}`,
3583 requestedSchema: { type: "object", properties: {} },
3584 });
3585 const response = yield* handler({ address, args, request });
3586 if (response.action !== "accept") {
3587 return yield* new ElicitationDeclinedError({
3588 address,
3589 action: response.action,
3590 });
3591 }
3592 });
3593
3594 // ------------------------------------------------------------------
3595 // 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