fix: strip stray trailing } from reply when LLM botches JSON

This commit is contained in:
ymq 2026-08-10 08:31:35 +08:00
parent 5f0c419986
commit 6f717f1d13

View File

@ -164,6 +164,8 @@ def _parse(raw):
# Strip any {"action":"tool_call"...} JSON fragments from reply text
import re as _re2
clean = _re2.sub(r'\s*\{[^}]*"action"\s*:\s*"tool_call"[^}]*\}\s*', ' ', raw).strip()
# Remove stray trailing braces from malformed JSON attempts
clean = clean.rstrip().rstrip('}').strip()
return {"action":"reply","message":clean or raw}
def _w_text(t): return {"widgettype":"Text","options":{"text":t,"css":"agent-text","halign":"left"}}