fix(web): normalize structured thought rows

This commit is contained in:
Miguel Palhas
2026-09-06 22:21:19 +01:00
parent 0b1c9e15cf
commit 059316cbac
2 changed files with 13 additions and 7 deletions
+8 -3
View File
@@ -40,10 +40,15 @@ describe("buildTranscriptRow: user/agent/thought", () => {
expect(ps[0].innerHTML).toContain("<code>three</code>");
});
it("renders a thought row as plain text", () => {
const el = buildTranscriptRow(row("agent_thought", { content: { type: "text", text: "hmm" } }));
it("trims ACP framing whitespace and renders thought-row inline markdown", () => {
const el = buildTranscriptRow(
row("agent_thought", {
content: { type: "text", text: "\n\n**Planning comply tool commentary update**\n" },
}),
);
expect(el.className).toContain("st-row-thought");
expect(el.textContent).toBe("hmm");
expect(el.textContent).toBe("Planning comply tool commentary update");
expect(el.querySelector("strong")?.textContent).toBe("Planning comply tool commentary update");
});
it("falls back to a labelled placeholder for non-text content, never crashing", () => {
+5 -4
View File
@@ -196,20 +196,21 @@ function makeCopyable(node: HTMLElement, text: string, label: string): void {
function buildContentRow(row: TranscriptRow, variant: "user" | "agent" | "thought"): HTMLElement {
const data = row.data as { content?: AcpContentBlock; messageId?: string } | undefined;
const text = contentBlockText(data?.content);
const displayText = variant === "thought" ? text.trim() : text;
const wrap = el("div", `st-row st-row-${variant}`);
const body = el("div", "st-body");
if (variant === "user") {
const line = el("div", "st-user-text");
line.textContent = text;
line.textContent = displayText;
body.appendChild(line);
} else if (variant === "agent") {
renderProse(body, text);
renderProse(body, displayText);
} else {
body.textContent = text;
body.innerHTML = renderInlineMarkdown(displayText);
}
wrap.appendChild(body);
const label = variant === "user" ? "message" : variant === "agent" ? "response" : "thought";
makeCopyable(wrap, text, label);
makeCopyable(wrap, displayText, label);
return wrap;
}