mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 13:00:44 +00:00
fix(ui): render text-block tool results
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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(
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user