diff --git a/tools/server/webui/src/lib/services/chat.service.ts b/tools/server/webui/src/lib/services/chat.service.ts index f61d712187..06f961155e 100644 --- a/tools/server/webui/src/lib/services/chat.service.ts +++ b/tools/server/webui/src/lib/services/chat.service.ts @@ -1,4 +1,5 @@ import { getJsonHeaders } from '$lib/utils'; +import { formatAttachmentText } from '$lib/utils/attachment-display'; import { AGENTIC_REGEX } from '$lib/constants/agentic'; import { AttachmentType, MessageRole, ReasoningFormat } from '$lib/enums'; import type { ApiChatMessageContentPart } from '$lib/types/api'; @@ -671,7 +672,7 @@ export class ChatService { for (const textFile of textFiles) { contentParts.push({ type: 'text', - text: `\n\n--- File: ${textFile.name} ---\n${textFile.content}` + text: formatAttachmentText('File', textFile.name, textFile.content) }); } @@ -684,7 +685,7 @@ export class ChatService { for (const legacyContextFile of legacyContextFiles) { contentParts.push({ type: 'text', - text: `\n\n--- File: ${legacyContextFile.name} ---\n${legacyContextFile.content}` + text: formatAttachmentText('File', legacyContextFile.name, legacyContextFile.content) }); } @@ -719,7 +720,7 @@ export class ChatService { } else { contentParts.push({ type: 'text', - text: `\n\n--- PDF File: ${pdfFile.name} ---\n${pdfFile.content}` + text: formatAttachmentText('PDF File', pdfFile.name, pdfFile.content) }); } } @@ -732,7 +733,12 @@ export class ChatService { for (const mcpPrompt of mcpPrompts) { contentParts.push({ type: 'text', - text: `\n\n--- MCP Prompt: ${mcpPrompt.name} (${mcpPrompt.serverName}) ---\n${mcpPrompt.content}` + text: formatAttachmentText( + 'MCP Prompt', + mcpPrompt.name, + mcpPrompt.content, + mcpPrompt.serverName + ) }); } diff --git a/tools/server/webui/src/lib/utils/attachment-display.ts b/tools/server/webui/src/lib/utils/attachment-display.ts index de80c9b28c..78e7afa863 100644 --- a/tools/server/webui/src/lib/utils/attachment-display.ts +++ b/tools/server/webui/src/lib/utils/attachment-display.ts @@ -1,6 +1,26 @@ import { AttachmentType, FileTypeCategory, SpecialFileType } from '$lib/enums'; import { getFileTypeCategory, getFileTypeCategoryByExtension, isImageFile } from '$lib/utils'; +/** + * Formats attachment content for API requests with consistent header style. + * Used when converting message attachments to text content parts. + * + * @param label - Type label (e.g., 'File', 'PDF File', 'MCP Prompt') + * @param name - File or attachment name + * @param content - The actual content to include + * @param extra - Optional extra info to append to name (e.g., server name for MCP) + * @returns Formatted string with header and content + */ +export function formatAttachmentText( + label: string, + name: string, + content: string, + extra?: string +): string { + const header = extra ? `${name} (${extra})` : name; + return `\n\n--- ${label}: ${header} ---\n${content}`; +} + export interface AttachmentDisplayItemsOptions { uploadedFiles?: ChatUploadedFile[]; attachments?: DatabaseMessageExtra[];