import type { AssistantMessage as AssistantMessageType, ImageContent, TextContent, ToolCall, ToolResultMessage as ToolResultMessageType, UserMessage as UserMessageType, } from "@mariozechner/pi-ai"; import { html, LitElement, type TemplateResult } from "lit"; import { customElement, property } from "lit/decorators.js"; import { renderTool } from "../tools/index.js"; import type { Attachment } from "../utils/attachment-utils.js"; import { formatUsage } from "../utils/format.js"; import { i18n } from "../utils/i18n.js"; import "./ThinkingBlock.js"; import type { AgentTool } from "@mariozechner/pi-agent-core"; export type UserMessageWithAttachments = { role: "user-with-attachments"; content: string | (TextContent | ImageContent)[]; timestamp: number; attachments?: Attachment[]; }; // Artifact message type for session persistence export interface ArtifactMessage { role: "artifact"; action: "create" | "update" | "delete"; filename: string; content?: string; title?: string; timestamp: string; } declare module "@mariozechner/pi-agent-core" { interface CustomAgentMessages { "user-with-attachments": UserMessageWithAttachments; artifact: ArtifactMessage; } } @customElement("user-message") export class UserMessage extends LitElement { @property({ type: Object }) message!: UserMessageWithAttachments | UserMessageType; protected override createRenderRoot(): HTMLElement | DocumentFragment { return this; } override connectedCallback(): void { super.connectedCallback(); this.style.display = "block"; } override render() { const content = typeof this.message.content === "string" ? this.message.content : this.message.content.find((c) => c.type === "text")?.text || ""; return html`