Fix OpenCode server HTTP response parsing for parts array

This commit is contained in:
Adolfo Reyna
2026-08-07 19:43:03 -04:00
parent a8ad741a4d
commit 0aa790a8b0
+13 -8
View File
@@ -240,12 +240,16 @@ class OpenCodeLLM(FrameProcessor):
} }
async with session.post(msg_url, json=payload) as resp: async with session.post(msg_url, json=payload) as resp:
async for line in resp.content: if resp.status == 200:
line_str = line.decode("utf-8").strip() data = await resp.json()
if not line_str: parts = data.get("parts", []) if isinstance(data, dict) else []
continue for p in parts:
try: if isinstance(p, dict) and p.get("type") == "text" and "text" in p:
data = json.loads(line_str) 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: if "delta" in data:
text_chunk = _clean_spoken_text(data["delta"]) text_chunk = _clean_spoken_text(data["delta"])
if text_chunk: if text_chunk:
@@ -256,8 +260,9 @@ class OpenCodeLLM(FrameProcessor):
if text_chunk: if text_chunk:
chunks.append(text_chunk) chunks.append(text_chunk)
await self.push_frame(LLMTextFrame(text_chunk)) await self.push_frame(LLMTextFrame(text_chunk))
except json.JSONDecodeError: else:
pass err_text = await resp.text()
logger.error(f"OpenCode server HTTP {resp.status}: {err_text}")
except asyncio.CancelledError: except asyncio.CancelledError:
logger.info("OpenCode server turn cancelled mid-response.") logger.info("OpenCode server turn cancelled mid-response.")