From 1cd61601f399150646c3655ed266a0d92c6bb88f Mon Sep 17 00:00:00 2001 From: Richard Anaya Date: Wed, 18 Mar 2026 21:11:03 -0700 Subject: [PATCH] fix: handle direct array format for Pi tool results Pi sometimes sends tool results as a direct array [{"type":"text","text":"..."}] rather than wrapped in {"content": [...]}. Now handles both formats to properly extract text content instead of showing raw JSON. --- packages/adapters/pi-local/src/ui/parse-stdout.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/adapters/pi-local/src/ui/parse-stdout.ts b/packages/adapters/pi-local/src/ui/parse-stdout.ts index 57a78725..64a553e9 100644 --- a/packages/adapters/pi-local/src/ui/parse-stdout.ts +++ b/packages/adapters/pi-local/src/ui/parse-stdout.ts @@ -145,13 +145,18 @@ export function parsePiStdoutLine(line: string, ts: string): TranscriptEntry[] { const result = parsed.result; const isError = parsed.isError === true; - // Extract text from Pi's content array format: {"content": [{"type": "text", "text": "..."}]} + // Extract text from Pi's content array format + // Can be: {"content": [{"type": "text", "text": "..."}]} or [{"type": "text", "text": "..."}] let contentStr: string; if (typeof result === "string") { contentStr = result; + } else if (Array.isArray(result)) { + // Direct array format: result is [{"type": "text", "text": "..."}] + contentStr = extractTextContent(result as Array<{ type: string; text?: string }>); } else if (result && typeof result === "object") { const resultObj = result as Record; if (Array.isArray(resultObj.content)) { + // Wrapped format: result is {"content": [{"type": "text", "text": "..."}]} contentStr = extractTextContent(resultObj.content as Array<{ type: string; text?: string }>); } else { contentStr = JSON.stringify(result);