Pre-MCP UI and architecture cleanup (#19689)

This commit is contained in:
Aleksander Grygier
2026-02-18 12:02:02 +01:00
committed by GitHub
parent d0061be838
commit ea003229d3
52 changed files with 5553 additions and 4325 deletions
+4 -19
View File
@@ -3,8 +3,10 @@ import { AttachmentType } from '$lib/enums';
import type {
DatabaseMessageExtra,
DatabaseMessageExtraTextFile,
DatabaseMessageExtraLegacyContext
} from '$lib/types/database';
DatabaseMessageExtraLegacyContext,
ClipboardTextAttachment,
ParsedClipboardContent
} from '$lib/types';
/**
* Copy text to clipboard with toast notification
@@ -68,23 +70,6 @@ export async function copyCodeToClipboard(
return copyToClipboard(rawCode, successMessage, errorMessage);
}
/**
* Format for text attachments when copied to clipboard
*/
export interface ClipboardTextAttachment {
type: typeof AttachmentType.TEXT;
name: string;
content: string;
}
/**
* Parsed result from clipboard content
*/
export interface ParsedClipboardContent {
message: string;
textAttachments: ClipboardTextAttachment[];
}
/**
* Formats a message with text attachments for clipboard copying.
*
@@ -7,6 +7,7 @@ import { modelsStore } from '$lib/stores/models.svelte';
import { getFileTypeCategory } from '$lib/utils';
import { readFileAsText, isLikelyTextFile } from './text-files';
import { toast } from 'svelte-sonner';
import type { FileProcessingResult, ChatUploadedFile, DatabaseMessageExtra } from '$lib/types';
function readFileAsBase64(file: File): Promise<string> {
return new Promise((resolve, reject) => {
@@ -25,11 +26,6 @@ function readFileAsBase64(file: File): Promise<string> {
});
}
export interface FileProcessingResult {
extras: DatabaseMessageExtra[];
emptyFiles: string[];
}
export async function parseFilesToMessageExtras(
files: ChatUploadedFile[],
activeModelId?: string
+34 -6
View File
@@ -1,3 +1,11 @@
import {
MS_PER_SECOND,
SECONDS_PER_MINUTE,
SECONDS_PER_HOUR,
SHORT_DURATION_THRESHOLD,
MEDIUM_DURATION_THRESHOLD
} from '$lib/constants/formatters';
/**
* Formats file size in bytes to human readable format
* Supports Bytes, KB, MB, and GB
@@ -93,19 +101,19 @@ export function formatTime(date: Date): string {
export function formatPerformanceTime(ms: number): string {
if (ms < 0) return '0s';
const totalSeconds = ms / 1000;
const totalSeconds = ms / MS_PER_SECOND;
if (totalSeconds < 1) {
if (totalSeconds < SHORT_DURATION_THRESHOLD) {
return `${totalSeconds.toFixed(1)}s`;
}
if (totalSeconds < 10) {
if (totalSeconds < MEDIUM_DURATION_THRESHOLD) {
return `${totalSeconds.toFixed(1)}s`;
}
const hours = Math.floor(totalSeconds / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = Math.floor(totalSeconds % 60);
const hours = Math.floor(totalSeconds / SECONDS_PER_HOUR);
const minutes = Math.floor((totalSeconds % SECONDS_PER_HOUR) / SECONDS_PER_MINUTE);
const seconds = Math.floor(totalSeconds % SECONDS_PER_MINUTE);
const parts: string[] = [];
@@ -123,3 +131,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}`;
}
+29 -8
View File
@@ -13,10 +13,7 @@ export { apiFetch, apiFetchWithParams, apiPost, type ApiFetchOptions } from './a
export { validateApiKey } from './api-key-validation';
// Attachment utilities
export {
getAttachmentDisplayItems,
type AttachmentDisplayItemsOptions
} from './attachment-display';
export { getAttachmentDisplayItems } from './attachment-display';
export { isTextFile, isImageFile, isPdfFile, isAudioFile } from './attachment-type';
// Textarea utilities
@@ -46,9 +43,7 @@ export {
copyCodeToClipboard,
formatMessageForClipboard,
parseClipboardContent,
hasClipboardAttachments,
type ClipboardTextAttachment,
type ParsedClipboardContent
hasClipboardAttachments
} from './clipboard';
// File preview utilities
@@ -64,7 +59,15 @@ export {
} from './file-type';
// Formatting utilities
export { formatFileSize, formatParameters, formatNumber } from './formatters';
export {
formatFileSize,
formatParameters,
formatNumber,
formatJsonPretty,
formatTime,
formatPerformanceTime,
formatAttachmentText
} from './formatters';
// IME utilities
export { isIMEComposing } from './is-ime-composing';
@@ -94,5 +97,23 @@ export { getLanguageFromFilename } from './syntax-highlight-language';
// Text file utilities
export { isTextFileByName, readFileAsText, isLikelyTextFile } from './text-files';
// Debounce utilities
export { debounce } from './debounce';
// Image error fallback utilities
export { getImageErrorFallbackHtml } from './image-error-fallback';
// Data URL utilities
export { createBase64DataUrl } from './data-url';
// Cache utilities
export { TTLCache, ReactiveTTLMap, type TTLCacheOptions } from './cache-ttl';
// Abort signal utilities
export {
throwIfAborted,
isAbortError,
createLinkedController,
createTimeoutSignal,
withAbortSignal
} from './abort';