fix: extract text content from Pi's tool result content arrays
Pi returns tool results in format: {"content": [{"type": "text", "text": "..."}]}
Previously we were JSON.stringify-ing the whole object, showing as:
{"content":[{"type":"text","text":"..."}]}
Now we extract the actual text content for cleaner display.
This commit is contained in:
parent
47a6d86174
commit
6eb9545a72
1 changed files with 26 additions and 2 deletions
|
|
@ -72,7 +72,17 @@ export function parsePiStdoutLine(line: string, ts: string): TranscriptEntry[] {
|
||||||
for (const tr of toolResults) {
|
for (const tr of toolResults) {
|
||||||
const content = tr.content;
|
const content = tr.content;
|
||||||
const isError = tr.isError === true;
|
const isError = tr.isError === true;
|
||||||
const contentStr = typeof content === "string" ? content : JSON.stringify(content);
|
|
||||||
|
// Extract text from Pi's content array format
|
||||||
|
let contentStr: string;
|
||||||
|
if (typeof content === "string") {
|
||||||
|
contentStr = content;
|
||||||
|
} else if (Array.isArray(content)) {
|
||||||
|
contentStr = extractTextContent(content as Array<{ type: string; text?: string }>);
|
||||||
|
} else {
|
||||||
|
contentStr = JSON.stringify(content);
|
||||||
|
}
|
||||||
|
|
||||||
entries.push({
|
entries.push({
|
||||||
kind: "tool_result",
|
kind: "tool_result",
|
||||||
ts,
|
ts,
|
||||||
|
|
@ -134,7 +144,21 @@ export function parsePiStdoutLine(line: string, ts: string): TranscriptEntry[] {
|
||||||
const toolName = asString(parsed.toolName);
|
const toolName = asString(parsed.toolName);
|
||||||
const result = parsed.result;
|
const result = parsed.result;
|
||||||
const isError = parsed.isError === true;
|
const isError = parsed.isError === true;
|
||||||
const contentStr = typeof result === "string" ? result : JSON.stringify(result);
|
|
||||||
|
// Extract text from Pi's content array format: {"content": [{"type": "text", "text": "..."}]}
|
||||||
|
let contentStr: string;
|
||||||
|
if (typeof result === "string") {
|
||||||
|
contentStr = result;
|
||||||
|
} else if (result && typeof result === "object") {
|
||||||
|
const resultObj = result as Record<string, unknown>;
|
||||||
|
if (Array.isArray(resultObj.content)) {
|
||||||
|
contentStr = extractTextContent(resultObj.content as Array<{ type: string; text?: string }>);
|
||||||
|
} else {
|
||||||
|
contentStr = JSON.stringify(result);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
contentStr = JSON.stringify(result);
|
||||||
|
}
|
||||||
|
|
||||||
return [{
|
return [{
|
||||||
kind: "tool_result",
|
kind: "tool_result",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue