]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/blob
99daa10e3e2902681ec00e09df8523b515de27d1
[pkg/ggml/sources/llama.cpp] /
1 <script lang="ts">
2 import type { Snippet } from 'svelte';
3 import * as Tooltip from '$lib/components/ui/tooltip';
4 import * as Sheet from '$lib/components/ui/sheet';
5 import { TOOLTIP_DELAY_DURATION } from '$lib/constants';
6 import {
7 ATTACHMENT_FILE_ITEMS,
8 ATTACHMENT_EXTRA_ITEMS,
9 ATTACHMENT_MCP_ITEMS
10 } from '$lib/constants/attachment-menu';
11 import { McpLogo } from '$lib/components/app';
12 import { useAttachmentMenu } from '$lib/hooks/use-attachment-menu.svelte';
13 import { AttachmentMenuItemId } from '$lib/enums';
14 import { PencilRuler } from '@lucide/svelte';
15 import { ROUTES, SETTINGS_SECTION_SLUGS } from '$lib/constants/routes';
16 import { RouterService } from '$lib/services/router.service';
17
18 interface Props {
19 class?: string;
20 disabled?: boolean;
21 hasAudioModality?: boolean;
22 hasVisionModality?: boolean;
23 hasMcpPromptsSupport?: boolean;
24 hasMcpResourcesSupport?: boolean;
25 onFileUpload?: () => void;
26 onSystemPromptClick?: () => void;
27 onMcpPromptClick?: () => void;
28 onMcpResourcesClick?: () => void;
29 trigger: Snippet<[{ disabled: boolean; onclick?: () => void }]>;
30 }
31
32 let {
33 class: className = '',
34 disabled = false,
35 hasAudioModality = false,
36 hasVisionModality = false,
37 hasMcpPromptsSupport = false,
38 hasMcpResourcesSupport = false,
39 onFileUpload,
40 onSystemPromptClick,
41 onMcpPromptClick,
42 onMcpResourcesClick,
43 trigger
44 }: Props = $props();
45
46 let sheetOpen = $state(false);
47
48 const attachmentMenu = useAttachmentMenu(
49 () => ({ hasVisionModality, hasAudioModality, hasMcpPromptsSupport, hasMcpResourcesSupport }),
50 () => ({ onFileUpload, onSystemPromptClick, onMcpPromptClick, onMcpResourcesClick }),
51 () => {
52 sheetOpen = false;
53 }
54 );
55
56 const sheetItemClass =
57 'flex w-full items-center gap-3 rounded-md px-3 py-2.5 text-left text-sm transition-colors hover:bg-accent active:bg-accent disabled:cursor-not-allowed disabled:opacity-50';
58 </script>
59
60 <div class="flex items-center gap-1 {className}">
61 <Sheet.Root bind:open={sheetOpen}>
62 {@render trigger({ disabled, onclick: () => (sheetOpen = true) })}
63 <!-- <ChatFormActionAddButton {disabled} onclick={() => (sheetOpen = true)} /> -->
64
65 <Sheet.Content side="bottom" class="max-h-[85vh] gap-0 overflow-y-auto">
66 <Sheet.Header>
67 <Sheet.Title>Add to chat</Sheet.Title>
68
69 <Sheet.Description class="sr-only">
70 Add files, system prompt or configure MCP servers
71 </Sheet.Description>
72 </Sheet.Header>
73
74 <div class="flex flex-col gap-1 px-1.5 pb-2">
75 {#each ATTACHMENT_FILE_ITEMS as item (item.id)}
76 {@const enabled = attachmentMenu.isItemEnabled(item.enabledWhen)}
77 {#if enabled}
78 <button
79 type="button"
80 class={sheetItemClass}
81 onclick={() => attachmentMenu.callbacks[item.action]()}
82 >
83 <item.icon class="h-4 w-4 shrink-0" />
84
85 <span>{item.label}</span>
86 </button>
87 {:else if item.disabledTooltip}
88 <Tooltip.Root delayDuration={TOOLTIP_DELAY_DURATION}>
89 <Tooltip.Trigger>
90 <button type="button" class={sheetItemClass} disabled>
91 <item.icon class="h-4 w-4 shrink-0" />
92
93 <span>{item.label}</span>
94 </button>
95 </Tooltip.Trigger>
96
97 <Tooltip.Content side="right">
98 <p>{item.disabledTooltip}</p>
99 </Tooltip.Content>
100 </Tooltip.Root>
101 {/if}
102 {/each}
103
104 {#if !attachmentMenu.isItemEnabled('hasVisionModality')}
105 {@const pdfItem = ATTACHMENT_FILE_ITEMS.find((i) => i.id === AttachmentMenuItemId.PDF)}
106 {#if pdfItem}
107 <Tooltip.Root delayDuration={TOOLTIP_DELAY_DURATION}>
108 <Tooltip.Trigger>
109 <button
110 type="button"
111 class={sheetItemClass}
112 onclick={() => attachmentMenu.callbacks[pdfItem.action]()}
113 >
114 <pdfItem.icon class="h-4 w-4 shrink-0" />
115
116 <span>{pdfItem.label}</span>
117 </button>
118 </Tooltip.Trigger>
119
120 <Tooltip.Content side="right">
121 <p>PDFs will be converted to text. Image-based PDFs may not work properly.</p>
122 </Tooltip.Content>
123 </Tooltip.Root>
124 {/if}
125 {/if}
126
127 {#each ATTACHMENT_EXTRA_ITEMS as item (item.id)}
128 {#if item.id === AttachmentMenuItemId.SYSTEM_MESSAGE}
129 <Tooltip.Root delayDuration={TOOLTIP_DELAY_DURATION}>
130 <Tooltip.Trigger>
131 <button
132 type="button"
133 class={sheetItemClass}
134 onclick={() => attachmentMenu.callbacks[item.action]()}
135 >
136 <item.icon class="h-4 w-4 shrink-0" />
137
138 <span>{item.label}</span>
139 </button>
140 </Tooltip.Trigger>
141
142 <Tooltip.Content side="right">
143 <p>{attachmentMenu.getSystemMessageTooltip()}</p>
144 </Tooltip.Content>
145 </Tooltip.Root>
146 {/if}
147 {/each}
148
149 <div class="my-2 border-t"></div>
150
151 <a href={ROUTES.MCP_SERVERS} class="flex items-center gap-3 px-3 py-2">
152 <McpLogo class="inline h-4 w-4" />
153
154 <span class="text-sm">MCP Servers</span>
155 </a>
156
157 <a
158 href={RouterService.settings(SETTINGS_SECTION_SLUGS.TOOLS)}
159 class="flex items-center gap-3 px-3 py-2"
160 >
161 <PencilRuler class="inline h-4 w-4" />
162
163 <span class="text-sm">Tools</span>
164 </a>
165
166 {#each ATTACHMENT_MCP_ITEMS as item (item.id)}
167 {#if attachmentMenu.isItemVisible(item.visibleWhen)}
168 <button
169 type="button"
170 class={sheetItemClass}
171 onclick={() => attachmentMenu.callbacks[item.action]()}
172 >
173 <item.icon class="h-4 w-4 shrink-0" />
174
175 <span>{item.label}</span>
176 </button>
177 {/if}
178 {/each}
179 </div>
180 </Sheet.Content>
181 </Sheet.Root>
182 </div>