/** * @toolplex/ai-engine - Schema Utilities * * Pure utility functions for JSON Schema manipulation. * Used for tool schema processing before passing to AI SDK. */ import type { LoggerAdapter } from "../adapters/types.js"; /** * Deep sanitize tool parameters by recursively parsing stringified JSON values * * Some LLMs incorrectly stringify nested objects in tool parameters. * This function recursively detects and parses such stringified values while * respecting the tool's input schema to avoid corrupting legitimate string parameters. * * CRITICAL FIX: This function is now schema-aware. It will NOT parse strings that * the schema explicitly declares as type "string". This prevents catastrophic bugs * where tools expecting JSON content as a string (e.g., write_file) would receive * a parsed object instead. * * FIELD-AWARE FIX: Special handling for the 'arguments' field in call_tool. * ChatGPT and other models sometimes stringify this field even though it should * always be an object. This is a documented OpenAI issue (July 2024). * * @param params - The parameters to sanitize * @param schema - The JSON Schema for these parameters (optional but recommended) * @param fieldName - The name of the field being processed (for field-aware logic) * @param logger - Optional logger for debug output * @returns Sanitized parameters */ export declare function deepSanitizeParams(params: any, schema?: any, fieldName?: string, logger?: LoggerAdapter): any; /** * Resolve $ref references in JSON Schema by inlining from $defs * * Some MCP servers (like ElevenLabs) return tool schemas with $ref references * that point to $defs entries. The AI SDK's jsonSchema() validator (via AJV) * fails to resolve these references if they're not properly structured. * * This function: * 1. Extracts $defs from the root schema (if present) * 2. Recursively replaces $ref references with their actual definitions * 3. Falls back to permissive schema ({}) for unresolved references * * @param schema - The JSON Schema to process * @param defs - The $defs object from the root schema (optional, extracted from schema if not provided) * @param logger - Optional logger for warnings * @returns Schema with $ref references resolved */ export declare function resolveSchemaRefs(schema: any, defs?: Record, logger?: LoggerAdapter): any; /** * Sanitize JSON Schema for Google Gemini compatibility * * Gemini has strict schema requirements for function calling: * - No oneOf, anyOf, allOf constructs * - No const values * - enum only allowed for string types * - Object types must have properties defined (even if empty) * - required arrays cause issues with AI SDK transformation */ export declare function sanitizeSchemaForGemini(schema: any): any; /** * Clean a tool schema for AI SDK consumption * * Combines all schema processing steps: * 1. Remove $schema reference * 2. Resolve $ref references * 3. Apply Gemini sanitization if needed * * @param schema - Raw tool input schema from MCP * @param isGemini - Whether the target model is Google Gemini * @param logger - Optional logger * @returns Cleaned schema ready for AI SDK */ export declare function cleanToolSchema(schema: any, isGemini?: boolean, logger?: LoggerAdapter): any; //# sourceMappingURL=schema.d.ts.map