2 import { File, FolderOpen, MessageSquare, Zap } from '@lucide/svelte';
10 } from '@lucide/svelte';
11 import { McpLogo } from '$lib/components/app';
12 import { Checkbox } from '$lib/components/ui/checkbox';
13 import * as Collapsible from '$lib/components/ui/collapsible';
14 import * as Sheet from '$lib/components/ui/sheet';
15 import { Switch } from '$lib/components/ui/switch';
16 import * as Tooltip from '$lib/components/ui/tooltip';
18 ATTACHMENT_FILE_ITEMS,
20 TOOLTIP_DELAY_DURATION
21 } from '$lib/constants';
22 import { HealthCheckStatus } from '$lib/enums';
23 import { AttachmentAction } from '$lib/enums/attachment.enums';
24 import { useAttachmentMenu } from '$lib/hooks/use-attachment-menu.svelte';
25 import { useReasoningMenu } from '$lib/hooks/use-reasoning-menu.svelte';
26 import { useToolsPanel } from '$lib/hooks/use-tools-panel.svelte';
27 import { conversationsStore, mcpStore } from '$lib/stores';
28 import type { Snippet } from 'svelte';
33 hasAudioModality?: boolean;
34 hasVideoModality?: boolean;
35 hasVisionModality?: boolean;
36 hasMcpPromptsSupport?: boolean;
37 hasMcpResourcesSupport?: boolean;
38 onFileUpload?: () => void;
39 onSystemPromptClick?: () => void;
40 onMcpPromptClick?: () => void;
41 onMcpResourcesClick?: () => void;
42 trigger: Snippet<[{ disabled: boolean; onclick?: () => void }]>;
46 class: className = '',
48 hasAudioModality = false,
49 hasMcpPromptsSupport = false,
50 hasMcpResourcesSupport = false,
51 hasVideoModality = false,
52 hasVisionModality = false,
60 let sheetOpen = $state(false);
61 let reasoningExpanded = $state(false);
62 let filesExpanded = $state(true);
63 let toolsExpanded = $state(false);
64 let mcpExpanded = $state(false);
66 const attachmentMenu = useAttachmentMenu(
70 hasMcpResourcesSupport,
74 () => ({ onFileUpload, onMcpPromptClick, onMcpResourcesClick, onSystemPromptClick }),
80 const toolsPanel = useToolsPanel();
81 const reasoning = useReasoningMenu();
83 const sheetItemClass =
84 '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';
86 const sheetItemRowClass =
87 'flex w-full items-center justify-between gap-2 rounded-md px-3 py-2 text-left text-sm transition-colors hover:bg-accent';
89 let mcpServers = $derived(mcpStore.getServers());
92 <div class="flex items-center gap-1 {className}">
93 <Sheet.Root bind:open={sheetOpen}>
94 {@render trigger({ disabled, onclick: () => (sheetOpen = true) })}
96 <Sheet.Content side="bottom" class="max-h-[85vh] gap-0 overflow-y-auto">
98 <Sheet.Title>Add to chat</Sheet.Title>
100 <Sheet.Description class="sr-only">
101 Add files, system prompt or configure MCP servers
105 <div class="flex flex-col gap-1 px-1.5 pb-2">
106 {#if reasoning.modelSupportsThinking}
108 open={reasoningExpanded}
109 onOpenChange={(open) => (reasoningExpanded = open)}
111 <Collapsible.Trigger class={sheetItemClass}>
112 {#if reasoningExpanded}
113 <ChevronDown class="{ICON_CLASS_DEFAULT} shrink-0" />
115 <ChevronRight class="{ICON_CLASS_DEFAULT} shrink-0" />
118 {#if reasoning.thinkingEnabled}
119 <Lightbulb class="{ICON_CLASS_DEFAULT} shrink-0 text-amber-400" />
120 {:else if reasoning.isOff}
121 <LightbulbOff class="{ICON_CLASS_DEFAULT} shrink-0 text-muted-foreground" />
123 <Lightbulb class="{ICON_CLASS_DEFAULT} shrink-0 text-muted-foreground" />
126 <span class="flex-1">Reasoning</span>
128 <span class="text-xs capitalize text-muted-foreground">
129 {reasoning.currentEffort}
131 </Collapsible.Trigger>
133 <Collapsible.Content>
134 <div class="flex flex-col gap-0.5 pl-4">
135 {#each reasoning.levels as level (level.value)}
136 {@const tokenLabel = reasoning.tokenLabel(level)}
139 class={sheetItemRowClass}
140 class:bg-accent={reasoning.isSelected(level)}
141 onclick={() => reasoning.select(level)}
143 <div class="flex min-w-0 items-center gap-3">
144 {#if reasoning.isSelected(level)}
145 <Check class="{ICON_CLASS_DEFAULT} shrink-0 text-foreground" />
147 <div class="{ICON_CLASS_DEFAULT} shrink-0"></div>
150 <span class="text-sm">{level.label}</span>
154 <span class="shrink-0 text-[11px] text-muted-foreground opacity-60">
161 </Collapsible.Content>
165 <Collapsible.Root open={filesExpanded} onOpenChange={(open) => (filesExpanded = open)}>
166 <Collapsible.Trigger class={sheetItemClass}>
168 <ChevronDown class="{ICON_CLASS_DEFAULT} shrink-0" />
170 <ChevronRight class="{ICON_CLASS_DEFAULT} shrink-0" />
173 <File class="{ICON_CLASS_DEFAULT} shrink-0" />
175 <span class="flex-1">Add files</span>
176 </Collapsible.Trigger>
178 <Collapsible.Content>
179 <div class="flex flex-col gap-0.5 pl-4">
180 {#each ATTACHMENT_FILE_ITEMS as item (item.id)}
181 {@const enabled = attachmentMenu.isItemEnabled(item.enabledWhen)}
185 class={sheetItemClass}
186 onclick={() => attachmentMenu.callbacks[item.action]()}
188 <item.icon class="{ICON_CLASS_DEFAULT} shrink-0" />
190 <span>{item.label}</span>
192 {:else if item.disabledTooltip}
193 <Tooltip.Root delayDuration={TOOLTIP_DELAY_DURATION}>
195 <button type="button" class={sheetItemClass} disabled>
196 <item.icon class="{ICON_CLASS_DEFAULT} shrink-0" />
198 <span>{item.label}</span>
202 <Tooltip.Content side="right">
203 <p>{item.disabledTooltip}</p>
209 </Collapsible.Content>
212 <Collapsible.Root open={mcpExpanded} onOpenChange={(open) => (mcpExpanded = open)}>
213 <Collapsible.Trigger class={sheetItemClass}>
215 <ChevronDown class="{ICON_CLASS_DEFAULT} shrink-0" />
217 <ChevronRight class="{ICON_CLASS_DEFAULT} shrink-0" />
220 <McpLogo class="inline {ICON_CLASS_DEFAULT} shrink-0" />
222 <span class="flex-1">MCP Servers</span>
224 <span class="text-xs text-muted-foreground">
225 {mcpServers.length} server{mcpServers.length !== 1 ? 's' : ''}
227 </Collapsible.Trigger>
229 <Collapsible.Content>
230 <div class="flex flex-col gap-0.5 pl-4">
231 {#each mcpServers as server (server.id)}
232 {@const healthState = mcpStore.getHealthCheckState(server.id)}
233 {@const hasError = healthState.status === HealthCheckStatus.ERROR}
234 {@const displayName = mcpStore.getServerLabel(server)}
235 {@const faviconUrl = mcpStore.getServerFavicon(server.id)}
236 {@const isEnabled = conversationsStore.isMcpServerEnabledForChat(server.id)}
240 class={sheetItemRowClass}
241 onclick={() => !hasError && conversationsStore.toggleMcpServerForChat(server.id)}
244 <div class="flex min-w-0 flex-1 items-center gap-2">
249 class="{ICON_CLASS_DEFAULT} shrink-0 rounded-sm"
251 (e.currentTarget as HTMLImageElement).style.display = 'none';
256 <span class="min-w-0 truncate text-sm">{displayName}</span>
261 class="shrink-0 rounded bg-destructive/15 px-1.5 py-0.5 text-xs text-destructive"
268 onCheckedChange={() => conversationsStore.toggleMcpServerForChat(server.id)}
274 {#if mcpServers.length === 0}
275 <div class="px-3 py-2 text-center text-sm text-muted-foreground">
276 No MCP servers configured
280 </Collapsible.Content>
283 {#if toolsPanel.totalToolCount > 0}
284 <Collapsible.Root open={toolsExpanded} onOpenChange={(open) => (toolsExpanded = open)}>
285 <Collapsible.Trigger class={sheetItemClass}>
287 <ChevronDown class="{ICON_CLASS_DEFAULT} shrink-0" />
289 <ChevronRight class="{ICON_CLASS_DEFAULT} shrink-0" />
292 <PencilRuler class="inline {ICON_CLASS_DEFAULT} shrink-0" />
294 <span class="flex-1">Tools</span>
296 <span class="text-xs text-muted-foreground">
297 {toolsPanel.totalToolCount} tool{toolsPanel.totalToolCount !== 1 ? 's' : ''}
299 </Collapsible.Trigger>
301 <Collapsible.Content>
302 <div class="flex flex-col gap-0.5 pl-4">
303 {#each toolsPanel.activeGroups as group (group.key)}
304 {@const checked = toolsPanel.isGroupChecked(group)}
305 {@const enabledCount = toolsPanel.getEnabledToolCount(group)}
306 {@const favicon = toolsPanel.getFavicon(group)}
310 class={sheetItemRowClass}
311 onclick={() => toolsPanel.toggleGroupByKey(group.key)}
317 class="{ICON_CLASS_DEFAULT} shrink-0 rounded-sm"
319 (e.currentTarget as HTMLImageElement).style.display = 'none';
324 <span class="min-w-0 flex-1 truncate text-sm font-medium">{group.label}</span>
326 <span class="shrink-0 text-xs text-muted-foreground">
327 {enabledCount}/{group.tools.length}
332 class="{ICON_CLASS_DEFAULT} shrink-0"
333 onclick={(e) => e.stopPropagation()}
334 onCheckedChange={() => toolsPanel.toggleGroupByKey(group.key)}
339 </Collapsible.Content>
345 class={sheetItemClass}
346 onclick={() => attachmentMenu.callbacks[AttachmentAction.SYSTEM_PROMPT_CLICK]()}
348 <MessageSquare class="{ICON_CLASS_DEFAULT} shrink-0" />
350 <span>System Message</span>
353 {#if hasMcpPromptsSupport}
356 class={sheetItemClass}
357 onclick={() => attachmentMenu.callbacks[AttachmentAction.MCP_PROMPT_CLICK]()}
359 <Zap class="{ICON_CLASS_DEFAULT} shrink-0" />
361 <span>MCP Prompt</span>
365 {#if hasMcpResourcesSupport}
368 class={sheetItemClass}
369 onclick={() => attachmentMenu.callbacks[AttachmentAction.MCP_RESOURCES_CLICK]()}
371 <FolderOpen class="{ICON_CLASS_DEFAULT} shrink-0" />
373 <span>MCP Resources</span>