@mastra/core
Version:
75 lines • 3.54 kB
TypeScript
import type { ToolToConvert } from './tool-builder/builder.js';
import type { BeforeApprovalFn, NeedsApprovalFn, VercelTool } from './types.js';
/**
* Checks if a tool is a Mastra Tool, using both instanceof and marker.
* The marker fallback handles environments like Vite SSR where the same
* module may be loaded multiple times, causing instanceof to fail.
*/
export declare function isMastraTool(tool: unknown): boolean;
/**
* Checks if a tool is a Vercel Tool (AI SDK tool)
* @param tool - The tool to check
* @returns True if the tool is a Vercel Tool, false otherwise
*/
export declare function isVercelTool(tool?: ToolToConvert): tool is VercelTool;
type ProviderTool = {
type: 'provider-defined' | 'provider';
id: string;
args?: Record<string, unknown>;
inputSchema?: unknown;
outputSchema?: unknown;
requestContextSchema?: unknown;
};
/**
* Checks if a tool is a provider-defined tool from the AI SDK.
* Provider tools (like google.tools.googleSearch(), openai.tools.webSearch()) have:
* - type: "provider-defined" (AI SDK v5) or "provider" (AI SDK v6)
* - id: in format 'provider.tool_name' (e.g., 'google.google_search')
*
* These tools have a lazy `inputSchema` function that returns an AI SDK Schema
* (not a Zod schema), so they require special handling during serialization.
*/
export declare function isProviderDefinedTool(tool: unknown): tool is ProviderTool;
/**
* Alias for callers that prefer the shorter provider-tool terminology.
*/
export declare const isProviderTool: typeof isProviderDefinedTool;
/**
* Extracts the model-facing tool name from a provider tool id.
* e.g. 'openai.web_search' -> 'web_search'
*/
export declare function getProviderToolName(providerId: string): string;
/**
* Marks a built tool as never requiring approval, overriding a global `requireToolApproval`
* (e.g. skill tools). Only the approval resolvers read this, so it does not affect
* tool-call concurrency or eager execution the way a `requireApproval` function would.
*/
export declare function markApprovalExempt(tool: object): void;
export declare function isApprovalExempt(tool: unknown): boolean;
/**
* Marks a tool an agent built from one of its `workflows`. Enumerable so that
* wrappers which spread the tool (e.g. tool hooks) keep the marker.
*/
export declare function markAgentWorkflowTool(tool: object): void;
export declare function isAgentWorkflowTool(tool: unknown): boolean;
/**
* Reads a per-tool {@link NeedsApprovalFn} attached to a tool instance, if present.
*
* Runtime tool maps are loosely typed (AI SDK `ToolSet` shape plus Mastra extras), so the
* `needsApprovalFn` decided by {@link CoreToolBuilder} / the MCP client is read off an
* arbitrary tool-like value. This helper centralizes that access with a typed result so the
* runtime never has to reach through `any` for it.
*/
export declare function getNeedsApprovalFn(tool: unknown): NeedsApprovalFn | undefined;
/**
* Reads a per-tool {@link BeforeApprovalFn} attached to a tool instance, if present.
*/
export declare function getBeforeApprovalFn(tool: unknown): BeforeApprovalFn | undefined;
/**
* Marks a {@link CoreToolBuilder} `beforeApproval` wrapper that expects trusted runtime values
* (request context and actor) as a third argument for its authorization check.
*/
export declare function markBuiltBeforeApproval<T extends BeforeApprovalFn>(fn: T): T;
export declare function isBuiltBeforeApproval(fn: BeforeApprovalFn): boolean;
export {};
//# sourceMappingURL=toolchecks.d.ts.map