char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
fe235f434
char/aliceai-t5-moe
1import { page } from '$app/state' ; 2import { AttachmentAction } from '$lib/enums' ; 3 4export interface AttachmentModalityFlags { 5hasVisionModality :boolean ; 6hasAudioModality :boolean ; 7hasVideoModality :boolean ; 8} 9 10export interface AttachmentActionCallbacks { 11onFileUpload ?:() => void ; 12onSystemPromptClick ?:() => void ; 13} 14 15export interface UseAttachmentMenuReturn { 16readonly callbacks :Record < string , () => void >; 17isItemEnabled ( enabledWhen :string | undefined ) :boolean ; 18getSystemMessageTooltip () :string ; 19} 20 21/** 22* useAttachmentMenu - Shared logic for attachment menu components. 23* 24* Encapsulates the modality-flag checks and callback wrapping that is 25* identical across the desktop dropdown (`ChatFormActionAddDropdown`) 26* and the mobile sheet (`ChatFormActionAddSheet`). 27* 28* @param getFlags - Getter returning the current modality capability flags. 29* @param getCallbacks - Getter returning the raw action callbacks from props. 30* @param close - Function that dismisses the hosting UI element (dropdown / sheet). 31*/ 32export function useAttachmentMenu ( 33getFlags :() => AttachmentModalityFlags , 34getCallbacks :() => AttachmentActionCallbacks , 35close :() => void 36) :UseAttachmentMenuReturn { 37const modalityFlags = $derived ( getFlags ()); 38const callbacks = $derived . by (() => { 39const cbs = getCallbacks (); 40const wrap = ( fn ?:() => void ) => () => { 41close (); 42fn ?.(); 43}; 44 45return { 46[ AttachmentAction . FILE_UPLOAD ] :wrap ( cbs . onFileUpload ), 47[ AttachmentAction . SYSTEM_PROMPT_CLICK ] :wrap ( cbs . onSystemPromptClick ) 48}; 49}); 50 51function isItemEnabled ( enabledWhen :string | undefined ) :boolean { 52if ( ! enabledWhen || enabledWhen === 'always' ) return true ; 53 54return !! modalityFlags [ enabledWhen as keyof AttachmentModalityFlags ]; 55} 56 57function getSystemMessageTooltip () :string { 58return ! page . params . id 59 ?'Add custom system message for a new conversation' 60 :'Inject custom system message at the beginning of the conversation' ; 61} 62 63return { 64get callbacks () { 65return callbacks ; 66}, 67 getSystemMessageTooltip, 68 isItemEnabled 69}; 70}