mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-11 09:42:15 +03:00
A tool_use/tool_result turn's text is the tool call's raw JSON arguments (or a stringified result) — slicing that raw JSON at a fixed character offset (TEXT_PREVIEW_LENGTH) routinely landed mid-string, storing INVALID JSON. The conversations page's toTurn() then failed to JSON.parse it and fell back to showing the raw, still-escaped text verbatim: a large edit/write/apply_patch-style tool call with a long content field rendered with literal `\n` sequences visible instead of real line breaks, looking exactly like a JSON-escaping bug rather than a big diff. Confirmed live on omniroute-dev: 3 stored `edit` tool_use previews were sitting at exactly 8000 chars with "Unterminated string in JSON" on parse. buildTextPreview now parses first and caps oversized string VALUES inside the JSON instead of slicing the raw blob, so a truncated payload is always valid, re-parseable JSON. Plain text turns are unaffected (still a simple slice — a cut-off sentence is harmless). Also fixes JsonViewer's string rendering to preserve line breaks (whitespace-pre-wrap) — a correctly-parsed multi-line tool argument was still visually squashing onto one line without it. Unrelated cleanup found while editing: conversationTracker.ts had two literal NUL bytes (pre-existing, not introduced by this change) sitting where a template-literal space belonged, making the file register as binary to grep/rg/file. Restored to plain spaces. Co-authored-by: Markus Hartung <markus.hartung@gmail.com>