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';
8 ATTACHMENT_EXTRA_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';
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 }]>;
33 class: className = '',
35 hasAudioModality = false,
36 hasVisionModality = false,
37 hasMcpPromptsSupport = false,
38 hasMcpResourcesSupport = false,
46 let sheetOpen = $state(false);
48 const attachmentMenu = useAttachmentMenu(
49 () => ({ hasVisionModality, hasAudioModality, hasMcpPromptsSupport, hasMcpResourcesSupport }),
50 () => ({ onFileUpload, onSystemPromptClick, onMcpPromptClick, onMcpResourcesClick }),
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';
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)} /> -->
65 <Sheet.Content side="bottom" class="max-h-[85vh] gap-0 overflow-y-auto">
67 <Sheet.Title>Add to chat</Sheet.Title>
69 <Sheet.Description class="sr-only">
70 Add files, system prompt or configure MCP servers
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)}
80 class={sheetItemClass}
81 onclick={() => attachmentMenu.callbacks[item.action]()}
83 <item.icon class="h-4 w-4 shrink-0" />
85 <span>{item.label}</span>
87 {:else if item.disabledTooltip}
88 <Tooltip.Root delayDuration={TOOLTIP_DELAY_DURATION}>
90 <button type="button" class={sheetItemClass} disabled>
91 <item.icon class="h-4 w-4 shrink-0" />
93 <span>{item.label}</span>
97 <Tooltip.Content side="right">
98 <p>{item.disabledTooltip}</p>
104 {#if !attachmentMenu.isItemEnabled('hasVisionModality')}
105 {@const pdfItem = ATTACHMENT_FILE_ITEMS.find((i) => i.id === AttachmentMenuItemId.PDF)}
107 <Tooltip.Root delayDuration={TOOLTIP_DELAY_DURATION}>
111 class={sheetItemClass}
112 onclick={() => attachmentMenu.callbacks[pdfItem.action]()}
114 <pdfItem.icon class="h-4 w-4 shrink-0" />
116 <span>{pdfItem.label}</span>
120 <Tooltip.Content side="right">
121 <p>PDFs will be converted to text. Image-based PDFs may not work properly.</p>
127 {#each ATTACHMENT_EXTRA_ITEMS as item (item.id)}
128 {#if item.id === AttachmentMenuItemId.SYSTEM_MESSAGE}
129 <Tooltip.Root delayDuration={TOOLTIP_DELAY_DURATION}>
133 class={sheetItemClass}
134 onclick={() => attachmentMenu.callbacks[item.action]()}
136 <item.icon class="h-4 w-4 shrink-0" />
138 <span>{item.label}</span>
142 <Tooltip.Content side="right">
143 <p>{attachmentMenu.getSystemMessageTooltip()}</p>
149 <div class="my-2 border-t"></div>
151 <a href={ROUTES.MCP_SERVERS} class="flex items-center gap-3 px-3 py-2">
152 <McpLogo class="inline h-4 w-4" />
154 <span class="text-sm">MCP Servers</span>
158 href={RouterService.settings(SETTINGS_SECTION_SLUGS.TOOLS)}
159 class="flex items-center gap-3 px-3 py-2"
161 <PencilRuler class="inline h-4 w-4" />
163 <span class="text-sm">Tools</span>
166 {#each ATTACHMENT_MCP_ITEMS as item (item.id)}
167 {#if attachmentMenu.isItemVisible(item.visibleWhen)}
170 class={sheetItemClass}
171 onclick={() => attachmentMenu.callbacks[item.action]()}
173 <item.icon class="h-4 w-4 shrink-0" />
175 <span>{item.label}</span>