From 3ecaaa593725855d6b4135dee0ac61827e7abb65 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Fri, 26 Dec 2025 22:50:04 +0100 Subject: [PATCH] Fix CustomMessageEntry content type to match UserMessage content: string | (TextContent | ImageContent)[] This matches the UserMessage type from pi-ai, so content can be passed directly to AppMessage without conversion. --- .../coding-agent/docs/session-tree-plan.md | 8 ++--- .../coding-agent/src/core/session-manager.ts | 33 ++++--------------- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/packages/coding-agent/docs/session-tree-plan.md b/packages/coding-agent/docs/session-tree-plan.md index b6ac5f45..204cb598 100644 --- a/packages/coding-agent/docs/session-tree-plan.md +++ b/packages/coding-agent/docs/session-tree-plan.md @@ -110,10 +110,10 @@ Hook-injected messages that participate in LLM context. Unlike `CustomEntry` ```typescript export interface CustomMessageEntry extends SessionEntryBase { type: "custom_message"; - customType: string; // Hook identifier - content: (string | Attachment)[]; // Message content - details?: T; // Hook-specific data for state reconstruction on reload - display: boolean; // Whether to display in TUI + customType: string; // Hook identifier + content: string | (TextContent | ImageContent)[]; // Message content (same as UserMessage) + details?: T; // Hook-specific data for state reconstruction on reload + display: boolean; // Whether to display in TUI } ``` diff --git a/packages/coding-agent/src/core/session-manager.ts b/packages/coding-agent/src/core/session-manager.ts index 02e43194..ed6fbdfb 100644 --- a/packages/coding-agent/src/core/session-manager.ts +++ b/packages/coding-agent/src/core/session-manager.ts @@ -1,4 +1,5 @@ -import type { AppMessage, Attachment } from "@mariozechner/pi-agent-core"; +import type { AppMessage } from "@mariozechner/pi-agent-core"; +import type { ImageContent, TextContent } from "@mariozechner/pi-ai"; import { randomUUID } from "crypto"; import { appendFileSync, @@ -101,7 +102,7 @@ export interface LabelEntry extends SessionEntryBase { export interface CustomMessageEntry extends SessionEntryBase { type: "custom_message"; customType: string; - content: (string | Attachment)[]; + content: string | (TextContent | ImageContent)[]; details?: T; display: boolean; } @@ -161,31 +162,11 @@ export function createSummaryMessage(summary: string, timestamp: string): AppMes }; } -/** Convert CustomMessageEntry content to AppMessage format */ +/** Convert CustomMessageEntry to AppMessage format */ function createCustomMessage(entry: CustomMessageEntry): AppMessage { - // Convert content array to AppMessage content format - const content = entry.content.map((item) => { - if (typeof item === "string") { - return { type: "text" as const, text: item }; - } - // Attachment - convert to appropriate content type - if (item.type === "image") { - return { - type: "image" as const, - data: item.content, - mimeType: item.mimeType, - }; - } - // Document attachment - use extracted text or indicate document - return { - type: "text" as const, - text: item.extractedText ?? `[Document: ${item.fileName}]`, - }; - }); - return { role: "user", - content, + content: entry.content, timestamp: new Date(entry.timestamp).getTime(), }; } @@ -684,14 +665,14 @@ export class SessionManager { /** * Append a custom message entry (for hooks) that participates in LLM context. * @param customType Hook identifier for filtering on reload - * @param content Message content (strings and attachments) + * @param content Message content (string or TextContent/ImageContent array) * @param display Whether to show in TUI (true = styled display, false = hidden) * @param details Optional hook-specific metadata (not sent to LLM) * @returns Entry id */ appendCustomMessageEntry( customType: string, - content: (string | Attachment)[], + content: string | (TextContent | ImageContent)[], display: boolean, details?: T, ): string {