Fix web-ui and example for new agent API

- AgentInterface composes UserMessageWithAttachments for attachments
- Updated example to use convertToLlm instead of transport/messageTransformer
- Fixed declaration merging: target pi-agent-core, add path to example tsconfig
- Fixed typo in CustomAgentMessages key (user-with-attachment -> user-with-attachments)
- customMessageTransformer properly converts UserMessageWithAttachments to content blocks
This commit is contained in:
Mario Zechner 2025-12-28 11:01:12 +01:00
parent 6ddc7418da
commit 7a39f9eb11
6 changed files with 70 additions and 24 deletions

View file

@ -12,6 +12,7 @@ import type { Agent, AgentEvent } from "@mariozechner/pi-agent-core";
import type { Attachment } from "../utils/attachment-utils.js";
import { formatUsage } from "../utils/format.js";
import { i18n } from "../utils/i18n.js";
import type { UserMessageWithAttachments } from "./Messages.js";
import type { StreamingMessageContainer } from "./StreamingMessageContainer.js";
@customElement("agent-interface")
@ -202,7 +203,18 @@ export class AgentInterface extends LitElement {
this._messageEditor.attachments = [];
this._autoScroll = true; // Enable auto-scroll when sending a message
await this.session?.prompt(input, attachments);
// Compose message with attachments if any
if (attachments && attachments.length > 0) {
const message: UserMessageWithAttachments = {
role: "user-with-attachments",
content: input,
attachments,
timestamp: Date.now(),
};
await this.session?.prompt(message);
} else {
await this.session?.prompt(input);
}
}
private renderMessages() {

View file

@ -9,6 +9,7 @@ import { Brain, Loader2, Paperclip, Send, Sparkles, Square } from "lucide";
import { type Attachment, loadAttachment } from "../utils/attachment-utils.js";
import { i18n } from "../utils/i18n.js";
import "./AttachmentTile.js";
import type { ThinkingLevel } from "@mariozechner/pi-agent-core";
@customElement("message-editor")
export class MessageEditor extends LitElement {
@ -28,7 +29,7 @@ export class MessageEditor extends LitElement {
@property() isStreaming = false;
@property() currentModel?: Model<any>;
@property() thinkingLevel: "off" | "minimal" | "low" | "medium" | "high" = "off";
@property() thinkingLevel: ThinkingLevel = "off";
@property() showAttachmentButton = true;
@property() showModelSelector = true;
@property() showThinkingSelector = true;

View file

@ -34,7 +34,7 @@ export interface ArtifactMessage {
declare module "@mariozechner/pi-agent-core" {
interface CustomAgentMessages {
"user-with-attachment": UserMessageWithAttachments;
"user-with-attachments": UserMessageWithAttachments;
artifact: ArtifactMessage;
}
}