/** * Tool Schema Translation * * Translates tool/function schemas between different LLM provider formats. * Each provider has different conventions for defining tools that models can use. * * Format Comparison: * | Feature | Anthropic | OpenAI | Gemini | * |-----------------|------------------|---------------------|---------------------| * | Schema key | input_schema | parameters | parameters | * | Wrapper | none | function: { } | functionDeclarations| * | Description | description | function.description| description | */ import { type Tool } from '../types.js'; /** * Anthropic tool format. * Tools are defined at the top level with input_schema for parameters. */ export interface AnthropicTool { name: string; description: string; input_schema: { type: 'object'; properties: Record; required?: string[]; }; } /** * OpenAI tool format. * Tools are wrapped in a function object with type: "function". */ export interface OpenAITool { type: 'function'; function: { name: string; description: string; parameters: { type: 'object'; properties: Record; required?: string[]; }; }; } /** * OpenAI function definition (inner part of OpenAITool). * Used when providers expect just the function definition. */ export interface OpenAIFunction { name: string; description: string; parameters: { type: 'object'; properties: Record; required?: string[]; }; } /** * Gemini function declaration. * Used inside the functionDeclarations array. */ export interface GeminiFunctionDeclaration { name: string; description: string; parameters: { type: 'object'; properties: Record; required?: string[]; }; } /** * Gemini tool format. * Tools are wrapped in a functionDeclarations array. */ export interface GeminiTool { functionDeclarations: GeminiFunctionDeclaration[]; } /** * Translate tools to Anthropic format. * * Anthropic uses a straightforward format where tools are defined with: * - name: The tool name * - description: Human-readable description * - input_schema: JSON Schema for parameters * * Since our internal Tool type follows the Anthropic format, * this is essentially a pass-through with validation. * * @param tools - Array of tools in internal format * @returns Array of tools in Anthropic format * @throws TranslationError if validation fails * * @example * const tools = [{ name: "search", description: "Search the web", input_schema: {...} }]; * const anthropicTools = toAnthropicTools(tools); * // Returns: [{ name: "search", description: "Search the web", input_schema: {...} }] */ export declare function toAnthropicTools(tools: Tool[]): AnthropicTool[]; /** * Translate tools to OpenAI format. * * OpenAI wraps tools in a specific structure: * - type: "function" (indicates it's a function tool) * - function: Object containing name, description, and parameters * * The main difference from Anthropic is: * - Uses `parameters` instead of `input_schema` * - Wraps everything in a `function` object * - Adds `type: "function"` at the top level * * @param tools - Array of tools in internal format * @returns Array of tools in OpenAI format * @throws TranslationError if validation fails * * @example * const tools = [{ name: "search", description: "Search the web", input_schema: {...} }]; * const openaiTools = toOpenAITools(tools); * // Returns: [{ type: "function", function: { name: "search", description: "...", parameters: {...} } }] */ export declare function toOpenAITools(tools: Tool[]): OpenAITool[]; /** * Translate tools to OpenAI function format (without wrapper). * * Some OpenAI-compatible APIs expect just the function definitions * without the { type: "function", function: {...} } wrapper. * * @param tools - Array of tools in internal format * @returns Array of function definitions * @throws TranslationError if validation fails */ export declare function toOpenAIFunctions(tools: Tool[]): OpenAIFunction[]; /** * Translate tools to Gemini format. * * Gemini uses a different structure where all function declarations * are grouped into a single object: * - functionDeclarations: Array of function definitions * * Each function declaration contains: * - name: Function name * - description: Human-readable description * - parameters: JSON Schema for parameters * * Note: Gemini expects a single tool object containing all functions, * not an array of tool objects. * * @param tools - Array of tools in internal format * @returns Single Gemini tool object containing all function declarations * @throws TranslationError if validation fails * * @example * const tools = [{ name: "search", description: "Search the web", input_schema: {...} }]; * const geminiTools = toGeminiTools(tools); * // Returns: { functionDeclarations: [{ name: "search", description: "...", parameters: {...} }] } */ export declare function toGeminiTools(tools: Tool[]): GeminiTool; /** * Translate tools to Gemini format as an array (for API compatibility). * * Some Gemini API versions expect an array containing the tool object. * This is a convenience wrapper around toGeminiTools. * * @param tools - Array of tools in internal format * @returns Array containing a single Gemini tool object * @throws TranslationError if validation fails */ export declare function toGeminiToolsArray(tools: Tool[]): GeminiTool[]; /** * Translate Anthropic tools to internal format. * * Since our internal format matches Anthropic, this is essentially a pass-through * with validation. * * @param tools - Array of Anthropic tools * @returns Array of tools in internal format * @throws TranslationError if validation fails */ export declare function fromAnthropicTools(tools: AnthropicTool[]): Tool[]; /** * Translate OpenAI tools to internal format. * * Unwraps the function object and converts parameters to input_schema. * * @param tools - Array of OpenAI tools * @returns Array of tools in internal format * @throws TranslationError if validation fails */ export declare function fromOpenAITools(tools: OpenAITool[]): Tool[]; /** * Translate Gemini tools to internal format. * * Extracts function declarations from the Gemini tool object. * * @param tool - Gemini tool object containing function declarations * @returns Array of tools in internal format * @throws TranslationError if validation fails */ export declare function fromGeminiTools(tool: GeminiTool): Tool[]; /** * Translate tools to a specific provider format. * * Convenience function for dynamic provider selection. * * @param tools - Array of tools in internal format * @param provider - Target provider name * @returns Tools in the appropriate provider format * @throws TranslationError if the provider is unknown */ export declare function translateTools(tools: Tool[], provider: 'anthropic' | 'openai' | 'google' | 'gemini' | 'ollama' | 'openrouter' | 'zai'): AnthropicTool[] | OpenAITool[] | GeminiTool; //# sourceMappingURL=tools.d.ts.map