import { html } from "@mariozechner/mini-lit"; import type { Model } from "@mariozechner/pi-ai"; import { getModel } from "@mariozechner/pi-ai"; import { LitElement } from "lit"; import { customElement, state } from "lit/decorators.js"; import { ModelSelector } from "./dialogs/ModelSelector.js"; import "./MessageEditor.js"; import type { Attachment } from "./utils/attachment-utils.js"; @customElement("pi-chat-panel") export class ChatPanel extends LitElement { @state() currentModel: Model | null = null; @state() messageText = ""; @state() attachments: Attachment[] = []; createRenderRoot() { return this; } override async connectedCallback() { super.connectedCallback(); // Set default model this.currentModel = getModel("anthropic", "claude-3-5-haiku-20241022"); } private handleSend = (text: string, attachments: Attachment[]) => { // For now just alert and clear alert(`Message: ${text}\nAttachments: ${attachments.length}`); this.messageText = ""; this.attachments = []; }; private handleModelSelect = () => { ModelSelector.open(this.currentModel, (model) => { this.currentModel = model; }); }; render() { return html`
{ this.messageText = value; }} .onSend=${this.handleSend} .onModelSelect=${this.handleModelSelect} .onFilesChange=${(files: Attachment[]) => { this.attachments = files; }} >
`; } }