@mastra/core
Version:
48 lines • 2.96 kB
TypeScript
import type { LanguageModelV2FunctionTool, LanguageModelV2ProviderDefinedTool, LanguageModelV2ToolChoice } from '../../../../_types/@ai-sdk_provider@2.0.5/dist/index.js';
import type { LanguageModelV3FunctionTool, LanguageModelV3ProviderTool, LanguageModelV3ToolChoice } from '../../../../_types/@ai-sdk_provider@3.0.19/dist/index.js';
import type { Tool, ToolChoice } from '../../../../_types/@internal_ai-sdk-v5@0.0.98/dist/index.js';
import type { ModelToolDefinition } from '../../../../observability/index.js';
/** Model specification version for tool type conversion */
export type ModelSpecVersion = 'v2' | 'v3' | 'v4';
/** Combined tool types for both V2 and V3 */
type PreparedTool = LanguageModelV2FunctionTool | LanguageModelV2ProviderDefinedTool | LanguageModelV3FunctionTool | LanguageModelV3ProviderTool;
type PreparedToolChoice = LanguageModelV2ToolChoice | LanguageModelV3ToolChoice;
export declare function prepareToolsAndToolChoice<TOOLS extends Record<string, Tool>>({ tools, toolChoice, activeTools, targetVersion, stripToolsWhenNone, }: {
tools: TOOLS | undefined;
toolChoice: ToolChoice<TOOLS> | undefined;
activeTools: Array<keyof TOOLS> | undefined;
/** Target model version: 'v2' for AI SDK v5, 'v3' for AI SDK v6, 'v4' for AI SDK v7. Defaults to 'v2'. */
targetVersion?: ModelSpecVersion;
/**
* Drop tool definitions when toolChoice is 'none'. Set this when the request also carries a
* structured-output schema: providers like Gemini reject tools combined with
* response_format: json_schema (#14459). Otherwise tools are kept (AI SDK semantics) so
* providers like Bedrock don't strip tool-call history from the prompt (#25908).
*/
stripToolsWhenNone?: boolean;
}): {
tools: PreparedTool[] | undefined;
toolChoice: PreparedToolChoice | undefined;
};
/**
* Serialize a tool set into `ModelToolDefinition[]` for the `tools` attribute
* on MODEL_GENERATION and MODEL_INFERENCE spans, reusing the same conversion the provider request
* goes through so exporters see the schemas the model actually received.
*
* Pass the model's `specificationVersion` so provider tools carry the same
* `type` the request does ('provider' for v3/v4 models, 'provider-defined'
* otherwise).
*
* Never throws — tracing must not break model execution. Returns undefined
* when there are no tools or serialization fails.
*/
export declare function getToolDefinitionsForTracing<TOOLS extends Record<string, Tool>>({ tools, toolChoice, activeTools, specificationVersion, stripToolsWhenNone, }: {
tools: TOOLS | undefined;
toolChoice: ToolChoice<TOOLS> | undefined;
activeTools: Array<keyof TOOLS> | undefined;
specificationVersion?: string;
/** Must match the flag used for the provider request — see prepareToolsAndToolChoice. */
stripToolsWhenNone?: boolean;
}): ModelToolDefinition[] | undefined;
export {};
//# sourceMappingURL=prepare-tools.d.ts.map