char-fork/llama.cpp

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

Aleksander Grygierui: Replace per-conversation MCP overrides with per-conversation tool policy (#27745)fe235f434

char/aliceai-t5-moe
2.0 KiB70 linesraw
1import { page } from '$app/state';
2import { AttachmentAction } from '$lib/enums';
3
4export interface AttachmentModalityFlags {
5	hasVisionModality: boolean;
6	hasAudioModality: boolean;
7	hasVideoModality: boolean;
8}
9
10export interface AttachmentActionCallbacks {
11	onFileUpload?: () => void;
12	onSystemPromptClick?: () => void;
13}
14
15export interface UseAttachmentMenuReturn {
16	readonly callbacks: Record<string, () => void>;
17	isItemEnabled(enabledWhen: string | undefined): boolean;
18	getSystemMessageTooltip(): 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(
33	getFlags: () => AttachmentModalityFlags,
34	getCallbacks: () => AttachmentActionCallbacks,
35	close: () => void
36): UseAttachmentMenuReturn {
37	const modalityFlags = $derived(getFlags());
38	const callbacks = $derived.by(() => {
39		const cbs = getCallbacks();
40		const wrap = (fn?: () => void) => () => {
41			close();
42			fn?.();
43		};
44
45		return {
46			[AttachmentAction.FILE_UPLOAD]: wrap(cbs.onFileUpload),
47			[AttachmentAction.SYSTEM_PROMPT_CLICK]: wrap(cbs.onSystemPromptClick)
48		};
49	});
50
51	function isItemEnabled(enabledWhen: string | undefined): boolean {
52		if (!enabledWhen || enabledWhen === 'always') return true;
53
54		return !!modalityFlags[enabledWhen as keyof AttachmentModalityFlags];
55	}
56
57	function getSystemMessageTooltip(): string {
58		return !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
63	return {
64		get callbacks() {
65			return callbacks;
66		},
67		getSystemMessageTooltip,
68		isItemEnabled
69	};
70}