char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
92d1bb0c9
char/aliceai-t5-moe
1import { AttachmentType , FileTypeCategory , SpecialFileType } from '$lib/enums' ; 2import type { 3AttachmentDisplayItemsOptions , 4ChatAttachmentDisplayItem , 5ChatUploadedFile 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 { 14if ( item . attachment ?. type === AttachmentType . MCP_PROMPT ) { 15return true ; 16} 17 18if ( item . uploadedFile ?. type === SpecialFileType . MCP_PROMPT && item . uploadedFile . mcpPrompt ) { 19return true ; 20} 21 22return false ; 23} 24 25/** 26* Check if a display item represents an MCP resource 27*/ 28export function isMcpResource ( item :ChatAttachmentDisplayItem ) :boolean { 29return 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 { 36const categoryByMime = getFileTypeCategory ( file . type ); 37 38if ( categoryByMime ) { 39return categoryByMime ; 40} 41 42return 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 ( 50options :AttachmentDisplayItemsOptions 51) :ChatAttachmentDisplayItem [] { 52const { attachments= [], uploadedFiles= [] } = options ; 53const items :ChatAttachmentDisplayItem [] = []; 54 55// Add uploaded files (ChatForm) 56for ( const file of uploadedFiles ) { 57items . push ({ 58id :file . id , 59isImage :getUploadedFileCategory ( file ) === FileTypeCategory . IMAGE , 60isLoading :file . isLoading , 61loadError :file . loadError , 62name :file . name , 63preview :file . preview , 64size :file . size , 65textContent :file . textContent , 66uploadedFile :file 67}); 68} 69 70// Add stored attachments (ChatMessage) 71for ( const [ index , attachment ] of attachments . entries ()) { 72const isImage = isImageFile ( attachment ); 73 74items . push ({ 75 attachment, 76attachmentIndex :index , 77id :`attachment- ${ index } ` , 78 isImage, 79name :attachment . name , 80preview :isImage && 'base64Url' in attachment ?attachment . base64Url :undefined , 81size :'size' in attachment ?attachment . size :undefined , 82textContent :'content' in attachment ?attachment . content :undefined 83}); 84} 85 86return items . reverse (); 87}