diff --git a/opencode_llm.py b/opencode_llm.py index 7fe1546..4d5e9bb 100644 --- a/opencode_llm.py +++ b/opencode_llm.py @@ -240,12 +240,16 @@ class OpenCodeLLM(FrameProcessor): } async with session.post(msg_url, json=payload) as resp: - async for line in resp.content: - line_str = line.decode("utf-8").strip() - if not line_str: - continue - try: - data = json.loads(line_str) + if resp.status == 200: + data = await resp.json() + parts = data.get("parts", []) if isinstance(data, dict) else [] + for p in parts: + if isinstance(p, dict) and p.get("type") == "text" and "text" in p: + text_chunk = _clean_spoken_text(p["text"]) + if text_chunk: + chunks.append(text_chunk) + await self.push_frame(LLMTextFrame(text_chunk)) + if not chunks and isinstance(data, dict): if "delta" in data: text_chunk = _clean_spoken_text(data["delta"]) if text_chunk: @@ -256,8 +260,9 @@ class OpenCodeLLM(FrameProcessor): if text_chunk: chunks.append(text_chunk) await self.push_frame(LLMTextFrame(text_chunk)) - except json.JSONDecodeError: - pass + else: + err_text = await resp.text() + logger.error(f"OpenCode server HTTP {resp.status}: {err_text}") except asyncio.CancelledError: logger.info("OpenCode server turn cancelled mid-response.")