refactor: Utility function

This commit is contained in:
Aleksander Grygier 2026-01-26 09:00:41 +01:00
parent 5ee232d81c
commit 176abf3175
4 changed files with 23 additions and 23 deletions

View File

@ -1,5 +1,4 @@
import { getJsonHeaders } from '$lib/utils';
import { formatAttachmentText } from '$lib/utils/attachment-display';
import { getJsonHeaders, formatAttachmentText } from '$lib/utils';
import { AGENTIC_REGEX } from '$lib/constants/agentic';
import { AttachmentType, MessageRole, ReasoningFormat } from '$lib/enums';
import type { ApiChatMessageContentPart } from '$lib/types/api';

View File

@ -6,26 +6,6 @@ import type {
DatabaseMessageExtra
} from '$lib/types';
/**
* 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}`;
}
/**
* Check if an uploaded file is an MCP prompt
*/

View File

@ -123,3 +123,23 @@ export function formatPerformanceTime(ms: number): string {
return parts.join(' ');
}
/**
* 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}`;
}

View File

@ -64,7 +64,8 @@ export {
formatNumber,
formatJsonPretty,
formatTime,
formatPerformanceTime
formatPerformanceTime,
formatAttachmentText
} from './formatters';
// IME utilities