diff --git a/packages/web-ui/src/tools/artifacts/artifacts-tool-renderer.ts b/packages/web-ui/src/tools/artifacts/artifacts-tool-renderer.ts index cd7abbdd..83591dc1 100644 --- a/packages/web-ui/src/tools/artifacts/artifacts-tool-renderer.ts +++ b/packages/web-ui/src/tools/artifacts/artifacts-tool-renderer.ts @@ -1,10 +1,11 @@ import { Diff, html, type TemplateResult } from "@mariozechner/mini-lit"; import "@mariozechner/mini-lit/dist/CodeBlock.js"; import type { ToolResultMessage } from "@mariozechner/pi-ai"; +import { createRef, ref } from "lit/directives/ref.js"; import { FileCode2 } from "lucide"; import "../../components/ConsoleBlock.js"; import { i18n } from "../../utils/i18n.js"; -import { renderHeader } from "../renderer-registry.js"; +import { renderCollapsibleHeader, renderHeader } from "../renderer-registry.js"; import type { ToolRenderer } from "../types.js"; import type { ArtifactsParams } from "./artifacts.js"; @@ -51,7 +52,11 @@ export class ArtifactsToolRenderer implements ToolRenderer | undefined, isStreaming?: boolean, ): TemplateResult { - const state = result ? (result.isError ? "error" : "complete") : "inprogress"; + const state = result ? (result.isError ? "error" : "complete") : isStreaming ? "inprogress" : "inprogress"; + + // Create refs for collapsible sections + const contentRef = createRef(); + const chevronRef = createRef(); // Helper to get command labels const getCommandLabels = (command: string): { streaming: string; complete: string } => { @@ -82,14 +87,16 @@ export class ArtifactsToolRenderer implements ToolRenderer - ${renderHeader(state, FileCode2, headerText)} - ${content ? html`` : ""} - ${ - isHtml - ? html`` - : html`
${result.output || i18n("An error occurred")}
` - } +
+ ${renderCollapsibleHeader(state, FileCode2, headerText, contentRef, chevronRef, false)} +
+ ${content ? html`` : ""} + ${ + isHtml + ? html`` + : html`
${result.output || i18n("An error occurred")}
` + } +
`; } @@ -115,9 +122,11 @@ export class ArtifactsToolRenderer implements ToolRenderer - ${renderHeader(state, FileCode2, headerText)} - +
+ ${renderCollapsibleHeader(state, FileCode2, headerText, contentRef, chevronRef, false)} +
+ +
`; } @@ -126,9 +135,11 @@ export class ArtifactsToolRenderer implements ToolRenderer - ${renderHeader(state, FileCode2, headerText)} - +
+ ${renderCollapsibleHeader(state, FileCode2, headerText, contentRef, chevronRef, false)} +
+ +
`; } @@ -140,10 +151,12 @@ export class ArtifactsToolRenderer implements ToolRenderer - ${renderHeader(state, FileCode2, headerText)} - ${codeContent ? html`` : ""} - ${isHtml && logs ? html`` : ""} +
+ ${renderCollapsibleHeader(state, FileCode2, headerText, contentRef, chevronRef, false)} +
+ ${codeContent ? html`` : ""} + ${isHtml && logs ? html`` : ""} +
`; } @@ -173,31 +186,42 @@ export class ArtifactsToolRenderer implements ToolRenderer - ${renderHeader(state, FileCode2, headerText)} - ${ - content - ? html`` - : "" - } +
+ ${renderCollapsibleHeader(state, FileCode2, headerText, contentRef, chevronRef, false)} +
+ ${ + content + ? html`` + : "" + } +
`; case "update": return html` -
- ${renderHeader(state, FileCode2, headerText)} - ${ - old_str !== undefined && new_str !== undefined - ? Diff({ oldText: old_str, newText: new_str, className: "mt-2" }) - : "" - } +
+ ${renderCollapsibleHeader(state, FileCode2, headerText, contentRef, chevronRef, false)} +
+ ${ + old_str !== undefined && new_str !== undefined + ? Diff({ oldText: old_str, newText: new_str }) + : "" + } +
`; case "get": - case "delete": case "logs": + return html` +
+ ${renderCollapsibleHeader(state, FileCode2, headerText, contentRef, chevronRef, false)} +
+
+ `; + + case "delete": default: return renderHeader(state, FileCode2, headerText); }