import { icon } from "@mariozechner/mini-lit"; import "@mariozechner/mini-lit/dist/CopyButton.js"; import { html, LitElement, type TemplateResult } from "lit"; import { customElement, property, state } from "lit/decorators.js"; import { createRef, type Ref, ref } from "lit/directives/ref.js"; import { repeat } from "lit/directives/repeat.js"; import { ChevronDown, ChevronRight, ChevronsDown, Lock } from "lucide"; import { i18n } from "../../utils/i18n.js"; interface LogEntry { type: "log" | "error"; text: string; } @customElement("artifact-console") export class Console extends LitElement { @property({ attribute: false }) logs: LogEntry[] = []; @state() private expanded = false; @state() private autoscroll = true; private logsContainerRef: Ref = createRef(); protected createRenderRoot() { return this; // light DOM } override updated() { // Autoscroll to bottom when new logs arrive if (this.autoscroll && this.expanded && this.logsContainerRef.value) { this.logsContainerRef.value.scrollTop = this.logsContainerRef.value.scrollHeight; } } private getLogsText(): string { return this.logs.map((l) => `[${l.type}] ${l.text}`).join("\n"); } override render(): TemplateResult { const errorCount = this.logs.filter((l) => l.type === "error").length; const summary = errorCount > 0 ? `${i18n("console")} (${errorCount} ${errorCount === 1 ? "error" : "errors"})` : `${i18n("console")} (${this.logs.length})`; return html`
${ this.expanded ? html` ` : "" }
${ this.expanded ? html`
${repeat( this.logs, (_log, index) => index, (log) => html`
[${log.type}] ${log.text}
`, )}
` : "" }
`; } }