@sveda-ai/svelte 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,689 @@
1
+ <script lang="ts">
2
+ import {
3
+ History,
4
+ Maximize2,
5
+ MessageCircle,
6
+ MessageSquare,
7
+ Minimize2,
8
+ PanelRight,
9
+ Plus,
10
+ Send,
11
+ Sparkles,
12
+ Square,
13
+ X,
14
+ } from 'lucide-svelte';
15
+ import { onMount, tick } from 'svelte';
16
+ import ChatHistoryList from './ChatHistoryList.svelte';
17
+ import { useSvedaChatLayout } from '../hooks/useSvedaChatLayout.svelte.js';
18
+ import {
19
+ buildChatTabTitleMap,
20
+ getUserMessageText,
21
+ renderMarkdown,
22
+ userMessageHasVisibleContent,
23
+ } from '@sveda-ai/chat';
24
+ import type { SvedaDisplayMessage } from '@sveda-ai/core';
25
+ import { useSvedaConfig, useSvedaContext, useSvedaT } from '../context.js';
26
+ import { useSvedaLauncher } from '../appearance.js';
27
+ import { useSvedaChat } from '../hooks/useSvedaChat.svelte.js';
28
+ import { useSvedaStreaming } from '../hooks/useSvedaStreaming.svelte.js';
29
+ import { cn } from '../lib/utils.js';
30
+ import type { SvedaModelOption, SvedaQuickPrompt } from '../provider.js';
31
+
32
+ interface Props {
33
+ models?: SvedaModelOption[];
34
+ quickPrompts?: SvedaQuickPrompt[];
35
+ brandName?: string;
36
+ brandLogo?: string;
37
+ pageUrl?: string;
38
+ onNavigate?: (url: string) => void;
39
+ notify?: (kind: 'error', message: string) => void;
40
+ agentTasksSubscribe?: (onPayload: (payload: unknown) => void) => void | (() => void);
41
+ }
42
+
43
+ let {
44
+ models,
45
+ quickPrompts,
46
+ brandName,
47
+ brandLogo,
48
+ pageUrl = '',
49
+ onNavigate,
50
+ notify,
51
+ agentTasksSubscribe,
52
+ }: Props = $props();
53
+
54
+ const config = useSvedaConfig();
55
+ const ctx = useSvedaContext();
56
+ const t = useSvedaT();
57
+ const launcher = useSvedaLauncher();
58
+ const chat = useSvedaChat();
59
+ const layout = useSvedaChatLayout({
60
+ getIsMinimized: () => chat.isMinimized,
61
+ hostEmbed: ctx.hostEmbed,
62
+ fillHost: ctx.fillHost,
63
+ });
64
+
65
+ let showHistorySidebar = $state(false);
66
+ let pendingDeleteChatId = $state<string | null>(null);
67
+ let pendingRenameChatId = $state<string | null>(null);
68
+ let renameTitle = $state('');
69
+ const iconButtonClass =
70
+ 'inline-flex h-9 w-9 items-center justify-center bg-transparent text-muted-foreground hover:text-foreground';
71
+
72
+ const resolvedModels = $derived(models ?? config.models);
73
+ const resolvedPrompts = $derived(quickPrompts ?? config.quickPrompts);
74
+ const resolvedBrandName = $derived(brandName ?? config.brand.name);
75
+ const resolvedBrandLogo = $derived(brandLogo ?? config.brand.logoUrl ?? '');
76
+
77
+ let inputMessage = $state('');
78
+ let selectedChatModel = $state('');
79
+ let messagesContainer: HTMLDivElement | null = $state(null);
80
+ let errorBanner = $state('');
81
+
82
+ const PAGE_SESSION_BOOT_KEY = '__SVEDA_CHAT_PAGE_BOOTED__';
83
+
84
+ const scrollToBottom = (options?: { behavior?: string; onlyIfNearBottom?: boolean }) => {
85
+ const el = messagesContainer;
86
+ if (!el) return;
87
+ if (options?.onlyIfNearBottom) {
88
+ const distance = el.scrollHeight - el.scrollTop - el.clientHeight;
89
+ if (distance > 120) return;
90
+ }
91
+ el.scrollTo({
92
+ top: el.scrollHeight,
93
+ behavior: (options?.behavior as ScrollBehavior) ?? 'smooth',
94
+ });
95
+ };
96
+
97
+ const streaming = useSvedaStreaming(
98
+ {
99
+ getCurrentChat: () => chat.currentChat,
100
+ setChatMessages: chat.setChatMessages,
101
+ setChatTitle: chat.setChatTitle,
102
+ refreshChatTitleFromServer: chat.refreshChatTitleFromServer,
103
+ incrementChatTokens: chat.incrementChatTokens,
104
+ setChatContextWindowTokens: chat.setChatContextWindowTokens,
105
+ },
106
+ scrollToBottom,
107
+ {
108
+ newChatLabel: () => t('newChat'),
109
+ resolveSendOptions: () => {
110
+ const model = selectedChatModel || resolvedModels[0]?.id;
111
+ return model ? { model } : {};
112
+ },
113
+ onError: (_chatId, error) => {
114
+ const message =
115
+ error instanceof Error && error.message.trim()
116
+ ? error.message
117
+ : t('errorSendingMessage');
118
+ errorBanner = message;
119
+ notify?.('error', message);
120
+ },
121
+ },
122
+ );
123
+
124
+ const launcherLabel = $derived.by(() => {
125
+ const custom = launcher.label.trim();
126
+ return custom !== '' ? custom : resolvedBrandName;
127
+ });
128
+
129
+ const launcherImage = $derived.by(() => {
130
+ const uploaded = launcher.image.trim();
131
+ if (uploaded !== '') return uploaded;
132
+ return resolvedBrandLogo;
133
+ });
134
+
135
+ const displayMessages = $derived(chat.currentChat?.messages ?? []);
136
+ const hasUserMessages = $derived(
137
+ displayMessages.some((m) => m.role === 'user' && userMessageHasVisibleContent(m)),
138
+ );
139
+
140
+ const tabTitles = $derived(buildChatTabTitleMap(chat.openChatTabs, t));
141
+
142
+ const welcomeText = $derived(t('welcomeMessage'));
143
+ const headerTitle = $derived(chat.currentChat?.title || t('chatTitle'));
144
+
145
+ const canSend = $derived(
146
+ inputMessage.trim().length > 0 && !chat.isLoading && !streaming.isStreaming,
147
+ );
148
+
149
+ const assistantText = (message: SvedaDisplayMessage): string => {
150
+ const content = (message as { content?: unknown }).content;
151
+ if (typeof content === 'string') return content;
152
+ if (!Array.isArray(message.parts)) return '';
153
+ return message.parts
154
+ .filter((part) => part && typeof part === 'object' && (part as { type?: string }).type === 'text')
155
+ .map((part) => String((part as { text?: string }).text ?? ''))
156
+ .join('');
157
+ };
158
+
159
+ const messageHtml = (message: SvedaDisplayMessage): string => {
160
+ if (message.role === 'user') {
161
+ return '';
162
+ }
163
+ return renderMarkdown(assistantText(message));
164
+ };
165
+
166
+ const handleSend = async () => {
167
+ const text = inputMessage.trim();
168
+ if (!text || chat.isLoading || streaming.isStreaming) return;
169
+ errorBanner = '';
170
+ inputMessage = '';
171
+ chat.maximizeChat();
172
+ chat.setLoading(true);
173
+ try {
174
+ await streaming.sendMessage(text, pageUrl ? { pageUrl } : undefined);
175
+ } finally {
176
+ chat.setLoading(false);
177
+ await tick();
178
+ scrollToBottom({ behavior: 'smooth', onlyIfNearBottom: false });
179
+ }
180
+ };
181
+
182
+ const handleKeydown = (event: KeyboardEvent) => {
183
+ if (event.key === 'Enter' && !event.shiftKey) {
184
+ event.preventDefault();
185
+ void handleSend();
186
+ }
187
+ };
188
+
189
+ const handleNewChat = () => {
190
+ chat.createNewChat();
191
+ inputMessage = '';
192
+ errorBanner = '';
193
+ if (layout.isMobile) {
194
+ showHistorySidebar = false;
195
+ }
196
+ };
197
+
198
+ const handleSelectChat = async (chatId: string) => {
199
+ streaming.clearChatUnread(chatId);
200
+ await chat.setCurrentChat(chatId);
201
+ if (layout.isMobile) {
202
+ showHistorySidebar = false;
203
+ }
204
+ await tick();
205
+ scrollToBottom({ behavior: 'auto', onlyIfNearBottom: false });
206
+ };
207
+
208
+ const confirmDelete = () => {
209
+ if (pendingDeleteChatId) {
210
+ void chat.deleteChat(pendingDeleteChatId);
211
+ }
212
+ pendingDeleteChatId = null;
213
+ };
214
+
215
+ const confirmRename = () => {
216
+ const title = renameTitle.trim();
217
+ if (pendingRenameChatId && title) {
218
+ chat.renameChat(pendingRenameChatId, title);
219
+ }
220
+ pendingRenameChatId = null;
221
+ renameTitle = '';
222
+ };
223
+
224
+ const historyAsideClass = $derived(
225
+ cn(
226
+ 'sveda-chat-surface flex min-h-0 w-80 shrink-0 flex-col overflow-hidden bg-background',
227
+ layout.isMobile
228
+ ? 'h-full max-w-[88vw] border-r border-border'
229
+ : ctx.fillHost
230
+ ? 'h-full border-r border-border'
231
+ : layout.viewMode === 'fixed'
232
+ ? 'absolute right-full top-0 z-10 h-full border-r border-border'
233
+ : 'h-full rounded-[var(--sveda-radius)] border border-border',
234
+ ),
235
+ );
236
+
237
+ const nonImmersiveShellClass = $derived(
238
+ layout.isMobile || layout.viewMode === 'fixed'
239
+ ? 'relative flex h-full min-h-0 min-w-0 flex-1 flex-row'
240
+ : ctx.fillHost
241
+ ? 'relative flex h-full min-h-0 min-w-0 w-full flex-row items-stretch overflow-hidden'
242
+ : 'relative flex min-h-0 flex-row items-stretch gap-2',
243
+ );
244
+
245
+ const cardClass = $derived(
246
+ cn(
247
+ 'sveda-chat-surface relative flex min-h-0 flex-col overflow-visible',
248
+ layout.viewMode === 'floating' && !layout.isMobile && !ctx.fillHost && 'sveda-chat-frame',
249
+ (ctx.fillHost || layout.isMobile) && 'border-0',
250
+ layout.isMobile && 'h-full min-w-0 flex-1 rounded-none',
251
+ layout.viewMode === 'fixed' &&
252
+ !layout.isMobile &&
253
+ 'h-full min-w-0 flex-1 rounded-none border-b-0 border-l border-r-0 border-t-0 border-border',
254
+ layout.viewMode === 'floating' && 'rounded-[var(--sveda-radius)]',
255
+ (layout.isMobile || layout.viewMode === 'fixed') && 'rounded-none',
256
+ layout.viewMode === 'floating' && !layout.isMobile && !ctx.fillHost && 'min-w-0 shrink-0',
257
+ layout.viewMode === 'floating' && !layout.isMobile && ctx.fillHost && 'h-full min-w-0 flex-1',
258
+ ),
259
+ );
260
+
261
+ const handleQuickPrompt = (prompt: SvedaQuickPrompt) => {
262
+ inputMessage = prompt.prompt;
263
+ void handleSend();
264
+ };
265
+
266
+ onMount(() => {
267
+ if (resolvedModels[0]?.id) {
268
+ selectedChatModel = resolvedModels[0].id;
269
+ }
270
+
271
+ if (typeof agentTasksSubscribe === 'function') {
272
+ agentTasksSubscribe(() => {});
273
+ }
274
+
275
+ void (async () => {
276
+ await chat.loadHistories();
277
+ const globalScope = window as unknown as Record<string, unknown>;
278
+ const isPageBooted = Boolean(globalScope[PAGE_SESSION_BOOT_KEY]);
279
+ if (!isPageBooted) {
280
+ globalScope[PAGE_SESSION_BOOT_KEY] = true;
281
+ chat.createNewChat();
282
+ } else if (!chat.currentChat) {
283
+ if (chat.sortedHistories.length > 0) {
284
+ await chat.setCurrentChat(chat.sortedHistories[0].id);
285
+ } else {
286
+ chat.createNewChat();
287
+ }
288
+ }
289
+ await tick();
290
+ scrollToBottom({ behavior: 'auto', onlyIfNearBottom: false });
291
+ })();
292
+ });
293
+ </script>
294
+
295
+ {#snippet toolbar(immersiveDesktop: boolean)}
296
+ <header
297
+ class="flex h-12 shrink-0 flex-row items-center justify-between border-b border-border bg-card px-3 {layout.viewMode === 'floating' && !layout.isMobile ? 'rounded-t-[var(--sveda-radius)]' : 'rounded-none'}"
298
+ >
299
+ {#if !immersiveDesktop}
300
+ <div class="flex min-w-0 flex-1 items-center gap-2">
301
+ <button
302
+ type="button"
303
+ class="{iconButtonClass} {showHistorySidebar ? 'bg-muted/60 text-foreground' : ''}"
304
+ aria-label={t('chatHistory')}
305
+ title={t('chatHistory')}
306
+ onclick={() => (showHistorySidebar = !showHistorySidebar)}
307
+ >
308
+ <History class="h-4 w-4" />
309
+ </button>
310
+ <h2 class="min-w-0 flex-1 truncate text-left font-mono text-[11px] font-normal uppercase tracking-[0.14em] text-foreground">
311
+ {headerTitle}
312
+ </h2>
313
+ </div>
314
+ {:else}
315
+ <div class="flex min-w-0 flex-1 items-center gap-4">
316
+ <div class="w-[min(20rem,33vw)] min-w-0">
317
+ <div class="flex items-center gap-2">
318
+ {#if resolvedBrandLogo}
319
+ <img src={resolvedBrandLogo} alt={resolvedBrandName} class="size-7 shrink-0 rounded" />
320
+ {:else}
321
+ <Sparkles class="size-5 shrink-0 text-primary" />
322
+ {/if}
323
+ <span class="truncate text-lg font-bold leading-none text-foreground">{resolvedBrandName}</span>
324
+ </div>
325
+ </div>
326
+ <h2 class="min-w-0 flex-1 truncate text-left font-mono text-[11px] font-normal uppercase tracking-[0.14em] text-foreground">
327
+ {headerTitle}
328
+ </h2>
329
+ </div>
330
+ {/if}
331
+ <div class="flex shrink-0 items-center gap-0.5">
332
+ {#if !layout.isMobile && layout.viewMode === 'immersive'}
333
+ <button type="button" class={iconButtonClass} aria-label={t('immersiveModeExit')} title={t('immersiveModeExit')} onclick={layout.exitImmersiveMode}>
334
+ <Minimize2 class="h-4 w-4" />
335
+ </button>
336
+ {/if}
337
+ {#if !layout.isMobile && layout.viewMode !== 'immersive'}
338
+ <button type="button" class={iconButtonClass} aria-label={t('immersiveModeEnter')} title={t('immersiveModeEnter')} onclick={layout.enterImmersiveMode}>
339
+ <Maximize2 class="h-4 w-4" />
340
+ </button>
341
+ <button
342
+ type="button"
343
+ class={iconButtonClass}
344
+ aria-label={layout.viewMode === 'floating' ? t('viewModeFixed') : t('viewModeFloating')}
345
+ title={layout.viewMode === 'floating' ? t('viewModeFixed') : t('viewModeFloating')}
346
+ onclick={layout.toggleViewMode}
347
+ >
348
+ {#if layout.viewMode === 'floating'}
349
+ <PanelRight class="h-4 w-4" />
350
+ {:else}
351
+ <MessageSquare class="h-4 w-4" />
352
+ {/if}
353
+ </button>
354
+ {/if}
355
+ <button type="button" class={iconButtonClass} aria-label={t('toolbarMinimize')} title={t('toolbarMinimize')} onclick={() => chat.minimizeChat()}>
356
+ <X class="h-4 w-4" />
357
+ </button>
358
+ </div>
359
+ </header>
360
+ {/snippet}
361
+
362
+ {#snippet tabs(compact: boolean)}
363
+ {#if chat.openChatTabs.length > 0}
364
+ <div class="flex shrink-0 items-stretch border-b border-border bg-card {compact ? 'px-3' : 'px-4'}">
365
+ <div class="min-w-0 flex-1 overflow-x-auto">
366
+ <div class="flex h-12 min-w-max items-end gap-px px-1">
367
+ {#each chat.openChatTabs as tab (tab.id)}
368
+ <div
369
+ role="button"
370
+ tabindex="0"
371
+ class={cn(
372
+ 'inline-flex h-10 max-w-56 shrink-0 items-center gap-1.5 whitespace-nowrap border-b border-transparent px-3 py-2 font-mono text-[11px] tracking-[0.12em] text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none',
373
+ chat.currentChat?.id === tab.id ? 'border-foreground bg-transparent text-foreground' : '',
374
+ )}
375
+ onclick={() => void handleSelectChat(tab.id)}
376
+ onkeydown={(e) => {
377
+ if (e.key === 'Enter' || e.key === ' ') {
378
+ e.preventDefault();
379
+ void handleSelectChat(tab.id);
380
+ }
381
+ }}
382
+ >
383
+ <span class="min-w-0 truncate">{tabTitles.get(tab.id) ?? tab.title}</span>
384
+ {#if streaming.streamingChatIds.has(tab.id)}
385
+ <span class="h-1.5 w-1.5 shrink-0 rounded-full bg-foreground" aria-label={t('chatTabRunning')}></span>
386
+ {:else if streaming.unreadChatIds.has(tab.id)}
387
+ <span class="h-1.5 w-1.5 shrink-0 rounded-full bg-primary" aria-label={t('chatTabUnread')}></span>
388
+ {/if}
389
+ <button
390
+ type="button"
391
+ class="ml-0.5 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground"
392
+ aria-label={t('closeChatTab')}
393
+ onclick={(e) => {
394
+ e.stopPropagation();
395
+ void chat.closeChatTab(tab.id);
396
+ }}
397
+ >
398
+ <X class="h-3 w-3" />
399
+ </button>
400
+ </div>
401
+ {/each}
402
+ <button
403
+ type="button"
404
+ class="inline-flex h-10 shrink-0 items-center px-2 text-muted-foreground hover:text-foreground"
405
+ aria-label={t('newChat')}
406
+ onclick={handleNewChat}
407
+ >
408
+ <Plus class="h-4 w-4" />
409
+ </button>
410
+ </div>
411
+ </div>
412
+ </div>
413
+ {/if}
414
+ {/snippet}
415
+
416
+ {#snippet thread()}
417
+ <div bind:this={messagesContainer} class="flex min-h-0 flex-1 flex-col overflow-y-auto px-4 py-4">
418
+ {#if !hasUserMessages}
419
+ <div class="mt-auto flex flex-col gap-3">
420
+ <p class="font-sans text-sm text-foreground">{welcomeText}</p>
421
+ {#if resolvedPrompts.length > 0}
422
+ <div class="flex flex-col gap-2">
423
+ <p class="font-mono text-[11px] tracking-[0.08em] text-muted-foreground">{t('quickPromptsTitle')}</p>
424
+ <div class="flex flex-wrap gap-2">
425
+ {#each resolvedPrompts as prompt (prompt.label)}
426
+ <button
427
+ type="button"
428
+ class="border border-border bg-secondary px-3 py-1.5 font-mono text-[11px] tracking-[0.08em] text-secondary-foreground transition-opacity hover:opacity-90 disabled:opacity-50"
429
+ disabled={chat.isLoading || streaming.isStreaming}
430
+ onclick={() => handleQuickPrompt(prompt)}
431
+ >
432
+ {prompt.label}
433
+ </button>
434
+ {/each}
435
+ </div>
436
+ </div>
437
+ {/if}
438
+ </div>
439
+ {:else}
440
+ <div class="mt-auto flex flex-col gap-4">
441
+ {#each displayMessages as message (message.id)}
442
+ {#if message.role === 'user' && userMessageHasVisibleContent(message)}
443
+ <div class="ml-8 max-w-[90%] border border-border bg-muted px-3 py-2 font-sans text-sm text-foreground">
444
+ {getUserMessageText(message)}
445
+ </div>
446
+ {:else if message.role === 'assistant'}
447
+ {@const html = messageHtml(message)}
448
+ {#if html}
449
+ <div class="prose mr-4 max-w-none font-sans text-sm text-foreground">
450
+ {@html html}
451
+ </div>
452
+ {/if}
453
+ {/if}
454
+ {/each}
455
+ {#if streaming.isThinking || streaming.isStreaming}
456
+ <p class="font-mono text-[11px] tracking-[0.08em] text-muted-foreground">
457
+ {streaming.thinkingMessage || t('preparingReply')}
458
+ </p>
459
+ {/if}
460
+ </div>
461
+ {/if}
462
+ </div>
463
+ {#if errorBanner}
464
+ <div class="mx-3 mb-2 border border-dashed border-destructive px-3 py-2 font-mono text-[11px] tracking-[0.08em] text-destructive">
465
+ {errorBanner}
466
+ </div>
467
+ {/if}
468
+ <div class="flex flex-shrink-0 flex-col bg-background p-3">
469
+ <div class="relative flex flex-col border border-dashed border-foreground bg-background">
470
+ <textarea
471
+ class="sveda-chat-input-textarea max-h-[250px] min-h-[60px] w-full resize-none border-0 bg-transparent p-3 font-sans text-sm text-foreground shadow-none outline-none ring-0 placeholder:font-mono placeholder:text-[11px] placeholder:tracking-[0.08em] placeholder:text-muted-foreground"
472
+ style="height: 60px; outline: none; box-shadow: none"
473
+ placeholder={t('typeMessage')}
474
+ bind:value={inputMessage}
475
+ disabled={chat.isLoading}
476
+ onkeydown={handleKeydown}
477
+ ></textarea>
478
+ <div class="flex items-center justify-between gap-2 border-t border-border/40 px-2 py-1.5">
479
+ <div class="min-w-0 flex-1">
480
+ {#if resolvedModels.length > 0}
481
+ <select
482
+ class="max-w-full border-0 bg-transparent font-mono text-[11px] tracking-[0.08em] text-muted-foreground outline-none"
483
+ bind:value={selectedChatModel}
484
+ disabled={chat.isLoading || streaming.isStreaming}
485
+ >
486
+ {#each resolvedModels as model (model.id)}
487
+ <option value={model.id}>{model.label || model.id}</option>
488
+ {/each}
489
+ </select>
490
+ {/if}
491
+ </div>
492
+ {#if streaming.isStreaming}
493
+ <button type="button" class="inline-flex h-9 w-9 items-center justify-center text-muted-foreground hover:text-foreground" aria-label="Stop" onclick={() => streaming.stopStreaming()}>
494
+ <Square class="h-4 w-4" />
495
+ </button>
496
+ {:else}
497
+ <button
498
+ type="button"
499
+ class="inline-flex h-9 w-9 items-center justify-center text-muted-foreground hover:text-foreground disabled:opacity-40"
500
+ aria-label="Send"
501
+ disabled={!canSend}
502
+ onclick={() => void handleSend()}
503
+ >
504
+ <Send class="h-4 w-4" />
505
+ </button>
506
+ {/if}
507
+ </div>
508
+ </div>
509
+ </div>
510
+ {/snippet}
511
+
512
+ {#snippet newChatButton()}
513
+ <button
514
+ type="button"
515
+ class="inline-flex h-10 w-full items-center justify-center gap-2 bg-primary px-3 font-mono text-[11px] tracking-[0.14em] text-primary-foreground"
516
+ onclick={handleNewChat}
517
+ >
518
+ <Plus class="h-4 w-4" />
519
+ {t('newChat')}
520
+ </button>
521
+ {/snippet}
522
+
523
+ {#snippet historyColumn()}
524
+ <div class="border-b border-border/50 p-3">{@render newChatButton()}</div>
525
+ <div class="min-h-0 flex-1">
526
+ <ChatHistoryList
527
+ histories={chat.sortedHistories}
528
+ currentChatId={chat.currentChat?.id}
529
+ onSelectChat={(chatId) => void handleSelectChat(chatId)}
530
+ onDeleteChat={(chatId) => (pendingDeleteChatId = chatId)}
531
+ onRenameChat={(chatId) => {
532
+ const history = chat.sortedHistories.find((item) => item.id === chatId);
533
+ pendingRenameChatId = chatId;
534
+ renameTitle = history?.title ?? '';
535
+ }}
536
+ />
537
+ </div>
538
+ {/snippet}
539
+
540
+ <div class={layout.chatShellClass} style={layout.chatShellStyle} data-testid="sveda-chat">
541
+ {#if !chat.isMinimized}
542
+ <div
543
+ class={layout.isMobile || layout.viewMode === 'fixed' || ctx.fillHost
544
+ ? 'flex h-full min-h-0 w-full min-w-0 flex-1'
545
+ : layout.viewMode === 'immersive'
546
+ ? 'flex h-full min-h-0 w-full min-w-0 flex-1 flex-col'
547
+ : 'flex gap-2'}
548
+ >
549
+ {#if layout.isImmersiveDesktop}
550
+ <div class="sveda-chat-surface flex h-full min-h-0 w-full flex-1 flex-col">
551
+ {@render toolbar(true)}
552
+ <div class="flex min-h-0 flex-1 flex-row">
553
+ <aside class="sveda-chat-surface flex w-[min(20rem,33vw)] shrink-0 flex-col border-r border-border">
554
+ {@render historyColumn()}
555
+ </aside>
556
+ <div class="sveda-chat-surface flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden">
557
+ {@render tabs(false)}
558
+ <div class="mx-auto flex min-h-0 w-full max-w-7xl flex-1 flex-col overflow-hidden px-4">
559
+ {@render thread()}
560
+ </div>
561
+ </div>
562
+ </div>
563
+ </div>
564
+ {:else}
565
+ <div class={nonImmersiveShellClass} style={layout.floatShellStyle}>
566
+ {#if showHistorySidebar && !layout.isMobile}
567
+ <aside class={historyAsideClass}>
568
+ {@render historyColumn()}
569
+ </aside>
570
+ {/if}
571
+ <div class={cardClass} style={layout.chatCardStyle}>
572
+ <div class="sveda-chat-surface relative flex min-h-0 flex-1 flex-col overflow-hidden p-0">
573
+ <div class="flex min-h-0 flex-1 flex-col">
574
+ {@render toolbar(false)}
575
+ {@render tabs(true)}
576
+ {@render thread()}
577
+ </div>
578
+ </div>
579
+ {#if layout.viewMode === 'floating' && !layout.isMobile && !ctx.fillHost}
580
+ <span class="pointer-events-none absolute -left-px -top-px z-10 h-2.5 w-2.5 border-l border-t border-foreground" aria-hidden="true"></span>
581
+ <span class="pointer-events-none absolute -right-px -top-px z-10 h-2.5 w-2.5 border-r border-t border-foreground" aria-hidden="true"></span>
582
+ <span class="pointer-events-none absolute -bottom-px -left-px z-10 h-2.5 w-2.5 border-b border-l border-foreground" aria-hidden="true"></span>
583
+ <span class="pointer-events-none absolute -bottom-px -right-px z-10 h-2.5 w-2.5 border-b border-r border-foreground" aria-hidden="true"></span>
584
+ {/if}
585
+ {#if !layout.isMobile && layout.viewMode === 'fixed'}
586
+ <div
587
+ class="absolute bottom-3 left-0 top-3 z-10 w-1 touch-none cursor-ew-resize hover:bg-primary/30"
588
+ role="separator"
589
+ aria-orientation="vertical"
590
+ aria-label="Resize chat"
591
+ onpointerdown={(event) => layout.startResize('fixed-left', event)}
592
+ ></div>
593
+ {/if}
594
+ {#if !layout.isMobile && layout.viewMode === 'floating'}
595
+ <div
596
+ class="absolute left-0 top-0 z-10 h-3 w-3 touch-none cursor-nw-resize hover:bg-primary/20"
597
+ role="separator"
598
+ aria-label="Resize chat"
599
+ onpointerdown={(event) => layout.startResize('top-left', event)}
600
+ ></div>
601
+ <div
602
+ class="absolute left-3 right-3 top-0 z-10 h-1 touch-none cursor-n-resize hover:bg-primary/30"
603
+ role="separator"
604
+ aria-orientation="horizontal"
605
+ aria-label="Resize chat height"
606
+ onpointerdown={(event) => layout.startResize('top', event)}
607
+ ></div>
608
+ <div
609
+ class="absolute bottom-3 left-0 top-3 z-10 w-1 touch-none cursor-w-resize hover:bg-primary/30"
610
+ role="separator"
611
+ aria-orientation="vertical"
612
+ aria-label="Resize chat width"
613
+ onpointerdown={(event) => layout.startResize('left', event)}
614
+ ></div>
615
+ {/if}
616
+ </div>
617
+ </div>
618
+ {/if}
619
+ </div>
620
+ {/if}
621
+
622
+ {#if layout.isMobile && showHistorySidebar && !chat.isMinimized}
623
+ <div class="fixed inset-0 z-[60] flex bg-black/40" onclick={() => (showHistorySidebar = false)} role="presentation">
624
+ <aside class="sveda-chat-surface flex h-full w-80 max-w-[88vw] flex-col bg-background" onclick={(event) => event.stopPropagation()} role="presentation">
625
+ {@render historyColumn()}
626
+ </aside>
627
+ </div>
628
+ {/if}
629
+
630
+ {#if chat.isMinimized && !layout.isMobile && !ctx.hideLauncher}
631
+ <button
632
+ type="button"
633
+ class="inline-flex h-auto min-w-0 items-center justify-center gap-2 rounded-none border border-primary bg-primary px-3.5 py-2 font-mono text-[11px] tracking-[0.14em] text-primary-foreground shadow-none transition-opacity hover:opacity-90"
634
+ onclick={() => void chat.openChat()}
635
+ >
636
+ {#if launcherImage}
637
+ <img src={launcherImage} alt={t('assistantLogoAlt')} class="h-6 w-6 flex-shrink-0 object-cover min-[1872px]:h-10 min-[1872px]:w-10" />
638
+ {:else}
639
+ <MessageCircle class="h-6 w-6 flex-shrink-0" />
640
+ {/if}
641
+ {#if launcherLabel}
642
+ <span class="font-mono text-[11px] font-normal tracking-[0.14em]">{launcherLabel}</span>
643
+ {/if}
644
+ </button>
645
+ {/if}
646
+
647
+ {#if pendingDeleteChatId}
648
+ <div class="fixed inset-0 z-[70] flex items-center justify-center bg-black/40 p-4" role="dialog" aria-modal="true">
649
+ <div class="w-full max-w-sm border border-border bg-card p-4 text-card-foreground shadow-lg">
650
+ <h3 class="text-base font-semibold">{t('commonDelete')}</h3>
651
+ <p class="mt-2 text-sm text-muted-foreground">{t('confirmDeleteChat')}</p>
652
+ <div class="mt-4 flex justify-end gap-2">
653
+ <button type="button" class="border border-border px-3 py-2 text-sm" onclick={() => (pendingDeleteChatId = null)}>{t('commonCancel')}</button>
654
+ <button type="button" class="bg-primary px-3 py-2 text-sm text-primary-foreground" onclick={confirmDelete}>{t('commonDelete')}</button>
655
+ </div>
656
+ </div>
657
+ </div>
658
+ {/if}
659
+
660
+ {#if pendingRenameChatId}
661
+ <div class="fixed inset-0 z-[70] flex items-center justify-center bg-black/40 p-4" role="dialog" aria-modal="true">
662
+ <div class="w-full max-w-sm border border-border bg-card p-4 text-card-foreground shadow-lg">
663
+ <h3 class="text-base font-semibold">{t('renameChat')}</h3>
664
+ <input
665
+ bind:value={renameTitle}
666
+ type="text"
667
+ placeholder={t('renameChatPlaceholder')}
668
+ class="mt-3 h-10 w-full border border-input bg-input px-3 text-sm outline-none"
669
+ onkeydown={(event) => {
670
+ if (event.key === 'Enter') confirmRename();
671
+ }}
672
+ />
673
+ <div class="mt-4 flex justify-end gap-2">
674
+ <button
675
+ type="button"
676
+ class="border border-border px-3 py-2 text-sm"
677
+ onclick={() => {
678
+ pendingRenameChatId = null;
679
+ renameTitle = '';
680
+ }}
681
+ >
682
+ {t('commonCancel')}
683
+ </button>
684
+ <button type="button" class="bg-primary px-3 py-2 text-sm text-primary-foreground" onclick={confirmRename}>{t('commonSave')}</button>
685
+ </div>
686
+ </div>
687
+ </div>
688
+ {/if}
689
+ </div>