@mastra/core
Version:
59 lines • 3.2 kB
TypeScript
import type { ActorSignal } from '../../../auth/ee/index.js';
import type { IMastraLogger } from '../../../logger/index.js';
import type { RequestContext } from '../../../request-context/index.js';
import type { RequireToolApproval } from '../../../tools/index.js';
import type { ToolApprovalContext, ToolBeforeHookResult } from '../../../tools/types.js';
/**
* Set to `true` next to a function-form `requireToolApproval`. The function is dropped when the
* run's request context is stored, so a resume that doesn't pass it again falls back to this
* JSON-safe stand-in and requires approval for every call, the safe default the durable agent's
* boolean shadow also uses.
*/
export declare const REQUIRE_TOOL_APPROVAL_FALLBACK_KEY = "__mastra_requireToolApprovalFallback";
/** Request-context keys that carry the run's approval policy; approval policies never see them. */
export declare const INTERNAL_APPROVAL_KEYS: ReadonlySet<string>;
/** The run's approval policy: the live option, else what the request context carries for it. */
export declare function resolveRunToolApprovalPolicy(live: RequireToolApproval | undefined, requestContext: RequestContext | undefined): RequireToolApproval | undefined;
export declare function buildToolApprovalContext({ toolName, args, requestContext, workspace, }: {
toolName: string;
args: ToolApprovalContext['args'];
requestContext?: RequestContext;
workspace?: ToolApprovalContext['workspace'];
}): ToolApprovalContext;
/**
* Resolves whether a single tool call requires approval.
*
* The global `requireToolApproval` option (boolean, or a function evaluated per call) and the
* tool's own boolean `requireApproval` flag seed the decision. A per-tool `needsApprovalFn`
* (from `createTool({ requireApproval: fn })` or an MCP-derived tool) is authoritative when
* present and overrides the seed. Any policy that throws defaults to requiring approval.
*
* Shared by the tool-call step and the tool-call concurrency resolver so both use one rule.
*/
export declare function resolveToolApprovalVerdict({ tool, requireToolApproval, context, logger, }: {
tool: unknown;
requireToolApproval?: RequireToolApproval;
context: ToolApprovalContext;
logger?: IMastraLogger;
}): Promise<boolean>;
/**
* Runs the checks for a call that is about to suspend for approval: the tool's input
* validation, then its `beforeApproval` hook. Returns `{ proceed: false, output }` when the
* input is invalid (output is the same validation error `execute` would return) or when the
* hook rejects the call; otherwise `undefined` so the call continues to the approval gate.
* A hook that throws is logged and treated as "continue": the approval gate still protects
* execution.
*/
export declare function runBeforeApprovalChecks({ tool, input, context, logger, }: {
tool: unknown;
input: unknown;
context: {
toolCallId: string;
toolName: string;
requestContext?: RequestContext;
workspace?: ToolApprovalContext['workspace'];
actor?: ActorSignal;
};
logger?: IMastraLogger;
}): Promise<ToolBeforeHookResult | undefined>;
//# sourceMappingURL=tool-approval-verdict.d.ts.map