fix(chat): return clean assistant text instead of raw codex event stream

This commit is contained in:
Prime Backup Bot
2026-03-12 00:20:50 +00:00
parent 30aca465a7
commit 14294bdf2d
+21 -1
View File
@@ -109,10 +109,30 @@ def run_prime(args: list[str]) -> tuple[int, str]:
def _chat_answer(text: str) -> str:
import json
prompt = f"You are Prime, Jason's assistant. Reply naturally and concisely. User message: {text}"
code, out = run_prime(['dispatch','planning', prompt])
if code == 0 and out:
return out[:3000]
# out is JSON from prime dispatch; planning raw may be event stream lines
try:
obj = json.loads(out)
raw = str(obj.get('raw',''))
best = None
for line in raw.splitlines():
line=line.strip()
if not line.startswith('{'):
continue
try:
ev = json.loads(line)
except Exception:
continue
item = ev.get('item') or {}
if item.get('type') == 'agent_message' and item.get('text'):
best = item.get('text')
if best:
return best[:1200]
except Exception:
pass
return "Got it — I can help with that."
def help_text() -> str: