/** * TOON Format Utility * * Provides JSON to TOON conversion for token-efficient encoding. * TOON format can reduce token count by 30-60% for JSON data. * * Uses the official @toon-format/toon library when available. */ /** * Ensures the TOON library is loaded. Call this before using jsonToToon in tests. */ export declare function ensureToonLoaded(): Promise; /** * Check if a string appears to be in TOON format. * TOON format characteristics: * - Uses key: value syntax (like YAML) * - Uses array notation like [3] or {fields} * - Does NOT start with { or [ * - Often has patterns like "name[N]:" or "name{fields}:" * * @param str - String to check * @returns true if string appears to be TOON format */ export declare function isToonFormat(str: string): boolean; /** * Extract the first valid JSON object or array from a string. * Handles pure JSON or JSON embedded in text (e.g., tool responses). * * @param str - The string to extract JSON from * @returns Object with found status, parsed JSON, and indices */ export declare function extractFirstJson(str: string): { found: boolean; parsed: unknown; startIndex: number; endIndex: number; }; /** * Convert JSON content to TOON format for token efficiency. * Extracts JSON from string if embedded, converts to TOON. * Returns original string if: * - Already in TOON format * - Not JSON * - TOON conversion fails or is larger * * @param str - The string containing JSON to convert * @returns Object with conversion status, result, and reduction percentage */ export declare function jsonToToon(str: string): { converted: boolean; result: string; reduction: number; alreadyToon?: boolean; error?: string; }; /** * Check if TOON library is loaded and available */ export declare function isToonAvailable(): boolean; /** * Result of processing tool output */ export interface ProcessToolOutputResult { /** The processed content string */ content: string; /** Whether TOON conversion was applied */ toonConverted: boolean; /** Whether content was truncated */ truncated: boolean; /** Percentage reduction from TOON (0 if not converted) */ reduction: number; /** Whether input was already in TOON format */ alreadyToon: boolean; /** Original content length */ originalLength: number; /** Estimated original tokens (~4 chars per token) */ originalTokens: number; /** Final content length */ finalLength: number; /** Estimated final tokens */ finalTokens: number; /** Error message if TOON conversion failed (for debugging) */ toonError?: string; } /** * Options for processing tool output */ export interface ProcessToolOutputOptions { /** Maximum output length in characters (default: 100000) */ maxLength?: number; /** Whether to apply TOON conversion (default: true) */ enableToon?: boolean; /** Minimum content size to attempt TOON conversion (default: 1000) */ minSizeForToon?: number; /** Minimum reduction % to accept TOON result (default: 10) */ minReductionPercent?: number; } /** * Process tool output: apply TOON conversion if beneficial, then truncate if needed. * This is the main entry point for processing any tool output (regular or MCP). * * Flow: * 1. Check if already TOON format → skip conversion * 2. Try TOON conversion if content is JSON and large enough * 3. Truncate if still exceeds maxLength (with smart break points) * * @param content - The tool output content * @param options - Processing options * @returns Processed content and metadata */ export declare function processToolOutput(content: string, options?: ProcessToolOutputOptions): ProcessToolOutputResult;