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 } from '$lib/stores/conversations.svelte';
28 import { mcpStore } from '$lib/stores/mcp.svelte';
29 import type { Snippet } from 'svelte';
34 hasAudioModality?: boolean;
35 hasVideoModality?: boolean;
36 hasVisionModality?: boolean;
37 hasMcpPromptsSupport?: boolean;
38 hasMcpResourcesSupport?: boolean;
39 onFileUpload?: () => void;
40 onSystemPromptClick?: () => void;
41 onMcpPromptClick?: () => void;
42 onMcpResourcesClick?: () => void;
43 trigger: Snippet<[{ disabled: boolean; onclick?: () => void }]>;
47 class: className = '',
49 hasAudioModality = false,
50 hasMcpPromptsSupport = false,
51 hasMcpResourcesSupport = false,
52 hasVideoModality = false,
53 hasVisionModality = false,
61 let sheetOpen = $state(false);
62 let reasoningExpanded = $state(false);
63 let filesExpanded = $state(true);
64 let toolsExpanded = $state(false);
65 let mcpExpanded = $state(false);
67 const attachmentMenu = useAttachmentMenu(
71 hasMcpResourcesSupport,
75 () => ({ onFileUpload, onMcpPromptClick, onMcpResourcesClick, onSystemPromptClick }),
81 const toolsPanel = useToolsPanel();
82 const reasoning = useReasoningMenu();
84 const sheetItemClass =
85 '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';
87 const sheetItemRowClass =
88 'flex w-full items-center justify-between gap-2 rounded-md px-3 py-2 text-left text-sm transition-colors hover:bg-accent';
90 let mcpServers = $derived(mcpStore.getServers());
93 <div class="flex items-center gap-1 {className}">
94 <Sheet.Root bind:open={sheetOpen}>
95 {@render trigger({ disabled, onclick: () => (sheetOpen = true) })}
97 <Sheet.Content side="bottom" class="max-h-[85vh] gap-0 overflow-y-auto">
99 <Sheet.Title>Add to chat</Sheet.Title>
101 <Sheet.Description class="sr-only">
102 Add files, system prompt or configure MCP servers
106 <div class="flex flex-col gap-1 px-1.5 pb-2">
107 {#if reasoning.modelSupportsThinking}
109 open={reasoningExpanded}
110 onOpenChange={(open) => (reasoningExpanded = open)}
112 <Collapsible.Trigger class={sheetItemClass}>
113 {#if reasoningExpanded}
114 <ChevronDown class="{ICON_CLASS_DEFAULT} shrink-0" />
116 <ChevronRight class="{ICON_CLASS_DEFAULT} shrink-0" />
119 {#if reasoning.thinkingEnabled}
120 <Lightbulb class="{ICON_CLASS_DEFAULT} shrink-0 text-amber-400" />
121 {:else if reasoning.isOff}
122 <LightbulbOff class="{ICON_CLASS_DEFAULT} shrink-0 text-muted-foreground" />
124 <Lightbulb class="{ICON_CLASS_DEFAULT} shrink-0 text-muted-foreground" />
127 <span class="flex-1">Reasoning</span>
129 <span class="text-xs capitalize text-muted-foreground">
130 {reasoning.currentEffort}
132 </Collapsible.Trigger>
134 <Collapsible.Content>
135 <div class="flex flex-col gap-0.5 pl-4">
136 {#each reasoning.levels as level (level.value)}
137 {@const tokenLabel = reasoning.tokenLabel(level)}
140 class={sheetItemRowClass}
141 class:bg-accent={reasoning.isSelected(level)}
142 onclick={() => reasoning.select(level)}
144 <div class="flex min-w-0 items-center gap-3">
145 {#if reasoning.isSelected(level)}
146 <Check class="{ICON_CLASS_DEFAULT} shrink-0 text-foreground" />
148 <div class="{ICON_CLASS_DEFAULT} shrink-0"></div>
151 <span class="text-sm">{level.label}</span>
155 <span class="shrink-0 text-[11px] text-muted-foreground opacity-60">
162 </Collapsible.Content>
166 <Collapsible.Root open={filesExpanded} onOpenChange={(open) => (filesExpanded = open)}>
167 <Collapsible.Trigger class={sheetItemClass}>
169 <ChevronDown class="{ICON_CLASS_DEFAULT} shrink-0" />
171 <ChevronRight class="{ICON_CLASS_DEFAULT} shrink-0" />
174 <File class="{ICON_CLASS_DEFAULT} shrink-0" />
176 <span class="flex-1">Add files</span>
177 </Collapsible.Trigger>
179 <Collapsible.Content>
180 <div class="flex flex-col gap-0.5 pl-4">
181 {#each ATTACHMENT_FILE_ITEMS as item (item.id)}
182 {@const enabled = attachmentMenu.isItemEnabled(item.enabledWhen)}
186 class={sheetItemClass}
187 onclick={() => attachmentMenu.callbacks[item.action]()}
189 <item.icon class="{ICON_CLASS_DEFAULT} shrink-0" />
191 <span>{item.label}</span>
193 {:else if item.disabledTooltip}
194 <Tooltip.Root delayDuration={TOOLTIP_DELAY_DURATION}>
196 <button type="button" class={sheetItemClass} disabled>
197 <item.icon class="{ICON_CLASS_DEFAULT} shrink-0" />
199 <span>{item.label}</span>
203 <Tooltip.Content side="right">
204 <p>{item.disabledTooltip}</p>
210 </Collapsible.Content>
213 <Collapsible.Root open={mcpExpanded} onOpenChange={(open) => (mcpExpanded = open)}>
214 <Collapsible.Trigger class={sheetItemClass}>
216 <ChevronDown class="{ICON_CLASS_DEFAULT} shrink-0" />
218 <ChevronRight class="{ICON_CLASS_DEFAULT} shrink-0" />
221 <McpLogo class="inline {ICON_CLASS_DEFAULT} shrink-0" />
223 <span class="flex-1">MCP Servers</span>
225 <span class="text-xs text-muted-foreground">
226 {mcpServers.length} server{mcpServers.length !== 1 ? 's' : ''}
228 </Collapsible.Trigger>
230 <Collapsible.Content>
231 <div class="flex flex-col gap-0.5 pl-4">
232 {#each mcpServers as server (server.id)}
233 {@const healthState = mcpStore.getHealthCheckState(server.id)}
234 {@const hasError = healthState.status === HealthCheckStatus.ERROR}
235 {@const displayName = mcpStore.getServerLabel(server)}
236 {@const faviconUrl = mcpStore.getServerFavicon(server.id)}
237 {@const isEnabled = conversationsStore.isMcpServerEnabledForChat(server.id)}
241 class={sheetItemRowClass}
242 onclick={() => !hasError && conversationsStore.toggleMcpServerForChat(server.id)}
245 <div class="flex min-w-0 flex-1 items-center gap-2">
250 class="{ICON_CLASS_DEFAULT} shrink-0 rounded-sm"
252 (e.currentTarget as HTMLImageElement).style.display = 'none';
257 <span class="min-w-0 truncate text-sm">{displayName}</span>
262 class="shrink-0 rounded bg-destructive/15 px-1.5 py-0.5 text-xs text-destructive"
269 onCheckedChange={() => conversationsStore.toggleMcpServerForChat(server.id)}
275 {#if mcpServers.length === 0}
276 <div class="px-3 py-2 text-center text-sm text-muted-foreground">
277 No MCP servers configured
281 </Collapsible.Content>
284 {#if toolsPanel.totalToolCount > 0}
285 <Collapsible.Root open={toolsExpanded} onOpenChange={(open) => (toolsExpanded = open)}>
286 <Collapsible.Trigger class={sheetItemClass}>
288 <ChevronDown class="{ICON_CLASS_DEFAULT} shrink-0" />
290 <ChevronRight class="{ICON_CLASS_DEFAULT} shrink-0" />
293 <PencilRuler class="inline {ICON_CLASS_DEFAULT} shrink-0" />
295 <span class="flex-1">Tools</span>
297 <span class="text-xs text-muted-foreground">
298 {toolsPanel.totalToolCount} tool{toolsPanel.totalToolCount !== 1 ? 's' : ''}
300 </Collapsible.Trigger>
302 <Collapsible.Content>
303 <div class="flex flex-col gap-0.5 pl-4">
304 {#each toolsPanel.activeGroups as group (group.key)}
305 {@const checked = toolsPanel.isGroupChecked(group)}
306 {@const enabledCount = toolsPanel.getEnabledToolCount(group)}
307 {@const favicon = toolsPanel.getFavicon(group)}
311 class={sheetItemRowClass}
312 onclick={() => toolsPanel.toggleGroupByKey(group.key)}
318 class="{ICON_CLASS_DEFAULT} shrink-0 rounded-sm"
320 (e.currentTarget as HTMLImageElement).style.display = 'none';
325 <span class="min-w-0 flex-1 truncate text-sm font-medium">{group.label}</span>
327 <span class="shrink-0 text-xs text-muted-foreground">
328 {enabledCount}/{group.tools.length}
333 class="{ICON_CLASS_DEFAULT} shrink-0"
334 onclick={(e) => e.stopPropagation()}
335 onCheckedChange={() => toolsPanel.toggleGroupByKey(group.key)}
340 </Collapsible.Content>
346 class={sheetItemClass}
347 onclick={() => attachmentMenu.callbacks[AttachmentAction.SYSTEM_PROMPT_CLICK]()}
349 <MessageSquare class="{ICON_CLASS_DEFAULT} shrink-0" />
351 <span>System Message</span>
354 {#if hasMcpPromptsSupport}
357 class={sheetItemClass}
358 onclick={() => attachmentMenu.callbacks[AttachmentAction.MCP_PROMPT_CLICK]()}
360 <Zap class="{ICON_CLASS_DEFAULT} shrink-0" />
362 <span>MCP Prompt</span>
366 {#if hasMcpResourcesSupport}
369 class={sheetItemClass}
370 onclick={() => attachmentMenu.callbacks[AttachmentAction.MCP_RESOURCES_CLICK]()}
372 <FolderOpen class="{ICON_CLASS_DEFAULT} shrink-0" />
374 <span>MCP Resources</span>