char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Aleksander Grygierui: Linting & Formatting scripts (#26819)92d1bb0c9

char/aliceai-t5-moe
2.5 KiB87 linesraw
1import { AttachmentType, FileTypeCategory, SpecialFileType } from '$lib/enums';
2import type {
3	AttachmentDisplayItemsOptions,
4	ChatAttachmentDisplayItem,
5	ChatUploadedFile
6} from '$lib/types';
7import { getFileTypeCategory, getFileTypeCategoryByExtension, isImageFile } from '$lib/utils';
8
9/**
10 * Check if a display item represents an MCP prompt
11 * (either from attachment type or uploaded file with mcpPrompt metadata)
12 */
13export function isMcpPrompt(item: ChatAttachmentDisplayItem): boolean {
14	if (item.attachment?.type === AttachmentType.MCP_PROMPT) {
15		return true;
16	}
17
18	if (item.uploadedFile?.type === SpecialFileType.MCP_PROMPT && item.uploadedFile.mcpPrompt) {
19		return true;
20	}
21
22	return false;
23}
24
25/**
26 * Check if a display item represents an MCP resource
27 */
28export function isMcpResource(item: ChatAttachmentDisplayItem): boolean {
29	return item.attachment?.type === AttachmentType.MCP_RESOURCE;
30}
31
32/**
33 * Gets the file type category from an uploaded file, checking both MIME type and extension
34 */
35function getUploadedFileCategory(file: ChatUploadedFile): FileTypeCategory | null {
36	const categoryByMime = getFileTypeCategory(file.type);
37
38	if (categoryByMime) {
39		return categoryByMime;
40	}
41
42	return getFileTypeCategoryByExtension(file.name);
43}
44
45/**
46 * Creates a unified list of display items from uploaded files and stored attachments.
47 * Items are returned in reverse order (newest first).
48 */
49export function getAttachmentDisplayItems(
50	options: AttachmentDisplayItemsOptions
51): ChatAttachmentDisplayItem[] {
52	const { attachments = [], uploadedFiles = [] } = options;
53	const items: ChatAttachmentDisplayItem[] = [];
54
55	// Add uploaded files (ChatForm)
56	for (const file of uploadedFiles) {
57		items.push({
58			id: file.id,
59			isImage: getUploadedFileCategory(file) === FileTypeCategory.IMAGE,
60			isLoading: file.isLoading,
61			loadError: file.loadError,
62			name: file.name,
63			preview: file.preview,
64			size: file.size,
65			textContent: file.textContent,
66			uploadedFile: file
67		});
68	}
69
70	// Add stored attachments (ChatMessage)
71	for (const [index, attachment] of attachments.entries()) {
72		const isImage = isImageFile(attachment);
73
74		items.push({
75			attachment,
76			attachmentIndex: index,
77			id: `attachment-${index}`,
78			isImage,
79			name: attachment.name,
80			preview: isImage && 'base64Url' in attachment ? attachment.base64Url : undefined,
81			size: 'size' in attachment ? attachment.size : undefined,
82			textContent: 'content' in attachment ? attachment.content : undefined
83		});
84	}
85
86	return items.reverse();
87}