= {
create: { streaming: i18n("Creating artifact"), complete: i18n("Created artifact") },
update: { streaming: i18n("Updating artifact"), complete: i18n("Updated artifact") },
rewrite: { streaming: i18n("Rewriting artifact"), complete: i18n("Rewrote artifact") },
get: { streaming: i18n("Getting artifact"), complete: i18n("Got artifact") },
delete: { streaming: i18n("Deleting artifact"), complete: i18n("Deleted artifact") },
logs: { streaming: i18n("Getting logs"), complete: i18n("Got logs") },
};
return labels[command] || { streaming: i18n("Processing artifact"), complete: i18n("Processed artifact") };
};
// Helper to render header text with inline artifact pill
const renderHeaderWithPill = (labelText: string, filename?: string): TemplateResult => {
if (filename) {
return html`${labelText} ${ArtifactPill(filename, this.artifactsPanel)}`;
}
return html`${labelText}`;
};
// Error handling
if (result?.isError) {
const command = params?.command;
const filename = params?.filename;
const labels = command
? getCommandLabels(command)
: { streaming: i18n("Processing artifact"), complete: i18n("Processed artifact") };
const headerText = labels.streaming;
// For create/update/rewrite errors, show code block + console/error
if (command === "create" || command === "update" || command === "rewrite") {
const content = params?.content || "";
const { old_str, new_str } = params || {};
const isDiff = command === "update";
const diffContent =
old_str !== undefined && new_str !== undefined ? Diff({ oldText: old_str, newText: new_str }) : "";
const isHtml = filename?.endsWith(".html");
return html`
${renderCollapsibleHeader(state, FileCode2, renderHeaderWithPill(headerText, filename), contentRef, chevronRef, false)}
${isDiff ? diffContent : content ? html`
` : ""}
${
isHtml
? html`
`
: html`
${result.output || i18n("An error occurred")}
`
}
`;
}
// For other errors, just show error message
return html`
${renderHeader(state, FileCode2, headerText)}
${result.output || i18n("An error occurred")}
`;
}
// Full params + result
if (result && params) {
const { command, filename, content } = params;
const labels = command
? getCommandLabels(command)
: { streaming: i18n("Processing artifact"), complete: i18n("Processed artifact") };
const headerText = labels.complete;
// GET command: show code block with file content
if (command === "get") {
const fileContent = result.output || i18n("(no output)");
return html`
${renderCollapsibleHeader(state, FileCode2, renderHeaderWithPill(headerText, filename), contentRef, chevronRef, false)}
`;
}
// LOGS command: show console block
if (command === "logs") {
const logs = result.output || i18n("(no output)");
return html`
${renderCollapsibleHeader(state, FileCode2, renderHeaderWithPill(headerText, filename), contentRef, chevronRef, false)}
`;
}
// CREATE/UPDATE/REWRITE: always show code block, + console block for .html files
if (command === "create" || command === "rewrite") {
const codeContent = content || "";
const isHtml = filename?.endsWith(".html");
const logs = result.output || "";
return html`
${renderCollapsibleHeader(state, FileCode2, renderHeaderWithPill(headerText, filename), contentRef, chevronRef, false)}
${codeContent ? html`` : ""}
${isHtml && logs ? html`` : ""}
`;
}
if (command === "update") {
const isHtml = filename?.endsWith(".html");
const logs = result.output || "";
return html`
${renderCollapsibleHeader(state, FileCode2, renderHeaderWithPill(headerText, filename), contentRef, chevronRef, false)}
${Diff({ oldText: params.old_str || "", newText: params.new_str || "" })}
${isHtml && logs ? html`` : ""}
`;
}
// For DELETE, just show header
return html`
${renderHeader(state, FileCode2, renderHeaderWithPill(headerText, filename))}
`;
}
// Params only (streaming or waiting for result)
if (params) {
const { command, filename, content, old_str, new_str } = params;
// If no command yet
if (!command) {
return renderHeader(state, FileCode2, i18n("Preparing artifact..."));
}
const labels = getCommandLabels(command);
const headerText = labels.streaming;
// Render based on command type
switch (command) {
case "create":
case "rewrite":
return html`
${renderCollapsibleHeader(state, FileCode2, renderHeaderWithPill(headerText, filename), contentRef, chevronRef, false)}
${
content
? html``
: ""
}
`;
case "update":
return html`
${renderCollapsibleHeader(state, FileCode2, renderHeaderWithPill(headerText, filename), contentRef, chevronRef, false)}
${
old_str !== undefined && new_str !== undefined
? Diff({ oldText: old_str, newText: new_str })
: ""
}
`;
case "get":
case "logs":
return html`
${renderCollapsibleHeader(state, FileCode2, renderHeaderWithPill(headerText, filename), contentRef, chevronRef, false)}
`;
default:
return html`
${renderHeader(state, FileCode2, renderHeaderWithPill(headerText, filename))}
`;
}
}
// No params or result yet
return renderHeader(state, FileCode2, i18n("Preparing artifact..."));
}
}