{"version":3,"file":"toonFormat.cjs","sources":["../../../src/utils/toonFormat.ts"],"sourcesContent":["/**\n * TOON Format Utility\n *\n * Provides JSON to TOON conversion for token-efficient encoding.\n * TOON format can reduce token count by 30-60% for JSON data.\n *\n * Uses the official @toon-format/toon library when available.\n */\n\n// Dynamic import holder for the TOON library (ESM)\nlet toonEncode: ((data: unknown) => string) | null = null;\nlet toonLoadAttempted = false;\nlet toonLoadPromise: Promise<boolean> | null = null;\n\n/**\n * Lazily loads the TOON library\n * Tries both ESM dynamic import and CommonJS require for compatibility\n */\nasync function loadToonLibrary(): Promise<boolean> {\n  if (toonLoadAttempted) return toonEncode !== null;\n  toonLoadAttempted = true;\n\n  // Try ESM dynamic import first\n  try {\n    const mod = await import('@toon-format/toon');\n    toonEncode = mod.encode;\n    return true;\n  } catch {\n    // ESM import failed, try CommonJS require\n    try {\n      // eslint-disable-next-line @typescript-eslint/no-require-imports\n      const mod = require('@toon-format/toon');\n      toonEncode = mod.encode;\n      return true;\n    } catch {\n      // Library not available - that's OK, we'll return original content\n      return false;\n    }\n  }\n}\n\n/**\n * Ensures the TOON library is loaded. Call this before using jsonToToon in tests.\n */\nexport async function ensureToonLoaded(): Promise<boolean> {\n  if (!toonLoadPromise) {\n    toonLoadPromise = loadToonLibrary();\n  }\n  return toonLoadPromise;\n}\n\n// Start loading immediately\nensureToonLoaded();\n\n/**\n * Check if a string appears to be in TOON format.\n * TOON format characteristics:\n * - Uses key: value syntax (like YAML)\n * - Uses array notation like [3] or {fields}\n * - Does NOT start with { or [\n * - Often has patterns like \"name[N]:\" or \"name{fields}:\"\n *\n * @param str - String to check\n * @returns true if string appears to be TOON format\n */\nexport function isToonFormat(str: string): boolean {\n  if (typeof str !== 'string' || str.length === 0) return false;\n\n  const trimmed = str.trim();\n\n  // TOON doesn't start with JSON brackets\n  if (trimmed.startsWith('{') || trimmed.startsWith('[')) return false;\n\n  // Check for TOON-specific patterns:\n  // 1. Key-value with colon (but not URL-like patterns)\n  // 2. Array notation like \"items[3]:\" or \"data[10]:\"\n  // 3. Object schema notation like \"items{id,name}:\"\n  const toonPatterns = [\n    /^\\w+:$/m, // Simple key: at start of line\n    /^\\w+\\[\\d+\\]:/m, // Array notation: items[3]:\n    /^\\w+\\{[^}]+\\}:/m, // Schema notation: items{id,name}:\n    /^\\w+\\[\\d+\\]\\{[^}]+\\}:/m, // Combined: items[3]{id,name}:\n  ];\n\n  // Must match at least one TOON pattern\n  const hasToonPattern = toonPatterns.some((pattern) => pattern.test(trimmed));\n\n  // Additional check: TOON typically has multiple lines with consistent indentation\n  const lines = trimmed.split('\\n').filter((l) => l.trim());\n  const hasMultipleKeyValueLines =\n    lines.filter((l) => /^\\s*\\w+.*:/.test(l)).length >= 2;\n\n  return hasToonPattern || hasMultipleKeyValueLines;\n}\n\n/**\n * Extract the first valid JSON object or array from a string.\n * Handles pure JSON or JSON embedded in text (e.g., tool responses).\n *\n * @param str - The string to extract JSON from\n * @returns Object with found status, parsed JSON, and indices\n */\nexport function extractFirstJson(str: string): {\n  found: boolean;\n  parsed: unknown;\n  startIndex: number;\n  endIndex: number;\n} {\n  if (typeof str !== 'string' || str.length === 0) {\n    return { found: false, parsed: null, startIndex: -1, endIndex: -1 };\n  }\n\n  // Find the first { or [ character\n  const objStart = str.indexOf('{');\n  const arrStart = str.indexOf('[');\n\n  if (objStart === -1 && arrStart === -1) {\n    return { found: false, parsed: null, startIndex: -1, endIndex: -1 };\n  }\n\n  let startIndex: number;\n  if (objStart === -1) {\n    startIndex = arrStart;\n  } else if (arrStart === -1) {\n    startIndex = objStart;\n  } else {\n    startIndex = Math.min(objStart, arrStart);\n  }\n\n  // Find the matching closing bracket using a stack-based approach\n  // Properly handle strings to avoid counting brackets inside strings\n  let depth = 0;\n  let inString = false;\n  let escapeNext = false;\n\n  for (let i = startIndex; i < str.length; i++) {\n    const char = str[i];\n\n    if (escapeNext) {\n      escapeNext = false;\n      continue;\n    }\n\n    if (char === '\\\\' && inString) {\n      escapeNext = true;\n      continue;\n    }\n\n    if (char === '\"') {\n      inString = !inString;\n      continue;\n    }\n\n    if (inString) continue;\n\n    if (char === '{' || char === '[') depth++;\n    if (char === '}' || char === ']') depth--;\n\n    if (depth === 0) {\n      // Found matching bracket, try to parse\n      const jsonStr = str.substring(startIndex, i + 1);\n      try {\n        const parsed = JSON.parse(jsonStr);\n        return { found: true, parsed, startIndex, endIndex: i };\n      } catch {\n        // Not valid JSON at this bracket level, continue searching\n        // Reset and look for the next JSON start after this position\n        const nextResult = extractFirstJson(str.substring(i + 1));\n        if (nextResult.found) {\n          return {\n            found: true,\n            parsed: nextResult.parsed,\n            startIndex: i + 1 + nextResult.startIndex,\n            endIndex: i + 1 + nextResult.endIndex,\n          };\n        }\n        return { found: false, parsed: null, startIndex: -1, endIndex: -1 };\n      }\n    }\n  }\n\n  return { found: false, parsed: null, startIndex: -1, endIndex: -1 };\n}\n\n/**\n * Convert JSON content to TOON format for token efficiency.\n * Extracts JSON from string if embedded, converts to TOON.\n * Returns original string if:\n * - Already in TOON format\n * - Not JSON\n * - TOON conversion fails or is larger\n *\n * @param str - The string containing JSON to convert\n * @returns Object with conversion status, result, and reduction percentage\n */\nexport function jsonToToon(str: string): {\n  converted: boolean;\n  result: string;\n  reduction: number;\n  alreadyToon?: boolean;\n  error?: string;\n} {\n  if (!toonEncode || typeof str !== 'string') {\n    return {\n      converted: false,\n      result: str,\n      reduction: 0,\n      error: !toonEncode ? 'TOON library not loaded' : undefined,\n    };\n  }\n\n  // Check if already in TOON format - skip conversion\n  if (isToonFormat(str)) {\n    return { converted: false, result: str, reduction: 0, alreadyToon: true };\n  }\n\n  try {\n    const { found, parsed, startIndex, endIndex } = extractFirstJson(str);\n\n    if (!found || !parsed) {\n      return {\n        converted: false,\n        result: str,\n        reduction: 0,\n        error: 'No JSON found in content',\n      };\n    }\n\n    // Check if this JSON structure would benefit from TOON\n    // Text-heavy content (emails, documents) won't compress well\n    if (!isToonBeneficial(parsed)) {\n      return {\n        converted: false,\n        result: str,\n        reduction: 0,\n        error:\n          'Content is text-heavy (>70% string values), TOON not beneficial',\n      };\n    }\n\n    const toonResult = toonEncode(parsed);\n\n    // Preserve text before and after the JSON block\n    const textBefore = str.substring(0, startIndex);\n    const textAfter = str.substring(endIndex + 1);\n\n    // Build the full result: textBefore + TOON + textAfter\n    const fullResult = textBefore + toonResult + textAfter;\n\n    if (fullResult.length < str.length) {\n      const reduction = Math.round(\n        ((str.length - fullResult.length) / str.length) * 100\n      );\n      return { converted: true, result: fullResult, reduction };\n    } else {\n      // TOON output was larger or same size - not beneficial\n      return {\n        converted: false,\n        result: str,\n        reduction: 0,\n        error: `TOON output not smaller (${fullResult.length} >= ${str.length})`,\n      };\n    }\n  } catch (err) {\n    // TOON encoding or extraction failed - log error for debugging\n    const errorMsg = err instanceof Error ? err.message : String(err);\n    return {\n      converted: false,\n      result: str,\n      reduction: 0,\n      error: `TOON conversion error: ${errorMsg}`,\n    };\n  }\n}\n\n/**\n * Check if TOON library is loaded and available\n */\nexport function isToonAvailable(): boolean {\n  return toonEncode !== null;\n}\n\n/**\n * Result of processing tool output\n */\nexport interface ProcessToolOutputResult {\n  /** The processed content string */\n  content: string;\n  /** Whether TOON conversion was applied */\n  toonConverted: boolean;\n  /** Whether content was truncated */\n  truncated: boolean;\n  /** Percentage reduction from TOON (0 if not converted) */\n  reduction: number;\n  /** Whether input was already in TOON format */\n  alreadyToon: boolean;\n  /** Original content length */\n  originalLength: number;\n  /** Estimated original tokens (~4 chars per token) */\n  originalTokens: number;\n  /** Final content length */\n  finalLength: number;\n  /** Estimated final tokens */\n  finalTokens: number;\n  /** Error message if TOON conversion failed (for debugging) */\n  toonError?: string;\n}\n\n/**\n * Options for processing tool output\n */\nexport interface ProcessToolOutputOptions {\n  /** Maximum output length in characters (default: 100000) */\n  maxLength?: number;\n  /** Whether to apply TOON conversion (default: true) */\n  enableToon?: boolean;\n  /** Minimum content size to attempt TOON conversion (default: 1000) */\n  minSizeForToon?: number;\n  /** Minimum reduction % to accept TOON result (default: 10) */\n  minReductionPercent?: number;\n}\n\n/**\n * Analyze JSON structure to determine if TOON conversion would be beneficial.\n * Text-heavy content (emails, documents) doesn't compress well with TOON.\n * Structured data (API responses, metadata) compresses much better.\n *\n * @param parsed - Parsed JSON object\n * @returns true if TOON conversion is likely beneficial\n */\nfunction isToonBeneficial(parsed: unknown): boolean {\n  if (!parsed || typeof parsed !== 'object') return false;\n\n  const jsonStr = JSON.stringify(parsed);\n  const totalLength = jsonStr.length;\n\n  // Count characters in string values (text content)\n  let textContentLength = 0;\n\n  function countTextContent(obj: unknown): void {\n    if (typeof obj === 'string') {\n      // Count string length (this is text content that TOON can't compress)\n      textContentLength += obj.length;\n    } else if (Array.isArray(obj)) {\n      obj.forEach(countTextContent);\n    } else if (obj && typeof obj === 'object') {\n      Object.values(obj).forEach(countTextContent);\n    }\n  }\n\n  countTextContent(parsed);\n\n  // Calculate ratio of text content to total JSON\n  const textRatio = textContentLength / totalLength;\n\n  // If more than 70% is text content, TOON won't help much\n  // TOON compresses structure (field names, brackets), not text\n  return textRatio < 0.7;\n}\n\n/**\n * Process tool output: apply TOON conversion if beneficial, then truncate if needed.\n * This is the main entry point for processing any tool output (regular or MCP).\n *\n * Flow:\n * 1. Check if already TOON format → skip conversion\n * 2. Try TOON conversion if content is JSON and large enough\n * 3. Truncate if still exceeds maxLength (with smart break points)\n *\n * @param content - The tool output content\n * @param options - Processing options\n * @returns Processed content and metadata\n */\nexport function processToolOutput(\n  content: string,\n  options: ProcessToolOutputOptions = {}\n): ProcessToolOutputResult {\n  const {\n    maxLength = 100000,\n    enableToon = true,\n    minSizeForToon = 1000,\n    minReductionPercent = 10, // Increased from 5% - only apply TOON when clearly beneficial\n  } = options;\n\n  const originalLength = content.length;\n  const originalTokens = Math.ceil(originalLength / 4);\n\n  let result = content;\n  let toonConverted = false;\n  let alreadyToon = false;\n  let reduction = 0;\n  let truncated = false;\n  let toonError: string | undefined;\n\n  // Step 1: Check if already TOON format\n  if (isToonFormat(content)) {\n    alreadyToon = true;\n  }\n  // Step 2: Apply TOON conversion if enabled and content is large enough\n  else if (enableToon && content.length > minSizeForToon) {\n    const toonResult = jsonToToon(content);\n    if (toonResult.alreadyToon) {\n      alreadyToon = true;\n    } else if (\n      toonResult.converted &&\n      toonResult.reduction >= minReductionPercent\n    ) {\n      result = toonResult.result;\n      toonConverted = true;\n      reduction = toonResult.reduction;\n    } else if (toonResult.error) {\n      // Track error for debugging\n      toonError = toonResult.error;\n    } else if (\n      toonResult.converted &&\n      toonResult.reduction < minReductionPercent\n    ) {\n      // TOON converted but reduction was too small to be worth it\n      toonError = `TOON reduction ${toonResult.reduction}% below threshold ${minReductionPercent}%`;\n    } else if (!toonResult.converted) {\n      // Conversion failed without explicit error - investigate\n      toonError =\n        toonResult.error || 'TOON conversion returned false with no error';\n    }\n  }\n\n  // Step 3: Truncate if still too long (with smart break points)\n  if (result.length > maxLength) {\n    let truncatedStr = result.substring(0, maxLength);\n\n    // Try to find a clean break point\n    if (toonConverted || alreadyToon) {\n      // For TOON format, break at newline for cleaner output\n      const lastNewline = truncatedStr.lastIndexOf('\\n');\n      if (lastNewline > maxLength * 0.7) {\n        truncatedStr = truncatedStr.substring(0, lastNewline);\n      }\n    } else {\n      // For JSON, try to find a clean JSON break point\n      const lastCompleteItem = truncatedStr.lastIndexOf('},');\n      const lastArrayItem = truncatedStr.lastIndexOf('],');\n      const breakPoint = Math.max(lastCompleteItem, lastArrayItem);\n      if (breakPoint > maxLength * 0.5) {\n        truncatedStr = truncatedStr.substring(0, breakPoint + 1);\n      }\n    }\n\n    // Build truncation message\n    const truncationInfo = toonConverted\n      ? `Original ${originalLength.toLocaleString()} chars → TOON ${result.length.toLocaleString()} chars (${reduction}% saved). ` +\n        `Still exceeds ${maxLength.toLocaleString()} char limit.`\n      : `Original output was ${originalLength.toLocaleString()} characters (~${originalTokens.toLocaleString()} tokens).`;\n\n    result =\n      truncatedStr +\n      `\\n\\n[OUTPUT_TRUNCATED: ${truncationInfo} Please use more specific queries or smaller date ranges.]`;\n    truncated = true;\n  }\n\n  const finalLength = result.length;\n  const finalTokens = Math.ceil(finalLength / 4);\n\n  return {\n    content: result,\n    toonConverted,\n    truncated,\n    reduction,\n    alreadyToon,\n    originalLength,\n    originalTokens,\n    finalLength,\n    finalTokens,\n    toonError,\n  };\n}\n"],"names":[],"mappings":";;AAAA;;;;;;;AAOG;AAEH;AACA,IAAI,UAAU,GAAuC,IAAI;AACzD,IAAI,iBAAiB,GAAG,KAAK;AAC7B,IAAI,eAAe,GAA4B,IAAI;AAEnD;;;AAGG;AACH,eAAe,eAAe,GAAA;AAC5B,IAAA,IAAI,iBAAiB;QAAE,OAAO,UAAU,KAAK,IAAI;IACjD,iBAAiB,GAAG,IAAI;;AAGxB,IAAA,IAAI;AACF,QAAA,MAAM,GAAG,GAAG,MAAM,OAAO,mBAAmB,CAAC;AAC7C,QAAA,UAAU,GAAG,GAAG,CAAC,MAAM;AACvB,QAAA,OAAO,IAAI;IACb;AAAE,IAAA,MAAM;;AAEN,QAAA,IAAI;;AAEF,YAAA,MAAM,GAAG,GAAG,OAAO,CAAC,mBAAmB,CAAC;AACxC,YAAA,UAAU,GAAG,GAAG,CAAC,MAAM;AACvB,YAAA,OAAO,IAAI;QACb;AAAE,QAAA,MAAM;;AAEN,YAAA,OAAO,KAAK;QACd;IACF;AACF;AAEA;;AAEG;AACI,eAAe,gBAAgB,GAAA;IACpC,IAAI,CAAC,eAAe,EAAE;QACpB,eAAe,GAAG,eAAe,EAAE;IACrC;AACA,IAAA,OAAO,eAAe;AACxB;AAEA;AACA,gBAAgB,EAAE;AAElB;;;;;;;;;;AAUG;AACG,SAAU,YAAY,CAAC,GAAW,EAAA;IACtC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;AAAE,QAAA,OAAO,KAAK;AAE7D,IAAA,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE;;AAG1B,IAAA,IAAI,OAAO,C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