fix(chat): return clean assistant text instead of raw codex event stream
This commit is contained in:
@@ -109,10 +109,30 @@ def run_prime(args: list[str]) -> tuple[int, str]:
|
|||||||
|
|
||||||
|
|
||||||
def _chat_answer(text: str) -> str:
|
def _chat_answer(text: str) -> str:
|
||||||
|
import json
|
||||||
prompt = f"You are Prime, Jason's assistant. Reply naturally and concisely. User message: {text}"
|
prompt = f"You are Prime, Jason's assistant. Reply naturally and concisely. User message: {text}"
|
||||||
code, out = run_prime(['dispatch','planning', prompt])
|
code, out = run_prime(['dispatch','planning', prompt])
|
||||||
if code == 0 and out:
|
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."
|
return "Got it — I can help with that."
|
||||||
|
|
||||||
def help_text() -> str:
|
def help_text() -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user