fix(ui): render text-block tool results

This commit is contained in:
Peter Steinberger
2026-05-04 04:25:49 +01:00
parent 6f8b9bb573
commit a4df85e55f
4 changed files with 51 additions and 1 deletions

View File

@@ -361,7 +361,15 @@
.chat-tool-card__block-content {
color: var(--text);
overflow-x: auto;
overflow: auto;
max-height: min(520px, 60vh);
}
.chat-tool-card__inline {
margin-top: 10px;
white-space: pre-wrap;
overflow-wrap: anywhere;
word-break: break-word;
}
.chat-tool-card__block-preview {

View File

@@ -136,6 +136,35 @@ describe("tool-card extraction", () => {
});
});
it("extracts tool result output from text block content arrays", () => {
const cards = extractToolCards(
{
role: "assistant",
content: [
{
type: "toolcall",
id: "call-read",
name: "read",
input: { path: "README.md" },
},
{
type: "tool_result",
id: "call-read",
name: "read",
content: [
{ type: "text", text: "# Heading" },
{ type: "text", text: "file body" },
],
},
],
},
"msg:read",
);
expect(cards).toHaveLength(1);
expect(cards[0]?.outputText).toBe("# Heading\nfile body");
});
it("builds sidebar content with input and empty output status", () => {
const [card] = extractToolCards(
{

View File

@@ -48,6 +48,18 @@ function extractToolText(item: Record<string, unknown>): string | undefined {
if (typeof item.content === "string") {
return item.content;
}
if (Array.isArray(item.content)) {
const parts = item.content.flatMap((entry) => {
if (!entry || typeof entry !== "object") {
return [];
}
const text = (entry as { text?: unknown }).text;
return typeof text === "string" ? [text] : [];
});
if (parts.length > 0) {
return parts.join("\n");
}
}
return undefined;
}