diff --git a/prime_core/telegram_control.py b/prime_core/telegram_control.py index 0c9dd37..1d7ca53 100644 --- a/prime_core/telegram_control.py +++ b/prime_core/telegram_control.py @@ -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: