Instructions to use Felipe97/llama-cpp-compiled with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use Felipe97/llama-cpp-compiled with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf Felipe97/llama-cpp-compiled # Run inference directly in the terminal: llama cli -hf Felipe97/llama-cpp-compiled
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf Felipe97/llama-cpp-compiled # Run inference directly in the terminal: llama cli -hf Felipe97/llama-cpp-compiled
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama serve -hf Felipe97/llama-cpp-compiled # Run inference directly in the terminal: ./build/bin/llama cli -hf Felipe97/llama-cpp-compiled
Use Docker
docker model run hf.co/Felipe97/llama-cpp-compiled
- Llama new
- LM Studio
- Jan
- Ollama
How to use Felipe97/llama-cpp-compiled with Ollama:
ollama run hf.co/Felipe97/llama-cpp-compiled
- Unsloth Desktop
- Docker Model Runner
How to use Felipe97/llama-cpp-compiled with Docker Model Runner:
docker model run hf.co/Felipe97/llama-cpp-compiled
- Lemonade
How to use Felipe97/llama-cpp-compiled with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull Felipe97/llama-cpp-compiled
Run and chat with the model
lemonade run user.llama-cpp-compiled-{{QUANT_TAG}}List all available models
lemonade list
- Atomic Chat
Upload folder using huggingface_hub (part 11)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +3 -0
- tools/ui/src/lib/components/app/mcp/McpServerCard/McpServerCardActions.svelte +40 -0
- tools/ui/src/lib/components/app/mcp/McpServerCard/McpServerCardCompact.svelte +45 -0
- tools/ui/src/lib/components/app/mcp/McpServerCard/McpServerCardDeleteDialog.svelte +36 -0
- tools/ui/src/lib/components/app/mcp/McpServerCard/McpServerCardEditForm.svelte +95 -0
- tools/ui/src/lib/components/app/mcp/McpServerCard/McpServerCardHeader.svelte +72 -0
- tools/ui/src/lib/components/app/mcp/McpServerCard/McpServerCardToolsList.svelte +47 -0
- tools/ui/src/lib/components/app/mcp/McpServerCardSkeleton.svelte +42 -0
- tools/ui/src/lib/components/app/mcp/McpServerForm.svelte +259 -0
- tools/ui/src/lib/components/app/mcp/McpServerIdentity.svelte +63 -0
- tools/ui/src/lib/components/app/mcp/McpServerInfo.svelte +35 -0
- tools/ui/src/lib/components/app/mcp/index.ts +265 -0
- tools/ui/src/lib/components/app/misc/CodeBlockActions.svelte +33 -0
- tools/ui/src/lib/components/app/misc/ConversationSelection.svelte +181 -0
- tools/ui/src/lib/components/app/misc/KeyboardShortcutInfo.svelte +33 -0
- tools/ui/src/lib/components/app/misc/Logo.svelte +15 -0
- tools/ui/src/lib/components/app/misc/ScrollCarousel.svelte +131 -0
- tools/ui/src/lib/components/app/misc/TruncatedText.svelte +50 -0
- tools/ui/src/lib/components/app/misc/index.ts +61 -0
- tools/ui/src/lib/components/app/models/ModelBadge.svelte +62 -0
- tools/ui/src/lib/components/app/models/ModelId.svelte +163 -0
- tools/ui/src/lib/components/app/models/ModelLoadHighlight.svelte +11 -0
- tools/ui/src/lib/components/app/models/ModelsSelectorDropdown.svelte +417 -0
- tools/ui/src/lib/components/app/models/ModelsSelectorList.svelte +76 -0
- tools/ui/src/lib/components/app/models/ModelsSelectorOption.svelte +214 -0
- tools/ui/src/lib/components/app/models/ModelsSelectorSheet.svelte +210 -0
- tools/ui/src/lib/components/app/models/index.ts +111 -0
- tools/ui/src/lib/components/app/models/utils.ts +101 -0
- tools/ui/src/lib/components/app/navigation/DropdownMenuActions.svelte +92 -0
- tools/ui/src/lib/components/app/navigation/DropdownMenuSearchable.svelte +50 -0
- tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigation.svelte +482 -0
- tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationActions.svelte +209 -0
- tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationConversationItem.svelte +332 -0
- tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationConversationList.svelte +205 -0
- tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationSearch.svelte +21 -0
- tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationSearchResults.svelte +94 -0
- tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationSelectionBar.svelte +163 -0
- tools/ui/src/lib/components/app/navigation/index.ts +204 -0
- tools/ui/src/lib/components/app/server/ServerErrorSplash.svelte +292 -0
- tools/ui/src/lib/components/app/server/ServerLoadingSplash.svelte +32 -0
- tools/ui/src/lib/components/app/server/ServerStatus.svelte +69 -0
- tools/ui/src/lib/components/app/server/index.ts +80 -0
- tools/ui/src/lib/components/app/settings/SettingsChat/SettingsChat.svelte +183 -0
- tools/ui/src/lib/components/app/settings/SettingsChat/SettingsChatFields.svelte +330 -0
- tools/ui/src/lib/components/app/settings/SettingsChat/SettingsChatImportExportSection.svelte +63 -0
- tools/ui/src/lib/components/app/settings/SettingsChat/SettingsChatImportExportTab.svelte +348 -0
- tools/ui/src/lib/components/app/settings/SettingsChat/SettingsChatParameterSourceIndicator.svelte +19 -0
- tools/ui/src/lib/components/app/settings/SettingsChat/SettingsChatToolsTab.svelte +136 -0
- tools/ui/src/lib/components/app/settings/SettingsChatDesktopSidebar.svelte +31 -0
- tools/ui/src/lib/components/app/settings/SettingsChatMobileHeader.svelte +61 -0
.gitattributes
CHANGED
|
@@ -79,3 +79,6 @@ tools/mtmd/test-1.jpeg filter=lfs diff=lfs merge=lfs -text
|
|
| 79 |
tools/mtmd/test-2.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 80 |
tools/mtmd/test-3.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 81 |
tools/mtmd/tests/test-1-positive.png filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
tools/mtmd/test-2.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 80 |
tools/mtmd/test-3.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 81 |
tools/mtmd/tests/test-1-positive.png filter=lfs diff=lfs merge=lfs -text
|
| 82 |
+
tools/ui/static/recommended-mcp/huggingface.ico filter=lfs diff=lfs merge=lfs -text
|
| 83 |
+
tools/ui/tests/stories/fixtures/assets/beautiful-flowers-lotus.webp filter=lfs diff=lfs merge=lfs -text
|
| 84 |
+
tools/ui/tests/stories/fixtures/assets/example.pdf filter=lfs diff=lfs merge=lfs -text
|
tools/ui/src/lib/components/app/mcp/McpServerCard/McpServerCardActions.svelte
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { Pencil, RefreshCw, Trash2 } from '@lucide/svelte';
|
| 3 |
+
import { Button } from '$lib/components/ui/button';
|
| 4 |
+
|
| 5 |
+
interface Props {
|
| 6 |
+
isHealthChecking: boolean;
|
| 7 |
+
onEdit: () => void;
|
| 8 |
+
onRefresh: () => void;
|
| 9 |
+
onDelete: () => void;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
let { isHealthChecking, onDelete, onEdit, onRefresh }: Props = $props();
|
| 13 |
+
</script>
|
| 14 |
+
|
| 15 |
+
<div class="flex shrink-0 items-center gap-1">
|
| 16 |
+
<Button aria-label="Edit" class="h-7 w-7" onclick={onEdit} size="icon" variant="ghost">
|
| 17 |
+
<Pencil class="h-3.5 w-3.5" />
|
| 18 |
+
</Button>
|
| 19 |
+
|
| 20 |
+
<Button
|
| 21 |
+
aria-label="Refresh"
|
| 22 |
+
class="h-7 w-7"
|
| 23 |
+
disabled={isHealthChecking}
|
| 24 |
+
onclick={onRefresh}
|
| 25 |
+
size="icon"
|
| 26 |
+
variant="ghost"
|
| 27 |
+
>
|
| 28 |
+
<RefreshCw class="h-3.5 w-3.5" />
|
| 29 |
+
</Button>
|
| 30 |
+
|
| 31 |
+
<Button
|
| 32 |
+
aria-label="Delete"
|
| 33 |
+
class="hover:text-destructive-foreground h-7 w-7 text-destructive hover:bg-destructive/10"
|
| 34 |
+
onclick={onDelete}
|
| 35 |
+
size="icon"
|
| 36 |
+
variant="ghost"
|
| 37 |
+
>
|
| 38 |
+
<Trash2 class="h-3.5 w-3.5" />
|
| 39 |
+
</Button>
|
| 40 |
+
</div>
|
tools/ui/src/lib/components/app/mcp/McpServerCard/McpServerCardCompact.svelte
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import * as Card from '$lib/components/ui/card';
|
| 3 |
+
import type { RecommendedMCPServer } from '$lib/types';
|
| 4 |
+
import { mode } from 'mode-watcher';
|
| 5 |
+
|
| 6 |
+
interface Props {
|
| 7 |
+
server: RecommendedMCPServer;
|
| 8 |
+
onClick?: () => void;
|
| 9 |
+
selected?: boolean;
|
| 10 |
+
dimmed?: boolean;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
let { dimmed = false, onClick, selected = false, server }: Props = $props();
|
| 14 |
+
|
| 15 |
+
let activeIconUrl = $derived.by(() => {
|
| 16 |
+
const isDark = mode.current === 'dark';
|
| 17 |
+
|
| 18 |
+
if (isDark && server.iconUrlDark) return server.iconUrlDark;
|
| 19 |
+
|
| 20 |
+
if (!isDark && server.iconUrlLight) return server.iconUrlLight;
|
| 21 |
+
|
| 22 |
+
return server.iconUrl;
|
| 23 |
+
});
|
| 24 |
+
</script>
|
| 25 |
+
|
| 26 |
+
<Card.Root
|
| 27 |
+
class={`relative gap-3! select-none bg-muted/30 p-4 transition-all ${onClick ? 'cursor-pointer hover:bg-muted/50 hover:opacity-100' : ''} ${selected ? 'bg-muted/30 ring-1 ring-primary/40' : ''} ${dimmed ? 'opacity-50' : ''}`}
|
| 28 |
+
onclick={onClick}
|
| 29 |
+
>
|
| 30 |
+
<div class="flex min-w-0 items-center gap-2">
|
| 31 |
+
{#if activeIconUrl}
|
| 32 |
+
<img
|
| 33 |
+
alt=""
|
| 34 |
+
class="h-5 w-5 shrink-0 rounded"
|
| 35 |
+
decoding="async"
|
| 36 |
+
loading="lazy"
|
| 37 |
+
src={activeIconUrl}
|
| 38 |
+
/>
|
| 39 |
+
{/if}
|
| 40 |
+
|
| 41 |
+
<h4 class="min-w-0 flex-1 truncate font-medium">{server.name}</h4>
|
| 42 |
+
</div>
|
| 43 |
+
|
| 44 |
+
<p class="text-xs text-muted-foreground">{server.description}</p>
|
| 45 |
+
</Card.Root>
|
tools/ui/src/lib/components/app/mcp/McpServerCard/McpServerCardDeleteDialog.svelte
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import * as AlertDialog from '$lib/components/ui/alert-dialog';
|
| 3 |
+
|
| 4 |
+
interface Props {
|
| 5 |
+
open: boolean;
|
| 6 |
+
displayName: string;
|
| 7 |
+
onOpenChange: (open: boolean) => void;
|
| 8 |
+
onConfirm: () => void;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
let { displayName, onConfirm, onOpenChange, open = $bindable() }: Props = $props();
|
| 12 |
+
</script>
|
| 13 |
+
|
| 14 |
+
<AlertDialog.Root bind:open {onOpenChange}>
|
| 15 |
+
<AlertDialog.Content>
|
| 16 |
+
<AlertDialog.Header>
|
| 17 |
+
<AlertDialog.Title>Delete Server</AlertDialog.Title>
|
| 18 |
+
|
| 19 |
+
<AlertDialog.Description>
|
| 20 |
+
Are you sure you want to delete <strong>{displayName}</strong>? This action cannot be
|
| 21 |
+
undone.
|
| 22 |
+
</AlertDialog.Description>
|
| 23 |
+
</AlertDialog.Header>
|
| 24 |
+
|
| 25 |
+
<AlertDialog.Footer>
|
| 26 |
+
<AlertDialog.Cancel>Cancel</AlertDialog.Cancel>
|
| 27 |
+
|
| 28 |
+
<AlertDialog.Action
|
| 29 |
+
class="text-destructive-foreground bg-destructive hover:bg-destructive/90"
|
| 30 |
+
onclick={onConfirm}
|
| 31 |
+
>
|
| 32 |
+
Delete
|
| 33 |
+
</AlertDialog.Action>
|
| 34 |
+
</AlertDialog.Footer>
|
| 35 |
+
</AlertDialog.Content>
|
| 36 |
+
</AlertDialog.Root>
|
tools/ui/src/lib/components/app/mcp/McpServerCard/McpServerCardEditForm.svelte
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { McpServerForm } from '$lib/components/app/mcp';
|
| 3 |
+
import { Button } from '$lib/components/ui/button';
|
| 4 |
+
import { parseHeadersToArray } from '$lib/utils';
|
| 5 |
+
|
| 6 |
+
interface Props {
|
| 7 |
+
serverId: string;
|
| 8 |
+
serverUrl: string;
|
| 9 |
+
serverUseProxy?: boolean;
|
| 10 |
+
/** Current automatic label, prefilled so the user can customize it. */
|
| 11 |
+
serverLabel?: string;
|
| 12 |
+
onSave: (url: string, headers: string, useProxy: boolean, name?: string) => void;
|
| 13 |
+
onCancel: () => void;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
let {
|
| 17 |
+
onCancel,
|
| 18 |
+
onSave,
|
| 19 |
+
serverId,
|
| 20 |
+
serverLabel = '',
|
| 21 |
+
serverUrl,
|
| 22 |
+
serverUseProxy = false
|
| 23 |
+
}: Props = $props();
|
| 24 |
+
|
| 25 |
+
let editUrl = $derived(serverUrl);
|
| 26 |
+
let editName = $derived(serverLabel);
|
| 27 |
+
let editHeaders = $state('');
|
| 28 |
+
let editUseProxy = $derived(serverUseProxy);
|
| 29 |
+
|
| 30 |
+
let urlError = $derived.by(() => {
|
| 31 |
+
if (!editUrl.trim()) return 'URL is required';
|
| 32 |
+
|
| 33 |
+
try {
|
| 34 |
+
new URL(editUrl);
|
| 35 |
+
|
| 36 |
+
return null;
|
| 37 |
+
} catch {
|
| 38 |
+
return 'Invalid URL format';
|
| 39 |
+
}
|
| 40 |
+
});
|
| 41 |
+
|
| 42 |
+
let headerPairsValid = $derived(
|
| 43 |
+
parseHeadersToArray(editHeaders).every((p) => p.key.trim() && p.value.trim())
|
| 44 |
+
);
|
| 45 |
+
let canSave = $derived(!urlError && headerPairsValid);
|
| 46 |
+
|
| 47 |
+
function handleSave() {
|
| 48 |
+
if (!canSave) return;
|
| 49 |
+
|
| 50 |
+
// An unchanged prefill keeps following the automatic label; only an
|
| 51 |
+
// actual edit becomes a persisted custom display name.
|
| 52 |
+
const name = editName.trim() !== serverLabel.trim() ? editName.trim() : undefined;
|
| 53 |
+
|
| 54 |
+
onSave(editUrl.trim(), editHeaders.trim(), editUseProxy, name);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
function handleSubmit(event: SubmitEvent) {
|
| 58 |
+
event.preventDefault();
|
| 59 |
+
handleSave();
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
export function setInitialValues(url: string, headers: string, useProxy: boolean, name = '') {
|
| 63 |
+
editUrl = url;
|
| 64 |
+
editHeaders = headers;
|
| 65 |
+
editUseProxy = useProxy;
|
| 66 |
+
editName = name;
|
| 67 |
+
}
|
| 68 |
+
</script>
|
| 69 |
+
|
| 70 |
+
<form class="contents" onsubmit={handleSubmit}>
|
| 71 |
+
<div class="space-y-4">
|
| 72 |
+
<p class="font-medium">Configure Server</p>
|
| 73 |
+
|
| 74 |
+
<McpServerForm
|
| 75 |
+
headers={editHeaders}
|
| 76 |
+
id={serverId}
|
| 77 |
+
name={editName}
|
| 78 |
+
onHeadersChange={(v) => (editHeaders = v)}
|
| 79 |
+
onNameChange={(v) => (editName = v)}
|
| 80 |
+
onUrlChange={(v) => (editUrl = v)}
|
| 81 |
+
onUseProxyChange={(v) => (editUseProxy = v)}
|
| 82 |
+
url={editUrl}
|
| 83 |
+
urlError={editUrl ? urlError : null}
|
| 84 |
+
useProxy={editUseProxy}
|
| 85 |
+
/>
|
| 86 |
+
|
| 87 |
+
<div class="flex items-center justify-end gap-2">
|
| 88 |
+
<Button onclick={onCancel} size="sm" variant="secondary">Cancel</Button>
|
| 89 |
+
|
| 90 |
+
<Button disabled={!canSave} size="sm" type="submit">
|
| 91 |
+
{serverUrl.trim() ? 'Update' : 'Add'}
|
| 92 |
+
</Button>
|
| 93 |
+
</div>
|
| 94 |
+
</div>
|
| 95 |
+
</form>
|
tools/ui/src/lib/components/app/mcp/McpServerCard/McpServerCardHeader.svelte
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { McpCapabilitiesBadges, McpServerIdentity } from '$lib/components/app/mcp';
|
| 3 |
+
import { Badge } from '$lib/components/ui/badge';
|
| 4 |
+
import { Switch } from '$lib/components/ui/switch';
|
| 5 |
+
import { MCP_TRANSPORT_ICONS, MCP_TRANSPORT_LABELS } from '$lib/constants';
|
| 6 |
+
import { MCPTransportType } from '$lib/enums';
|
| 7 |
+
import type { MCPCapabilitiesInfo, MCPServerInfo } from '$lib/types';
|
| 8 |
+
|
| 9 |
+
interface Props {
|
| 10 |
+
displayName: string;
|
| 11 |
+
faviconUrl?: string | null;
|
| 12 |
+
enabled: boolean;
|
| 13 |
+
disabled?: boolean;
|
| 14 |
+
onToggle: (enabled: boolean) => void;
|
| 15 |
+
onBrowseResources?: () => void;
|
| 16 |
+
serverInfo?: MCPServerInfo;
|
| 17 |
+
capabilities?: MCPCapabilitiesInfo;
|
| 18 |
+
transportType?: MCPTransportType;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
let {
|
| 22 |
+
capabilities,
|
| 23 |
+
disabled = false,
|
| 24 |
+
displayName,
|
| 25 |
+
enabled,
|
| 26 |
+
faviconUrl,
|
| 27 |
+
onBrowseResources,
|
| 28 |
+
onToggle,
|
| 29 |
+
serverInfo,
|
| 30 |
+
transportType
|
| 31 |
+
}: Props = $props();
|
| 32 |
+
</script>
|
| 33 |
+
|
| 34 |
+
<div class="space-y-3">
|
| 35 |
+
<div class="flex items-start justify-between gap-3">
|
| 36 |
+
<div class="flex min-w-0 flex-col gap-3">
|
| 37 |
+
<div class="inline-flex items-center gap-2">
|
| 38 |
+
<McpServerIdentity
|
| 39 |
+
{displayName}
|
| 40 |
+
{faviconUrl}
|
| 41 |
+
iconClass="h-5 w-5"
|
| 42 |
+
iconRounded="rounded"
|
| 43 |
+
nameClass="leading-6 font-medium"
|
| 44 |
+
{serverInfo}
|
| 45 |
+
/>
|
| 46 |
+
</div>
|
| 47 |
+
|
| 48 |
+
{#if capabilities || transportType}
|
| 49 |
+
<div class="flex flex-wrap items-center gap-1.5">
|
| 50 |
+
{#if transportType}
|
| 51 |
+
{@const TransportIcon = MCP_TRANSPORT_ICONS[transportType]}
|
| 52 |
+
<Badge class="h-5 gap-1 px-1.5 text-[10px]" variant="outline">
|
| 53 |
+
{#if TransportIcon}
|
| 54 |
+
<TransportIcon class="h-3 w-3" />
|
| 55 |
+
{/if}
|
| 56 |
+
|
| 57 |
+
{MCP_TRANSPORT_LABELS[transportType] || transportType}
|
| 58 |
+
</Badge>
|
| 59 |
+
{/if}
|
| 60 |
+
|
| 61 |
+
{#if capabilities}
|
| 62 |
+
<McpCapabilitiesBadges {capabilities} {onBrowseResources} />
|
| 63 |
+
{/if}
|
| 64 |
+
</div>
|
| 65 |
+
{/if}
|
| 66 |
+
</div>
|
| 67 |
+
|
| 68 |
+
<div class="flex shrink-0 items-center pl-2">
|
| 69 |
+
<Switch checked={enabled} {disabled} onCheckedChange={onToggle} />
|
| 70 |
+
</div>
|
| 71 |
+
</div>
|
| 72 |
+
</div>
|
tools/ui/src/lib/components/app/mcp/McpServerCard/McpServerCardToolsList.svelte
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { ChevronDown, ChevronRight } from '@lucide/svelte';
|
| 3 |
+
import { Badge } from '$lib/components/ui/badge';
|
| 4 |
+
import * as Collapsible from '$lib/components/ui/collapsible';
|
| 5 |
+
|
| 6 |
+
interface Tool {
|
| 7 |
+
name: string;
|
| 8 |
+
description?: string;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
interface Props {
|
| 12 |
+
tools: Tool[];
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
let { tools }: Props = $props();
|
| 16 |
+
|
| 17 |
+
let isExpanded = $state(false);
|
| 18 |
+
let toolsCount = $derived(tools.length);
|
| 19 |
+
</script>
|
| 20 |
+
|
| 21 |
+
<Collapsible.Root bind:open={isExpanded}>
|
| 22 |
+
<Collapsible.Trigger
|
| 23 |
+
class="flex w-full items-center gap-1 text-xs text-muted-foreground hover:text-foreground"
|
| 24 |
+
>
|
| 25 |
+
{#if isExpanded}
|
| 26 |
+
<ChevronDown class="h-3.5 w-3.5" />
|
| 27 |
+
{:else}
|
| 28 |
+
<ChevronRight class="h-3.5 w-3.5" />
|
| 29 |
+
{/if}
|
| 30 |
+
|
| 31 |
+
<span>{toolsCount} tools available · Show details</span>
|
| 32 |
+
</Collapsible.Trigger>
|
| 33 |
+
|
| 34 |
+
<Collapsible.Content class="mt-2">
|
| 35 |
+
<div class="max-h-64 space-y-3 overflow-y-auto">
|
| 36 |
+
{#each tools as tool (tool.name)}
|
| 37 |
+
<div>
|
| 38 |
+
<Badge variant="secondary">{tool.name}</Badge>
|
| 39 |
+
|
| 40 |
+
{#if tool.description}
|
| 41 |
+
<p class="mt-1 text-xs text-muted-foreground">{tool.description}</p>
|
| 42 |
+
{/if}
|
| 43 |
+
</div>
|
| 44 |
+
{/each}
|
| 45 |
+
</div>
|
| 46 |
+
</Collapsible.Content>
|
| 47 |
+
</Collapsible.Root>
|
tools/ui/src/lib/components/app/mcp/McpServerCardSkeleton.svelte
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import * as Card from '$lib/components/ui/card';
|
| 3 |
+
import { Skeleton } from '$lib/components/ui/skeleton';
|
| 4 |
+
</script>
|
| 5 |
+
|
| 6 |
+
<Card.Root class="grid gap-3 p-4">
|
| 7 |
+
<div class="flex items-center justify-between gap-4">
|
| 8 |
+
<div class="flex items-center gap-2">
|
| 9 |
+
<Skeleton class="h-5 w-5 rounded" />
|
| 10 |
+
|
| 11 |
+
<Skeleton class="h-5 w-28" />
|
| 12 |
+
|
| 13 |
+
<Skeleton class="h-5 w-12 rounded-full" />
|
| 14 |
+
</div>
|
| 15 |
+
|
| 16 |
+
<Skeleton class="h-6 w-11 rounded-full" />
|
| 17 |
+
</div>
|
| 18 |
+
|
| 19 |
+
<div class="flex flex-wrap gap-1.5">
|
| 20 |
+
<Skeleton class="h-5 w-14 rounded-full" />
|
| 21 |
+
|
| 22 |
+
<Skeleton class="h-5 w-12 rounded-full" />
|
| 23 |
+
|
| 24 |
+
<Skeleton class="h-5 w-16 rounded-full" />
|
| 25 |
+
</div>
|
| 26 |
+
|
| 27 |
+
<div class="space-y-1.5">
|
| 28 |
+
<Skeleton class="h-4 w-40" />
|
| 29 |
+
|
| 30 |
+
<Skeleton class="h-4 w-52" />
|
| 31 |
+
</div>
|
| 32 |
+
|
| 33 |
+
<Skeleton class="h-3.5 w-36" />
|
| 34 |
+
|
| 35 |
+
<div class="flex justify-end gap-2">
|
| 36 |
+
<Skeleton class="h-8 w-8 rounded" />
|
| 37 |
+
|
| 38 |
+
<Skeleton class="h-8 w-8 rounded" />
|
| 39 |
+
|
| 40 |
+
<Skeleton class="h-8 w-8 rounded" />
|
| 41 |
+
</div>
|
| 42 |
+
</Card.Root>
|
tools/ui/src/lib/components/app/mcp/McpServerForm.svelte
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { KeyValuePairs } from '$lib/components/app';
|
| 3 |
+
import { Input } from '$lib/components/ui/input';
|
| 4 |
+
import { Switch } from '$lib/components/ui/switch';
|
| 5 |
+
import { CLI_FLAGS, HEADERS, MCP_SERVER_URL_PLACEHOLDER } from '$lib/constants';
|
| 6 |
+
import { UrlProtocol } from '$lib/enums';
|
| 7 |
+
import { mcpStore } from '$lib/stores';
|
| 8 |
+
import type { KeyValuePair } from '$lib/types';
|
| 9 |
+
import { parseHeadersToArray, serializeHeaders } from '$lib/utils';
|
| 10 |
+
|
| 11 |
+
interface Props {
|
| 12 |
+
url: string;
|
| 13 |
+
headers: string;
|
| 14 |
+
name?: string;
|
| 15 |
+
onNameChange?: (name: string) => void;
|
| 16 |
+
/** Shown in the empty display name field, e.g. the current automatic label. */
|
| 17 |
+
namePlaceholder?: string;
|
| 18 |
+
useProxy?: boolean;
|
| 19 |
+
onUrlChange: (url: string) => void;
|
| 20 |
+
onHeadersChange: (headers: string) => void;
|
| 21 |
+
onUseProxyChange?: (useProxy: boolean) => void;
|
| 22 |
+
urlError?: string | null;
|
| 23 |
+
id?: string;
|
| 24 |
+
/**
|
| 25 |
+
* "Wants Authorization" is the user's *intent* to add a Bearer token
|
| 26 |
+
* (separate from `hasAuthorization` which reflects what's already in
|
| 27 |
+
* the headers). Bindable so a parent - e.g. the recommendation cards
|
| 28 |
+
* on the "Add New Server" dialog - can flip the switch on when the
|
| 29 |
+
* picked server ships a `needsAuthorization: true` flag.
|
| 30 |
+
*/
|
| 31 |
+
wantsAuthorization?: boolean;
|
| 32 |
+
/**
|
| 33 |
+
* Marks the "Authorization" field as required. Locks the toggle so the
|
| 34 |
+
* user can't dismiss it, and visually marks the field with a red
|
| 35 |
+
* asterisk. The parent is expected to gate its submit affordance on
|
| 36 |
+
* the bearer token actually being filled. Used by the "Add New Server"
|
| 37 |
+
* dialog for recommendations whose `needsAuthorization` flag is true.
|
| 38 |
+
*/
|
| 39 |
+
required?: boolean;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
let {
|
| 43 |
+
headers,
|
| 44 |
+
id = 'server',
|
| 45 |
+
name = '',
|
| 46 |
+
namePlaceholder = 'Name reported by the server',
|
| 47 |
+
onHeadersChange,
|
| 48 |
+
onNameChange,
|
| 49 |
+
onUrlChange,
|
| 50 |
+
onUseProxyChange,
|
| 51 |
+
required = false,
|
| 52 |
+
url,
|
| 53 |
+
urlError = null,
|
| 54 |
+
useProxy = false,
|
| 55 |
+
wantsAuthorization = $bindable(false)
|
| 56 |
+
}: Props = $props();
|
| 57 |
+
|
| 58 |
+
let isWebSocket = $derived(
|
| 59 |
+
url.toLowerCase().startsWith(UrlProtocol.WEBSOCKET) ||
|
| 60 |
+
url.toLowerCase().startsWith(UrlProtocol.WEBSOCKET_SECURE)
|
| 61 |
+
);
|
| 62 |
+
|
| 63 |
+
let headerPairs = $derived<KeyValuePair[]>(parseHeadersToArray(headers));
|
| 64 |
+
|
| 65 |
+
// Heuristic: this dedicated UI only owns Authorization headers that already
|
| 66 |
+
// carry a Bearer scheme. Anything else (e.g. Basic, raw tokens) stays in the
|
| 67 |
+
// KV section so the user can still edit those values verbatim.
|
| 68 |
+
const matchesAuthorizationKey = (key: string): boolean =>
|
| 69 |
+
HEADERS.REDACTED.has(key.trim().toLowerCase());
|
| 70 |
+
|
| 71 |
+
const isBearerScheme = (value: string): boolean =>
|
| 72 |
+
value.trim().toLowerCase().startsWith(HEADERS.BEARER.toLowerCase());
|
| 73 |
+
|
| 74 |
+
const ownedByBearerUi = (p: KeyValuePair): boolean =>
|
| 75 |
+
matchesAuthorizationKey(p.key) && isBearerScheme(p.value);
|
| 76 |
+
|
| 77 |
+
let hasAuthorization = $derived(headerPairs.some(ownedByBearerUi));
|
| 78 |
+
|
| 79 |
+
let showAuthorization = $derived(hasAuthorization || wantsAuthorization);
|
| 80 |
+
|
| 81 |
+
let urlInput: HTMLInputElement | null = $state(null);
|
| 82 |
+
let bearerInput: HTMLInputElement | null = $state(null);
|
| 83 |
+
|
| 84 |
+
$effect(() => {
|
| 85 |
+
urlInput?.focus();
|
| 86 |
+
});
|
| 87 |
+
|
| 88 |
+
$effect(() => {
|
| 89 |
+
if (wantsAuthorization && bearerInput) {
|
| 90 |
+
bearerInput.focus();
|
| 91 |
+
}
|
| 92 |
+
});
|
| 93 |
+
|
| 94 |
+
let bearerToken = $derived.by(() => {
|
| 95 |
+
const auth = headerPairs.find(ownedByBearerUi);
|
| 96 |
+
|
| 97 |
+
if (!auth) return '';
|
| 98 |
+
|
| 99 |
+
return auth.value.trim().slice(HEADERS.BEARER.length).trim();
|
| 100 |
+
});
|
| 101 |
+
|
| 102 |
+
$effect(() => {
|
| 103 |
+
if (!headers.trim()) {
|
| 104 |
+
wantsAuthorization = false;
|
| 105 |
+
}
|
| 106 |
+
});
|
| 107 |
+
|
| 108 |
+
function updateHeaderPairs(newPairs: KeyValuePair[]) {
|
| 109 |
+
headerPairs = newPairs;
|
| 110 |
+
onHeadersChange(serializeHeaders(newPairs));
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
// The dedicated UI owns the Authorization slot end-to-end when the user
|
| 114 |
+
// engages it: any prior Authorization row (Bearer or otherwise) is replaced
|
| 115 |
+
// by exactly one { Authorization: "Bearer <token>" } entry. JSON's last-key
|
| 116 |
+
// behavior would otherwise pick one arbitrarily, so we strip first.
|
| 117 |
+
function updateBearerToken(token: string) {
|
| 118 |
+
const filtered = headerPairs.filter((p) => !matchesAuthorizationKey(p.key));
|
| 119 |
+
const trimmed = token.trim();
|
| 120 |
+
|
| 121 |
+
if (trimmed) {
|
| 122 |
+
filtered.push({ key: HEADERS.AUTHORIZATION, value: `${HEADERS.BEARER}${trimmed}` });
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
updateHeaderPairs(filtered);
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
function setUseAuthorization(checked: boolean) {
|
| 129 |
+
wantsAuthorization = checked;
|
| 130 |
+
|
| 131 |
+
if (!checked) {
|
| 132 |
+
// Only drop the entry this UI owns; a non-Bearer Authorization row
|
| 133 |
+
// authored in the KV section must survive a toggle off untouched.
|
| 134 |
+
const filtered = headerPairs.filter((p) => !ownedByBearerUi(p));
|
| 135 |
+
|
| 136 |
+
updateHeaderPairs(filtered);
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
</script>
|
| 140 |
+
|
| 141 |
+
<div class="grid gap-2">
|
| 142 |
+
<div class="mb-4">
|
| 143 |
+
<label class="mb-2 block text-xs font-medium select-none" for="server-url-{id}">
|
| 144 |
+
Server URL <span class="text-destructive">*</span>
|
| 145 |
+
</label>
|
| 146 |
+
|
| 147 |
+
<Input
|
| 148 |
+
bind:ref={urlInput}
|
| 149 |
+
class={urlError ? 'border-destructive' : ''}
|
| 150 |
+
id="server-url-{id}"
|
| 151 |
+
oninput={(e) => onUrlChange(e.currentTarget.value)}
|
| 152 |
+
placeholder={MCP_SERVER_URL_PLACEHOLDER}
|
| 153 |
+
type="url"
|
| 154 |
+
value={url}
|
| 155 |
+
/>
|
| 156 |
+
|
| 157 |
+
{#if urlError}
|
| 158 |
+
<p class="mt-1.5 text-xs text-destructive">{urlError}</p>
|
| 159 |
+
{/if}
|
| 160 |
+
</div>
|
| 161 |
+
|
| 162 |
+
<div class="mb-4">
|
| 163 |
+
<label class="mb-2 block text-xs font-medium select-none" for="server-name-{id}">
|
| 164 |
+
Display name
|
| 165 |
+
</label>
|
| 166 |
+
|
| 167 |
+
<Input
|
| 168 |
+
id="server-name-{id}"
|
| 169 |
+
oninput={(e) => onNameChange?.(e.currentTarget.value)}
|
| 170 |
+
placeholder={namePlaceholder}
|
| 171 |
+
type="text"
|
| 172 |
+
value={name}
|
| 173 |
+
/>
|
| 174 |
+
</div>
|
| 175 |
+
|
| 176 |
+
<label class="flex items-center gap-2 cursor-pointer select-none">
|
| 177 |
+
<Switch
|
| 178 |
+
checked={showAuthorization}
|
| 179 |
+
disabled={required}
|
| 180 |
+
id="use-authorization-{id}"
|
| 181 |
+
onCheckedChange={setUseAuthorization}
|
| 182 |
+
/>
|
| 183 |
+
|
| 184 |
+
<span class="text-xs text-muted-foreground">
|
| 185 |
+
Authorization{#if required}
|
| 186 |
+
<span class="text-destructive">*</span>{/if}
|
| 187 |
+
</span>
|
| 188 |
+
</label>
|
| 189 |
+
|
| 190 |
+
{#if showAuthorization}
|
| 191 |
+
<div class="relative mt-2">
|
| 192 |
+
<Input
|
| 193 |
+
bind:ref={bearerInput}
|
| 194 |
+
autocomplete="off"
|
| 195 |
+
class="pl-16"
|
| 196 |
+
id="bearer-token-{id}"
|
| 197 |
+
oninput={(e) => updateBearerToken(e.currentTarget.value)}
|
| 198 |
+
placeholder="Paste token here"
|
| 199 |
+
type="password"
|
| 200 |
+
value={bearerToken}
|
| 201 |
+
/>
|
| 202 |
+
|
| 203 |
+
<span
|
| 204 |
+
class="pointer-events-none absolute inset-y-0 left-3 flex items-center text-sm font-medium text-foreground"
|
| 205 |
+
>
|
| 206 |
+
Bearer
|
| 207 |
+
</span>
|
| 208 |
+
</div>
|
| 209 |
+
{/if}
|
| 210 |
+
|
| 211 |
+
<KeyValuePairs
|
| 212 |
+
addButtonLabel="Add"
|
| 213 |
+
class="mt-3"
|
| 214 |
+
emptyMessage="No custom headers configured."
|
| 215 |
+
keyPlaceholder="Header name"
|
| 216 |
+
onPairsChange={(pairs) => {
|
| 217 |
+
const auth = headerPairs.find(ownedByBearerUi);
|
| 218 |
+
|
| 219 |
+
updateHeaderPairs(auth ? [...pairs, auth] : pairs);
|
| 220 |
+
}}
|
| 221 |
+
pairs={headerPairs.filter((p) => !ownedByBearerUi(p))}
|
| 222 |
+
sectionLabel="Custom Headers"
|
| 223 |
+
sectionLabelOptional
|
| 224 |
+
valuePlaceholder="Value"
|
| 225 |
+
/>
|
| 226 |
+
|
| 227 |
+
{#if !isWebSocket && onUseProxyChange}
|
| 228 |
+
<label
|
| 229 |
+
class={[
|
| 230 |
+
'mt-3 flex items-start gap-2',
|
| 231 |
+
mcpStore.isProxyAvailable && 'cursor-pointer',
|
| 232 |
+
!mcpStore.isProxyAvailable && 'opacity-80'
|
| 233 |
+
]}
|
| 234 |
+
>
|
| 235 |
+
<Switch
|
| 236 |
+
checked={useProxy}
|
| 237 |
+
class="mt-1"
|
| 238 |
+
disabled={!mcpStore.isProxyAvailable}
|
| 239 |
+
id="use-proxy-{id}"
|
| 240 |
+
onCheckedChange={(checked) => onUseProxyChange?.(checked)}
|
| 241 |
+
/>
|
| 242 |
+
|
| 243 |
+
<span>
|
| 244 |
+
<span class="text-xs text-muted-foreground">Use llama-server proxy</span>
|
| 245 |
+
|
| 246 |
+
<br />
|
| 247 |
+
|
| 248 |
+
{#if !mcpStore.isProxyAvailable}
|
| 249 |
+
<span class="inline-flex gap-0.75 text-xs text-muted-foreground/60"
|
| 250 |
+
>(Run <pre>llama-server</pre>
|
| 251 |
+
with
|
| 252 |
+
<pre>{CLI_FLAGS.MCP_PROXY}</pre>
|
| 253 |
+
flag)</span
|
| 254 |
+
>
|
| 255 |
+
{/if}
|
| 256 |
+
</span>
|
| 257 |
+
</label>
|
| 258 |
+
{/if}
|
| 259 |
+
</div>
|
tools/ui/src/lib/components/app/mcp/McpServerIdentity.svelte
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { ExternalLink } from '@lucide/svelte';
|
| 3 |
+
import { McpLogo } from '$lib/components/app/mcp';
|
| 4 |
+
import { TruncatedText } from '$lib/components/app/misc';
|
| 5 |
+
import { Badge } from '$lib/components/ui/badge';
|
| 6 |
+
import type { MCPServerInfo } from '$lib/types';
|
| 7 |
+
import { sanitizeExternalUrl } from '$lib/utils';
|
| 8 |
+
|
| 9 |
+
interface Props {
|
| 10 |
+
displayName?: string;
|
| 11 |
+
faviconUrl?: string | null;
|
| 12 |
+
serverInfo?: MCPServerInfo;
|
| 13 |
+
iconClass?: string;
|
| 14 |
+
iconRounded?: string;
|
| 15 |
+
showVersion?: boolean;
|
| 16 |
+
showWebsite?: boolean;
|
| 17 |
+
nameClass?: string;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
let {
|
| 21 |
+
displayName,
|
| 22 |
+
faviconUrl = null,
|
| 23 |
+
iconClass = 'h-5 w-5',
|
| 24 |
+
iconRounded = 'rounded-sm',
|
| 25 |
+
nameClass,
|
| 26 |
+
serverInfo,
|
| 27 |
+
showVersion = true,
|
| 28 |
+
showWebsite = true
|
| 29 |
+
}: Props = $props();
|
| 30 |
+
|
| 31 |
+
let safeWebsiteUrl = $derived(
|
| 32 |
+
serverInfo?.websiteUrl ? sanitizeExternalUrl(serverInfo.websiteUrl) : null
|
| 33 |
+
);
|
| 34 |
+
</script>
|
| 35 |
+
|
| 36 |
+
<span class="flex min-w-0 items-center gap-1.5">
|
| 37 |
+
{#if faviconUrl}
|
| 38 |
+
<img alt="" class={['shrink-0 text-foreground', iconRounded, iconClass]} src={faviconUrl} />
|
| 39 |
+
{:else}
|
| 40 |
+
<McpLogo class={['shrink-0 text-foreground', iconRounded, iconClass].join(' ')} />
|
| 41 |
+
{/if}
|
| 42 |
+
|
| 43 |
+
<TruncatedText class={nameClass ?? ''} text={displayName ?? ''} />
|
| 44 |
+
|
| 45 |
+
{#if showVersion && serverInfo?.version}
|
| 46 |
+
<Badge class="h-4 max-w-24 min-w-0 shrink px-1 text-[10px]" variant="secondary">
|
| 47 |
+
<TruncatedText text={`v${serverInfo.version}`} />
|
| 48 |
+
</Badge>
|
| 49 |
+
{/if}
|
| 50 |
+
|
| 51 |
+
{#if showWebsite && safeWebsiteUrl}
|
| 52 |
+
<a
|
| 53 |
+
aria-label="Open website"
|
| 54 |
+
class="shrink-0 text-muted-foreground hover:text-foreground"
|
| 55 |
+
href={safeWebsiteUrl}
|
| 56 |
+
onclick={(e) => e.stopPropagation()}
|
| 57 |
+
rel="noopener noreferrer"
|
| 58 |
+
target="_blank"
|
| 59 |
+
>
|
| 60 |
+
<ExternalLink class="h-3 w-3" />
|
| 61 |
+
</a>
|
| 62 |
+
{/if}
|
| 63 |
+
</span>
|
tools/ui/src/lib/components/app/mcp/McpServerInfo.svelte
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { ChevronDown, ChevronRight } from '@lucide/svelte';
|
| 3 |
+
import * as Collapsible from '$lib/components/ui/collapsible';
|
| 4 |
+
|
| 5 |
+
interface Props {
|
| 6 |
+
instructions?: string;
|
| 7 |
+
class?: string;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
let { class: className, instructions }: Props = $props();
|
| 11 |
+
|
| 12 |
+
let isExpanded = $state(false);
|
| 13 |
+
</script>
|
| 14 |
+
|
| 15 |
+
{#if instructions}
|
| 16 |
+
<Collapsible.Root bind:open={isExpanded} class={className}>
|
| 17 |
+
<Collapsible.Trigger
|
| 18 |
+
class="flex w-full items-center gap-1 text-xs text-muted-foreground hover:text-foreground"
|
| 19 |
+
>
|
| 20 |
+
{#if isExpanded}
|
| 21 |
+
<ChevronDown class="h-3.5 w-3.5" />
|
| 22 |
+
{:else}
|
| 23 |
+
<ChevronRight class="h-3.5 w-3.5" />
|
| 24 |
+
{/if}
|
| 25 |
+
|
| 26 |
+
<span>Server instructions</span>
|
| 27 |
+
</Collapsible.Trigger>
|
| 28 |
+
|
| 29 |
+
<Collapsible.Content class="mt-2">
|
| 30 |
+
<p class="rounded bg-muted/50 p-2 text-xs text-muted-foreground">
|
| 31 |
+
{instructions}
|
| 32 |
+
</p>
|
| 33 |
+
</Collapsible.Content>
|
| 34 |
+
</Collapsible.Root>
|
| 35 |
+
{/if}
|
tools/ui/src/lib/components/app/mcp/index.ts
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
*
|
| 3 |
+
* MCP (Model Context Protocol)
|
| 4 |
+
*
|
| 5 |
+
* Components for managing MCP server connections and displaying server status.
|
| 6 |
+
* MCP enables agentic workflows by connecting to external tool servers.
|
| 7 |
+
*
|
| 8 |
+
* The MCP system integrates with:
|
| 9 |
+
* - `mcpStore` for server CRUD operations and health checks
|
| 10 |
+
* - `conversationsStore` for per-conversation server enable/disable
|
| 11 |
+
*
|
| 12 |
+
*/
|
| 13 |
+
|
| 14 |
+
/**
|
| 15 |
+
* **McpServersSettings** - MCP servers configuration section
|
| 16 |
+
*
|
| 17 |
+
* Settings section for configuring MCP server connections.
|
| 18 |
+
* Displays server cards with status, tools, and management actions.
|
| 19 |
+
* Used within the MCP tab of ChatSettings.
|
| 20 |
+
*
|
| 21 |
+
* **Architecture:**
|
| 22 |
+
* - Manages add server form state locally
|
| 23 |
+
* - Delegates server display to McpServerCard components
|
| 24 |
+
* - Integrates with mcpStore for server operations
|
| 25 |
+
* - Shows skeleton loading states during health checks
|
| 26 |
+
*
|
| 27 |
+
* **Features:**
|
| 28 |
+
* - Add new MCP servers by URL with validation
|
| 29 |
+
* - Server cards with connection status indicators
|
| 30 |
+
* - Health check status (connected/disconnected/error)
|
| 31 |
+
* - Tools list per server showing available capabilities
|
| 32 |
+
* - Enable/disable toggle per conversation
|
| 33 |
+
* - Edit/delete server actions
|
| 34 |
+
* - Skeleton loading states during connection
|
| 35 |
+
* - Empty state with helpful message
|
| 36 |
+
*
|
| 37 |
+
* @example
|
| 38 |
+
* ```svelte
|
| 39 |
+
* <McpServersSettings />
|
| 40 |
+
* ```
|
| 41 |
+
*/
|
| 42 |
+
export { default as McpServersSettings } from '../settings/SettingsMcpServers.svelte';
|
| 43 |
+
|
| 44 |
+
/**
|
| 45 |
+
* **McpActiveServersAvatars** - Active MCP servers indicator
|
| 46 |
+
*
|
| 47 |
+
* Compact avatar row showing favicons of active MCP servers.
|
| 48 |
+
* Displays up to 3 server icons with "+N" counter for additional servers.
|
| 49 |
+
* Clickable to open MCP settings dialog.
|
| 50 |
+
*
|
| 51 |
+
* **Architecture:**
|
| 52 |
+
* - Filters servers by enabled status and health check
|
| 53 |
+
* - Fetches favicons from server URLs
|
| 54 |
+
* - Integrates with conversationsStore for per-chat server state
|
| 55 |
+
*
|
| 56 |
+
* **Features:**
|
| 57 |
+
* - Overlapping favicon avatars (max 3 visible)
|
| 58 |
+
* - "+N" counter for additional servers
|
| 59 |
+
* - Click handler for settings navigation
|
| 60 |
+
* - Disabled state support
|
| 61 |
+
* - Only shows healthy, enabled servers
|
| 62 |
+
*
|
| 63 |
+
* @example
|
| 64 |
+
* ```svelte
|
| 65 |
+
* <McpActiveServersAvatars
|
| 66 |
+
* onSettingsClick={() => showMcpSettings = true}
|
| 67 |
+
* />
|
| 68 |
+
* ```
|
| 69 |
+
*/
|
| 70 |
+
export { default as McpActiveServersAvatars } from './McpActiveServersAvatars.svelte';
|
| 71 |
+
|
| 72 |
+
/**
|
| 73 |
+
* **McpCapabilitiesBadges** - Server capabilities display
|
| 74 |
+
*
|
| 75 |
+
* Displays MCP server capabilities as colored badges.
|
| 76 |
+
* Shows which features the server supports (tools, resources, prompts, etc.).
|
| 77 |
+
*
|
| 78 |
+
* **Features:**
|
| 79 |
+
* - Tools badge (green) - server provides callable tools
|
| 80 |
+
* - Resources badge (blue) - server provides data resources
|
| 81 |
+
* - Prompts badge (purple) - server provides prompt templates
|
| 82 |
+
* - Logging badge (orange) - server supports logging
|
| 83 |
+
* - Completions badge (cyan) - server provides completions
|
| 84 |
+
* - Tasks badge (pink) - server supports task management
|
| 85 |
+
*/
|
| 86 |
+
export { default as McpCapabilitiesBadges } from './McpCapabilitiesBadges.svelte';
|
| 87 |
+
|
| 88 |
+
/**
|
| 89 |
+
* **McpConnectionLogs** - Connection log viewer
|
| 90 |
+
*
|
| 91 |
+
* Collapsible panel showing MCP server connection logs.
|
| 92 |
+
* Displays timestamped log entries with level-based styling.
|
| 93 |
+
*
|
| 94 |
+
* **Features:**
|
| 95 |
+
* - Collapsible log list with entry count
|
| 96 |
+
* - Connection time display in milliseconds
|
| 97 |
+
* - Log level icons and color coding
|
| 98 |
+
* - Scrollable log container with max height
|
| 99 |
+
* - Monospace font for log readability
|
| 100 |
+
*/
|
| 101 |
+
export { default as McpConnectionLogs } from './McpConnectionLogs.svelte';
|
| 102 |
+
|
| 103 |
+
/**
|
| 104 |
+
* **McpServerForm** - Server URL and headers input form
|
| 105 |
+
*
|
| 106 |
+
* Reusable form for entering MCP server connection details.
|
| 107 |
+
* Used in both add new server and edit server flows.
|
| 108 |
+
*
|
| 109 |
+
* **Features:**
|
| 110 |
+
* - URL input with validation error display
|
| 111 |
+
* - Custom headers key-value pairs editor
|
| 112 |
+
* - Controlled component with change callbacks
|
| 113 |
+
*
|
| 114 |
+
* @example
|
| 115 |
+
* ```svelte
|
| 116 |
+
* <McpServerForm
|
| 117 |
+
* url={serverUrl}
|
| 118 |
+
* headers={serverHeaders}
|
| 119 |
+
* onUrlChange={(v) => serverUrl = v}
|
| 120 |
+
* onHeadersChange={(v) => serverHeaders = v}
|
| 121 |
+
* urlError={validationError}
|
| 122 |
+
* />
|
| 123 |
+
* ```
|
| 124 |
+
*/
|
| 125 |
+
export { default as McpServerForm } from './McpServerForm.svelte';
|
| 126 |
+
|
| 127 |
+
/**
|
| 128 |
+
* MCP protocol logo SVG component. Renders the official MCP icon
|
| 129 |
+
* with customizable size via class and style props.
|
| 130 |
+
*/
|
| 131 |
+
export { default as McpLogo } from './McpLogo.svelte';
|
| 132 |
+
|
| 133 |
+
/**
|
| 134 |
+
*
|
| 135 |
+
* SERVER CARD
|
| 136 |
+
*
|
| 137 |
+
* Components for displaying individual MCP server status and controls.
|
| 138 |
+
* McpServerCard is the main component, with sub-components for specific sections.
|
| 139 |
+
*
|
| 140 |
+
*/
|
| 141 |
+
|
| 142 |
+
/**
|
| 143 |
+
* **McpServerCard** - Individual server display card
|
| 144 |
+
*
|
| 145 |
+
* Main component for displaying a single MCP server with all its details.
|
| 146 |
+
* Manages edit mode, delete confirmation, and health check actions.
|
| 147 |
+
*
|
| 148 |
+
* **Architecture:**
|
| 149 |
+
* - Composes header, tools list, logs, and actions sub-components
|
| 150 |
+
* - Manages local edit/delete state
|
| 151 |
+
* - Reads health state from mcpStore
|
| 152 |
+
* - Triggers health checks via mcpStore
|
| 153 |
+
*
|
| 154 |
+
* **Features:**
|
| 155 |
+
* - Server header with favicon, name, version, and toggle
|
| 156 |
+
* - Capabilities badges display
|
| 157 |
+
* - Tools list with descriptions
|
| 158 |
+
* - Connection logs viewer
|
| 159 |
+
* - Edit form for URL and headers
|
| 160 |
+
* - Delete confirmation dialog
|
| 161 |
+
* - Skeleton loading states
|
| 162 |
+
*/
|
| 163 |
+
export { default as McpServerCard } from './McpServerCard/McpServerCard.svelte';
|
| 164 |
+
|
| 165 |
+
/** Server card header with favicon, name, version badge, and enable toggle. */
|
| 166 |
+
export { default as McpServerCardHeader } from './McpServerCard/McpServerCardHeader.svelte';
|
| 167 |
+
|
| 168 |
+
/** Action buttons row: edit, refresh, delete. */
|
| 169 |
+
export { default as McpServerCardActions } from './McpServerCard/McpServerCardActions.svelte';
|
| 170 |
+
|
| 171 |
+
/** Collapsible tools list showing available server tools with descriptions. */
|
| 172 |
+
export { default as McpServerCardToolsList } from './McpServerCard/McpServerCardToolsList.svelte';
|
| 173 |
+
|
| 174 |
+
/** Inline edit form for server URL and custom headers. */
|
| 175 |
+
export { default as McpServerCardEditForm } from './McpServerCard/McpServerCardEditForm.svelte';
|
| 176 |
+
|
| 177 |
+
/** Delete confirmation dialog with server name display. */
|
| 178 |
+
export { default as McpServerCardDeleteDialog } from './McpServerCard/McpServerCardDeleteDialog.svelte';
|
| 179 |
+
|
| 180 |
+
/** Skeleton loading state for server card during health checks. */
|
| 181 |
+
export { default as McpServerCardSkeleton } from './McpServerCardSkeleton.svelte';
|
| 182 |
+
|
| 183 |
+
/**
|
| 184 |
+
* **McpServerCardCompact** - Condensed MCP server card
|
| 185 |
+
*
|
| 186 |
+
* Static card for picker-style UIs (e.g. recommended MCP servers in the
|
| 187 |
+
* Add New Server dialog). Shows an optional favicon, the server name, and
|
| 188 |
+
* a short description. Performs no network requests - safe to render
|
| 189 |
+
* without contacting any upstream server until the user explicitly adds
|
| 190 |
+
* the server.
|
| 191 |
+
*/
|
| 192 |
+
export { default as McpServerCardCompact } from './McpServerCard/McpServerCardCompact.svelte';
|
| 193 |
+
|
| 194 |
+
/**
|
| 195 |
+
* **McpServerIdentity** - Server identity display (icon, name, version)
|
| 196 |
+
*
|
| 197 |
+
* Reusable headless component for displaying server name, favicon/icon, and version badge.
|
| 198 |
+
* Accepts all data via props with no store dependencies for predictable rendering.
|
| 199 |
+
*
|
| 200 |
+
* **Features:**
|
| 201 |
+
* - Server favicon/icon with fallback
|
| 202 |
+
* - Truncated display name with max-width
|
| 203 |
+
* - Optional version badge (v1.2.3)
|
| 204 |
+
* - Optional external link to server website
|
| 205 |
+
*
|
| 206 |
+
* @example
|
| 207 |
+
* ```svelte
|
| 208 |
+
* <McpServerIdentity displayName={name} faviconUrl={iconUrl} serverInfo={info} />
|
| 209 |
+
* ```
|
| 210 |
+
*/
|
| 211 |
+
export { default as McpServerIdentity } from './McpServerIdentity.svelte';
|
| 212 |
+
|
| 213 |
+
/**
|
| 214 |
+
* **McpServerInfo** - Server instructions display
|
| 215 |
+
*
|
| 216 |
+
* Collapsible panel showing server-provided instructions.
|
| 217 |
+
* Displays guidance text from the MCP server for users.
|
| 218 |
+
*/
|
| 219 |
+
export { default as McpServerInfo } from './McpServerInfo.svelte';
|
| 220 |
+
|
| 221 |
+
/**
|
| 222 |
+
* **McpResourcesBrowser** - MCP resources tree browser
|
| 223 |
+
*
|
| 224 |
+
* Tree view component showing resources grouped by server.
|
| 225 |
+
* Supports resource selection and quick attach actions.
|
| 226 |
+
*
|
| 227 |
+
* **Features:**
|
| 228 |
+
* - Collapsible server sections
|
| 229 |
+
* - Resource icons based on MIME type
|
| 230 |
+
* - Resource selection highlighting
|
| 231 |
+
* - Quick attach button per resource
|
| 232 |
+
* - Refresh all resources action
|
| 233 |
+
* - Loading states per server
|
| 234 |
+
*/
|
| 235 |
+
export { default as McpResourcesBrowser } from './McpResourcesBrowser/McpResourcesBrowser.svelte';
|
| 236 |
+
|
| 237 |
+
/**
|
| 238 |
+
* **McpResourcePreview** - MCP resource content preview
|
| 239 |
+
*
|
| 240 |
+
* Preview panel showing resource content with metadata.
|
| 241 |
+
* Supports text and binary content display.
|
| 242 |
+
*
|
| 243 |
+
* **Features:**
|
| 244 |
+
* - Text content display with monospace formatting
|
| 245 |
+
* - Image preview for image MIME types
|
| 246 |
+
* - Copy to clipboard action
|
| 247 |
+
* - Download content action
|
| 248 |
+
* - Resource metadata display (MIME type, priority, server)
|
| 249 |
+
* - Loading and error states
|
| 250 |
+
*/
|
| 251 |
+
export { default as McpResourcePreview } from './McpResourcePreview.svelte';
|
| 252 |
+
|
| 253 |
+
/**
|
| 254 |
+
* **McpResourceTemplateForm** - MCP resource template variable form
|
| 255 |
+
*
|
| 256 |
+
* Form for filling in resource template variables with auto-completion
|
| 257 |
+
* via the Completions API. Shows live URI preview as variables are filled.
|
| 258 |
+
*
|
| 259 |
+
* **Features:**
|
| 260 |
+
* - Template variable input fields
|
| 261 |
+
* - Completions API integration for variable auto-complete
|
| 262 |
+
* - Live URI preview as variables are filled
|
| 263 |
+
* - Read resolved resource action
|
| 264 |
+
*/
|
| 265 |
+
export { default as McpResourceTemplateForm } from './McpResourceTemplateForm.svelte';
|
tools/ui/src/lib/components/app/misc/CodeBlockActions.svelte
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { Eye } from '@lucide/svelte';
|
| 3 |
+
import { ActionIcon, ActionIconCopyToClipboard } from '$lib/components/app';
|
| 4 |
+
import { FileTypeText } from '$lib/enums';
|
| 5 |
+
|
| 6 |
+
interface Props {
|
| 7 |
+
code: string;
|
| 8 |
+
language: string;
|
| 9 |
+
disabled?: boolean;
|
| 10 |
+
onPreview?: (code: string, language: string) => void;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
let { code, disabled = false, language, onPreview }: Props = $props();
|
| 14 |
+
|
| 15 |
+
const showPreview = $derived(language?.toLowerCase() === FileTypeText.HTML);
|
| 16 |
+
</script>
|
| 17 |
+
|
| 18 |
+
<div class="code-block-actions">
|
| 19 |
+
<ActionIconCopyToClipboard
|
| 20 |
+
ariaLabel={disabled ? 'Code incomplete' : 'Copy code'}
|
| 21 |
+
canCopy={!disabled}
|
| 22 |
+
text={code}
|
| 23 |
+
/>
|
| 24 |
+
|
| 25 |
+
{#if showPreview}
|
| 26 |
+
<ActionIcon
|
| 27 |
+
{disabled}
|
| 28 |
+
icon={Eye}
|
| 29 |
+
onclick={() => onPreview!(code, language)}
|
| 30 |
+
tooltip={disabled ? 'Code incomplete' : 'Preview code'}
|
| 31 |
+
/>
|
| 32 |
+
{/if}
|
| 33 |
+
</div>
|
tools/ui/src/lib/components/app/misc/ConversationSelection.svelte
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import SearchInput from '$lib/components/app/forms/SearchInput.svelte';
|
| 3 |
+
import { Button } from '$lib/components/ui/button';
|
| 4 |
+
import { Checkbox } from '$lib/components/ui/checkbox';
|
| 5 |
+
import { ScrollArea } from '$lib/components/ui/scroll-area';
|
| 6 |
+
import { UI_DATA_ATTRS } from '$lib/constants';
|
| 7 |
+
import { useMarqueeSelection } from '$lib/hooks/use-marquee-selection.svelte';
|
| 8 |
+
import { SvelteSet } from 'svelte/reactivity';
|
| 9 |
+
|
| 10 |
+
interface Props {
|
| 11 |
+
conversations: DatabaseConversation[];
|
| 12 |
+
messageCountMap?: Map<string, number>;
|
| 13 |
+
mode: 'export' | 'import';
|
| 14 |
+
onCancel: () => void;
|
| 15 |
+
onConfirm: (selectedConversations: DatabaseConversation[]) => void;
|
| 16 |
+
isOpen?: boolean;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
let {
|
| 20 |
+
conversations,
|
| 21 |
+
isOpen = true,
|
| 22 |
+
messageCountMap = new Map(),
|
| 23 |
+
mode,
|
| 24 |
+
onCancel,
|
| 25 |
+
onConfirm
|
| 26 |
+
}: Props = $props();
|
| 27 |
+
|
| 28 |
+
let searchQuery = $state('');
|
| 29 |
+
let selectedIds = $state.raw<SvelteSet<string>>(getInitialSelectedIds());
|
| 30 |
+
|
| 31 |
+
function getInitialSelectedIds(): SvelteSet<string> {
|
| 32 |
+
return new SvelteSet(conversations.map((c) => c.id));
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
let filteredConversations = $derived(
|
| 36 |
+
conversations.filter((conv) => {
|
| 37 |
+
const name = conv.name || 'Untitled conversation';
|
| 38 |
+
|
| 39 |
+
return name.toLowerCase().includes(searchQuery.toLowerCase());
|
| 40 |
+
})
|
| 41 |
+
);
|
| 42 |
+
|
| 43 |
+
let orderedIds = $derived(filteredConversations.map((c) => c.id));
|
| 44 |
+
|
| 45 |
+
let allSelected = $derived(
|
| 46 |
+
filteredConversations.length > 0 &&
|
| 47 |
+
filteredConversations.every((conv) => selectedIds.has(conv.id))
|
| 48 |
+
);
|
| 49 |
+
|
| 50 |
+
let someSelected = $derived(
|
| 51 |
+
filteredConversations.some((conv) => selectedIds.has(conv.id)) && !allSelected
|
| 52 |
+
);
|
| 53 |
+
|
| 54 |
+
const marquee = useMarqueeSelection({
|
| 55 |
+
enabled: () => isOpen,
|
| 56 |
+
orderedIds: () => orderedIds,
|
| 57 |
+
selectedIds: () => selectedIds
|
| 58 |
+
});
|
| 59 |
+
|
| 60 |
+
function toggleAll() {
|
| 61 |
+
const newSet = new SvelteSet(selectedIds);
|
| 62 |
+
|
| 63 |
+
if (allSelected) {
|
| 64 |
+
filteredConversations.forEach((conv) => newSet.delete(conv.id));
|
| 65 |
+
} else {
|
| 66 |
+
filteredConversations.forEach((conv) => newSet.add(conv.id));
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
selectedIds = newSet;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
function handleConfirm() {
|
| 73 |
+
const selected = conversations.filter((conv) => selectedIds.has(conv.id));
|
| 74 |
+
|
| 75 |
+
onConfirm(selected);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
function handleCancel() {
|
| 79 |
+
selectedIds = getInitialSelectedIds();
|
| 80 |
+
searchQuery = '';
|
| 81 |
+
marquee.reset();
|
| 82 |
+
|
| 83 |
+
onCancel();
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
export function reset() {
|
| 87 |
+
selectedIds = getInitialSelectedIds();
|
| 88 |
+
searchQuery = '';
|
| 89 |
+
marquee.reset();
|
| 90 |
+
}
|
| 91 |
+
</script>
|
| 92 |
+
|
| 93 |
+
<div class="space-y-4">
|
| 94 |
+
<SearchInput bind:value={searchQuery} placeholder="Search conversations..." />
|
| 95 |
+
|
| 96 |
+
<div class="flex items-center justify-between text-sm text-muted-foreground">
|
| 97 |
+
<span>
|
| 98 |
+
{selectedIds.size} of {conversations.length} selected
|
| 99 |
+
{#if searchQuery}
|
| 100 |
+
({filteredConversations.length} shown)
|
| 101 |
+
{/if}
|
| 102 |
+
</span>
|
| 103 |
+
</div>
|
| 104 |
+
|
| 105 |
+
<div class="overflow-hidden rounded-md border">
|
| 106 |
+
<ScrollArea class="h-100">
|
| 107 |
+
<table class="w-full">
|
| 108 |
+
<thead class="sticky top-0 z-10 bg-muted">
|
| 109 |
+
<tr class="border-b">
|
| 110 |
+
<th class="w-12 p-3 text-left">
|
| 111 |
+
<Checkbox
|
| 112 |
+
checked={allSelected}
|
| 113 |
+
indeterminate={someSelected}
|
| 114 |
+
onCheckedChange={toggleAll}
|
| 115 |
+
/>
|
| 116 |
+
</th>
|
| 117 |
+
|
| 118 |
+
<th class="p-3 text-left text-sm font-medium">Conversation Name</th>
|
| 119 |
+
|
| 120 |
+
<th class="w-32 p-3 text-left text-sm font-medium">Messages</th>
|
| 121 |
+
</tr>
|
| 122 |
+
</thead>
|
| 123 |
+
|
| 124 |
+
<tbody>
|
| 125 |
+
{#if filteredConversations.length === 0}
|
| 126 |
+
<tr>
|
| 127 |
+
<td class="p-8 text-center text-sm text-muted-foreground" colspan="3">
|
| 128 |
+
{#if searchQuery}
|
| 129 |
+
No conversations found matching "{searchQuery}"
|
| 130 |
+
{:else}
|
| 131 |
+
No conversations available
|
| 132 |
+
{/if}
|
| 133 |
+
</td>
|
| 134 |
+
</tr>
|
| 135 |
+
{:else}
|
| 136 |
+
{#each filteredConversations as conv (conv.id)}
|
| 137 |
+
{@const checked = selectedIds.has(conv.id)}
|
| 138 |
+
<tr
|
| 139 |
+
class="cursor-pointer border-b transition-colors hover:bg-muted/50 {checked
|
| 140 |
+
? 'bg-muted/75'
|
| 141 |
+
: ''}"
|
| 142 |
+
{...{ [UI_DATA_ATTRS.CONVERSATION_ROW]: conv.id }}
|
| 143 |
+
onclick={(event) => marquee.rowClick(conv.id, event.shiftKey)}
|
| 144 |
+
onmousedown={(event) => marquee.rowMouseDown(conv.id, event)}
|
| 145 |
+
>
|
| 146 |
+
<td class="p-3">
|
| 147 |
+
<Checkbox
|
| 148 |
+
{checked}
|
| 149 |
+
onclick={(event) => {
|
| 150 |
+
event.preventDefault();
|
| 151 |
+
event.stopPropagation();
|
| 152 |
+
marquee.rowClick(conv.id, event.shiftKey);
|
| 153 |
+
}}
|
| 154 |
+
/>
|
| 155 |
+
</td>
|
| 156 |
+
|
| 157 |
+
<td class="p-3 text-sm">
|
| 158 |
+
<div class="max-w-68 truncate" title={conv.name || 'Untitled conversation'}>
|
| 159 |
+
{conv.name || 'Untitled conversation'}
|
| 160 |
+
</div>
|
| 161 |
+
</td>
|
| 162 |
+
|
| 163 |
+
<td class="p-3 text-sm text-muted-foreground">
|
| 164 |
+
{messageCountMap.get(conv.id) ?? 0}
|
| 165 |
+
</td>
|
| 166 |
+
</tr>
|
| 167 |
+
{/each}
|
| 168 |
+
{/if}
|
| 169 |
+
</tbody>
|
| 170 |
+
</table>
|
| 171 |
+
</ScrollArea>
|
| 172 |
+
</div>
|
| 173 |
+
|
| 174 |
+
<div class="flex justify-end gap-2">
|
| 175 |
+
<Button onclick={handleCancel} variant="outline">Cancel</Button>
|
| 176 |
+
|
| 177 |
+
<Button disabled={selectedIds.size === 0} onclick={handleConfirm}>
|
| 178 |
+
{mode === 'export' ? 'Export' : 'Import'} ({selectedIds.size})
|
| 179 |
+
</Button>
|
| 180 |
+
</div>
|
| 181 |
+
</div>
|
tools/ui/src/lib/components/app/misc/KeyboardShortcutInfo.svelte
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { ArrowBigUp } from '@lucide/svelte';
|
| 3 |
+
|
| 4 |
+
interface Props {
|
| 5 |
+
keys: string[];
|
| 6 |
+
variant?: 'default' | 'destructive';
|
| 7 |
+
class?: string;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
let { class: className = '', keys, variant = 'default' }: Props = $props();
|
| 11 |
+
|
| 12 |
+
let baseClasses =
|
| 13 |
+
'px-1 pointer-events-none inline-flex select-none items-center gap-0.5 font-sans text-md font-medium opacity-0 transition-opacity -my-1';
|
| 14 |
+
let variantClasses = $derived(
|
| 15 |
+
variant === 'destructive' ? 'text-destructive' : 'text-muted-foreground'
|
| 16 |
+
);
|
| 17 |
+
</script>
|
| 18 |
+
|
| 19 |
+
<kbd class="{baseClasses} {variantClasses} {className}">
|
| 20 |
+
{#each keys as key, index (index)}
|
| 21 |
+
{#if key === 'shift'}
|
| 22 |
+
<ArrowBigUp class="h-1 w-1 {variant === 'destructive' ? 'text-destructive' : ''} -mr-1" />
|
| 23 |
+
{:else if key === 'cmd'}
|
| 24 |
+
<span class={variant === 'destructive' ? 'text-destructive' : ''}>⌘</span>
|
| 25 |
+
{:else}
|
| 26 |
+
{key.toUpperCase()}
|
| 27 |
+
{/if}
|
| 28 |
+
|
| 29 |
+
{#if index < keys.length - 1}
|
| 30 |
+
<span> </span>
|
| 31 |
+
{/if}
|
| 32 |
+
{/each}
|
| 33 |
+
</kbd>
|
tools/ui/src/lib/components/app/misc/Logo.svelte
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script>
|
| 2 |
+
import logoMark from '$lib/assets/logo.svg?raw';
|
| 3 |
+
let { class: className = '', style = '' } = $props();
|
| 4 |
+
</script>
|
| 5 |
+
|
| 6 |
+
<div class={className} {style}>
|
| 7 |
+
{@html logoMark}
|
| 8 |
+
</div>
|
| 9 |
+
|
| 10 |
+
<style>
|
| 11 |
+
div :global(svg) {
|
| 12 |
+
width: var(--size, 1rem);
|
| 13 |
+
height: var(--size, 1rem);
|
| 14 |
+
}
|
| 15 |
+
</style>
|
tools/ui/src/lib/components/app/misc/ScrollCarousel.svelte
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { ChevronLeft, ChevronRight } from '@lucide/svelte';
|
| 3 |
+
import { cn } from '$lib/components/ui/utils';
|
| 4 |
+
import { ICON_CLASS_DEFAULT } from '$lib/constants';
|
| 5 |
+
import { ScrollCarouselVariant } from '$lib/enums';
|
| 6 |
+
import { useScrollCarousel } from '$lib/hooks/use-scroll-carousel.svelte';
|
| 7 |
+
import type { Snippet } from 'svelte';
|
| 8 |
+
|
| 9 |
+
interface Props {
|
| 10 |
+
children: Snippet;
|
| 11 |
+
/** External carousel hook for callers that need to drive it (e.g. scrollToCenter). */
|
| 12 |
+
carousel?: ReturnType<typeof useScrollCarousel>;
|
| 13 |
+
/** Classes for the outer relative wrapper. */
|
| 14 |
+
class?: string;
|
| 15 |
+
/** Classes for the scrollable overflow container. */
|
| 16 |
+
containerClass?: string;
|
| 17 |
+
/** Classes for the min-w-max content wrapper. */
|
| 18 |
+
innerClass?: string;
|
| 19 |
+
/** Tailwind gap class applied to the content wrapper. */
|
| 20 |
+
gapSize?: string;
|
| 21 |
+
/** Show the arrows whenever the content overflows, even without hover. */
|
| 22 |
+
alwaysShowArrows?: boolean;
|
| 23 |
+
/** Arrow placement and styling. */
|
| 24 |
+
variant?: ScrollCarouselVariant;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
let {
|
| 28 |
+
alwaysShowArrows = false,
|
| 29 |
+
carousel: externalCarousel,
|
| 30 |
+
children,
|
| 31 |
+
class: className = '',
|
| 32 |
+
containerClass = '',
|
| 33 |
+
gapSize = '3',
|
| 34 |
+
innerClass = '',
|
| 35 |
+
variant = ScrollCarouselVariant.TOP
|
| 36 |
+
}: Props = $props();
|
| 37 |
+
|
| 38 |
+
const internalCarousel = useScrollCarousel();
|
| 39 |
+
const carousel = $derived(externalCarousel ?? internalCarousel);
|
| 40 |
+
|
| 41 |
+
const isCenter = $derived(variant === ScrollCarouselVariant.CENTER);
|
| 42 |
+
|
| 43 |
+
function scrollLeft(event?: MouseEvent) {
|
| 44 |
+
event?.stopPropagation();
|
| 45 |
+
event?.preventDefault();
|
| 46 |
+
|
| 47 |
+
const container = carousel.scrollContainer;
|
| 48 |
+
|
| 49 |
+
if (!container) return;
|
| 50 |
+
|
| 51 |
+
container.scrollBy({ behavior: 'smooth', left: -(container.clientWidth * 0.67) });
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
function scrollRight(event?: MouseEvent) {
|
| 55 |
+
event?.stopPropagation();
|
| 56 |
+
event?.preventDefault();
|
| 57 |
+
|
| 58 |
+
const container = carousel.scrollContainer;
|
| 59 |
+
|
| 60 |
+
if (!container) return;
|
| 61 |
+
|
| 62 |
+
container.scrollBy({ behavior: 'smooth', left: container.clientWidth * 0.67 });
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
export function resetScroll() {
|
| 66 |
+
const container = carousel.scrollContainer;
|
| 67 |
+
|
| 68 |
+
if (!container) return;
|
| 69 |
+
|
| 70 |
+
container.scrollLeft = 0;
|
| 71 |
+
setTimeout(() => carousel.updateScrollButtons(), 0);
|
| 72 |
+
}
|
| 73 |
+
</script>
|
| 74 |
+
|
| 75 |
+
<div
|
| 76 |
+
class={cn('group relative', !isCenter && 'flex items-center', className)}
|
| 77 |
+
style={!isCenter ? 'scroll-padding: 1rem;' : undefined}
|
| 78 |
+
>
|
| 79 |
+
<button
|
| 80 |
+
class={cn(
|
| 81 |
+
'absolute z-10 flex h-6 w-6 items-center justify-center rounded-full shadow-md transition-opacity',
|
| 82 |
+
isCenter
|
| 83 |
+
? 'top-1/2 left-4 -translate-y-1/2 bg-background/25 backdrop-blur-xs hover:bg-background/45 disabled:pointer-events-none disabled:opacity-0'
|
| 84 |
+
: 'left-2 bg-muted backdrop-blur-sm hover:bg-accent',
|
| 85 |
+
!isCenter &&
|
| 86 |
+
(carousel.canScrollLeft
|
| 87 |
+
? alwaysShowArrows
|
| 88 |
+
? 'opacity-100'
|
| 89 |
+
: 'opacity-0 group-hover:opacity-100'
|
| 90 |
+
: 'pointer-events-none opacity-0')
|
| 91 |
+
)}
|
| 92 |
+
{...isCenter ? { disabled: !carousel.canScrollLeft } : {}}
|
| 93 |
+
aria-label="Scroll left"
|
| 94 |
+
onclick={scrollLeft}
|
| 95 |
+
>
|
| 96 |
+
<ChevronLeft class={ICON_CLASS_DEFAULT} />
|
| 97 |
+
</button>
|
| 98 |
+
|
| 99 |
+
<div
|
| 100 |
+
bind:this={carousel.scrollContainer}
|
| 101 |
+
class={cn('scrollbar-hide overflow-x-auto', containerClass)}
|
| 102 |
+
onscroll={carousel.updateScrollButtons}
|
| 103 |
+
>
|
| 104 |
+
<div
|
| 105 |
+
bind:this={carousel.contentContainer}
|
| 106 |
+
class={cn('flex min-w-max', isCenter && 'items-start', `gap-${gapSize}`, innerClass)}
|
| 107 |
+
>
|
| 108 |
+
{@render children?.()}
|
| 109 |
+
</div>
|
| 110 |
+
</div>
|
| 111 |
+
|
| 112 |
+
<button
|
| 113 |
+
class={cn(
|
| 114 |
+
'absolute z-10 flex h-6 w-6 items-center justify-center rounded-full shadow-md transition-opacity',
|
| 115 |
+
isCenter
|
| 116 |
+
? 'top-1/2 right-4 -translate-y-1/2 bg-background/25 backdrop-blur-xs hover:bg-background/45 disabled:pointer-events-none disabled:opacity-0'
|
| 117 |
+
: 'right-2 bg-muted backdrop-blur-sm hover:bg-accent',
|
| 118 |
+
!isCenter &&
|
| 119 |
+
(carousel.canScrollRight
|
| 120 |
+
? alwaysShowArrows
|
| 121 |
+
? 'opacity-100'
|
| 122 |
+
: 'opacity-0 group-hover:opacity-100'
|
| 123 |
+
: 'pointer-events-none opacity-0')
|
| 124 |
+
)}
|
| 125 |
+
{...isCenter ? { disabled: !carousel.canScrollRight } : {}}
|
| 126 |
+
aria-label="Scroll right"
|
| 127 |
+
onclick={scrollRight}
|
| 128 |
+
>
|
| 129 |
+
<ChevronRight class={ICON_CLASS_DEFAULT} />
|
| 130 |
+
</button>
|
| 131 |
+
</div>
|
tools/ui/src/lib/components/app/misc/TruncatedText.svelte
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import * as Tooltip from '$lib/components/ui/tooltip';
|
| 3 |
+
|
| 4 |
+
interface Props {
|
| 5 |
+
text: string;
|
| 6 |
+
class?: string;
|
| 7 |
+
showTooltip?: boolean;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
let { class: className = '', showTooltip = true, text }: Props = $props();
|
| 11 |
+
|
| 12 |
+
let textElement: HTMLSpanElement | undefined = $state();
|
| 13 |
+
let isTruncated = $state(false);
|
| 14 |
+
|
| 15 |
+
function checkTruncation() {
|
| 16 |
+
if (textElement) {
|
| 17 |
+
isTruncated = textElement.scrollWidth > textElement.clientWidth;
|
| 18 |
+
}
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
$effect(() => {
|
| 22 |
+
if (textElement) {
|
| 23 |
+
checkTruncation();
|
| 24 |
+
|
| 25 |
+
const observer = new ResizeObserver(checkTruncation);
|
| 26 |
+
|
| 27 |
+
observer.observe(textElement);
|
| 28 |
+
|
| 29 |
+
return () => observer.disconnect();
|
| 30 |
+
}
|
| 31 |
+
});
|
| 32 |
+
</script>
|
| 33 |
+
|
| 34 |
+
{#if isTruncated && showTooltip}
|
| 35 |
+
<Tooltip.Root>
|
| 36 |
+
<Tooltip.Trigger class="{className} min-w-0">
|
| 37 |
+
<span bind:this={textElement} class="block truncate">
|
| 38 |
+
{text}
|
| 39 |
+
</span>
|
| 40 |
+
</Tooltip.Trigger>
|
| 41 |
+
|
| 42 |
+
<Tooltip.Content class="z-[9999]">
|
| 43 |
+
<p>{text}</p>
|
| 44 |
+
</Tooltip.Content>
|
| 45 |
+
</Tooltip.Root>
|
| 46 |
+
{:else}
|
| 47 |
+
<span bind:this={textElement} class="{className} block min-w-0 truncate">
|
| 48 |
+
{text}
|
| 49 |
+
</span>
|
| 50 |
+
{/if}
|
tools/ui/src/lib/components/app/misc/index.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
*
|
| 3 |
+
* MISC
|
| 4 |
+
*
|
| 5 |
+
* Miscellaneous utility components.
|
| 6 |
+
*
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
/**
|
| 10 |
+
* **ConversationSelection** - Multi-select conversation picker
|
| 11 |
+
*
|
| 12 |
+
* List of conversations with checkboxes for multi-selection.
|
| 13 |
+
* Used in import/export dialogs for selecting conversations.
|
| 14 |
+
*
|
| 15 |
+
* **Features:**
|
| 16 |
+
* - Search/filter conversations by name
|
| 17 |
+
* - Select all / deselect all controls
|
| 18 |
+
* - Shift-click for range selection
|
| 19 |
+
* - Message count display per conversation
|
| 20 |
+
* - Mode-specific UI (export vs import)
|
| 21 |
+
*/
|
| 22 |
+
export { default as ConversationSelection } from './ConversationSelection.svelte';
|
| 23 |
+
|
| 24 |
+
/**
|
| 25 |
+
* **TruncatedText** - Text with ellipsis and tooltip
|
| 26 |
+
*
|
| 27 |
+
* Displays text with automatic truncation and full content in tooltip.
|
| 28 |
+
* Useful for long names or paths in constrained spaces.
|
| 29 |
+
*/
|
| 30 |
+
export { default as TruncatedText } from './TruncatedText.svelte';
|
| 31 |
+
|
| 32 |
+
/**
|
| 33 |
+
* **KeyboardShortcutInfo** - Keyboard shortcut hint display
|
| 34 |
+
*
|
| 35 |
+
* Displays keyboard shortcut hints (e.g., "⌘ + Enter").
|
| 36 |
+
* Supports special keys like shift, cmd, and custom text.
|
| 37 |
+
*/
|
| 38 |
+
export { default as KeyboardShortcutInfo } from './KeyboardShortcutInfo.svelte';
|
| 39 |
+
|
| 40 |
+
/**
|
| 41 |
+
* **ScrollCarousel** - Feature/carousel with center-aligned overflow controls
|
| 42 |
+
*
|
| 43 |
+
* Horizontal scrollable container with arrows that center the focused item.
|
| 44 |
+
*/
|
| 45 |
+
export { default as ScrollCarousel } from './ScrollCarousel.svelte';
|
| 46 |
+
|
| 47 |
+
/**
|
| 48 |
+
* **CodeBlockActions** - Actions bar for code blocks (copy, preview)
|
| 49 |
+
*
|
| 50 |
+
* Displays copy-to-clipboard and preview buttons for code blocks.
|
| 51 |
+
* Preview button is shown only for HTML code blocks.
|
| 52 |
+
*/
|
| 53 |
+
export { default as CodeBlockActions } from './CodeBlockActions.svelte';
|
| 54 |
+
|
| 55 |
+
/**
|
| 56 |
+
* **Logo** - Application brand mark
|
| 57 |
+
*
|
| 58 |
+
* Inline SVG of the application logo. Accepts styling via the standard
|
| 59 |
+
* `class` and `style` props and inherits color via `currentColor`.
|
| 60 |
+
*/
|
| 61 |
+
export { default as Logo } from './Logo.svelte';
|
tools/ui/src/lib/components/app/models/ModelBadge.svelte
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import ModelId from './ModelId.svelte';
|
| 3 |
+
import { Package } from '@lucide/svelte';
|
| 4 |
+
import { ActionIconCopyToClipboard, BadgeInfo } from '$lib/components/app';
|
| 5 |
+
import * as Tooltip from '$lib/components/ui/tooltip';
|
| 6 |
+
import { modelsStore, serverStore } from '$lib/stores';
|
| 7 |
+
|
| 8 |
+
interface Props {
|
| 9 |
+
class?: string;
|
| 10 |
+
model?: string;
|
| 11 |
+
onclick?: () => void;
|
| 12 |
+
showCopyIcon?: boolean;
|
| 13 |
+
showTooltip?: boolean;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
let {
|
| 17 |
+
class: className = '',
|
| 18 |
+
model: modelProp,
|
| 19 |
+
onclick,
|
| 20 |
+
showCopyIcon = false,
|
| 21 |
+
showTooltip = false
|
| 22 |
+
}: Props = $props();
|
| 23 |
+
|
| 24 |
+
let model = $derived(modelProp || modelsStore.singleModelName);
|
| 25 |
+
let isModelMode = $derived(serverStore.isModelMode);
|
| 26 |
+
let shouldShow = $derived(model && (modelProp !== undefined || isModelMode));
|
| 27 |
+
</script>
|
| 28 |
+
|
| 29 |
+
{#snippet badgeContent(triggerProps?: Record<string, unknown>)}
|
| 30 |
+
<BadgeInfo {...triggerProps ?? {}} class={className} {onclick}>
|
| 31 |
+
{#snippet icon()}
|
| 32 |
+
<Package class="h-3 w-3" />
|
| 33 |
+
{/snippet}
|
| 34 |
+
|
| 35 |
+
{#if model}
|
| 36 |
+
<ModelId modelId={model} />
|
| 37 |
+
{/if}
|
| 38 |
+
|
| 39 |
+
{#if showCopyIcon}
|
| 40 |
+
<ActionIconCopyToClipboard ariaLabel="Copy model name" text={model || ''} />
|
| 41 |
+
{/if}
|
| 42 |
+
</BadgeInfo>
|
| 43 |
+
{/snippet}
|
| 44 |
+
|
| 45 |
+
{#if shouldShow}
|
| 46 |
+
{#if showTooltip}
|
| 47 |
+
<Tooltip.Root>
|
| 48 |
+
<Tooltip.Trigger>
|
| 49 |
+
<!-- prevent another nested button element -->
|
| 50 |
+
{#snippet child({ props })}
|
| 51 |
+
{@render badgeContent(props)}
|
| 52 |
+
{/snippet}
|
| 53 |
+
</Tooltip.Trigger>
|
| 54 |
+
|
| 55 |
+
<Tooltip.Content>
|
| 56 |
+
{onclick ? 'Click for model details' : model}
|
| 57 |
+
</Tooltip.Content>
|
| 58 |
+
</Tooltip.Root>
|
| 59 |
+
{:else}
|
| 60 |
+
{@render badgeContent()}
|
| 61 |
+
{/if}
|
| 62 |
+
{/if}
|
tools/ui/src/lib/components/app/models/ModelId.svelte
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { TruncatedText } from '$lib/components/app';
|
| 3 |
+
import * as Tooltip from '$lib/components/ui/tooltip';
|
| 4 |
+
import {
|
| 5 |
+
CAPABILITY_FLAG_KEYS,
|
| 6 |
+
CAPABILITY_ICONS,
|
| 7 |
+
CAPABILITY_LABELS,
|
| 8 |
+
MODALITY_FLAG_KEYS,
|
| 9 |
+
MODALITY_ICONS,
|
| 10 |
+
MODALITY_LABELS
|
| 11 |
+
} from '$lib/constants';
|
| 12 |
+
import { ModelCapability, ModelModality } from '$lib/enums';
|
| 13 |
+
import { ModelsService } from '$lib/services/models.service';
|
| 14 |
+
import { settingsStore } from '$lib/stores';
|
| 15 |
+
import type { ModelCapabilities, ModelModalities } from '$lib/types/models';
|
| 16 |
+
|
| 17 |
+
interface Props {
|
| 18 |
+
modelId: string;
|
| 19 |
+
hideOrgName?: boolean;
|
| 20 |
+
showRaw?: boolean;
|
| 21 |
+
showRawTooltip?: boolean;
|
| 22 |
+
hideQuantization?: boolean;
|
| 23 |
+
hideTags?: boolean;
|
| 24 |
+
aliases?: string[];
|
| 25 |
+
tags?: string[];
|
| 26 |
+
modalities?: ModelModalities;
|
| 27 |
+
capabilities?: ModelCapabilities;
|
| 28 |
+
class?: string;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
let {
|
| 32 |
+
aliases,
|
| 33 |
+
capabilities,
|
| 34 |
+
class: className = '',
|
| 35 |
+
hideOrgName = false,
|
| 36 |
+
hideQuantization,
|
| 37 |
+
hideTags,
|
| 38 |
+
modalities,
|
| 39 |
+
modelId,
|
| 40 |
+
showRaw = undefined,
|
| 41 |
+
showRawTooltip = false,
|
| 42 |
+
tags,
|
| 43 |
+
...rest
|
| 44 |
+
}: Props = $props();
|
| 45 |
+
|
| 46 |
+
const badgeClass =
|
| 47 |
+
'inline-flex w-fit shrink-0 items-center justify-center whitespace-nowrap rounded-md border border-border/50 px-1 py-0 text-[10px] font-mono bg-foreground/15 dark:bg-foreground/10 text-foreground [a&]:hover:bg-foreground/25';
|
| 48 |
+
const tagBadgeClass =
|
| 49 |
+
'inline-flex w-fit shrink-0 items-center justify-center whitespace-nowrap rounded-md border border-border/50 px-1 py-0 text-[10px] font-mono text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground';
|
| 50 |
+
|
| 51 |
+
let parsed = $derived(ModelsService.parseModelId(modelId));
|
| 52 |
+
let resolvedShowRaw = $derived(
|
| 53 |
+
showRaw ?? (settingsStore.config.showRawModelNames as boolean) ?? false
|
| 54 |
+
);
|
| 55 |
+
let resolvedHideQuantization = $derived(
|
| 56 |
+
hideQuantization ?? !settingsStore.config.showModelQuantization
|
| 57 |
+
);
|
| 58 |
+
let resolvedHideTags = $derived(hideTags ?? !settingsStore.config.showModelTags);
|
| 59 |
+
|
| 60 |
+
let uniqueAliases = $derived([...new Set(aliases ?? [])]);
|
| 61 |
+
let uniqueTags = $derived([...new Set([...(parsed.tags ?? []), ...(tags ?? [])])]);
|
| 62 |
+
|
| 63 |
+
const allModalities = [ModelModality.VISION, ModelModality.VIDEO, ModelModality.AUDIO] as const;
|
| 64 |
+
const allCapabilities: ModelCapability[] = [ModelCapability.REASONING];
|
| 65 |
+
|
| 66 |
+
let activeModalities = $derived(
|
| 67 |
+
allModalities.filter((modality) => modalities?.[MODALITY_FLAG_KEYS[modality]])
|
| 68 |
+
);
|
| 69 |
+
let activeCapabilities = $derived(
|
| 70 |
+
allCapabilities.filter((capability) => capabilities?.[CAPABILITY_FLAG_KEYS[capability]])
|
| 71 |
+
);
|
| 72 |
+
|
| 73 |
+
let primaryAlias = $derived(uniqueAliases.length === 1 ? uniqueAliases[0] : null);
|
| 74 |
+
let displayName = $derived(primaryAlias ?? parsed.modelName ?? modelId);
|
| 75 |
+
</script>
|
| 76 |
+
|
| 77 |
+
{#if resolvedShowRaw}
|
| 78 |
+
<TruncatedText class="font-medium {className}" showTooltip={false} text={modelId} {...rest} />
|
| 79 |
+
{:else}
|
| 80 |
+
{#snippet nameAndBadges()}
|
| 81 |
+
<span class="min-w-0 truncate font-medium">
|
| 82 |
+
{#if !hideOrgName && parsed.orgName}{parsed.orgName}/{/if}{displayName}
|
| 83 |
+
</span>
|
| 84 |
+
|
| 85 |
+
<span class="inline-flex items-center gap-1">
|
| 86 |
+
{#if parsed.params}
|
| 87 |
+
<span class={badgeClass}>
|
| 88 |
+
{parsed.params}{parsed.activatedParams ? `-${parsed.activatedParams}` : ''}
|
| 89 |
+
</span>
|
| 90 |
+
{/if}
|
| 91 |
+
|
| 92 |
+
{#if parsed.quantization && !resolvedHideQuantization}
|
| 93 |
+
<span class={badgeClass}>
|
| 94 |
+
{parsed.quantization}
|
| 95 |
+
</span>
|
| 96 |
+
{/if}
|
| 97 |
+
|
| 98 |
+
{#if primaryAlias}
|
| 99 |
+
{#if primaryAlias !== parsed.modelName}
|
| 100 |
+
<span class={badgeClass}>{parsed.modelName ?? modelId}</span>
|
| 101 |
+
{/if}
|
| 102 |
+
{:else if uniqueAliases.length > 1}
|
| 103 |
+
{#each uniqueAliases as alias (alias)}
|
| 104 |
+
<span class={badgeClass}>{alias}</span>
|
| 105 |
+
{/each}
|
| 106 |
+
{/if}
|
| 107 |
+
|
| 108 |
+
{#if uniqueTags.length > 0 && !resolvedHideTags}
|
| 109 |
+
{#each uniqueTags as tag (tag)}
|
| 110 |
+
<span class={tagBadgeClass}>{tag}</span>
|
| 111 |
+
{/each}
|
| 112 |
+
{/if}
|
| 113 |
+
</span>
|
| 114 |
+
{/snippet}
|
| 115 |
+
|
| 116 |
+
<span class="flex min-w-0 items-center gap-1.5 {className}" {...rest}>
|
| 117 |
+
{#if showRawTooltip}
|
| 118 |
+
<Tooltip.Root>
|
| 119 |
+
<Tooltip.Trigger class="flex min-w-0 items-center gap-1.5">
|
| 120 |
+
{@render nameAndBadges()}
|
| 121 |
+
</Tooltip.Trigger>
|
| 122 |
+
|
| 123 |
+
<Tooltip.Content>
|
| 124 |
+
<p>{modelId}</p>
|
| 125 |
+
</Tooltip.Content>
|
| 126 |
+
</Tooltip.Root>
|
| 127 |
+
{:else}
|
| 128 |
+
{@render nameAndBadges()}
|
| 129 |
+
{/if}
|
| 130 |
+
|
| 131 |
+
{#if activeCapabilities.length > 0 || activeModalities.length > 0}
|
| 132 |
+
<span class="inline-flex items-center gap-1.25 text-muted-foreground">
|
| 133 |
+
{#each activeCapabilities as capability (capability)}
|
| 134 |
+
{@const CapabilityIcon = CAPABILITY_ICONS[capability]}
|
| 135 |
+
|
| 136 |
+
<Tooltip.Root>
|
| 137 |
+
<Tooltip.Trigger>
|
| 138 |
+
<CapabilityIcon class="h-3 w-3 text-muted-foreground" />
|
| 139 |
+
</Tooltip.Trigger>
|
| 140 |
+
|
| 141 |
+
<Tooltip.Content>
|
| 142 |
+
<p>{CAPABILITY_LABELS[capability]}</p>
|
| 143 |
+
</Tooltip.Content>
|
| 144 |
+
</Tooltip.Root>
|
| 145 |
+
{/each}
|
| 146 |
+
|
| 147 |
+
{#each activeModalities as modality (modality)}
|
| 148 |
+
{@const ModalityIcon = MODALITY_ICONS[modality]}
|
| 149 |
+
|
| 150 |
+
<Tooltip.Root>
|
| 151 |
+
<Tooltip.Trigger>
|
| 152 |
+
<ModalityIcon class="h-3 w-3 text-muted-foreground" />
|
| 153 |
+
</Tooltip.Trigger>
|
| 154 |
+
|
| 155 |
+
<Tooltip.Content>
|
| 156 |
+
<p>{MODALITY_LABELS[modality]}</p>
|
| 157 |
+
</Tooltip.Content>
|
| 158 |
+
</Tooltip.Root>
|
| 159 |
+
{/each}
|
| 160 |
+
</span>
|
| 161 |
+
{/if}
|
| 162 |
+
</span>
|
| 163 |
+
{/if}
|
tools/ui/src/lib/components/app/models/ModelLoadHighlight.svelte
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
let { percent }: { percent: number } = $props();
|
| 3 |
+
</script>
|
| 4 |
+
|
| 5 |
+
<!-- thin determinate load bar pinned to the bottom edge, pulsing while it fills -->
|
| 6 |
+
<div class="pointer-events-none absolute inset-x-0 bottom-0 h-0.5 overflow-hidden rounded-b-sm">
|
| 7 |
+
<div
|
| 8 |
+
class="h-full animate-pulse bg-primary transition-[width] duration-200 ease-out"
|
| 9 |
+
style="width: {percent}%"
|
| 10 |
+
></div>
|
| 11 |
+
</div>
|
tools/ui/src/lib/components/app/models/ModelsSelectorDropdown.svelte
ADDED
|
@@ -0,0 +1,417 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import ModelLoadHighlight from './ModelLoadHighlight.svelte';
|
| 3 |
+
import type { ModelItem } from './utils';
|
| 4 |
+
import { ChevronDown, Lightbulb, Loader2 } from '@lucide/svelte';
|
| 5 |
+
import {
|
| 6 |
+
ChatFormActionAddReasoningSubmenu,
|
| 7 |
+
DialogModelInformation,
|
| 8 |
+
DropdownMenuSearchable,
|
| 9 |
+
ModelId,
|
| 10 |
+
ModelsSelectorList,
|
| 11 |
+
ModelsSelectorOption
|
| 12 |
+
} from '$lib/components/app';
|
| 13 |
+
import * as DropdownMenu from '$lib/components/ui/dropdown-menu';
|
| 14 |
+
import * as Tooltip from '$lib/components/ui/tooltip';
|
| 15 |
+
import { MODEL_SELECTOR_ICON, SETTINGS_KEYS } from '$lib/constants';
|
| 16 |
+
import { KeyboardKey, ServerModelStatus } from '$lib/enums';
|
| 17 |
+
import { useModelsSelector } from '$lib/hooks/use-models-selector.svelte';
|
| 18 |
+
import { useReasoningMenu } from '$lib/hooks/use-reasoning-menu.svelte';
|
| 19 |
+
import { modelsStore, settingsStore } from '$lib/stores';
|
| 20 |
+
import { modelLoadFraction } from '$lib/utils';
|
| 21 |
+
|
| 22 |
+
interface Props {
|
| 23 |
+
class?: string;
|
| 24 |
+
currentModel?: string | null;
|
| 25 |
+
disabled?: boolean;
|
| 26 |
+
forceForegroundText?: boolean;
|
| 27 |
+
onModelChange?: (modelId: string, modelName: string) => Promise<boolean> | boolean | void;
|
| 28 |
+
useGlobalSelection?: boolean;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
let {
|
| 32 |
+
class: className = '',
|
| 33 |
+
currentModel = null,
|
| 34 |
+
disabled = false,
|
| 35 |
+
forceForegroundText = false,
|
| 36 |
+
onModelChange,
|
| 37 |
+
useGlobalSelection = false
|
| 38 |
+
}: Props = $props();
|
| 39 |
+
|
| 40 |
+
let isOpen = $state(false);
|
| 41 |
+
let highlightedId = $state<string | null>(null);
|
| 42 |
+
// The model submenu opens together with the menu so the list and its search
|
| 43 |
+
// box are immediately available, as before the submenu was introduced
|
| 44 |
+
let modelSubOpen = $state(false);
|
| 45 |
+
|
| 46 |
+
const ms = useModelsSelector({
|
| 47 |
+
currentModel: () => currentModel,
|
| 48 |
+
onModelChange: () => onModelChange,
|
| 49 |
+
onOpenChange: (open) => {
|
| 50 |
+
isOpen = open;
|
| 51 |
+
highlightedId = null;
|
| 52 |
+
|
| 53 |
+
if (open) {
|
| 54 |
+
// Defer submenu open so the Sub component is mounted first;
|
| 55 |
+
// setting bind:open synchronously can be lost if the Sub hasn't
|
| 56 |
+
// rendered yet.
|
| 57 |
+
queueMicrotask(() => {
|
| 58 |
+
if (isOpen) modelSubOpen = true;
|
| 59 |
+
});
|
| 60 |
+
} else {
|
| 61 |
+
modelSubOpen = false;
|
| 62 |
+
}
|
| 63 |
+
},
|
| 64 |
+
useGlobalSelection: () => useGlobalSelection
|
| 65 |
+
});
|
| 66 |
+
|
| 67 |
+
const reasoning = useReasoningMenu();
|
| 68 |
+
|
| 69 |
+
const showOrgNameInTrigger = $derived(
|
| 70 |
+
settingsStore.config[SETTINGS_KEYS.SHOW_MODEL_ORG_NAME_IN_TRIGGER] ?? false
|
| 71 |
+
);
|
| 72 |
+
|
| 73 |
+
$effect(() => {
|
| 74 |
+
void ms.searchTerm;
|
| 75 |
+
highlightedId = null;
|
| 76 |
+
});
|
| 77 |
+
|
| 78 |
+
// Focus the model submenu's search box without scrolling the page. bits-ui
|
| 79 |
+
// auto-focuses the opened content by default, which can yank the page
|
| 80 |
+
// scroll; we prevent that on the Content and refocus the search here.
|
| 81 |
+
$effect(() => {
|
| 82 |
+
if (!isOpen || !modelSubOpen) return;
|
| 83 |
+
|
| 84 |
+
requestAnimationFrame(() => {
|
| 85 |
+
const search = document.querySelector<HTMLElement>(
|
| 86 |
+
'[data-slot="dropdown-menu-sub-content"] input'
|
| 87 |
+
);
|
| 88 |
+
|
| 89 |
+
search?.focus({ preventScroll: true });
|
| 90 |
+
});
|
| 91 |
+
});
|
| 92 |
+
|
| 93 |
+
// Keyboard navigation follows the on-screen row order, not the flat option list order.
|
| 94 |
+
let visualOrder = $derived.by(() => {
|
| 95 |
+
const order: string[] = [];
|
| 96 |
+
|
| 97 |
+
for (const item of ms.groupedFilteredOptions.loaded) order.push(item.option.id);
|
| 98 |
+
for (const item of ms.groupedFilteredOptions.favorites) order.push(item.option.id);
|
| 99 |
+
for (const group of ms.groupedFilteredOptions.available) {
|
| 100 |
+
for (const item of group.items) order.push(item.option.id);
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
return order;
|
| 104 |
+
});
|
| 105 |
+
|
| 106 |
+
let highlightedIndex = $derived(highlightedId ? visualOrder.indexOf(highlightedId) : -1);
|
| 107 |
+
|
| 108 |
+
function moveHighlight(direction: 1 | -1) {
|
| 109 |
+
const len = visualOrder.length;
|
| 110 |
+
|
| 111 |
+
if (len === 0) {
|
| 112 |
+
highlightedId = null;
|
| 113 |
+
|
| 114 |
+
return;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
let index = highlightedIndex;
|
| 118 |
+
|
| 119 |
+
if (index === -1) {
|
| 120 |
+
index = direction === 1 ? 0 : len - 1;
|
| 121 |
+
} else {
|
| 122 |
+
index = (index + direction + len) % len;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
highlightedId = visualOrder[index];
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
// Alt+Enter only unloads and keeps the dropdown open.
|
| 129 |
+
async function handleModelKeyAction(modelId: string, unload: boolean) {
|
| 130 |
+
if (!unload) {
|
| 131 |
+
void ms.handleSelect(modelId);
|
| 132 |
+
|
| 133 |
+
return;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
const model = modelsStore.routerModels.find((m) => m.id === modelId);
|
| 137 |
+
const status = model?.status?.value as ServerModelStatus | undefined;
|
| 138 |
+
|
| 139 |
+
if (status === ServerModelStatus.LOADING) return;
|
| 140 |
+
|
| 141 |
+
await modelsStore.status.unload(modelId);
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
export function open() {
|
| 145 |
+
ms.handleOpenChange(true);
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
function handleSearchKeyDown(event: KeyboardEvent) {
|
| 149 |
+
if (event.isComposing) return;
|
| 150 |
+
|
| 151 |
+
if (event.key === KeyboardKey.ARROW_DOWN) {
|
| 152 |
+
event.preventDefault();
|
| 153 |
+
moveHighlight(1);
|
| 154 |
+
} else if (event.key === KeyboardKey.ARROW_UP) {
|
| 155 |
+
event.preventDefault();
|
| 156 |
+
moveHighlight(-1);
|
| 157 |
+
} else if (event.key === KeyboardKey.ENTER) {
|
| 158 |
+
event.preventDefault();
|
| 159 |
+
|
| 160 |
+
if (highlightedId) {
|
| 161 |
+
void handleModelKeyAction(highlightedId, event.altKey);
|
| 162 |
+
} else if (visualOrder.length > 0) {
|
| 163 |
+
highlightedId = visualOrder[0];
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
</script>
|
| 168 |
+
|
| 169 |
+
<div class={['relative inline-flex flex-col items-end gap-1', className]}>
|
| 170 |
+
{#if ms.loading && ms.options.length === 0 && ms.isRouter}
|
| 171 |
+
<div class="flex items-center gap-2 text-xs text-muted-foreground">
|
| 172 |
+
<Loader2 class="h-3.5 w-3.5 animate-spin" />
|
| 173 |
+
|
| 174 |
+
Loading models…
|
| 175 |
+
</div>
|
| 176 |
+
{:else if ms.options.length === 0 && ms.isRouter}
|
| 177 |
+
{#if currentModel}
|
| 178 |
+
<span
|
| 179 |
+
class={[
|
| 180 |
+
'inline-flex items-center gap-1.5 rounded-sm bg-muted-foreground/10 px-1.5 py-1 text-xs text-muted-foreground',
|
| 181 |
+
className
|
| 182 |
+
]}
|
| 183 |
+
style="max-width: min(calc(100cqw - 10rem), 20rem)"
|
| 184 |
+
>
|
| 185 |
+
<MODEL_SELECTOR_ICON class="h-3.5 w-3.5 shrink-0" />
|
| 186 |
+
</span>
|
| 187 |
+
{:else}
|
| 188 |
+
<p class="text-xs text-muted-foreground">No models available.</p>
|
| 189 |
+
{/if}
|
| 190 |
+
{:else}
|
| 191 |
+
{@const selectedOption = ms.getDisplayOption()}
|
| 192 |
+
{@const triggerModel = selectedOption?.model}
|
| 193 |
+
{@const triggerStatus = triggerModel
|
| 194 |
+
? modelsStore.routerModels.find((m) => m.id === triggerModel)?.status?.value
|
| 195 |
+
: undefined}
|
| 196 |
+
{@const triggerLoading =
|
| 197 |
+
!!triggerModel &&
|
| 198 |
+
(triggerStatus === ServerModelStatus.LOADING ||
|
| 199 |
+
modelsStore.status.isOperationInProgress(triggerModel))}
|
| 200 |
+
{@const triggerLoadPercent = triggerLoading
|
| 201 |
+
? Math.round(modelLoadFraction(modelsStore.status.getLoadProgress(triggerModel)) * 100)
|
| 202 |
+
: 0}
|
| 203 |
+
|
| 204 |
+
{#if ms.isRouter}
|
| 205 |
+
<DropdownMenu.Root bind:open={isOpen} onOpenChange={ms.handleOpenChange}>
|
| 206 |
+
<Tooltip.Root>
|
| 207 |
+
<Tooltip.Trigger>
|
| 208 |
+
<!-- prevent another nested button element -->
|
| 209 |
+
{#snippet child({ props })}
|
| 210 |
+
<DropdownMenu.Trigger
|
| 211 |
+
{...props}
|
| 212 |
+
class={[
|
| 213 |
+
`relative inline-grid cursor-pointer grid-cols-[1fr_auto_1fr] items-center gap-1 rounded-sm bg-background px-1.5 py-1 text-xs shadow-sm transition hover:bg-muted-foreground/20 focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-60 dark:bg-muted-foreground/15 dark:text-secondary-foreground`,
|
| 214 |
+
!ms.isCurrentModelInCache
|
| 215 |
+
? 'bg-red-400/10 !text-red-400 hover:bg-red-400/20 hover:text-red-400'
|
| 216 |
+
: forceForegroundText
|
| 217 |
+
? 'text-foreground'
|
| 218 |
+
: ms.isHighlightedCurrentModelActive
|
| 219 |
+
? 'text-foreground'
|
| 220 |
+
: 'text-foreground',
|
| 221 |
+
isOpen && 'text-foreground',
|
| 222 |
+
'max-w-[min(calc(100vw-4rem) md:max-w-[min(calc(100cqw-9rem),25rem)]'
|
| 223 |
+
]}
|
| 224 |
+
disabled={disabled || ms.updating}
|
| 225 |
+
>
|
| 226 |
+
<MODEL_SELECTOR_ICON class="h-3.5 w-3.5 shrink-0" />
|
| 227 |
+
|
| 228 |
+
<span class="flex min-w-0 items-center gap-1">
|
| 229 |
+
{#if selectedOption}
|
| 230 |
+
<ModelId
|
| 231 |
+
class="min-w-0 overflow-hidden"
|
| 232 |
+
hideOrgName={!showOrgNameInTrigger}
|
| 233 |
+
hideQuantization
|
| 234 |
+
modelId={selectedOption.model}
|
| 235 |
+
/>
|
| 236 |
+
{:else}
|
| 237 |
+
<span class="min-w-0 font-medium">Select model</span>
|
| 238 |
+
{/if}
|
| 239 |
+
|
| 240 |
+
{#if reasoning.isReasoningActive}
|
| 241 |
+
<Lightbulb class="h-3.5 w-3.5 shrink-0 text-amber-400" />
|
| 242 |
+
{/if}
|
| 243 |
+
</span>
|
| 244 |
+
|
| 245 |
+
{#if ms.updating || ms.isLoadingModel}
|
| 246 |
+
<Loader2 class="h-3 w-3.5 shrink-0 animate-spin" />
|
| 247 |
+
{:else}
|
| 248 |
+
<ChevronDown class="h-3 w-3.5 shrink-0" />
|
| 249 |
+
{/if}
|
| 250 |
+
|
| 251 |
+
{#if triggerLoading}
|
| 252 |
+
<ModelLoadHighlight percent={triggerLoadPercent} />
|
| 253 |
+
{/if}
|
| 254 |
+
</DropdownMenu.Trigger>
|
| 255 |
+
{/snippet}
|
| 256 |
+
</Tooltip.Trigger>
|
| 257 |
+
|
| 258 |
+
{#if selectedOption}
|
| 259 |
+
<Tooltip.Content>
|
| 260 |
+
<p class="font-mono">{selectedOption.model}</p>
|
| 261 |
+
</Tooltip.Content>
|
| 262 |
+
{/if}
|
| 263 |
+
</Tooltip.Root>
|
| 264 |
+
|
| 265 |
+
<DropdownMenu.Content
|
| 266 |
+
align="end"
|
| 267 |
+
class="w-full md:min-w-64 md:max-w-80 max-w-[calc(100vw-2rem)]"
|
| 268 |
+
onOpenAutoFocus={(event) => event.preventDefault()}
|
| 269 |
+
>
|
| 270 |
+
<DropdownMenu.Sub bind:open={modelSubOpen}>
|
| 271 |
+
<DropdownMenu.SubTrigger class="flex cursor-pointer items-center gap-2">
|
| 272 |
+
<MODEL_SELECTOR_ICON class="h-4 w-4" />
|
| 273 |
+
|
| 274 |
+
{#if selectedOption}
|
| 275 |
+
<ModelId
|
| 276 |
+
class="min-w-0 flex-1 overflow-hidden"
|
| 277 |
+
hideOrgName={!showOrgNameInTrigger}
|
| 278 |
+
hideQuantization
|
| 279 |
+
modelId={selectedOption.model}
|
| 280 |
+
/>
|
| 281 |
+
{:else}
|
| 282 |
+
<span class="min-w-0 flex-1 truncate text-muted-foreground">No model</span>
|
| 283 |
+
{/if}
|
| 284 |
+
</DropdownMenu.SubTrigger>
|
| 285 |
+
|
| 286 |
+
<DropdownMenu.SubContent class="w-100 max-w-[calc(100vw-2rem)] pt-0">
|
| 287 |
+
<DropdownMenuSearchable
|
| 288 |
+
emptyMessage="No models found."
|
| 289 |
+
isEmpty={ms.filteredOptions.length === 0 && ms.isCurrentModelInCache}
|
| 290 |
+
onSearchChange={(v) => ms.setSearchTerm(v)}
|
| 291 |
+
onSearchKeyDown={handleSearchKeyDown}
|
| 292 |
+
placeholder="Search models..."
|
| 293 |
+
searchValue={ms.searchTerm}
|
| 294 |
+
>
|
| 295 |
+
<div class="models-list">
|
| 296 |
+
{#if !ms.isCurrentModelInCache && currentModel}
|
| 297 |
+
<!-- Show unavailable model as first option (disabled) -->
|
| 298 |
+
<button
|
| 299 |
+
aria-disabled="true"
|
| 300 |
+
aria-selected="true"
|
| 301 |
+
class="flex w-full cursor-not-allowed items-center bg-red-400/10 p-2 text-left text-sm text-red-400"
|
| 302 |
+
disabled
|
| 303 |
+
role="option"
|
| 304 |
+
type="button"
|
| 305 |
+
>
|
| 306 |
+
<ModelId class="flex-1" hideQuantization modelId={currentModel} />
|
| 307 |
+
|
| 308 |
+
<span class="ml-2 text-xs whitespace-nowrap opacity-70">(not available)</span>
|
| 309 |
+
</button>
|
| 310 |
+
{/if}
|
| 311 |
+
|
| 312 |
+
{#if ms.filteredOptions.length === 0}
|
| 313 |
+
<p class="px-4 py-3 text-sm text-muted-foreground">No models found.</p>
|
| 314 |
+
{/if}
|
| 315 |
+
|
| 316 |
+
{#snippet modelOption(item: ModelItem, hideOrgName: boolean)}
|
| 317 |
+
{@const { option } = item}
|
| 318 |
+
{@const isSelected = currentModel === option.model || ms.activeId === option.id}
|
| 319 |
+
{@const isHighlighted = option.id === highlightedId}
|
| 320 |
+
{@const isFav = ms.isFavorite(option.model)}
|
| 321 |
+
|
| 322 |
+
<ModelsSelectorOption
|
| 323 |
+
{hideOrgName}
|
| 324 |
+
{isFav}
|
| 325 |
+
{isHighlighted}
|
| 326 |
+
{isSelected}
|
| 327 |
+
onInfoClick={ms.handleInfoClick}
|
| 328 |
+
onKeyDown={(event) => {
|
| 329 |
+
if (event.key === KeyboardKey.ENTER || event.key === KeyboardKey.SPACE) {
|
| 330 |
+
event.preventDefault();
|
| 331 |
+
void handleModelKeyAction(option.id, event.altKey);
|
| 332 |
+
}
|
| 333 |
+
}}
|
| 334 |
+
onMouseEnter={() => (highlightedId = option.id)}
|
| 335 |
+
onSelect={ms.handleSelect}
|
| 336 |
+
{option}
|
| 337 |
+
/>
|
| 338 |
+
{/snippet}
|
| 339 |
+
|
| 340 |
+
<ModelsSelectorList
|
| 341 |
+
activeId={ms.activeId}
|
| 342 |
+
{currentModel}
|
| 343 |
+
groups={ms.groupedFilteredOptions}
|
| 344 |
+
onInfoClick={ms.handleInfoClick}
|
| 345 |
+
onSelect={ms.handleSelect}
|
| 346 |
+
renderOption={modelOption}
|
| 347 |
+
sectionHeaderClass="my-1.5 px-2 py-2 text-[13px] font-semibold text-muted-foreground/70 select-none"
|
| 348 |
+
/>
|
| 349 |
+
</div>
|
| 350 |
+
</DropdownMenuSearchable>
|
| 351 |
+
</DropdownMenu.SubContent>
|
| 352 |
+
</DropdownMenu.Sub>
|
| 353 |
+
|
| 354 |
+
<ChatFormActionAddReasoningSubmenu />
|
| 355 |
+
</DropdownMenu.Content>
|
| 356 |
+
</DropdownMenu.Root>
|
| 357 |
+
{:else}
|
| 358 |
+
<Tooltip.Root>
|
| 359 |
+
<Tooltip.Trigger>
|
| 360 |
+
<!-- prevent another nested button element -->
|
| 361 |
+
{#snippet child({ props })}
|
| 362 |
+
<button
|
| 363 |
+
{...props}
|
| 364 |
+
class={[
|
| 365 |
+
`inline-flex cursor-pointer items-center gap-1.5 rounded-sm bg-background px-1.5 py-1 text-xs shadow-sm transition hover:bg-muted-foreground/20 focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-60 dark:bg-muted-foreground/15 dark:text-secondary-foreground`,
|
| 366 |
+
!ms.isCurrentModelInCache
|
| 367 |
+
? 'bg-red-400/10 !text-red-400 hover:bg-red-400/20 hover:text-red-400'
|
| 368 |
+
: forceForegroundText
|
| 369 |
+
? 'text-foreground'
|
| 370 |
+
: ms.isHighlightedCurrentModelActive
|
| 371 |
+
? 'text-foreground'
|
| 372 |
+
: 'text-foreground',
|
| 373 |
+
isOpen && 'text-foreground'
|
| 374 |
+
]}
|
| 375 |
+
disabled={disabled || ms.updating}
|
| 376 |
+
onclick={() => ms.handleOpenChange(true)}
|
| 377 |
+
style="max-width: min(calc(100cqw - 6.5rem), 32rem)"
|
| 378 |
+
>
|
| 379 |
+
<MODEL_SELECTOR_ICON class="h-3.5 w-3.5 shrink-0" />
|
| 380 |
+
|
| 381 |
+
{#if selectedOption}
|
| 382 |
+
<ModelId
|
| 383 |
+
class="min-w-0 overflow-hidden"
|
| 384 |
+
hideOrgName={!showOrgNameInTrigger}
|
| 385 |
+
hideQuantization
|
| 386 |
+
modelId={selectedOption.model}
|
| 387 |
+
/>
|
| 388 |
+
{/if}
|
| 389 |
+
|
| 390 |
+
{#if reasoning.isReasoningActive}
|
| 391 |
+
<Lightbulb class="h-3.5 w-3.5 shrink-0 text-amber-400" />
|
| 392 |
+
{/if}
|
| 393 |
+
|
| 394 |
+
{#if ms.updating}
|
| 395 |
+
<Loader2 class="h-3 w-3.5 shrink-0 animate-spin" />
|
| 396 |
+
{/if}
|
| 397 |
+
</button>
|
| 398 |
+
{/snippet}
|
| 399 |
+
</Tooltip.Trigger>
|
| 400 |
+
|
| 401 |
+
{#if selectedOption}
|
| 402 |
+
<Tooltip.Content>
|
| 403 |
+
<p class="font-mono">{selectedOption.model}</p>
|
| 404 |
+
</Tooltip.Content>
|
| 405 |
+
{/if}
|
| 406 |
+
</Tooltip.Root>
|
| 407 |
+
{/if}
|
| 408 |
+
{/if}
|
| 409 |
+
</div>
|
| 410 |
+
|
| 411 |
+
{#if ms.showModelDialog}
|
| 412 |
+
<DialogModelInformation
|
| 413 |
+
modelId={ms.infoModelId}
|
| 414 |
+
onOpenChange={(v) => ms.setShowModelDialog(v)}
|
| 415 |
+
open={ms.showModelDialog}
|
| 416 |
+
/>
|
| 417 |
+
{/if}
|
tools/ui/src/lib/components/app/models/ModelsSelectorList.svelte
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import type { GroupedModelOptions, ModelItem } from './utils';
|
| 3 |
+
import { ModelsSelectorOption } from '$lib/components/app';
|
| 4 |
+
import { modelsStore } from '$lib/stores';
|
| 5 |
+
|
| 6 |
+
interface Props {
|
| 7 |
+
groups: GroupedModelOptions;
|
| 8 |
+
currentModel: string | null;
|
| 9 |
+
activeId: string | null;
|
| 10 |
+
sectionHeaderClass?: string;
|
| 11 |
+
orgHeaderClass?: string;
|
| 12 |
+
onSelect: (modelId: string) => void;
|
| 13 |
+
onInfoClick: (modelName: string) => void;
|
| 14 |
+
renderOption?: import('svelte').Snippet<[ModelItem, boolean]>;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
let {
|
| 18 |
+
activeId,
|
| 19 |
+
currentModel,
|
| 20 |
+
groups,
|
| 21 |
+
onInfoClick,
|
| 22 |
+
onSelect,
|
| 23 |
+
orgHeaderClass = 'px-2 py-2 text-[11px] font-semibold text-muted-foreground/50 select-none [&:not(:first-child)]:mt-1',
|
| 24 |
+
renderOption,
|
| 25 |
+
sectionHeaderClass = 'my-1 px-2 py-2 text-[13px] font-semibold text-muted-foreground/70 select-none'
|
| 26 |
+
}: Props = $props();
|
| 27 |
+
let render = $derived(renderOption ?? defaultOption);
|
| 28 |
+
</script>
|
| 29 |
+
|
| 30 |
+
{#snippet defaultOption(item: ModelItem, hideOrgName: boolean)}
|
| 31 |
+
{@const { option } = item}
|
| 32 |
+
{@const isSelected = currentModel === option.model || activeId === option.id}
|
| 33 |
+
{@const isFav = modelsStore.favoriteModelIds.has(option.model)}
|
| 34 |
+
|
| 35 |
+
<ModelsSelectorOption
|
| 36 |
+
{hideOrgName}
|
| 37 |
+
{isFav}
|
| 38 |
+
isHighlighted={false}
|
| 39 |
+
{isSelected}
|
| 40 |
+
{onInfoClick}
|
| 41 |
+
onKeyDown={() => {}}
|
| 42 |
+
onMouseEnter={() => {}}
|
| 43 |
+
{onSelect}
|
| 44 |
+
{option}
|
| 45 |
+
/>
|
| 46 |
+
{/snippet}
|
| 47 |
+
|
| 48 |
+
{#if groups.loaded.length > 0}
|
| 49 |
+
<p class={sectionHeaderClass}>Loaded models</p>
|
| 50 |
+
|
| 51 |
+
{#each groups.loaded as item (`loaded-${item.option.id}`)}
|
| 52 |
+
{@render render(item, false)}
|
| 53 |
+
{/each}
|
| 54 |
+
{/if}
|
| 55 |
+
|
| 56 |
+
{#if groups.favorites.length > 0}
|
| 57 |
+
<p class={sectionHeaderClass}>Favorite models</p>
|
| 58 |
+
|
| 59 |
+
{#each groups.favorites as item (`fav-${item.option.id}`)}
|
| 60 |
+
{@render render(item, true)}
|
| 61 |
+
{/each}
|
| 62 |
+
{/if}
|
| 63 |
+
|
| 64 |
+
{#if groups.available.length > 0}
|
| 65 |
+
<p class={sectionHeaderClass}>Available models</p>
|
| 66 |
+
|
| 67 |
+
{#each groups.available as group (group.orgName)}
|
| 68 |
+
{#if group.orgName}
|
| 69 |
+
<p class={orgHeaderClass}>{group.orgName}</p>
|
| 70 |
+
{/if}
|
| 71 |
+
|
| 72 |
+
{#each group.items as item (item.option.id)}
|
| 73 |
+
{@render render(item, true)}
|
| 74 |
+
{/each}
|
| 75 |
+
{/each}
|
| 76 |
+
{/if}
|
tools/ui/src/lib/components/app/models/ModelsSelectorOption.svelte
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import ModelLoadHighlight from './ModelLoadHighlight.svelte';
|
| 3 |
+
import {
|
| 4 |
+
CircleAlert,
|
| 5 |
+
Heart,
|
| 6 |
+
HeartOff,
|
| 7 |
+
Info,
|
| 8 |
+
Loader2,
|
| 9 |
+
Power,
|
| 10 |
+
PowerOff,
|
| 11 |
+
RotateCw
|
| 12 |
+
} from '@lucide/svelte';
|
| 13 |
+
import { ActionIcon, ModelId } from '$lib/components/app';
|
| 14 |
+
import { ICON_CLASS_DEFAULT } from '$lib/constants';
|
| 15 |
+
import { ServerModelStatus } from '$lib/enums';
|
| 16 |
+
import { modelsStore } from '$lib/stores';
|
| 17 |
+
import type { ModelOption } from '$lib/types/models';
|
| 18 |
+
import { modelLoadFraction, modelLoadProgressText } from '$lib/utils';
|
| 19 |
+
|
| 20 |
+
interface Props {
|
| 21 |
+
option: ModelOption;
|
| 22 |
+
isSelected: boolean;
|
| 23 |
+
isHighlighted: boolean;
|
| 24 |
+
isFav: boolean;
|
| 25 |
+
hideOrgName?: boolean;
|
| 26 |
+
onSelect: (modelId: string) => void;
|
| 27 |
+
onMouseEnter: () => void;
|
| 28 |
+
onKeyDown: (e: KeyboardEvent) => void;
|
| 29 |
+
onInfoClick?: (modelName: string) => void;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
let {
|
| 33 |
+
hideOrgName = false,
|
| 34 |
+
isFav,
|
| 35 |
+
isHighlighted,
|
| 36 |
+
isSelected,
|
| 37 |
+
onInfoClick,
|
| 38 |
+
onKeyDown,
|
| 39 |
+
onMouseEnter,
|
| 40 |
+
onSelect,
|
| 41 |
+
option
|
| 42 |
+
}: Props = $props();
|
| 43 |
+
|
| 44 |
+
let currentRouterModels = $derived(modelsStore.routerModels);
|
| 45 |
+
let serverStatus = $derived.by(() => {
|
| 46 |
+
const model = currentRouterModels.find((m) => m.id === option.model);
|
| 47 |
+
|
| 48 |
+
return (model?.status?.value as ServerModelStatus) ?? null;
|
| 49 |
+
});
|
| 50 |
+
let isOperationInProgress = $derived(modelsStore.status.isOperationInProgress(option.model));
|
| 51 |
+
let isFailed = $derived(serverStatus === ServerModelStatus.FAILED);
|
| 52 |
+
let isSleeping = $derived(serverStatus === ServerModelStatus.SLEEPING);
|
| 53 |
+
let isLoaded = $derived(
|
| 54 |
+
(serverStatus === ServerModelStatus.LOADED || isSleeping) && !isOperationInProgress
|
| 55 |
+
);
|
| 56 |
+
let isLoading = $derived(serverStatus === ServerModelStatus.LOADING || isOperationInProgress);
|
| 57 |
+
|
| 58 |
+
let loadProgress = $derived(isLoading ? modelsStore.status.getLoadProgress(option.model) : null);
|
| 59 |
+
let loadPercent = $derived(Math.round(modelLoadFraction(loadProgress) * 100));
|
| 60 |
+
let loadTitle = $derived(modelLoadProgressText(loadProgress));
|
| 61 |
+
let modalities = $derived(option.modalities);
|
| 62 |
+
let capabilities = $derived.by(() => ({
|
| 63 |
+
reasoning: modelsStore.props.checkModelSupportsThinking(option.model)
|
| 64 |
+
}));
|
| 65 |
+
</script>
|
| 66 |
+
|
| 67 |
+
<div
|
| 68 |
+
aria-selected={isSelected || isHighlighted}
|
| 69 |
+
class={[
|
| 70 |
+
'group relative flex w-full items-center gap-2 rounded-sm p-2 text-left text-sm transition focus:outline-none',
|
| 71 |
+
'cursor-pointer',
|
| 72 |
+
isSelected && !isHighlighted && 'bg-accent/50',
|
| 73 |
+
isHighlighted && 'bg-accent',
|
| 74 |
+
(isSelected || isHighlighted) && 'text-accent-foreground',
|
| 75 |
+
'hover:bg-accent',
|
| 76 |
+
'focus:bg-accent',
|
| 77 |
+
isLoaded ? 'text-popover-foreground' : 'text-muted-foreground'
|
| 78 |
+
]}
|
| 79 |
+
onclick={() => onSelect(option.id)}
|
| 80 |
+
onkeydown={onKeyDown}
|
| 81 |
+
onmouseenter={onMouseEnter}
|
| 82 |
+
role="option"
|
| 83 |
+
tabindex="0"
|
| 84 |
+
title={loadTitle}
|
| 85 |
+
>
|
| 86 |
+
<ModelId
|
| 87 |
+
aliases={option.aliases}
|
| 88 |
+
{capabilities}
|
| 89 |
+
class="flex-1"
|
| 90 |
+
{hideOrgName}
|
| 91 |
+
{modalities}
|
| 92 |
+
modelId={option.model}
|
| 93 |
+
showRawTooltip
|
| 94 |
+
tags={option.tags}
|
| 95 |
+
/>
|
| 96 |
+
|
| 97 |
+
<div class="flex shrink-0 items-center gap-1">
|
| 98 |
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
| 99 |
+
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
| 100 |
+
<div
|
| 101 |
+
class="pointer-events-none flex items-center justify-center gap-0.75 pl-2 opacity-0 group-hover:pointer-events-auto group-hover:opacity-100 [@media(pointer:coarse)]:pointer-events-auto [@media(pointer:coarse)]:opacity-100"
|
| 102 |
+
onclick={(e) => e.stopPropagation()}
|
| 103 |
+
>
|
| 104 |
+
{#if isFav}
|
| 105 |
+
<ActionIcon
|
| 106 |
+
class="h-3 w-3 hover:text-foreground"
|
| 107 |
+
icon={HeartOff}
|
| 108 |
+
iconSize="h-2.5 w-2.5"
|
| 109 |
+
onclick={() => modelsStore.toggleFavorite(option.model)}
|
| 110 |
+
tooltip="Remove from favorites"
|
| 111 |
+
/>
|
| 112 |
+
{:else}
|
| 113 |
+
<ActionIcon
|
| 114 |
+
class="h-3 w-3 hover:text-foreground"
|
| 115 |
+
icon={Heart}
|
| 116 |
+
iconSize="h-2.5 w-2.5"
|
| 117 |
+
onclick={() => modelsStore.toggleFavorite(option.model)}
|
| 118 |
+
tooltip="Add to favorites"
|
| 119 |
+
/>
|
| 120 |
+
{/if}
|
| 121 |
+
|
| 122 |
+
<!-- info button: only shown when model is loaded and callback is provided -->
|
| 123 |
+
{#if isLoaded && onInfoClick}
|
| 124 |
+
<ActionIcon
|
| 125 |
+
class="h-3 w-3 hover:text-foreground"
|
| 126 |
+
icon={Info}
|
| 127 |
+
iconSize="h-2.5 w-2.5"
|
| 128 |
+
onclick={() => onInfoClick(option.model)}
|
| 129 |
+
tooltip="Model information"
|
| 130 |
+
/>
|
| 131 |
+
{/if}
|
| 132 |
+
</div>
|
| 133 |
+
|
| 134 |
+
{#if isLoading}
|
| 135 |
+
<div class="flex w-4 items-center justify-center [@media(pointer:coarse)]:w-5">
|
| 136 |
+
<Loader2 class="{ICON_CLASS_DEFAULT} animate-spin text-muted-foreground" />
|
| 137 |
+
</div>
|
| 138 |
+
{:else if isFailed}
|
| 139 |
+
<div class="flex w-4 items-center justify-center [@media(pointer:coarse)]:w-auto">
|
| 140 |
+
<CircleAlert
|
| 141 |
+
class="h-3.5 w-3.5 text-red-500 group-hover:hidden [@media(pointer:coarse)]:hidden"
|
| 142 |
+
/>
|
| 143 |
+
|
| 144 |
+
<div class="hidden group-hover:flex [@media(pointer:coarse)]:flex">
|
| 145 |
+
<ActionIcon
|
| 146 |
+
class="h-3 w-3 text-red-500 hover:text-foreground"
|
| 147 |
+
icon={RotateCw}
|
| 148 |
+
iconSize="h-2.5 w-2.5"
|
| 149 |
+
onclick={() => modelsStore.status.load(option.model)}
|
| 150 |
+
stopPropagationOnClick
|
| 151 |
+
tooltip="Retry loading model"
|
| 152 |
+
/>
|
| 153 |
+
</div>
|
| 154 |
+
</div>
|
| 155 |
+
{:else if isSleeping}
|
| 156 |
+
<div class="flex w-4 items-center justify-center [@media(pointer:coarse)]:w-auto">
|
| 157 |
+
<span
|
| 158 |
+
class="h-2 w-2 rounded-full bg-orange-400 group-hover:hidden [@media(pointer:coarse)]:hidden"
|
| 159 |
+
></span>
|
| 160 |
+
|
| 161 |
+
<div class="hidden group-hover:flex [@media(pointer:coarse)]:flex">
|
| 162 |
+
<ActionIcon
|
| 163 |
+
class="h-3 w-3 text-red-500 hover:text-red-600 [@media(pointer:coarse)]:text-amber-500 [@media(pointer:coarse)]:hover:text-amber-600"
|
| 164 |
+
icon={PowerOff}
|
| 165 |
+
iconSize="h-2.5 w-2.5"
|
| 166 |
+
onclick={(e) => {
|
| 167 |
+
e?.stopPropagation();
|
| 168 |
+
modelsStore.status.unload(option.model);
|
| 169 |
+
}}
|
| 170 |
+
tooltip="Unload model"
|
| 171 |
+
/>
|
| 172 |
+
</div>
|
| 173 |
+
</div>
|
| 174 |
+
{:else if isLoaded}
|
| 175 |
+
<div class="flex w-4 items-center justify-center [@media(pointer:coarse)]:w-auto">
|
| 176 |
+
<span
|
| 177 |
+
class="h-2 w-2 rounded-full bg-green-500 group-hover:hidden [@media(pointer:coarse)]:hidden"
|
| 178 |
+
></span>
|
| 179 |
+
|
| 180 |
+
<div class="hidden group-hover:flex [@media(pointer:coarse)]:flex">
|
| 181 |
+
<ActionIcon
|
| 182 |
+
class="h-3 w-3 text-red-500 hover:text-red-600 [@media(pointer:coarse)]:text-green-500 [@media(pointer:coarse)]:hover:text-green-600"
|
| 183 |
+
icon={PowerOff}
|
| 184 |
+
iconSize="h-2.5 w-2.5"
|
| 185 |
+
onclick={() => modelsStore.status.unload(option.model)}
|
| 186 |
+
stopPropagationOnClick
|
| 187 |
+
tooltip="Unload model"
|
| 188 |
+
/>
|
| 189 |
+
</div>
|
| 190 |
+
</div>
|
| 191 |
+
{:else}
|
| 192 |
+
<div class="flex w-4 items-center justify-center [@media(pointer:coarse)]:w-auto">
|
| 193 |
+
<span
|
| 194 |
+
class="h-2 w-2 rounded-full bg-muted-foreground/50 group-hover:hidden [@media(pointer:coarse)]:hidden"
|
| 195 |
+
></span>
|
| 196 |
+
|
| 197 |
+
<div class="hidden group-hover:flex [@media(pointer:coarse)]:flex">
|
| 198 |
+
<ActionIcon
|
| 199 |
+
class="h-3 w-3 [@media(pointer:coarse)]:text-muted-foreground"
|
| 200 |
+
icon={Power}
|
| 201 |
+
iconSize="h-2.5 w-2.5"
|
| 202 |
+
onclick={() => modelsStore.status.load(option.model)}
|
| 203 |
+
stopPropagationOnClick
|
| 204 |
+
tooltip="Load model"
|
| 205 |
+
/>
|
| 206 |
+
</div>
|
| 207 |
+
</div>
|
| 208 |
+
{/if}
|
| 209 |
+
</div>
|
| 210 |
+
|
| 211 |
+
{#if isLoading}
|
| 212 |
+
<ModelLoadHighlight percent={loadPercent} />
|
| 213 |
+
{/if}
|
| 214 |
+
</div>
|
tools/ui/src/lib/components/app/models/ModelsSelectorSheet.svelte
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import ModelLoadHighlight from './ModelLoadHighlight.svelte';
|
| 3 |
+
import { ChevronDown, Loader2, Package } from '@lucide/svelte';
|
| 4 |
+
import {
|
| 5 |
+
DialogModelInformation,
|
| 6 |
+
ModelId,
|
| 7 |
+
ModelsSelectorList,
|
| 8 |
+
SearchInput
|
| 9 |
+
} from '$lib/components/app';
|
| 10 |
+
import * as Sheet from '$lib/components/ui/sheet';
|
| 11 |
+
import { ServerModelStatus } from '$lib/enums';
|
| 12 |
+
import { useModelsSelector } from '$lib/hooks/use-models-selector.svelte';
|
| 13 |
+
import { modelsStore } from '$lib/stores';
|
| 14 |
+
import { modelLoadFraction } from '$lib/utils';
|
| 15 |
+
|
| 16 |
+
interface Props {
|
| 17 |
+
class?: string;
|
| 18 |
+
currentModel?: string | null;
|
| 19 |
+
/** Callback when model changes. Return false to keep menu open (e.g., for validation failures) */
|
| 20 |
+
onModelChange?: (modelId: string, modelName: string) => Promise<boolean> | boolean | void;
|
| 21 |
+
disabled?: boolean;
|
| 22 |
+
forceForegroundText?: boolean;
|
| 23 |
+
/** When true, user's global selection takes priority over currentModel (for form selector) */
|
| 24 |
+
useGlobalSelection?: boolean;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
let {
|
| 28 |
+
class: className = '',
|
| 29 |
+
currentModel = null,
|
| 30 |
+
disabled = false,
|
| 31 |
+
forceForegroundText = false,
|
| 32 |
+
onModelChange,
|
| 33 |
+
useGlobalSelection = false
|
| 34 |
+
}: Props = $props();
|
| 35 |
+
|
| 36 |
+
let sheetOpen = $state(false);
|
| 37 |
+
|
| 38 |
+
const ms = useModelsSelector({
|
| 39 |
+
currentModel: () => currentModel,
|
| 40 |
+
onModelChange: () => onModelChange,
|
| 41 |
+
onOpenChange: (open) => {
|
| 42 |
+
sheetOpen = open;
|
| 43 |
+
},
|
| 44 |
+
useGlobalSelection: () => useGlobalSelection
|
| 45 |
+
});
|
| 46 |
+
|
| 47 |
+
export function open() {
|
| 48 |
+
ms.handleOpenChange(true);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
function handleSheetOpenChange(open: boolean) {
|
| 52 |
+
if (!open) {
|
| 53 |
+
ms.handleOpenChange(false);
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
</script>
|
| 57 |
+
|
| 58 |
+
<div class={['relative inline-flex flex-col items-end gap-1', className]}>
|
| 59 |
+
{#if ms.loading && ms.options.length === 0 && ms.isRouter}
|
| 60 |
+
<div class="flex items-center gap-2 text-xs text-muted-foreground">
|
| 61 |
+
<Loader2 class="h-3.5 w-3.5 animate-spin" />
|
| 62 |
+
Loading models…
|
| 63 |
+
</div>
|
| 64 |
+
{:else if ms.options.length === 0 && ms.isRouter}
|
| 65 |
+
<p class="text-xs text-muted-foreground">No models available.</p>
|
| 66 |
+
{:else}
|
| 67 |
+
{@const selectedOption = ms.getDisplayOption()}
|
| 68 |
+
{@const triggerModel = selectedOption?.model}
|
| 69 |
+
{@const triggerStatus = triggerModel
|
| 70 |
+
? modelsStore.routerModels.find((m) => m.id === triggerModel)?.status?.value
|
| 71 |
+
: undefined}
|
| 72 |
+
{@const triggerLoading =
|
| 73 |
+
!!triggerModel &&
|
| 74 |
+
(triggerStatus === ServerModelStatus.LOADING ||
|
| 75 |
+
modelsStore.status.isOperationInProgress(triggerModel))}
|
| 76 |
+
{@const triggerLoadPercent = triggerLoading
|
| 77 |
+
? Math.round(modelLoadFraction(modelsStore.status.getLoadProgress(triggerModel)) * 100)
|
| 78 |
+
: 0}
|
| 79 |
+
|
| 80 |
+
{#if ms.isRouter}
|
| 81 |
+
<button
|
| 82 |
+
class={[
|
| 83 |
+
`relative inline-flex cursor-pointer items-center gap-1.5 rounded-sm bg-background px-1.5 py-1 text-xs shadow-sm transition hover:bg-muted-foreground/20 focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-60 max-sm:px-3 max-sm:py-2 max-sm:text-sm dark:bg-muted-foreground/15 dark:text-secondary-foreground`,
|
| 84 |
+
!ms.isCurrentModelInCache
|
| 85 |
+
? 'bg-red-400/10 !text-red-400 hover:bg-red-400/20 hover:text-red-400'
|
| 86 |
+
: forceForegroundText
|
| 87 |
+
? 'text-foreground'
|
| 88 |
+
: ms.isHighlightedCurrentModelActive
|
| 89 |
+
? 'text-foreground'
|
| 90 |
+
: 'text-foreground',
|
| 91 |
+
sheetOpen && 'text-foreground'
|
| 92 |
+
]}
|
| 93 |
+
disabled={disabled || ms.updating}
|
| 94 |
+
onclick={() => ms.handleOpenChange(true)}
|
| 95 |
+
style="max-width: min(calc(100cqw - 9rem), 20rem)"
|
| 96 |
+
type="button"
|
| 97 |
+
>
|
| 98 |
+
<Package class="h-3.5 w-3.5 shrink-0" />
|
| 99 |
+
|
| 100 |
+
{#if !selectedOption}
|
| 101 |
+
<span class="min-w-0 font-medium">Select model</span>
|
| 102 |
+
{:else}
|
| 103 |
+
<ModelId
|
| 104 |
+
class="text-xs"
|
| 105 |
+
hideOrgName
|
| 106 |
+
hideQuantization
|
| 107 |
+
hideTags
|
| 108 |
+
modelId={selectedOption?.model || ''}
|
| 109 |
+
/>
|
| 110 |
+
{/if}
|
| 111 |
+
|
| 112 |
+
{#if ms.updating || ms.isLoadingModel}
|
| 113 |
+
<Loader2 class="h-3 w-3.5 shrink-0 animate-spin" />
|
| 114 |
+
{:else}
|
| 115 |
+
<ChevronDown class="h-3 w-3.5 shrink-0" />
|
| 116 |
+
{/if}
|
| 117 |
+
|
| 118 |
+
{#if triggerLoading}
|
| 119 |
+
<ModelLoadHighlight percent={triggerLoadPercent} />
|
| 120 |
+
{/if}
|
| 121 |
+
</button>
|
| 122 |
+
|
| 123 |
+
<Sheet.Root bind:open={sheetOpen} onOpenChange={handleSheetOpenChange}>
|
| 124 |
+
<Sheet.Content class="max-h-[85vh] gap-1" side="bottom">
|
| 125 |
+
<Sheet.Header>
|
| 126 |
+
<Sheet.Title>Select Model</Sheet.Title>
|
| 127 |
+
|
| 128 |
+
<Sheet.Description class="sr-only">
|
| 129 |
+
Choose a model to use for the conversation
|
| 130 |
+
</Sheet.Description>
|
| 131 |
+
</Sheet.Header>
|
| 132 |
+
|
| 133 |
+
<div class="flex flex-col gap-1 pb-4">
|
| 134 |
+
<div class="mb-3 px-4">
|
| 135 |
+
<SearchInput
|
| 136 |
+
onInput={(v) => ms.setSearchTerm(v)}
|
| 137 |
+
placeholder="Search models..."
|
| 138 |
+
value={ms.searchTerm}
|
| 139 |
+
/>
|
| 140 |
+
</div>
|
| 141 |
+
|
| 142 |
+
<div class="max-h-[60vh] overflow-y-auto px-2">
|
| 143 |
+
{#if !ms.isCurrentModelInCache && currentModel}
|
| 144 |
+
<button
|
| 145 |
+
class="flex w-full cursor-not-allowed items-center rounded-md bg-red-400/10 px-3 py-2.5 text-left text-sm text-red-400"
|
| 146 |
+
disabled
|
| 147 |
+
type="button"
|
| 148 |
+
>
|
| 149 |
+
<span class="min-w-0 flex-1 truncate">
|
| 150 |
+
{selectedOption?.name || currentModel}
|
| 151 |
+
</span>
|
| 152 |
+
|
| 153 |
+
<span class="ml-2 text-xs whitespace-nowrap opacity-70">(not available)</span>
|
| 154 |
+
</button>
|
| 155 |
+
|
| 156 |
+
<div class="my-1 h-px bg-border"></div>
|
| 157 |
+
{/if}
|
| 158 |
+
|
| 159 |
+
{#if ms.filteredOptions.length === 0}
|
| 160 |
+
<p class="px-3 py-3 text-center text-sm text-muted-foreground">No models found.</p>
|
| 161 |
+
{/if}
|
| 162 |
+
|
| 163 |
+
<ModelsSelectorList
|
| 164 |
+
activeId={ms.activeId}
|
| 165 |
+
{currentModel}
|
| 166 |
+
groups={ms.groupedFilteredOptions}
|
| 167 |
+
onInfoClick={ms.handleInfoClick}
|
| 168 |
+
onSelect={ms.handleSelect}
|
| 169 |
+
orgHeaderClass="px-2 py-2 text-xs font-semibold text-muted-foreground/60 select-none [&:not(:first-child)]:mt-2"
|
| 170 |
+
sectionHeaderClass="px-2 py-2 text-xs font-semibold text-muted-foreground/60 select-none"
|
| 171 |
+
/>
|
| 172 |
+
</div>
|
| 173 |
+
</div>
|
| 174 |
+
</Sheet.Content>
|
| 175 |
+
</Sheet.Root>
|
| 176 |
+
{:else}
|
| 177 |
+
<button
|
| 178 |
+
class={[
|
| 179 |
+
`inline-flex cursor-pointer items-center gap-1.5 rounded-sm bg-background px-1.5 py-1 text-xs shadow-sm transition hover:bg-muted-foreground/20 focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-60 dark:bg-muted-foreground/15 dark:text-secondary-foreground`,
|
| 180 |
+
!ms.isCurrentModelInCache
|
| 181 |
+
? 'bg-red-400/10 !text-red-400 hover:bg-red-400/20 hover:text-red-400'
|
| 182 |
+
: forceForegroundText
|
| 183 |
+
? 'text-foreground'
|
| 184 |
+
: ms.isHighlightedCurrentModelActive
|
| 185 |
+
? 'text-foreground'
|
| 186 |
+
: 'text-foreground'
|
| 187 |
+
]}
|
| 188 |
+
disabled={disabled || ms.updating}
|
| 189 |
+
onclick={() => ms.handleOpenChange(true)}
|
| 190 |
+
style="max-width: min(calc(100cqw - 6.5rem), 32rem)"
|
| 191 |
+
>
|
| 192 |
+
<Package class="h-3.5 w-3.5 shrink-0" />
|
| 193 |
+
|
| 194 |
+
<ModelId class="font-medium" hideQuantization modelId={selectedOption?.model || ''} />
|
| 195 |
+
|
| 196 |
+
{#if ms.updating}
|
| 197 |
+
<Loader2 class="h-3 w-3.5 shrink-0 animate-spin" />
|
| 198 |
+
{/if}
|
| 199 |
+
</button>
|
| 200 |
+
{/if}
|
| 201 |
+
{/if}
|
| 202 |
+
</div>
|
| 203 |
+
|
| 204 |
+
{#if ms.showModelDialog}
|
| 205 |
+
<DialogModelInformation
|
| 206 |
+
modelId={ms.infoModelId}
|
| 207 |
+
onOpenChange={(v) => ms.setShowModelDialog(v)}
|
| 208 |
+
open={ms.showModelDialog}
|
| 209 |
+
/>
|
| 210 |
+
{/if}
|
tools/ui/src/lib/components/app/models/index.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
*
|
| 3 |
+
* MODELS
|
| 4 |
+
*
|
| 5 |
+
* Components for model selection and display. Supports two server modes:
|
| 6 |
+
* - **Single model mode**: Server runs with one model, selector shows model info
|
| 7 |
+
* - **Router mode**: Server runs with multiple models, selector enables switching
|
| 8 |
+
*
|
| 9 |
+
* Integrates with modelsStore for model data and serverStore for mode detection.
|
| 10 |
+
*
|
| 11 |
+
*/
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* **ModelsSelectorDropdown** - Model selection dropdown (desktop)
|
| 15 |
+
*
|
| 16 |
+
* Dropdown for selecting AI models with status indicators,
|
| 17 |
+
* search, and model information display. Adapts UI based on server mode.
|
| 18 |
+
*
|
| 19 |
+
* **Architecture:**
|
| 20 |
+
* - Uses DropdownMenuSearchable for model list
|
| 21 |
+
* - Integrates with modelsStore for model options and selection
|
| 22 |
+
* - Detects router vs single mode from serverStore
|
| 23 |
+
* - Opens DialogModelInformation for model details
|
| 24 |
+
*
|
| 25 |
+
* **Features:**
|
| 26 |
+
* - Searchable model list with keyboard navigation
|
| 27 |
+
* - Model status indicators (loading/ready/error/updating)
|
| 28 |
+
* - Model capabilities badges (vision, tools, etc.)
|
| 29 |
+
* - Current/active model highlighting
|
| 30 |
+
* - Model information dialog on info button click
|
| 31 |
+
* - Router mode: shows all available models with status
|
| 32 |
+
* - Single mode: shows current model name only
|
| 33 |
+
* - Loading/updating skeleton states
|
| 34 |
+
* - Global selection support for form integration
|
| 35 |
+
*
|
| 36 |
+
* @example
|
| 37 |
+
* ```svelte
|
| 38 |
+
* <ModelsSelectorDropdown
|
| 39 |
+
* currentModel={conversation.modelId}
|
| 40 |
+
* onModelChange={(id, name) => updateModel(id)}
|
| 41 |
+
* useGlobalSelection
|
| 42 |
+
* />
|
| 43 |
+
* ```
|
| 44 |
+
*/
|
| 45 |
+
export { default as ModelsSelectorDropdown } from './ModelsSelectorDropdown.svelte';
|
| 46 |
+
|
| 47 |
+
/**
|
| 48 |
+
* **ModelsSelectorList** - Grouped model options list
|
| 49 |
+
*
|
| 50 |
+
* Renders grouped model options (loaded, favorites, available) with section
|
| 51 |
+
* headers and org subgroups. Shared between ModelsSelectorDropdown and ModelsSelectorSheet
|
| 52 |
+
* to avoid template duplication.
|
| 53 |
+
*
|
| 54 |
+
* Accepts an optional `renderOption` snippet to customize how each option is
|
| 55 |
+
* rendered (e.g., to add keyboard navigation or highlighting).
|
| 56 |
+
*/
|
| 57 |
+
export { default as ModelsSelectorList } from './ModelsSelectorList.svelte';
|
| 58 |
+
|
| 59 |
+
/**
|
| 60 |
+
* **ModelsSelectorOption** - Single model option row
|
| 61 |
+
*
|
| 62 |
+
* Renders a single model option with selection state, favorite toggle,
|
| 63 |
+
* load/unload actions, status indicators, and an info button.
|
| 64 |
+
* Used inside ModelsSelectorList or directly in custom render snippets.
|
| 65 |
+
*/
|
| 66 |
+
export { default as ModelsSelectorOption } from './ModelsSelectorOption.svelte';
|
| 67 |
+
|
| 68 |
+
/**
|
| 69 |
+
* **ModelsSelectorSheet** - Mobile model selection sheet
|
| 70 |
+
*
|
| 71 |
+
* Bottom sheet variant of ModelsSelectorDropdown optimized for touch interaction
|
| 72 |
+
* on mobile devices. Same functionality as ModelsSelectorDropdown but uses Sheet UI
|
| 73 |
+
* instead of DropdownMenu.
|
| 74 |
+
*/
|
| 75 |
+
export { default as ModelsSelectorSheet } from './ModelsSelectorSheet.svelte';
|
| 76 |
+
|
| 77 |
+
/** * **ModelBadge** - Model name display badge
|
| 78 |
+
*
|
| 79 |
+
* Compact badge showing current model name with package icon.
|
| 80 |
+
* Only visible in single model mode. Supports tooltip and copy functionality.
|
| 81 |
+
*
|
| 82 |
+
* **Architecture:**
|
| 83 |
+
* - Reads model name from modelsStore or prop
|
| 84 |
+
* - Checks server mode from serverStore
|
| 85 |
+
* - Uses BadgeInfo for consistent styling
|
| 86 |
+
*
|
| 87 |
+
* **Features:**
|
| 88 |
+
* - Optional copy to clipboard button
|
| 89 |
+
* - Optional tooltip with model details
|
| 90 |
+
* - Click handler for model info dialog
|
| 91 |
+
* - Only renders in model mode (not router)
|
| 92 |
+
*
|
| 93 |
+
* @example
|
| 94 |
+
* ```svelte
|
| 95 |
+
* <ModelBadge
|
| 96 |
+
* onclick={() => showModelInfo = true}
|
| 97 |
+
* showTooltip
|
| 98 |
+
* showCopyIcon
|
| 99 |
+
* />
|
| 100 |
+
* ```
|
| 101 |
+
*/
|
| 102 |
+
export { default as ModelBadge } from './ModelBadge.svelte';
|
| 103 |
+
|
| 104 |
+
/**
|
| 105 |
+
* **ModelId** - Parsed model identifier display
|
| 106 |
+
*
|
| 107 |
+
* Displays a model ID with optional org name, parameter badges, quantization,
|
| 108 |
+
* aliases, and tags. Supports raw mode to show the unprocessed model name.
|
| 109 |
+
* Respects the user's `showRawModelNames` setting.
|
| 110 |
+
*/
|
| 111 |
+
export { default as ModelId } from './ModelId.svelte';
|
tools/ui/src/lib/components/app/models/utils.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { ModelModality } from '$lib/enums';
|
| 2 |
+
import type { ModelOption } from '$lib/types/models';
|
| 3 |
+
import { SvelteMap } from 'svelte/reactivity';
|
| 4 |
+
|
| 5 |
+
export interface ModelItem {
|
| 6 |
+
option: ModelOption;
|
| 7 |
+
flatIndex: number;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
export interface OrgGroup {
|
| 11 |
+
orgName: string | null;
|
| 12 |
+
items: ModelItem[];
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
export interface GroupedModelOptions {
|
| 16 |
+
loaded: ModelItem[];
|
| 17 |
+
favorites: ModelItem[];
|
| 18 |
+
available: OrgGroup[];
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
function matchesModality(option: ModelOption, term: string): boolean {
|
| 22 |
+
const modalities = option.modalities;
|
| 23 |
+
|
| 24 |
+
if (!modalities) return false;
|
| 25 |
+
|
| 26 |
+
switch (term) {
|
| 27 |
+
case ModelModality.VISION.toLowerCase():
|
| 28 |
+
return modalities.vision;
|
| 29 |
+
case ModelModality.AUDIO.toLowerCase():
|
| 30 |
+
return modalities.audio;
|
| 31 |
+
case ModelModality.VIDEO.toLowerCase():
|
| 32 |
+
return modalities.video;
|
| 33 |
+
default:
|
| 34 |
+
return false;
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
export function filterModelOptions(options: ModelOption[], searchTerm: string): ModelOption[] {
|
| 39 |
+
const term = searchTerm.trim().toLowerCase();
|
| 40 |
+
|
| 41 |
+
if (!term) return options;
|
| 42 |
+
|
| 43 |
+
return options.filter(
|
| 44 |
+
(option) =>
|
| 45 |
+
option.model.toLowerCase().includes(term) ||
|
| 46 |
+
option.name?.toLowerCase().includes(term) ||
|
| 47 |
+
option.aliases?.some((alias: string) => alias.toLowerCase().includes(term)) ||
|
| 48 |
+
option.tags?.some((tag: string) => tag.toLowerCase().includes(term)) ||
|
| 49 |
+
matchesModality(option, term)
|
| 50 |
+
);
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
export function groupModelOptions(
|
| 54 |
+
filteredOptions: ModelOption[],
|
| 55 |
+
favoriteIds: Set<string>,
|
| 56 |
+
isModelLoaded: (model: string) => boolean
|
| 57 |
+
): GroupedModelOptions {
|
| 58 |
+
// Loaded models
|
| 59 |
+
const loaded: ModelItem[] = [];
|
| 60 |
+
|
| 61 |
+
for (let i = 0; i < filteredOptions.length; i++) {
|
| 62 |
+
if (isModelLoaded(filteredOptions[i].model)) {
|
| 63 |
+
loaded.push({ flatIndex: i, option: filteredOptions[i] });
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
// Favorites (excluding loaded)
|
| 68 |
+
const loadedModelIds = new Set(loaded.map((item) => item.option.model));
|
| 69 |
+
const favorites: ModelItem[] = [];
|
| 70 |
+
|
| 71 |
+
for (let i = 0; i < filteredOptions.length; i++) {
|
| 72 |
+
if (
|
| 73 |
+
favoriteIds.has(filteredOptions[i].model) &&
|
| 74 |
+
!loadedModelIds.has(filteredOptions[i].model)
|
| 75 |
+
) {
|
| 76 |
+
favorites.push({ flatIndex: i, option: filteredOptions[i] });
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
// Available models grouped by org (excluding loaded and favorites)
|
| 81 |
+
const available: OrgGroup[] = [];
|
| 82 |
+
const orgGroups = new SvelteMap<string, ModelItem[]>();
|
| 83 |
+
|
| 84 |
+
for (let i = 0; i < filteredOptions.length; i++) {
|
| 85 |
+
const option = filteredOptions[i];
|
| 86 |
+
|
| 87 |
+
if (loadedModelIds.has(option.model) || favoriteIds.has(option.model)) continue;
|
| 88 |
+
|
| 89 |
+
const key = option.parsedId?.orgName ?? '';
|
| 90 |
+
|
| 91 |
+
if (!orgGroups.has(key)) orgGroups.set(key, []);
|
| 92 |
+
|
| 93 |
+
orgGroups.get(key)!.push({ flatIndex: i, option });
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
for (const [orgName, items] of orgGroups) {
|
| 97 |
+
available.push({ items, orgName: orgName || null });
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
return { available, favorites, loaded };
|
| 101 |
+
}
|
tools/ui/src/lib/components/app/navigation/DropdownMenuActions.svelte
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { KeyboardShortcutInfo } from '$lib/components/app';
|
| 3 |
+
import * as DropdownMenu from '$lib/components/ui/dropdown-menu';
|
| 4 |
+
import * as Tooltip from '$lib/components/ui/tooltip';
|
| 5 |
+
import type { Component } from 'svelte';
|
| 6 |
+
|
| 7 |
+
interface ActionItem {
|
| 8 |
+
icon: Component;
|
| 9 |
+
label: string;
|
| 10 |
+
onclick: (event: Event) => void;
|
| 11 |
+
variant?: 'default' | 'destructive';
|
| 12 |
+
disabled?: boolean;
|
| 13 |
+
shortcut?: string[];
|
| 14 |
+
separator?: boolean;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
interface Props {
|
| 18 |
+
triggerIcon: Component;
|
| 19 |
+
triggerTooltip?: string;
|
| 20 |
+
triggerClass?: string;
|
| 21 |
+
actions: ActionItem[];
|
| 22 |
+
align?: 'start' | 'center' | 'end';
|
| 23 |
+
open?: boolean;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
let {
|
| 27 |
+
actions,
|
| 28 |
+
align = 'end',
|
| 29 |
+
open = $bindable(false),
|
| 30 |
+
triggerClass = '',
|
| 31 |
+
triggerIcon,
|
| 32 |
+
triggerTooltip
|
| 33 |
+
}: Props = $props();
|
| 34 |
+
</script>
|
| 35 |
+
|
| 36 |
+
<DropdownMenu.Root bind:open>
|
| 37 |
+
<Tooltip.Root>
|
| 38 |
+
<Tooltip.Trigger>
|
| 39 |
+
<!-- prevent another nested button element -->
|
| 40 |
+
{#snippet child({ props })}
|
| 41 |
+
<DropdownMenu.Trigger
|
| 42 |
+
{...props}
|
| 43 |
+
class="flex h-6 w-6 cursor-pointer items-center justify-center rounded-md p-0 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground focus:outline-none disabled:pointer-events-none disabled:opacity-50 data-[state=open]:bg-accent data-[state=open]:text-accent-foreground {triggerClass}"
|
| 44 |
+
onclick={(e) => e.stopPropagation()}
|
| 45 |
+
>
|
| 46 |
+
{@render iconComponent(triggerIcon, 'h-3 w-3')}
|
| 47 |
+
|
| 48 |
+
{#if triggerTooltip}
|
| 49 |
+
<span class="sr-only">{triggerTooltip}</span>
|
| 50 |
+
{/if}
|
| 51 |
+
</DropdownMenu.Trigger>
|
| 52 |
+
{/snippet}
|
| 53 |
+
</Tooltip.Trigger>
|
| 54 |
+
|
| 55 |
+
{#if triggerTooltip}
|
| 56 |
+
<Tooltip.Content>
|
| 57 |
+
<p>{triggerTooltip}</p>
|
| 58 |
+
</Tooltip.Content>
|
| 59 |
+
{/if}
|
| 60 |
+
</Tooltip.Root>
|
| 61 |
+
|
| 62 |
+
<DropdownMenu.Content {align} class="z-[999999] w-48">
|
| 63 |
+
{#each actions as action, index (action.label)}
|
| 64 |
+
{#if action.separator && index > 0}
|
| 65 |
+
<DropdownMenu.Separator />
|
| 66 |
+
{/if}
|
| 67 |
+
|
| 68 |
+
<DropdownMenu.Item
|
| 69 |
+
class="flex items-center justify-between hover:[&>kbd]:opacity-100"
|
| 70 |
+
disabled={action.disabled}
|
| 71 |
+
onclick={action.onclick}
|
| 72 |
+
variant={action.variant}
|
| 73 |
+
>
|
| 74 |
+
<div class="flex items-center gap-2">
|
| 75 |
+
{@render iconComponent(
|
| 76 |
+
action.icon,
|
| 77 |
+
`h-4 w-4 ${action.variant === 'destructive' ? 'text-destructive' : ''}`
|
| 78 |
+
)}
|
| 79 |
+
{action.label}
|
| 80 |
+
</div>
|
| 81 |
+
|
| 82 |
+
{#if action.shortcut}
|
| 83 |
+
<KeyboardShortcutInfo keys={action.shortcut} variant={action.variant} />
|
| 84 |
+
{/if}
|
| 85 |
+
</DropdownMenu.Item>
|
| 86 |
+
{/each}
|
| 87 |
+
</DropdownMenu.Content>
|
| 88 |
+
</DropdownMenu.Root>
|
| 89 |
+
|
| 90 |
+
{#snippet iconComponent(IconComponent: Component, className: string)}
|
| 91 |
+
<IconComponent class={className} />
|
| 92 |
+
{/snippet}
|
tools/ui/src/lib/components/app/navigation/DropdownMenuSearchable.svelte
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { SearchInput } from '$lib/components/app';
|
| 3 |
+
import * as DropdownMenu from '$lib/components/ui/dropdown-menu';
|
| 4 |
+
import type { Snippet } from 'svelte';
|
| 5 |
+
|
| 6 |
+
interface Props {
|
| 7 |
+
placeholder?: string;
|
| 8 |
+
searchValue?: string;
|
| 9 |
+
onSearchChange?: (value: string) => void;
|
| 10 |
+
onSearchKeyDown?: (event: KeyboardEvent) => void;
|
| 11 |
+
emptyMessage?: string;
|
| 12 |
+
isEmpty?: boolean;
|
| 13 |
+
children: Snippet;
|
| 14 |
+
footer?: Snippet;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
let {
|
| 18 |
+
children,
|
| 19 |
+
emptyMessage = 'No items found',
|
| 20 |
+
footer,
|
| 21 |
+
isEmpty = false,
|
| 22 |
+
onSearchChange,
|
| 23 |
+
onSearchKeyDown,
|
| 24 |
+
placeholder = 'Search...',
|
| 25 |
+
searchValue = $bindable('')
|
| 26 |
+
}: Props = $props();
|
| 27 |
+
</script>
|
| 28 |
+
|
| 29 |
+
<div class="sticky top-0 z-10 mb-2 bg-popover p-1 pt-2">
|
| 30 |
+
<SearchInput
|
| 31 |
+
bind:value={searchValue}
|
| 32 |
+
onInput={onSearchChange}
|
| 33 |
+
onKeyDown={onSearchKeyDown}
|
| 34 |
+
{placeholder}
|
| 35 |
+
/>
|
| 36 |
+
</div>
|
| 37 |
+
|
| 38 |
+
<div class="overflow-y-auto">
|
| 39 |
+
{@render children()}
|
| 40 |
+
|
| 41 |
+
{#if isEmpty}
|
| 42 |
+
<div class="px-2 py-3 text-center text-sm text-muted-foreground">{emptyMessage}</div>
|
| 43 |
+
{/if}
|
| 44 |
+
</div>
|
| 45 |
+
|
| 46 |
+
{#if footer}
|
| 47 |
+
<DropdownMenu.Separator />
|
| 48 |
+
|
| 49 |
+
{@render footer()}
|
| 50 |
+
{/if}
|
tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigation.svelte
ADDED
|
@@ -0,0 +1,482 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { PanelLeftClose, PanelLeftOpen, X } from '@lucide/svelte';
|
| 3 |
+
import { goto } from '$app/navigation';
|
| 4 |
+
import { page } from '$app/state';
|
| 5 |
+
import {
|
| 6 |
+
ActionIcon,
|
| 7 |
+
DialogConversationRename,
|
| 8 |
+
DialogSettingsChat,
|
| 9 |
+
Logo,
|
| 10 |
+
SidebarNavigationActions,
|
| 11 |
+
SidebarNavigationConversationList
|
| 12 |
+
} from '$lib/components/app';
|
| 13 |
+
import { ROUTES } from '$lib/constants';
|
| 14 |
+
import { TooltipSide } from '$lib/enums';
|
| 15 |
+
import { useKeyboardShortcuts } from '$lib/hooks/use-keyboard-shortcuts.svelte';
|
| 16 |
+
import { useMarqueeSelection } from '$lib/hooks/use-marquee-selection.svelte';
|
| 17 |
+
import { RouterService } from '$lib/services/router.service';
|
| 18 |
+
import { chatStore, conversationsStore, deviceStore, settingsStore, uiStore } from '$lib/stores';
|
| 19 |
+
import { buildConversationTree } from '$lib/utils';
|
| 20 |
+
import { circIn } from 'svelte/easing';
|
| 21 |
+
import { SvelteSet } from 'svelte/reactivity';
|
| 22 |
+
import { fade } from 'svelte/transition';
|
| 23 |
+
|
| 24 |
+
interface Props {
|
| 25 |
+
onSearchClick?: () => void;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
let { onSearchClick = () => {} }: Props = $props();
|
| 29 |
+
|
| 30 |
+
const { handleKeydown } = useKeyboardShortcuts({
|
| 31 |
+
activateSearchMode: () => onSearchClick(),
|
| 32 |
+
toggleSidebar: () => toggleExpandedMode()
|
| 33 |
+
});
|
| 34 |
+
|
| 35 |
+
let hoveredTooltip = $state<string | null>(null);
|
| 36 |
+
let logoHovered = $state(false);
|
| 37 |
+
|
| 38 |
+
const isStripExpanded = $derived(uiStore.isSidebarExpanded || hoveredTooltip !== null);
|
| 39 |
+
const isOnMobile = $derived(deviceStore.isMobile);
|
| 40 |
+
const alwaysShowOnDesktop = $derived(settingsStore.config.alwaysShowSidebarOnDesktop as boolean);
|
| 41 |
+
|
| 42 |
+
$effect(() => {
|
| 43 |
+
if (alwaysShowOnDesktop && !isOnMobile) {
|
| 44 |
+
uiStore.isSidebarExpanded = true;
|
| 45 |
+
}
|
| 46 |
+
});
|
| 47 |
+
|
| 48 |
+
function toggleExpandedMode() {
|
| 49 |
+
uiStore.isSidebarExpanded = !uiStore.isSidebarExpanded;
|
| 50 |
+
|
| 51 |
+
if (!uiStore.isSidebarExpanded) {
|
| 52 |
+
hoveredTooltip = null;
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
$effect(() => {
|
| 57 |
+
if (!uiStore.isSidebarExpanded) {
|
| 58 |
+
isSearchModeActive = false;
|
| 59 |
+
searchQuery = '';
|
| 60 |
+
|
| 61 |
+
if (isSelectionMode) exitSelectionMode();
|
| 62 |
+
|
| 63 |
+
cancelMobileCollapse();
|
| 64 |
+
}
|
| 65 |
+
});
|
| 66 |
+
|
| 67 |
+
$effect(() => {
|
| 68 |
+
if (deviceStore.isMobile && page.url.hash.includes(ROUTES.SEARCH)) {
|
| 69 |
+
uiStore.isSidebarExpanded = false;
|
| 70 |
+
}
|
| 71 |
+
});
|
| 72 |
+
|
| 73 |
+
let currentChatId = $derived(page.params.id);
|
| 74 |
+
let isSearchModeActive = $state(false);
|
| 75 |
+
let searchQuery = $state('');
|
| 76 |
+
|
| 77 |
+
let filteredConversations = $derived.by(() => {
|
| 78 |
+
if (isSearchModeActive) {
|
| 79 |
+
if (searchQuery.trim().length > 0) {
|
| 80 |
+
return conversationsStore.conversations.filter((conversation: { name: string }) =>
|
| 81 |
+
conversation.name.toLowerCase().includes(searchQuery.toLowerCase())
|
| 82 |
+
);
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
return [];
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
return conversationsStore.conversations;
|
| 89 |
+
});
|
| 90 |
+
|
| 91 |
+
let isSelectionMode = $state(false);
|
| 92 |
+
let selectedIds = new SvelteSet<string>();
|
| 93 |
+
|
| 94 |
+
let renameDialogOpen = $state(false);
|
| 95 |
+
let settingsDialogOpen = $state(false);
|
| 96 |
+
let renameTargetConversationId = $state<string | null>(null);
|
| 97 |
+
let renameDraft = $state('');
|
| 98 |
+
let renameOriginalTitle = $state('');
|
| 99 |
+
|
| 100 |
+
const renderedOrderIds = $derived(
|
| 101 |
+
buildConversationTree(filteredConversations).map((t) => t.conversation.id)
|
| 102 |
+
);
|
| 103 |
+
|
| 104 |
+
const allSelectedArePinned = $derived.by(() => {
|
| 105 |
+
if (selectedIds.size === 0) return false;
|
| 106 |
+
|
| 107 |
+
const convs = conversationsStore.conversations;
|
| 108 |
+
|
| 109 |
+
for (const id of selectedIds) {
|
| 110 |
+
const c = convs.find((conv) => conv.id === id);
|
| 111 |
+
|
| 112 |
+
if (c && !c.pinned) return false;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
return true;
|
| 116 |
+
});
|
| 117 |
+
|
| 118 |
+
const pinStateIsMixed = $derived.by(() => {
|
| 119 |
+
if (selectedIds.size === 0) return false;
|
| 120 |
+
|
| 121 |
+
const convs = conversationsStore.conversations;
|
| 122 |
+
|
| 123 |
+
let anyPinned = false;
|
| 124 |
+
let anyUnpinned = false;
|
| 125 |
+
|
| 126 |
+
for (const id of selectedIds) {
|
| 127 |
+
const c = convs.find((conv) => conv.id === id);
|
| 128 |
+
|
| 129 |
+
if (!c) continue;
|
| 130 |
+
|
| 131 |
+
if (c.pinned) anyPinned = true;
|
| 132 |
+
else anyUnpinned = true;
|
| 133 |
+
|
| 134 |
+
if (anyPinned && anyUnpinned) return true;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
return false;
|
| 138 |
+
});
|
| 139 |
+
|
| 140 |
+
const visibleSelectionStats = $derived.by(() => {
|
| 141 |
+
const visibleIds = filteredConversations.map((c) => c.id);
|
| 142 |
+
|
| 143 |
+
let selectedVisible = 0;
|
| 144 |
+
|
| 145 |
+
for (const id of visibleIds) {
|
| 146 |
+
if (selectedIds.has(id)) selectedVisible++;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
return {
|
| 150 |
+
selectedVisibleCount: selectedVisible,
|
| 151 |
+
visibleCount: visibleIds.length
|
| 152 |
+
};
|
| 153 |
+
});
|
| 154 |
+
|
| 155 |
+
function enterSelectionMode(id?: string) {
|
| 156 |
+
isSelectionMode = true;
|
| 157 |
+
|
| 158 |
+
if (id !== undefined) {
|
| 159 |
+
selectedIds.add(id);
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
function exitSelectionMode() {
|
| 164 |
+
isSelectionMode = false;
|
| 165 |
+
selectedIds.clear();
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
function toggleSelected(id: string) {
|
| 169 |
+
if (selectedIds.has(id)) {
|
| 170 |
+
selectedIds.delete(id);
|
| 171 |
+
} else {
|
| 172 |
+
selectedIds.add(id);
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
function toggleSelectAllVisible() {
|
| 177 |
+
const visibleIds = filteredConversations.map((c) => c.id);
|
| 178 |
+
const allSelected = visibleIds.length > 0 && visibleIds.every((id) => selectedIds.has(id));
|
| 179 |
+
|
| 180 |
+
if (allSelected) {
|
| 181 |
+
for (const id of visibleIds) selectedIds.delete(id);
|
| 182 |
+
} else {
|
| 183 |
+
for (const id of visibleIds) selectedIds.add(id);
|
| 184 |
+
}
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
async function handleBulkDelete() {
|
| 188 |
+
const ids = Array.from(selectedIds);
|
| 189 |
+
|
| 190 |
+
if (ids.length === 0) return;
|
| 191 |
+
|
| 192 |
+
await conversationsStore.bulkDeleteConversations(ids);
|
| 193 |
+
exitSelectionMode();
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
async function handleBulkPinToggle() {
|
| 197 |
+
const ids = Array.from(selectedIds);
|
| 198 |
+
|
| 199 |
+
if (ids.length === 0) return;
|
| 200 |
+
|
| 201 |
+
await conversationsStore.bulkToggleConversationPin(ids);
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
async function handleBulkExport() {
|
| 205 |
+
const ids = Array.from(selectedIds);
|
| 206 |
+
|
| 207 |
+
if (ids.length === 0) return;
|
| 208 |
+
|
| 209 |
+
await conversationsStore.bulkExportConversations(ids);
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
const marquee = useMarqueeSelection({
|
| 213 |
+
enabled: () => isSelectionMode,
|
| 214 |
+
orderedIds: () => renderedOrderIds,
|
| 215 |
+
selectedIds: () => selectedIds
|
| 216 |
+
});
|
| 217 |
+
|
| 218 |
+
function handleRowMouseDown(id: string, event: MouseEvent) {
|
| 219 |
+
if (!isSelectionMode) return;
|
| 220 |
+
|
| 221 |
+
marquee.rowMouseDown(id, event);
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
function handleSelectionClick(id: string, options: { shiftKey: boolean }): void {
|
| 225 |
+
if (!isSelectionMode) return;
|
| 226 |
+
|
| 227 |
+
marquee.rowClick(id, options.shiftKey);
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
async function selectConversation(id: string) {
|
| 231 |
+
if (deviceStore.isMobile) {
|
| 232 |
+
scheduleMobileCollapse();
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
await goto(RouterService.chat(id));
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
async function handleEditConversation(id: string) {
|
| 239 |
+
const conversation = conversationsStore.conversations.find((conv) => conv.id === id);
|
| 240 |
+
|
| 241 |
+
if (!conversation) return;
|
| 242 |
+
|
| 243 |
+
renameTargetConversationId = id;
|
| 244 |
+
renameOriginalTitle = conversation.name;
|
| 245 |
+
renameDraft = conversation.name;
|
| 246 |
+
renameDialogOpen = true;
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
async function handleRenameConfirm() {
|
| 250 |
+
const id = renameTargetConversationId;
|
| 251 |
+
|
| 252 |
+
if (!id) return;
|
| 253 |
+
|
| 254 |
+
const nextName = renameDraft.trim();
|
| 255 |
+
|
| 256 |
+
if (!nextName || nextName === renameOriginalTitle.trim()) return;
|
| 257 |
+
|
| 258 |
+
await conversationsStore.updateConversationName(id, nextName);
|
| 259 |
+
|
| 260 |
+
renameDialogOpen = false;
|
| 261 |
+
renameTargetConversationId = null;
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
function handleRenameCancel() {
|
| 265 |
+
renameDialogOpen = false;
|
| 266 |
+
renameTargetConversationId = null;
|
| 267 |
+
renameDraft = '';
|
| 268 |
+
renameOriginalTitle = '';
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
async function handleDeleteConversation(id: string) {
|
| 272 |
+
const conversation = conversationsStore.conversations.find((conv) => conv.id === id);
|
| 273 |
+
|
| 274 |
+
if (!conversation) return;
|
| 275 |
+
|
| 276 |
+
const confirmed = window.confirm(
|
| 277 |
+
`Delete "${conversation.name}"? This action cannot be undone.`
|
| 278 |
+
);
|
| 279 |
+
|
| 280 |
+
if (!confirmed) return;
|
| 281 |
+
|
| 282 |
+
await conversationsStore.deleteConversation(id, { deleteWithForks: false });
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
function handleStopGeneration(id: string) {
|
| 286 |
+
chatStore.stopGenerationForChat(id);
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
let innerWidth = $state(0);
|
| 290 |
+
let pendingCollapse = $state<ReturnType<typeof setTimeout> | null>(null);
|
| 291 |
+
|
| 292 |
+
function scheduleMobileCollapse() {
|
| 293 |
+
if (pendingCollapse) {
|
| 294 |
+
clearTimeout(pendingCollapse);
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
pendingCollapse = setTimeout(() => {
|
| 298 |
+
uiStore.isSidebarExpanded = false;
|
| 299 |
+
pendingCollapse = null;
|
| 300 |
+
}, 100);
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
function cancelMobileCollapse() {
|
| 304 |
+
if (pendingCollapse) {
|
| 305 |
+
clearTimeout(pendingCollapse);
|
| 306 |
+
pendingCollapse = null;
|
| 307 |
+
}
|
| 308 |
+
}
|
| 309 |
+
</script>
|
| 310 |
+
|
| 311 |
+
<svelte:window bind:innerWidth onkeydown={handleKeydown} />
|
| 312 |
+
|
| 313 |
+
{#if innerWidth > 768 || !page.url.hash.includes(ROUTES.SEARCH)}
|
| 314 |
+
<aside
|
| 315 |
+
class={[
|
| 316 |
+
'fixed md:sticky top-2 left-2 md:left-0 md:ml-2 md:mt-2 pt-2 z-10 w-[calc(100dvw-1rem)]',
|
| 317 |
+
'md:h-[calc(100dvh-1.125rem)]',
|
| 318 |
+
uiStore.isSidebarExpanded &&
|
| 319 |
+
(deviceStore.isStandalone
|
| 320 |
+
? 'h-[calc(100dvh-2rem)]'
|
| 321 |
+
: deviceStore.isIOSDevice
|
| 322 |
+
? 'h-[calc(100dvh-0.5rem)]'
|
| 323 |
+
: 'h-[calc(100dvh-1rem)]'),
|
| 324 |
+
'rounded-3xl md:rounded-2xl',
|
| 325 |
+
'flex flex-col justify-between',
|
| 326 |
+
'md:transition-[width,padding] duration-200 ease-out',
|
| 327 |
+
isStripExpanded && 'md:w-72 md:bg-muted/60 md:backdrop-blur-xl shadow-md',
|
| 328 |
+
!isStripExpanded && 'md:w-12',
|
| 329 |
+
uiStore.isSidebarExpanded && 'is-expanded'
|
| 330 |
+
]}
|
| 331 |
+
>
|
| 332 |
+
<div class="px-2 flex items-center justify-between">
|
| 333 |
+
<div
|
| 334 |
+
class="relative"
|
| 335 |
+
onmouseenter={() => (logoHovered = true)}
|
| 336 |
+
onmouseleave={() => (logoHovered = false)}
|
| 337 |
+
role="button"
|
| 338 |
+
tabindex="0"
|
| 339 |
+
>
|
| 340 |
+
<ActionIcon
|
| 341 |
+
ariaLabel={uiStore.isSidebarExpanded ? 'Go to start' : 'Expand navigation'}
|
| 342 |
+
class="{uiStore.isSidebarExpanded
|
| 343 |
+
? 'bg-muted! md:bg-foreground/5!'
|
| 344 |
+
: 'bg-transparent!'} md:h-9 md:w-9 h-10 w-10 rounded-full md:hover:bg-foreground/10! pointer-events-auto"
|
| 345 |
+
href={uiStore.isSidebarExpanded ? ROUTES.START : undefined}
|
| 346 |
+
icon={!uiStore.isSidebarExpanded && logoHovered && innerWidth > 768
|
| 347 |
+
? PanelLeftOpen
|
| 348 |
+
: Logo}
|
| 349 |
+
iconSize="h-4.5 w-4.5 md:h-4 md:w-4"
|
| 350 |
+
onclick={uiStore.isSidebarExpanded ? undefined : toggleExpandedMode}
|
| 351 |
+
size="lg"
|
| 352 |
+
tooltip={uiStore.isSidebarExpanded ? undefined : 'Open Sidebar'}
|
| 353 |
+
tooltipSide={TooltipSide.RIGHT}
|
| 354 |
+
/>
|
| 355 |
+
</div>
|
| 356 |
+
|
| 357 |
+
{#if isOnMobile || (uiStore.isSidebarExpanded && !alwaysShowOnDesktop)}
|
| 358 |
+
<div
|
| 359 |
+
in:fade={{ delay: 50, duration: 150, easing: circIn }}
|
| 360 |
+
out:fade={{ duration: 100 }}
|
| 361 |
+
class="flex items-center transition-all duration-150 ease-out {deviceStore.isMobile &&
|
| 362 |
+
!uiStore.isSidebarExpanded
|
| 363 |
+
? 'opacity-0 h-0!'
|
| 364 |
+
: ''}"
|
| 365 |
+
>
|
| 366 |
+
<ActionIcon
|
| 367 |
+
ariaLabel="Collapse navigation"
|
| 368 |
+
class="backdrop-blur-none md:h-9 md:w-9 h-10 w-10 rounded-full mr-1 hover:bg-accent!"
|
| 369 |
+
icon={deviceStore.isMobile ? X : PanelLeftClose}
|
| 370 |
+
iconSize="h-4.5 w-4.5 md:h-4 md:w-4"
|
| 371 |
+
onclick={toggleExpandedMode}
|
| 372 |
+
size="lg"
|
| 373 |
+
tooltip="Close Sidebar"
|
| 374 |
+
tooltipSide={TooltipSide.LEFT}
|
| 375 |
+
/>
|
| 376 |
+
</div>
|
| 377 |
+
{/if}
|
| 378 |
+
</div>
|
| 379 |
+
|
| 380 |
+
<div
|
| 381 |
+
in:fade={{ duration: 200 }}
|
| 382 |
+
out:fade={{ duration: 200 }}
|
| 383 |
+
class="mt-2 flex min-h-0 flex-1 flex-col gap-4 md:gap-1 {deviceStore.isMobile
|
| 384 |
+
? 'transition-[opacity,height] duration-200 ease-out'
|
| 385 |
+
: ''} {deviceStore.isMobile && !uiStore.isSidebarExpanded ? 'opacity-0 !h-0' : ''}"
|
| 386 |
+
>
|
| 387 |
+
<SidebarNavigationActions
|
| 388 |
+
bind:isSearchModeActive
|
| 389 |
+
bind:searchQuery
|
| 390 |
+
class="px-2"
|
| 391 |
+
isExpandedMode={innerWidth > 768 ? uiStore.isSidebarExpanded : true}
|
| 392 |
+
onNewChat={() => {
|
| 393 |
+
if (deviceStore.isMobile) {
|
| 394 |
+
scheduleMobileCollapse();
|
| 395 |
+
}
|
| 396 |
+
}}
|
| 397 |
+
onSearchClick={() => {
|
| 398 |
+
uiStore.isSidebarExpanded = true;
|
| 399 |
+
isSearchModeActive = true;
|
| 400 |
+
}}
|
| 401 |
+
onSearchDeactivated={() => {
|
| 402 |
+
isSearchModeActive = false;
|
| 403 |
+
searchQuery = '';
|
| 404 |
+
}}
|
| 405 |
+
onSettingsClick={() => (settingsDialogOpen = true)}
|
| 406 |
+
/>
|
| 407 |
+
|
| 408 |
+
{#if uiStore.isSidebarExpanded || isOnMobile}
|
| 409 |
+
<div class="flex min-h-0 flex-1 flex-col overflow-y-auto">
|
| 410 |
+
<SidebarNavigationConversationList
|
| 411 |
+
{allSelectedArePinned}
|
| 412 |
+
allVisibleSelected={visibleSelectionStats.visibleCount > 0 &&
|
| 413 |
+
visibleSelectionStats.selectedVisibleCount === visibleSelectionStats.visibleCount}
|
| 414 |
+
class="px-2"
|
| 415 |
+
{currentChatId}
|
| 416 |
+
{filteredConversations}
|
| 417 |
+
{isSearchModeActive}
|
| 418 |
+
{isSelectionMode}
|
| 419 |
+
onBulkDelete={handleBulkDelete}
|
| 420 |
+
onBulkExport={handleBulkExport}
|
| 421 |
+
onBulkPinToggle={handleBulkPinToggle}
|
| 422 |
+
onCloseSelection={exitSelectionMode}
|
| 423 |
+
onDelete={handleDeleteConversation}
|
| 424 |
+
onEdit={handleEditConversation}
|
| 425 |
+
onEnterSelectionMode={enterSelectionMode}
|
| 426 |
+
onRowMouseDown={handleRowMouseDown}
|
| 427 |
+
onSelect={selectConversation}
|
| 428 |
+
onSelectAllToggle={toggleSelectAllVisible}
|
| 429 |
+
onSelectionClick={handleSelectionClick}
|
| 430 |
+
onStop={handleStopGeneration}
|
| 431 |
+
onToggleSelect={toggleSelected}
|
| 432 |
+
{pinStateIsMixed}
|
| 433 |
+
{searchQuery}
|
| 434 |
+
{selectedIds}
|
| 435 |
+
someVisibleSelected={visibleSelectionStats.selectedVisibleCount > 0 &&
|
| 436 |
+
visibleSelectionStats.selectedVisibleCount < visibleSelectionStats.visibleCount}
|
| 437 |
+
visibleCount={visibleSelectionStats.visibleCount}
|
| 438 |
+
/>
|
| 439 |
+
</div>
|
| 440 |
+
{/if}
|
| 441 |
+
</div>
|
| 442 |
+
</aside>
|
| 443 |
+
{/if}
|
| 444 |
+
|
| 445 |
+
<DialogConversationRename
|
| 446 |
+
bind:open={renameDialogOpen}
|
| 447 |
+
bind:value={renameDraft}
|
| 448 |
+
currentTitle={renameOriginalTitle}
|
| 449 |
+
onCancel={handleRenameCancel}
|
| 450 |
+
onConfirm={handleRenameConfirm}
|
| 451 |
+
/>
|
| 452 |
+
|
| 453 |
+
<DialogSettingsChat bind:open={settingsDialogOpen} />
|
| 454 |
+
|
| 455 |
+
<style>
|
| 456 |
+
aside {
|
| 457 |
+
@media (max-width: 768px) {
|
| 458 |
+
--size: 1.125rem;
|
| 459 |
+
}
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
@media (max-width: 768px) {
|
| 463 |
+
aside {
|
| 464 |
+
&:not(.is-expanded) {
|
| 465 |
+
pointer-events: none;
|
| 466 |
+
}
|
| 467 |
+
}
|
| 468 |
+
|
| 469 |
+
aside.is-expanded::before {
|
| 470 |
+
content: '';
|
| 471 |
+
position: fixed;
|
| 472 |
+
top: -0.5rem;
|
| 473 |
+
bottom: -0.25rem;
|
| 474 |
+
left: -0.5rem;
|
| 475 |
+
right: -0.5rem;
|
| 476 |
+
z-index: -1;
|
| 477 |
+
background: var(--background);
|
| 478 |
+
backdrop-filter: blur(1rem);
|
| 479 |
+
pointer-events: none;
|
| 480 |
+
}
|
| 481 |
+
}
|
| 482 |
+
</style>
|
tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationActions.svelte
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { Search } from '@lucide/svelte';
|
| 3 |
+
import { goto } from '$app/navigation';
|
| 4 |
+
import { page } from '$app/state';
|
| 5 |
+
import { ActionIcon, KeyboardShortcutInfo, SearchInput } from '$lib/components/app';
|
| 6 |
+
import { Button } from '$lib/components/ui/button';
|
| 7 |
+
import {
|
| 8 |
+
ICON_CLASS_DEFAULT,
|
| 9 |
+
ICON_STRIP_TRANSITION_DELAY_MULTIPLIER,
|
| 10 |
+
ICON_STRIP_TRANSITION_DURATION,
|
| 11 |
+
ROUTES,
|
| 12 |
+
SIDEBAR_ACTIONS_ITEMS
|
| 13 |
+
} from '$lib/constants';
|
| 14 |
+
import { SidebarAction, TooltipSide } from '$lib/enums';
|
| 15 |
+
import { conversationsStore, deviceStore } from '$lib/stores';
|
| 16 |
+
import type { Component } from 'svelte';
|
| 17 |
+
import { onMount } from 'svelte';
|
| 18 |
+
import { circIn } from 'svelte/easing';
|
| 19 |
+
import { fade } from 'svelte/transition';
|
| 20 |
+
|
| 21 |
+
interface Props {
|
| 22 |
+
class: string;
|
| 23 |
+
isExpandedMode: boolean;
|
| 24 |
+
isSearchModeActive: boolean;
|
| 25 |
+
searchQuery: string;
|
| 26 |
+
onSearchDeactivated?: () => void;
|
| 27 |
+
onSearchClick?: () => void;
|
| 28 |
+
onNewChat?: () => void;
|
| 29 |
+
onSettingsClick?: () => void;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
let {
|
| 33 |
+
class: className,
|
| 34 |
+
isExpandedMode = false,
|
| 35 |
+
isSearchModeActive = $bindable(false),
|
| 36 |
+
onNewChat,
|
| 37 |
+
onSearchClick,
|
| 38 |
+
onSearchDeactivated,
|
| 39 |
+
onSettingsClick,
|
| 40 |
+
searchQuery = $bindable('')
|
| 41 |
+
}: Props = $props();
|
| 42 |
+
|
| 43 |
+
let initialized = $state(false);
|
| 44 |
+
let showIcons = $state(false);
|
| 45 |
+
let searchInputRef = $state<HTMLInputElement | null>(null);
|
| 46 |
+
|
| 47 |
+
const isOnMobile = $derived(deviceStore.isMobile);
|
| 48 |
+
|
| 49 |
+
$effect(() => {
|
| 50 |
+
if (isSearchModeActive && searchInputRef) {
|
| 51 |
+
searchInputRef.focus();
|
| 52 |
+
}
|
| 53 |
+
});
|
| 54 |
+
|
| 55 |
+
onMount(() => {
|
| 56 |
+
showIcons = true;
|
| 57 |
+
|
| 58 |
+
setTimeout(() => {
|
| 59 |
+
initialized = true;
|
| 60 |
+
}, ICON_STRIP_TRANSITION_DELAY_MULTIPLIER * SIDEBAR_ACTIONS_ITEMS.length);
|
| 61 |
+
});
|
| 62 |
+
|
| 63 |
+
function handleSearchModeDeactivate() {
|
| 64 |
+
isSearchModeActive = false;
|
| 65 |
+
searchQuery = '';
|
| 66 |
+
onSearchDeactivated?.();
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
function isItemActive(item: {
|
| 70 |
+
activeRouteId?: string;
|
| 71 |
+
activeRoutePrefix?: string;
|
| 72 |
+
activeUrlIncludes?: string;
|
| 73 |
+
}): boolean {
|
| 74 |
+
if (item.activeRouteId) {
|
| 75 |
+
return page.route.id === item.activeRouteId;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
if (item.activeRoutePrefix) {
|
| 79 |
+
return !!page.route.id?.startsWith(item.activeRoutePrefix);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
if (item.activeUrlIncludes) {
|
| 83 |
+
return page.url?.hash?.includes(item.activeUrlIncludes) ?? false;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
return false;
|
| 87 |
+
}
|
| 88 |
+
</script>
|
| 89 |
+
|
| 90 |
+
{#snippet itemIcon(IconComponent: Component)}
|
| 91 |
+
<IconComponent class={ICON_CLASS_DEFAULT} />
|
| 92 |
+
{/snippet}
|
| 93 |
+
|
| 94 |
+
{#if isSearchModeActive}
|
| 95 |
+
<div class="px-4 my-2">
|
| 96 |
+
<SearchInput
|
| 97 |
+
bind:ref={searchInputRef}
|
| 98 |
+
bind:value={searchQuery}
|
| 99 |
+
onClose={handleSearchModeDeactivate}
|
| 100 |
+
onKeyDown={(e) => e.key === 'Escape' && handleSearchModeDeactivate()}
|
| 101 |
+
placeholder="Search conversations..."
|
| 102 |
+
/>
|
| 103 |
+
</div>
|
| 104 |
+
{:else if isExpandedMode || isOnMobile}
|
| 105 |
+
<div
|
| 106 |
+
class="{className} flex flex-col gap-5 md:gap-1 mt-2 md:mt-0 {!isExpandedMode && isOnMobile
|
| 107 |
+
? 'hidden pointer-events-none'
|
| 108 |
+
: ''}"
|
| 109 |
+
>
|
| 110 |
+
{#each SIDEBAR_ACTIONS_ITEMS as item, i (item.tooltip)}
|
| 111 |
+
{@const isActive = isItemActive(item)}
|
| 112 |
+
{@const isSearchOnMobile = item.icon === Search && deviceStore.isMobile}
|
| 113 |
+
{@const itemHref = isSearchOnMobile ? ROUTES.SEARCH : item.route}
|
| 114 |
+
{@const itemOnClick =
|
| 115 |
+
item.action === SidebarAction.NEW_CHAT
|
| 116 |
+
? () => {
|
| 117 |
+
onNewChat?.();
|
| 118 |
+
void conversationsStore.openNewChat();
|
| 119 |
+
}
|
| 120 |
+
: item.action === SidebarAction.SETTINGS
|
| 121 |
+
? () => onSettingsClick?.()
|
| 122 |
+
: item.route
|
| 123 |
+
? () => {
|
| 124 |
+
onNewChat?.();
|
| 125 |
+
goto(item.route!);
|
| 126 |
+
}
|
| 127 |
+
: isSearchOnMobile
|
| 128 |
+
? undefined
|
| 129 |
+
: onSearchClick}
|
| 130 |
+
{@const itemTransition = {
|
| 131 |
+
delay: !initialized ? i * ICON_STRIP_TRANSITION_DELAY_MULTIPLIER : 0,
|
| 132 |
+
duration: ICON_STRIP_TRANSITION_DURATION,
|
| 133 |
+
easing: circIn
|
| 134 |
+
}}
|
| 135 |
+
|
| 136 |
+
{#if showIcons}
|
| 137 |
+
<div transition:fade={itemTransition}>
|
| 138 |
+
<Button
|
| 139 |
+
class="w-full min-w-9 justify-between px-2 backdrop-blur-none! hover:[&>kbd]:opacity-100 {isActive
|
| 140 |
+
? 'bg-accent text-accent-foreground'
|
| 141 |
+
: ''}"
|
| 142 |
+
href={itemHref}
|
| 143 |
+
onclick={itemOnClick}
|
| 144 |
+
size="default"
|
| 145 |
+
variant="ghost"
|
| 146 |
+
>
|
| 147 |
+
<span class="flex min-w-0 items-center px-0.5 gap-2">
|
| 148 |
+
{@render itemIcon(item.icon)}
|
| 149 |
+
|
| 150 |
+
{#if showIcons}
|
| 151 |
+
<span in:fade={itemTransition} out:fade={itemTransition} class="min-w-0 truncate"
|
| 152 |
+
>{item.tooltip}</span
|
| 153 |
+
>
|
| 154 |
+
{/if}
|
| 155 |
+
</span>
|
| 156 |
+
|
| 157 |
+
{#if item.keys}
|
| 158 |
+
<KeyboardShortcutInfo keys={item.keys} />
|
| 159 |
+
{/if}
|
| 160 |
+
</Button>
|
| 161 |
+
</div>
|
| 162 |
+
{/if}
|
| 163 |
+
{/each}
|
| 164 |
+
</div>
|
| 165 |
+
{:else}
|
| 166 |
+
<div class="{className} flex-col gap-1 hidden md:flex">
|
| 167 |
+
{#each SIDEBAR_ACTIONS_ITEMS as item, i (item.tooltip)}
|
| 168 |
+
{@const isActive = isItemActive(item)}
|
| 169 |
+
{@const isSearchOnMobile = item.icon === Search && deviceStore.isMobile}
|
| 170 |
+
{@const itemOnClick =
|
| 171 |
+
item.action === SidebarAction.NEW_CHAT
|
| 172 |
+
? () => {
|
| 173 |
+
onNewChat?.();
|
| 174 |
+
void conversationsStore.openNewChat();
|
| 175 |
+
}
|
| 176 |
+
: item.action === SidebarAction.SETTINGS
|
| 177 |
+
? () => onSettingsClick?.()
|
| 178 |
+
: item.route
|
| 179 |
+
? () => {
|
| 180 |
+
onNewChat?.();
|
| 181 |
+
goto(item.route!);
|
| 182 |
+
}
|
| 183 |
+
: isSearchOnMobile
|
| 184 |
+
? undefined
|
| 185 |
+
: onSearchClick}
|
| 186 |
+
{@const itemTransition = {
|
| 187 |
+
delay: !initialized ? i * ICON_STRIP_TRANSITION_DELAY_MULTIPLIER : 0,
|
| 188 |
+
duration: ICON_STRIP_TRANSITION_DURATION,
|
| 189 |
+
easing: circIn
|
| 190 |
+
}}
|
| 191 |
+
|
| 192 |
+
{#if showIcons}
|
| 193 |
+
<div transition:fade={itemTransition}>
|
| 194 |
+
<ActionIcon
|
| 195 |
+
class="h-9 w-9 rounded-full hover:bg-accent! {isActive
|
| 196 |
+
? 'bg-accent text-accent-foreground'
|
| 197 |
+
: ''}"
|
| 198 |
+
icon={item.icon}
|
| 199 |
+
iconSize={ICON_CLASS_DEFAULT}
|
| 200 |
+
onclick={itemOnClick}
|
| 201 |
+
size="lg"
|
| 202 |
+
tooltip={item.tooltip}
|
| 203 |
+
tooltipSide={TooltipSide.RIGHT}
|
| 204 |
+
/>
|
| 205 |
+
</div>
|
| 206 |
+
{/if}
|
| 207 |
+
{/each}
|
| 208 |
+
</div>
|
| 209 |
+
{/if}
|
tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationConversationItem.svelte
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import {
|
| 3 |
+
Download,
|
| 4 |
+
GitBranch,
|
| 5 |
+
ListChecks,
|
| 6 |
+
Loader2,
|
| 7 |
+
MoreHorizontal,
|
| 8 |
+
Pencil,
|
| 9 |
+
Pin,
|
| 10 |
+
PinOff,
|
| 11 |
+
Square,
|
| 12 |
+
Trash2
|
| 13 |
+
} from '@lucide/svelte';
|
| 14 |
+
import { DropdownMenuActions } from '$lib/components/app';
|
| 15 |
+
import { TruncatedText } from '$lib/components/app';
|
| 16 |
+
import { Checkbox } from '$lib/components/ui/checkbox';
|
| 17 |
+
import * as Tooltip from '$lib/components/ui/tooltip';
|
| 18 |
+
import { FORK_TREE_DEPTH_PADDING, ICON_CLASS_DEFAULT, UI_DATA_ATTRS } from '$lib/constants';
|
| 19 |
+
import { RouterService } from '$lib/services/router.service';
|
| 20 |
+
import { chatStore, conversationsStore } from '$lib/stores';
|
| 21 |
+
import { onMount } from 'svelte';
|
| 22 |
+
|
| 23 |
+
interface Props {
|
| 24 |
+
isActive?: boolean;
|
| 25 |
+
depth?: number;
|
| 26 |
+
conversation: DatabaseConversation;
|
| 27 |
+
isSelectionMode?: boolean;
|
| 28 |
+
isSelected?: boolean;
|
| 29 |
+
onDelete?: (id: string) => void;
|
| 30 |
+
onEdit?: (id: string) => void;
|
| 31 |
+
onSelect?: (id: string) => void;
|
| 32 |
+
onStop?: (id: string) => void;
|
| 33 |
+
onToggleSelect?: (id: string) => void;
|
| 34 |
+
onEnterSelectionMode?: (id: string) => void;
|
| 35 |
+
onSelectionClick?: (id: string, options: { shiftKey: boolean }) => void;
|
| 36 |
+
onRowMouseDown?: (id: string, event: MouseEvent) => void;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
let {
|
| 40 |
+
conversation,
|
| 41 |
+
depth = 0,
|
| 42 |
+
isActive = false,
|
| 43 |
+
isSelected = false,
|
| 44 |
+
isSelectionMode = false,
|
| 45 |
+
onDelete,
|
| 46 |
+
onEdit,
|
| 47 |
+
onEnterSelectionMode,
|
| 48 |
+
onRowMouseDown,
|
| 49 |
+
onSelect,
|
| 50 |
+
onSelectionClick,
|
| 51 |
+
onStop,
|
| 52 |
+
onToggleSelect
|
| 53 |
+
}: Props = $props();
|
| 54 |
+
|
| 55 |
+
let renderActionsDropdown = $state(false);
|
| 56 |
+
let dropdownOpen = $state(false);
|
| 57 |
+
|
| 58 |
+
let isLoading = $derived(chatStore.getAllLoadingChats().includes(conversation.id));
|
| 59 |
+
|
| 60 |
+
function handleEdit(event: Event) {
|
| 61 |
+
event.stopPropagation();
|
| 62 |
+
onEdit?.(conversation.id);
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
function handleDelete(event: Event) {
|
| 66 |
+
event.stopPropagation();
|
| 67 |
+
onDelete?.(conversation.id);
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
function handleStop(event: Event) {
|
| 71 |
+
event.stopPropagation();
|
| 72 |
+
onStop?.(conversation.id);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
function handleTogglePin() {
|
| 76 |
+
conversationsStore.toggleConversationPin(conversation.id);
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
function handleEnterSelectionMode(event: Event) {
|
| 80 |
+
event.stopPropagation();
|
| 81 |
+
onEnterSelectionMode?.(conversation.id);
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
function handleGlobalEditEvent(event: Event) {
|
| 85 |
+
const customEvent = event as CustomEvent<{ conversationId: string }>;
|
| 86 |
+
|
| 87 |
+
if (customEvent.detail.conversationId === conversation.id && isActive) {
|
| 88 |
+
handleEdit(event);
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
function handleMouseLeave() {
|
| 93 |
+
if (!dropdownOpen) {
|
| 94 |
+
renderActionsDropdown = false;
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
function handleMouseOver() {
|
| 99 |
+
if (isSelectionMode) return;
|
| 100 |
+
|
| 101 |
+
renderActionsDropdown = true;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
function handleSelect(event: MouseEvent) {
|
| 105 |
+
if (isSelectionMode) {
|
| 106 |
+
onSelectionClick?.(conversation.id, { shiftKey: event.shiftKey });
|
| 107 |
+
} else {
|
| 108 |
+
onSelect?.(conversation.id);
|
| 109 |
+
}
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
function handleCheckboxClick(event: MouseEvent) {
|
| 113 |
+
event.stopPropagation();
|
| 114 |
+
|
| 115 |
+
if (isSelectionMode) {
|
| 116 |
+
onSelectionClick?.(conversation.id, { shiftKey: event.shiftKey });
|
| 117 |
+
} else {
|
| 118 |
+
onToggleSelect?.(conversation.id);
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
function handleRowMouseDown(event: MouseEvent) {
|
| 123 |
+
onRowMouseDown?.(conversation.id, event);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
function handleCheckboxKeydown(event: KeyboardEvent) {
|
| 127 |
+
if (event.key !== ' ' && event.key !== 'Enter') return;
|
| 128 |
+
|
| 129 |
+
event.stopPropagation();
|
| 130 |
+
event.preventDefault();
|
| 131 |
+
|
| 132 |
+
if (isSelectionMode) {
|
| 133 |
+
onSelectionClick?.(conversation.id, { shiftKey: event.shiftKey });
|
| 134 |
+
} else {
|
| 135 |
+
onToggleSelect?.(conversation.id);
|
| 136 |
+
}
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
$effect(() => {
|
| 140 |
+
if (!dropdownOpen) {
|
| 141 |
+
renderActionsDropdown = false;
|
| 142 |
+
}
|
| 143 |
+
});
|
| 144 |
+
|
| 145 |
+
onMount(() => {
|
| 146 |
+
document.addEventListener('edit-active-conversation', handleGlobalEditEvent as EventListener);
|
| 147 |
+
|
| 148 |
+
return () => {
|
| 149 |
+
document.removeEventListener(
|
| 150 |
+
'edit-active-conversation',
|
| 151 |
+
handleGlobalEditEvent as EventListener
|
| 152 |
+
);
|
| 153 |
+
};
|
| 154 |
+
});
|
| 155 |
+
</script>
|
| 156 |
+
|
| 157 |
+
<button
|
| 158 |
+
class="group flex min-h-9 w-full cursor-pointer items-center justify-between space-x-3 rounded-lg py-1.5 text-left transition-colors hover:bg-foreground/10 {isActive
|
| 159 |
+
? 'bg-foreground/5 text-accent-foreground'
|
| 160 |
+
: ''} {isSelected ? 'bg-primary/10 hover:bg-primary/15' : ''} {isSelectionMode
|
| 161 |
+
? 'is-selection-mode'
|
| 162 |
+
: ''} px-2"
|
| 163 |
+
{...{ [UI_DATA_ATTRS.CONVERSATION_ROW]: conversation.id }}
|
| 164 |
+
onclick={(e) => handleSelect(e)}
|
| 165 |
+
onfocusin={handleMouseOver}
|
| 166 |
+
onfocusout={(e) => {
|
| 167 |
+
if (!e.currentTarget.contains(e.relatedTarget as Node | null)) {
|
| 168 |
+
handleMouseLeave();
|
| 169 |
+
}
|
| 170 |
+
}}
|
| 171 |
+
onmousedown={(e) => handleRowMouseDown(e)}
|
| 172 |
+
onmouseleave={handleMouseLeave}
|
| 173 |
+
onmouseover={handleMouseOver}
|
| 174 |
+
>
|
| 175 |
+
<div
|
| 176 |
+
style:padding-left="{depth * FORK_TREE_DEPTH_PADDING}px"
|
| 177 |
+
class="flex min-w-0 flex-1 items-center gap-2"
|
| 178 |
+
>
|
| 179 |
+
{#if isSelectionMode}
|
| 180 |
+
<div
|
| 181 |
+
aria-checked={isSelected}
|
| 182 |
+
aria-label={isSelected ? `Deselect ${conversation.name}` : `Select ${conversation.name}`}
|
| 183 |
+
class="shrink-0"
|
| 184 |
+
onclick={(e) => handleCheckboxClick(e)}
|
| 185 |
+
onkeydown={handleCheckboxKeydown}
|
| 186 |
+
role="checkbox"
|
| 187 |
+
tabindex="-1"
|
| 188 |
+
>
|
| 189 |
+
<Checkbox
|
| 190 |
+
aria-label={isSelected ? `Deselect ${conversation.name}` : `Select ${conversation.name}`}
|
| 191 |
+
checked={isSelected}
|
| 192 |
+
/>
|
| 193 |
+
</div>
|
| 194 |
+
{/if}
|
| 195 |
+
|
| 196 |
+
{#if depth > 0}
|
| 197 |
+
<Tooltip.Root>
|
| 198 |
+
<Tooltip.Trigger>
|
| 199 |
+
<!-- prevent another nested button element -->
|
| 200 |
+
{#snippet child({ props })}
|
| 201 |
+
<a
|
| 202 |
+
{...props}
|
| 203 |
+
class="flex shrink-0 items-center text-muted-foreground transition-colors hover:text-foreground"
|
| 204 |
+
href={RouterService.chat(conversation.forkedFromConversationId)}
|
| 205 |
+
>
|
| 206 |
+
<GitBranch class="h-3.5 w-3.5" />
|
| 207 |
+
</a>
|
| 208 |
+
{/snippet}
|
| 209 |
+
</Tooltip.Trigger>
|
| 210 |
+
|
| 211 |
+
<Tooltip.Content>
|
| 212 |
+
<p>See parent conversation</p>
|
| 213 |
+
</Tooltip.Content>
|
| 214 |
+
</Tooltip.Root>
|
| 215 |
+
{/if}
|
| 216 |
+
|
| 217 |
+
{#if isLoading}
|
| 218 |
+
<Tooltip.Root>
|
| 219 |
+
<Tooltip.Trigger>
|
| 220 |
+
<div
|
| 221 |
+
aria-label="Stop generation"
|
| 222 |
+
class="stop-button flex {ICON_CLASS_DEFAULT} shrink-0 cursor-pointer items-center justify-center rounded text-muted-foreground transition-colors hover:text-foreground"
|
| 223 |
+
onclick={handleStop}
|
| 224 |
+
onkeydown={(e) => e.key === 'Enter' && handleStop(e)}
|
| 225 |
+
role="button"
|
| 226 |
+
tabindex="0"
|
| 227 |
+
>
|
| 228 |
+
<Loader2 class="loading-icon h-3.5 w-3.5 animate-spin" />
|
| 229 |
+
|
| 230 |
+
<Square class="stop-icon hidden h-3 w-3 fill-current text-destructive" />
|
| 231 |
+
</div>
|
| 232 |
+
</Tooltip.Trigger>
|
| 233 |
+
|
| 234 |
+
<Tooltip.Content>
|
| 235 |
+
<p>Stop generation</p>
|
| 236 |
+
</Tooltip.Content>
|
| 237 |
+
</Tooltip.Root>
|
| 238 |
+
{/if}
|
| 239 |
+
|
| 240 |
+
<TruncatedText class="text-sm font-medium" showTooltip={false} text={conversation.name} />
|
| 241 |
+
</div>
|
| 242 |
+
|
| 243 |
+
{#if !isSelectionMode && renderActionsDropdown}
|
| 244 |
+
<div class="actions flex items-center">
|
| 245 |
+
<DropdownMenuActions
|
| 246 |
+
bind:open={dropdownOpen}
|
| 247 |
+
actions={[
|
| 248 |
+
{
|
| 249 |
+
icon: conversation.pinned ? PinOff : Pin,
|
| 250 |
+
label: conversation.pinned ? 'Unpin' : 'Pin',
|
| 251 |
+
onclick: (e: Event) => {
|
| 252 |
+
e.stopPropagation();
|
| 253 |
+
handleTogglePin();
|
| 254 |
+
}
|
| 255 |
+
},
|
| 256 |
+
{
|
| 257 |
+
icon: Pencil,
|
| 258 |
+
label: 'Edit',
|
| 259 |
+
onclick: handleEdit,
|
| 260 |
+
shortcut: ['shift', 'cmd', 'e']
|
| 261 |
+
},
|
| 262 |
+
{
|
| 263 |
+
icon: Download,
|
| 264 |
+
label: 'Export',
|
| 265 |
+
onclick: (e: Event) => {
|
| 266 |
+
e.stopPropagation();
|
| 267 |
+
conversationsStore.downloadConversation(conversation.id);
|
| 268 |
+
},
|
| 269 |
+
shortcut: ['shift', 'cmd', 's']
|
| 270 |
+
},
|
| 271 |
+
{
|
| 272 |
+
icon: ListChecks,
|
| 273 |
+
label: 'Select',
|
| 274 |
+
onclick: handleEnterSelectionMode
|
| 275 |
+
},
|
| 276 |
+
{
|
| 277 |
+
icon: Trash2,
|
| 278 |
+
label: 'Delete',
|
| 279 |
+
onclick: handleDelete,
|
| 280 |
+
separator: true,
|
| 281 |
+
shortcut: ['shift', 'cmd', 'd'],
|
| 282 |
+
variant: 'destructive'
|
| 283 |
+
}
|
| 284 |
+
]}
|
| 285 |
+
triggerIcon={MoreHorizontal}
|
| 286 |
+
triggerTooltip="More actions"
|
| 287 |
+
/>
|
| 288 |
+
</div>
|
| 289 |
+
{/if}
|
| 290 |
+
</button>
|
| 291 |
+
|
| 292 |
+
<style>
|
| 293 |
+
button {
|
| 294 |
+
:global([data-slot='dropdown-menu-trigger']:not([data-state='open'])) {
|
| 295 |
+
opacity: 0;
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
&:is(:hover) :global([data-slot='dropdown-menu-trigger']),
|
| 299 |
+
&:focus-within :global([data-slot='dropdown-menu-trigger']) {
|
| 300 |
+
opacity: 1;
|
| 301 |
+
}
|
| 302 |
+
@media (max-width: 768px) {
|
| 303 |
+
:global([data-slot='dropdown-menu-trigger']) {
|
| 304 |
+
opacity: 1 !important;
|
| 305 |
+
}
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
&.is-selection-mode :global([data-slot='dropdown-menu-trigger']) {
|
| 309 |
+
display: none !important;
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
.stop-button {
|
| 313 |
+
:global(.stop-icon) {
|
| 314 |
+
display: none;
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
:global(.loading-icon) {
|
| 318 |
+
display: block;
|
| 319 |
+
}
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
&:is(:hover) .stop-button {
|
| 323 |
+
:global(.stop-icon) {
|
| 324 |
+
display: block;
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
:global(.loading-icon) {
|
| 328 |
+
display: none;
|
| 329 |
+
}
|
| 330 |
+
}
|
| 331 |
+
}
|
| 332 |
+
</style>
|
tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationConversationList.svelte
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import SidebarNavigationConversationItem from './SidebarNavigationConversationItem.svelte';
|
| 3 |
+
import SidebarNavigationSearchResults from './SidebarNavigationSearchResults.svelte';
|
| 4 |
+
import SidebarNavigationSelectionBar from './SidebarNavigationSelectionBar.svelte';
|
| 5 |
+
import { Pin } from '@lucide/svelte';
|
| 6 |
+
import { buildConversationTree } from '$lib/utils';
|
| 7 |
+
|
| 8 |
+
interface Props {
|
| 9 |
+
class: string;
|
| 10 |
+
filteredConversations: DatabaseConversation[];
|
| 11 |
+
currentChatId: string | undefined;
|
| 12 |
+
isSearchModeActive: boolean;
|
| 13 |
+
searchQuery: string;
|
| 14 |
+
isSelectionMode?: boolean;
|
| 15 |
+
selectedIds?: Set<string>;
|
| 16 |
+
onSelect: (id: string) => void;
|
| 17 |
+
onEdit: (id: string) => void;
|
| 18 |
+
onDelete: (id: string) => void;
|
| 19 |
+
onStop: (id: string) => void;
|
| 20 |
+
onToggleSelect?: (id: string) => void;
|
| 21 |
+
onEnterSelectionMode?: (id: string) => void;
|
| 22 |
+
onSelectionClick?: (id: string, options: { shiftKey: boolean }) => void;
|
| 23 |
+
onRowMouseDown?: (id: string, event: MouseEvent) => void;
|
| 24 |
+
visibleCount: number;
|
| 25 |
+
allVisibleSelected: boolean;
|
| 26 |
+
someVisibleSelected: boolean;
|
| 27 |
+
allSelectedArePinned: boolean;
|
| 28 |
+
pinStateIsMixed: boolean;
|
| 29 |
+
onSelectAllToggle: () => void;
|
| 30 |
+
onBulkPinToggle: () => void;
|
| 31 |
+
onBulkExport: () => void;
|
| 32 |
+
onBulkDelete: () => void;
|
| 33 |
+
onCloseSelection: () => void;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
let {
|
| 37 |
+
allSelectedArePinned,
|
| 38 |
+
allVisibleSelected,
|
| 39 |
+
class: className,
|
| 40 |
+
currentChatId,
|
| 41 |
+
filteredConversations,
|
| 42 |
+
isSearchModeActive,
|
| 43 |
+
isSelectionMode = false,
|
| 44 |
+
onBulkDelete,
|
| 45 |
+
onBulkExport,
|
| 46 |
+
onBulkPinToggle,
|
| 47 |
+
onCloseSelection,
|
| 48 |
+
onDelete,
|
| 49 |
+
onEdit,
|
| 50 |
+
onEnterSelectionMode,
|
| 51 |
+
onRowMouseDown,
|
| 52 |
+
onSelect,
|
| 53 |
+
onSelectAllToggle,
|
| 54 |
+
onSelectionClick,
|
| 55 |
+
onStop,
|
| 56 |
+
onToggleSelect,
|
| 57 |
+
pinStateIsMixed,
|
| 58 |
+
searchQuery,
|
| 59 |
+
selectedIds = new Set<string>(),
|
| 60 |
+
someVisibleSelected,
|
| 61 |
+
visibleCount
|
| 62 |
+
}: Props = $props();
|
| 63 |
+
|
| 64 |
+
let conversationTree = $derived(buildConversationTree(filteredConversations));
|
| 65 |
+
|
| 66 |
+
let pinnedConversations = $derived(
|
| 67 |
+
conversationTree.filter(({ conversation }) => conversation.pinned)
|
| 68 |
+
);
|
| 69 |
+
|
| 70 |
+
let unpinnedConversations = $derived(
|
| 71 |
+
conversationTree.filter(({ conversation }) => !conversation.pinned)
|
| 72 |
+
);
|
| 73 |
+
|
| 74 |
+
const recentEmptyMessage = $derived(
|
| 75 |
+
searchQuery.length > 0 ? 'No results found' : 'No conversations yet'
|
| 76 |
+
);
|
| 77 |
+
</script>
|
| 78 |
+
|
| 79 |
+
<div class="flex min-h-0 flex-1 flex-col">
|
| 80 |
+
{#if isSearchModeActive}
|
| 81 |
+
<SidebarNavigationSearchResults
|
| 82 |
+
class={className}
|
| 83 |
+
{currentChatId}
|
| 84 |
+
{filteredConversations}
|
| 85 |
+
{isSelectionMode}
|
| 86 |
+
{onDelete}
|
| 87 |
+
{onEdit}
|
| 88 |
+
{onEnterSelectionMode}
|
| 89 |
+
{onRowMouseDown}
|
| 90 |
+
{onSelect}
|
| 91 |
+
{onSelectionClick}
|
| 92 |
+
{onStop}
|
| 93 |
+
{onToggleSelect}
|
| 94 |
+
{searchQuery}
|
| 95 |
+
{selectedIds}
|
| 96 |
+
/>
|
| 97 |
+
{:else}
|
| 98 |
+
{#if pinnedConversations.length > 0}
|
| 99 |
+
<div class="py-2 flex whitespace-nowrap {className}">
|
| 100 |
+
<div
|
| 101 |
+
class="text-muted-foreground inline-flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium gap-1"
|
| 102 |
+
>
|
| 103 |
+
<Pin class="h-3.5 w-3.5" />
|
| 104 |
+
|
| 105 |
+
<span>Pinned</span>
|
| 106 |
+
</div>
|
| 107 |
+
</div>
|
| 108 |
+
|
| 109 |
+
<ul class="flex w-full min-w-0 flex-col gap-4 md:gap-1 {className}">
|
| 110 |
+
{#each pinnedConversations as { conversation, depth } (conversation.id)}
|
| 111 |
+
<li class="group/item relative mb-1 p-0">
|
| 112 |
+
<SidebarNavigationConversationItem
|
| 113 |
+
conversation={{
|
| 114 |
+
currNode: conversation.currNode,
|
| 115 |
+
forkedFromConversationId: conversation.forkedFromConversationId,
|
| 116 |
+
id: conversation.id,
|
| 117 |
+
lastModified: conversation.lastModified,
|
| 118 |
+
name: conversation.name,
|
| 119 |
+
pinned: conversation.pinned
|
| 120 |
+
}}
|
| 121 |
+
{depth}
|
| 122 |
+
isActive={currentChatId === conversation.id}
|
| 123 |
+
isSelected={selectedIds.has(conversation.id)}
|
| 124 |
+
{isSelectionMode}
|
| 125 |
+
{onDelete}
|
| 126 |
+
{onEdit}
|
| 127 |
+
{onEnterSelectionMode}
|
| 128 |
+
{onRowMouseDown}
|
| 129 |
+
{onSelect}
|
| 130 |
+
{onSelectionClick}
|
| 131 |
+
{onStop}
|
| 132 |
+
{onToggleSelect}
|
| 133 |
+
/>
|
| 134 |
+
</li>
|
| 135 |
+
{/each}
|
| 136 |
+
</ul>
|
| 137 |
+
{/if}
|
| 138 |
+
|
| 139 |
+
<div class="mt-2 flex min-h-0 flex-1 flex-col gap-4 md:gap-0 whitespace-nowrap {className}">
|
| 140 |
+
{#if filteredConversations.length > 0}
|
| 141 |
+
<div
|
| 142 |
+
class="text-muted-foreground flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium"
|
| 143 |
+
>
|
| 144 |
+
Recent conversations
|
| 145 |
+
</div>
|
| 146 |
+
{/if}
|
| 147 |
+
|
| 148 |
+
<div class="min-h-0 flex-1 md:overflow-y-auto">
|
| 149 |
+
<ul class="flex w-full min-w-0 flex-col gap-4 md:gap-0">
|
| 150 |
+
{#each unpinnedConversations as { conversation, depth } (conversation.id)}
|
| 151 |
+
<li class="group/item relative mb-1 p-0">
|
| 152 |
+
<SidebarNavigationConversationItem
|
| 153 |
+
conversation={{
|
| 154 |
+
currNode: conversation.currNode,
|
| 155 |
+
forkedFromConversationId: conversation.forkedFromConversationId,
|
| 156 |
+
id: conversation.id,
|
| 157 |
+
lastModified: conversation.lastModified,
|
| 158 |
+
name: conversation.name,
|
| 159 |
+
pinned: conversation.pinned
|
| 160 |
+
}}
|
| 161 |
+
{depth}
|
| 162 |
+
isActive={currentChatId === conversation.id}
|
| 163 |
+
isSelected={selectedIds.has(conversation.id)}
|
| 164 |
+
{isSelectionMode}
|
| 165 |
+
{onDelete}
|
| 166 |
+
{onEdit}
|
| 167 |
+
{onEnterSelectionMode}
|
| 168 |
+
{onRowMouseDown}
|
| 169 |
+
{onSelect}
|
| 170 |
+
{onSelectionClick}
|
| 171 |
+
{onStop}
|
| 172 |
+
{onToggleSelect}
|
| 173 |
+
/>
|
| 174 |
+
</li>
|
| 175 |
+
{/each}
|
| 176 |
+
|
| 177 |
+
{#if unpinnedConversations.length === 0}
|
| 178 |
+
<li class="px-2 py-4 text-center">
|
| 179 |
+
<p class="mb-4 p-4 text-sm text-muted-foreground">
|
| 180 |
+
{recentEmptyMessage}
|
| 181 |
+
</p>
|
| 182 |
+
</li>
|
| 183 |
+
{/if}
|
| 184 |
+
</ul>
|
| 185 |
+
</div>
|
| 186 |
+
</div>
|
| 187 |
+
|
| 188 |
+
{#if isSelectionMode}
|
| 189 |
+
<SidebarNavigationSelectionBar
|
| 190 |
+
{allVisibleSelected}
|
| 191 |
+
class="sticky top-0 z-10 m-2 mt-0"
|
| 192 |
+
{onBulkDelete}
|
| 193 |
+
{onBulkExport}
|
| 194 |
+
{onBulkPinToggle}
|
| 195 |
+
onClose={onCloseSelection}
|
| 196 |
+
{onSelectAllToggle}
|
| 197 |
+
{pinStateIsMixed}
|
| 198 |
+
selectedCount={selectedIds.size}
|
| 199 |
+
someSelectedPinned={allSelectedArePinned}
|
| 200 |
+
{someVisibleSelected}
|
| 201 |
+
{visibleCount}
|
| 202 |
+
/>
|
| 203 |
+
{/if}
|
| 204 |
+
{/if}
|
| 205 |
+
</div>
|
tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationSearch.svelte
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { SearchInput } from '$lib/components/app';
|
| 3 |
+
|
| 4 |
+
interface Props {
|
| 5 |
+
value?: string;
|
| 6 |
+
placeholder?: string;
|
| 7 |
+
onInput?: (value: string) => void;
|
| 8 |
+
class?: string;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
let {
|
| 12 |
+
class: className,
|
| 13 |
+
onInput,
|
| 14 |
+
placeholder = 'Search conversations...',
|
| 15 |
+
value = $bindable('')
|
| 16 |
+
}: Props = $props();
|
| 17 |
+
</script>
|
| 18 |
+
|
| 19 |
+
<div class="mb-4 px-2 {className}">
|
| 20 |
+
<SearchInput bind:value {onInput} {placeholder} />
|
| 21 |
+
</div>
|
tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationSearchResults.svelte
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import SidebarNavigationConversationItem from './SidebarNavigationConversationItem.svelte';
|
| 3 |
+
import { buildConversationTree } from '$lib/utils';
|
| 4 |
+
|
| 5 |
+
interface Props {
|
| 6 |
+
class?: string;
|
| 7 |
+
searchQuery: string;
|
| 8 |
+
filteredConversations: DatabaseConversation[];
|
| 9 |
+
currentChatId: string | undefined;
|
| 10 |
+
isSelectionMode?: boolean;
|
| 11 |
+
selectedIds?: Set<string>;
|
| 12 |
+
onSelect: (id: string) => void;
|
| 13 |
+
onEdit: (id: string) => void;
|
| 14 |
+
onDelete: (id: string) => void;
|
| 15 |
+
onStop: (id: string) => void;
|
| 16 |
+
onToggleSelect?: (id: string) => void;
|
| 17 |
+
onEnterSelectionMode?: (id: string) => void;
|
| 18 |
+
onSelectionClick?: (id: string, options: { shiftKey: boolean }) => void;
|
| 19 |
+
onRowMouseDown?: (id: string, event: MouseEvent) => void;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
let {
|
| 23 |
+
class: className = '',
|
| 24 |
+
currentChatId,
|
| 25 |
+
filteredConversations,
|
| 26 |
+
isSelectionMode = false,
|
| 27 |
+
onDelete,
|
| 28 |
+
onEdit,
|
| 29 |
+
onEnterSelectionMode,
|
| 30 |
+
onRowMouseDown,
|
| 31 |
+
onSelect,
|
| 32 |
+
onSelectionClick,
|
| 33 |
+
onStop,
|
| 34 |
+
onToggleSelect,
|
| 35 |
+
searchQuery,
|
| 36 |
+
selectedIds = new Set<string>()
|
| 37 |
+
}: Props = $props();
|
| 38 |
+
|
| 39 |
+
let tree = $derived(buildConversationTree(filteredConversations));
|
| 40 |
+
|
| 41 |
+
const hasQuery = $derived(searchQuery.trim().length > 0);
|
| 42 |
+
const showHeader = $derived(hasQuery && filteredConversations.length > 0);
|
| 43 |
+
|
| 44 |
+
const emptyMessage = $derived(hasQuery ? 'No results found' : 'Start typing to see results');
|
| 45 |
+
</script>
|
| 46 |
+
|
| 47 |
+
<div class="flex min-h-0 flex-1 flex-col gap-2 whitespace-nowrap {className}">
|
| 48 |
+
{#if showHeader}
|
| 49 |
+
<div
|
| 50 |
+
class="text-muted-foreground flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium"
|
| 51 |
+
>
|
| 52 |
+
Search results
|
| 53 |
+
</div>
|
| 54 |
+
{/if}
|
| 55 |
+
|
| 56 |
+
<div class="min-h-0 flex-1 overflow-y-auto">
|
| 57 |
+
<ul class="flex w-full min-w-0 flex-col gap-1">
|
| 58 |
+
{#each tree as { conversation, depth } (conversation.id)}
|
| 59 |
+
<li class="group/item relative mb-1 p-0">
|
| 60 |
+
<SidebarNavigationConversationItem
|
| 61 |
+
conversation={{
|
| 62 |
+
currNode: conversation.currNode,
|
| 63 |
+
forkedFromConversationId: conversation.forkedFromConversationId,
|
| 64 |
+
id: conversation.id,
|
| 65 |
+
lastModified: conversation.lastModified,
|
| 66 |
+
name: conversation.name,
|
| 67 |
+
pinned: conversation.pinned
|
| 68 |
+
}}
|
| 69 |
+
{depth}
|
| 70 |
+
isActive={currentChatId === conversation.id}
|
| 71 |
+
isSelected={selectedIds.has(conversation.id)}
|
| 72 |
+
{isSelectionMode}
|
| 73 |
+
{onDelete}
|
| 74 |
+
{onEdit}
|
| 75 |
+
{onEnterSelectionMode}
|
| 76 |
+
{onRowMouseDown}
|
| 77 |
+
{onSelect}
|
| 78 |
+
{onSelectionClick}
|
| 79 |
+
{onStop}
|
| 80 |
+
{onToggleSelect}
|
| 81 |
+
/>
|
| 82 |
+
</li>
|
| 83 |
+
{/each}
|
| 84 |
+
|
| 85 |
+
{#if tree.length === 0}
|
| 86 |
+
<li class="px-2 py-4 text-center">
|
| 87 |
+
<p class="mb-4 p-4 text-sm text-muted-foreground">
|
| 88 |
+
{emptyMessage}
|
| 89 |
+
</p>
|
| 90 |
+
</li>
|
| 91 |
+
{/if}
|
| 92 |
+
</ul>
|
| 93 |
+
</div>
|
| 94 |
+
</div>
|
tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigationSelectionBar.svelte
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { Download, Pin, PinOff, Trash2, X } from '@lucide/svelte';
|
| 3 |
+
import { ActionIcon, DialogConfirmation } from '$lib/components/app';
|
| 4 |
+
import { Checkbox } from '$lib/components/ui/checkbox';
|
| 5 |
+
import { TooltipSide } from '$lib/enums';
|
| 6 |
+
|
| 7 |
+
interface Props {
|
| 8 |
+
class?: string;
|
| 9 |
+
selectedCount: number;
|
| 10 |
+
visibleCount: number;
|
| 11 |
+
allVisibleSelected: boolean;
|
| 12 |
+
someVisibleSelected: boolean;
|
| 13 |
+
someSelectedPinned: boolean;
|
| 14 |
+
pinStateIsMixed: boolean;
|
| 15 |
+
onSelectAllToggle: () => void;
|
| 16 |
+
onBulkPinToggle: () => void;
|
| 17 |
+
onBulkExport: () => void;
|
| 18 |
+
onBulkDelete: () => void;
|
| 19 |
+
onClose: () => void;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
let {
|
| 23 |
+
allVisibleSelected,
|
| 24 |
+
class: className = '',
|
| 25 |
+
onBulkDelete,
|
| 26 |
+
onBulkExport,
|
| 27 |
+
onBulkPinToggle,
|
| 28 |
+
onClose,
|
| 29 |
+
onSelectAllToggle,
|
| 30 |
+
pinStateIsMixed,
|
| 31 |
+
selectedCount,
|
| 32 |
+
someSelectedPinned,
|
| 33 |
+
someVisibleSelected,
|
| 34 |
+
visibleCount
|
| 35 |
+
}: Props = $props();
|
| 36 |
+
|
| 37 |
+
let showDeleteDialog = $state(false);
|
| 38 |
+
|
| 39 |
+
function handleDeleteClick() {
|
| 40 |
+
showDeleteDialog = true;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
function handleDeleteConfirm() {
|
| 44 |
+
showDeleteDialog = false;
|
| 45 |
+
onBulkDelete();
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
function handleDeleteCancel() {
|
| 49 |
+
showDeleteDialog = false;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
const hasSelection = $derived(selectedCount > 0);
|
| 53 |
+
const isMasterChecked = $derived(allVisibleSelected);
|
| 54 |
+
const isMasterIndeterminate = $derived(!allVisibleSelected && someVisibleSelected);
|
| 55 |
+
|
| 56 |
+
const pinTooltip = $derived(
|
| 57 |
+
hasSelection
|
| 58 |
+
? pinStateIsMixed
|
| 59 |
+
? 'Unavailable for mixed state selection'
|
| 60 |
+
: someSelectedPinned
|
| 61 |
+
? selectedCount === 1
|
| 62 |
+
? 'Unpin'
|
| 63 |
+
: 'Unpin all'
|
| 64 |
+
: selectedCount === 1
|
| 65 |
+
? 'Pin'
|
| 66 |
+
: 'Pin all'
|
| 67 |
+
: 'Pin'
|
| 68 |
+
);
|
| 69 |
+
|
| 70 |
+
const pinDisabled = $derived(!hasSelection || pinStateIsMixed);
|
| 71 |
+
</script>
|
| 72 |
+
|
| 73 |
+
<div
|
| 74 |
+
aria-label="Bulk actions for selected conversations"
|
| 75 |
+
class="flex items-center gap-1.5 rounded-xl border border-border/50 bg-background/50 px-2 py-1.5 shadow-sm backdrop-blur-xl {className}"
|
| 76 |
+
role="toolbar"
|
| 77 |
+
>
|
| 78 |
+
<label class="flex min-w-0 cursor-pointer items-center gap-2">
|
| 79 |
+
<Checkbox
|
| 80 |
+
aria-label={isMasterChecked ? 'Deselect all' : 'Select all'}
|
| 81 |
+
checked={isMasterChecked}
|
| 82 |
+
indeterminate={isMasterIndeterminate}
|
| 83 |
+
onCheckedChange={onSelectAllToggle}
|
| 84 |
+
/>
|
| 85 |
+
|
| 86 |
+
<span class="truncate text-xs font-medium text-muted-foreground">
|
| 87 |
+
{selectedCount} / {visibleCount} selected
|
| 88 |
+
</span>
|
| 89 |
+
</label>
|
| 90 |
+
|
| 91 |
+
<div class="ml-auto flex items-center gap-0.75">
|
| 92 |
+
<ActionIcon
|
| 93 |
+
ariaLabel={pinTooltip}
|
| 94 |
+
class="h-7 w-7 rounded-md bg-transparent backdrop-blur-none hover:bg-accent! {pinDisabled
|
| 95 |
+
? 'cursor-not-allowed'
|
| 96 |
+
: ''} {!pinDisabled ? 'opacity-100' : 'opacity-40'}"
|
| 97 |
+
disabled={pinDisabled}
|
| 98 |
+
icon={someSelectedPinned ? PinOff : Pin}
|
| 99 |
+
iconSize="h-3.5 w-3.5"
|
| 100 |
+
onclick={onBulkPinToggle}
|
| 101 |
+
size="sm"
|
| 102 |
+
tooltip={pinTooltip}
|
| 103 |
+
tooltipSide={TooltipSide.TOP}
|
| 104 |
+
/>
|
| 105 |
+
|
| 106 |
+
<ActionIcon
|
| 107 |
+
ariaLabel="Export selected"
|
| 108 |
+
class="h-7 w-7 rounded-md bg-transparent backdrop-blur-none hover:bg-accent! {hasSelection
|
| 109 |
+
? 'opacity-100'
|
| 110 |
+
: 'opacity-40'}"
|
| 111 |
+
disabled={!hasSelection}
|
| 112 |
+
icon={Download}
|
| 113 |
+
iconSize="h-3.5 w-3.5"
|
| 114 |
+
onclick={onBulkExport}
|
| 115 |
+
size="sm"
|
| 116 |
+
tooltip={hasSelection ? 'Export' : 'Export'}
|
| 117 |
+
tooltipSide={TooltipSide.TOP}
|
| 118 |
+
/>
|
| 119 |
+
|
| 120 |
+
<ActionIcon
|
| 121 |
+
ariaLabel="Delete selected"
|
| 122 |
+
class="h-7 w-7 rounded-md bg-transparent backdrop-blur-none hover:bg-destructive/10! dark:hover:bg-destructive/20! disabled:hover:bg-transparent {hasSelection
|
| 123 |
+
? 'opacity-100'
|
| 124 |
+
: 'opacity-40'}"
|
| 125 |
+
disabled={!hasSelection}
|
| 126 |
+
icon={Trash2}
|
| 127 |
+
iconSize="h-3.5 w-3.5 text-destructive"
|
| 128 |
+
onclick={handleDeleteClick}
|
| 129 |
+
size="sm"
|
| 130 |
+
tooltip="Delete selected"
|
| 131 |
+
tooltipSide={TooltipSide.TOP}
|
| 132 |
+
/>
|
| 133 |
+
|
| 134 |
+
<div aria-hidden="true" class="mx-1 h-4 w-px bg-border"></div>
|
| 135 |
+
|
| 136 |
+
<ActionIcon
|
| 137 |
+
ariaLabel="Exit bulk selection mode"
|
| 138 |
+
class="h-7 w-7 rounded-md bg-transparent backdrop-blur-none hover:bg-accent!"
|
| 139 |
+
icon={X}
|
| 140 |
+
iconSize="h-3.5 w-3.5"
|
| 141 |
+
onclick={onClose}
|
| 142 |
+
size="sm"
|
| 143 |
+
tooltip="Exit bulk selection mode"
|
| 144 |
+
tooltipSide={TooltipSide.TOP}
|
| 145 |
+
/>
|
| 146 |
+
</div>
|
| 147 |
+
</div>
|
| 148 |
+
|
| 149 |
+
<DialogConfirmation
|
| 150 |
+
bind:open={showDeleteDialog}
|
| 151 |
+
cancelText="Cancel"
|
| 152 |
+
confirmText={selectedCount === 1 ? 'Delete' : `Delete ${selectedCount}`}
|
| 153 |
+
description="This action cannot be undone. The selected conversation{selectedCount === 1
|
| 154 |
+
? ''
|
| 155 |
+
: 's'} and {selectedCount === 1
|
| 156 |
+
? 'its'
|
| 157 |
+
: 'their'} messages will be permanently removed, including any forks."
|
| 158 |
+
icon={Trash2}
|
| 159 |
+
onCancel={handleDeleteCancel}
|
| 160 |
+
onConfirm={handleDeleteConfirm}
|
| 161 |
+
title="Delete {selectedCount} conversation{selectedCount === 1 ? '' : 's'}"
|
| 162 |
+
variant="destructive"
|
| 163 |
+
/>
|
tools/ui/src/lib/components/app/navigation/index.ts
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
*
|
| 3 |
+
* NAVIGATION & MENUS
|
| 4 |
+
*
|
| 5 |
+
* Components for dropdown menus and action selection.
|
| 6 |
+
*
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
/**
|
| 10 |
+
* **DropdownMenuSearchable** - Searchable content for dropdown menus
|
| 11 |
+
*
|
| 12 |
+
* Renders a search input with filtered content area, empty state, and optional footer.
|
| 13 |
+
* Designed to be injected into any dropdown container (DropdownMenu.Content,
|
| 14 |
+
* DropdownMenu.SubContent, etc.) without providing its own Root.
|
| 15 |
+
*
|
| 16 |
+
* **Features:**
|
| 17 |
+
* - Search/filter input
|
| 18 |
+
* - Keyboard navigation support
|
| 19 |
+
* - Custom content and footer via snippets
|
| 20 |
+
* - Empty state message
|
| 21 |
+
*
|
| 22 |
+
* @example
|
| 23 |
+
* ```svelte
|
| 24 |
+
* <DropdownMenu.Root>
|
| 25 |
+
* <DropdownMenu.Trigger>...</DropdownMenu.Trigger>
|
| 26 |
+
* <DropdownMenu.Content class="pt-0">
|
| 27 |
+
* <DropdownMenuSearchable
|
| 28 |
+
* bind:searchValue
|
| 29 |
+
* placeholder="Search..."
|
| 30 |
+
* isEmpty={filteredItems.length === 0}
|
| 31 |
+
* >
|
| 32 |
+
* {#each items as item}<Item {item} />{/each}
|
| 33 |
+
* </DropdownMenuSearchable>
|
| 34 |
+
* </DropdownMenu.Content>
|
| 35 |
+
* </DropdownMenu.Root>
|
| 36 |
+
* ```
|
| 37 |
+
*/
|
| 38 |
+
export { default as DropdownMenuSearchable } from './DropdownMenuSearchable.svelte';
|
| 39 |
+
|
| 40 |
+
/**
|
| 41 |
+
* **DropdownMenuActions** - Multi-action dropdown menu
|
| 42 |
+
*
|
| 43 |
+
* Dropdown menu for multiple action options with icons and shortcuts.
|
| 44 |
+
* Supports destructive variants and keyboard shortcut hints.
|
| 45 |
+
*
|
| 46 |
+
* **Features:**
|
| 47 |
+
* - Configurable trigger icon with tooltip
|
| 48 |
+
* - Action items with icons and labels
|
| 49 |
+
* - Destructive variant styling
|
| 50 |
+
* - Keyboard shortcut display
|
| 51 |
+
* - Separator support between groups
|
| 52 |
+
*
|
| 53 |
+
* @example
|
| 54 |
+
* ```svelte
|
| 55 |
+
* <DropdownMenuActions
|
| 56 |
+
* triggerIcon={MoreHorizontal}
|
| 57 |
+
* triggerTooltip="More actions"
|
| 58 |
+
* actions={[
|
| 59 |
+
* { icon: Edit, label: 'Edit', onclick: handleEdit },
|
| 60 |
+
* { icon: Trash, label: 'Delete', onclick: handleDelete, variant: 'destructive' }
|
| 61 |
+
* ]}
|
| 62 |
+
* />
|
| 63 |
+
* ```
|
| 64 |
+
*/
|
| 65 |
+
export { default as DropdownMenuActions } from './DropdownMenuActions.svelte';
|
| 66 |
+
/**
|
| 67 |
+
* **SidebarNavigation** - Sidebar with actions menu and conversation list
|
| 68 |
+
*
|
| 69 |
+
* Collapsible sidebar displaying conversation history with search and
|
| 70 |
+
* management actions. Integrates with ShadCN sidebar component for
|
| 71 |
+
* consistent styling and mobile responsiveness.
|
| 72 |
+
*
|
| 73 |
+
* **Architecture:**
|
| 74 |
+
* - Uses ShadCN Sidebar.* components for structure
|
| 75 |
+
* - Fetches conversations from conversationsStore
|
| 76 |
+
* - Manages search state and filtered results locally
|
| 77 |
+
* - Handles conversation CRUD operations via conversationsStore
|
| 78 |
+
*
|
| 79 |
+
* **Navigation:**
|
| 80 |
+
* - Click conversation to navigate to `/chat/[id]`
|
| 81 |
+
* - New chat button navigates to `/` (root)
|
| 82 |
+
* - Active conversation highlighted based on route params
|
| 83 |
+
*
|
| 84 |
+
* **Conversation Management:**
|
| 85 |
+
* - Right-click or menu button for context menu
|
| 86 |
+
* - Rename: Opens inline edit dialog
|
| 87 |
+
* - Delete: Shows confirmation with conversation preview
|
| 88 |
+
* - Delete All: Removes all conversations with confirmation
|
| 89 |
+
*
|
| 90 |
+
* **Features:**
|
| 91 |
+
* - Search/filter conversations by title
|
| 92 |
+
* - Conversation list with message previews (first message truncated)
|
| 93 |
+
* - Active conversation highlighting
|
| 94 |
+
* - Mobile-responsive collapse/expand via ShadCN sidebar
|
| 95 |
+
* - New chat button in header
|
| 96 |
+
* - Settings button opens DialogChatSettings
|
| 97 |
+
*
|
| 98 |
+
* **Exported API:**
|
| 99 |
+
* - `activateSearchMode()` - Focus search input programmatically
|
| 100 |
+
* - `editActiveConversation()` - Open rename dialog for current conversation
|
| 101 |
+
*
|
| 102 |
+
* @example
|
| 103 |
+
* ```svelte
|
| 104 |
+
* <SidebarNavigation bind:this={sidebarRef} />
|
| 105 |
+
* ```
|
| 106 |
+
*/
|
| 107 |
+
export { default as SidebarNavigation } from './SidebarNavigation/SidebarNavigation.svelte';
|
| 108 |
+
|
| 109 |
+
/**
|
| 110 |
+
* Single conversation item in sidebar. Displays conversation title (truncated),
|
| 111 |
+
* last message preview, and timestamp. Shows context menu on right-click with
|
| 112 |
+
* rename and delete options. Highlights when active (matches current route).
|
| 113 |
+
* Handles click to navigate and keyboard accessibility.
|
| 114 |
+
*/
|
| 115 |
+
export { default as SidebarNavigationConversationItem } from './SidebarNavigation/SidebarNavigationConversationItem.svelte';
|
| 116 |
+
|
| 117 |
+
/**
|
| 118 |
+
* **SidebarNavigationSelectionBar** - Bulk action toolbar for selection mode
|
| 119 |
+
*
|
| 120 |
+
* Rendered above the conversation list when the sidebar enters selection mode.
|
| 121 |
+
* Hosts a master checkbox (with select-all / clear-all semantics over the
|
| 122 |
+
* currently-visible items), a selected-count caption, and bulk actions for
|
| 123 |
+
* pin/unpin, export, and delete. Delete uses
|
| 124 |
+
* {@link DialogConfirmation} before invoking the bulk store method.
|
| 125 |
+
*
|
| 126 |
+
* Pure-presentational; all operations are delegated via callbacks so the
|
| 127 |
+
* sidebar owns selection state and persistence.
|
| 128 |
+
*
|
| 129 |
+
* @example
|
| 130 |
+
* ```svelte
|
| 131 |
+
* <SidebarNavigationSelectionBar
|
| 132 |
+
* selectedCount={selectedIds.size}
|
| 133 |
+
* visibleCount={visibleConversations.length}
|
| 134 |
+
* allVisibleSelected={...}
|
| 135 |
+
* someVisibleSelected={...}
|
| 136 |
+
* someSelectedPinned={...}
|
| 137 |
+
* onSelectAllToggle={toggleSelectAll}
|
| 138 |
+
* onBulkPinToggle={handleBulkPin}
|
| 139 |
+
* onBulkExport={handleBulkExport}
|
| 140 |
+
* onBulkDelete={handleBulkDelete}
|
| 141 |
+
* onClose={exitSelectionMode}
|
| 142 |
+
* />
|
| 143 |
+
* ```
|
| 144 |
+
*/
|
| 145 |
+
export { default as SidebarNavigationSelectionBar } from './SidebarNavigation/SidebarNavigationSelectionBar.svelte';
|
| 146 |
+
|
| 147 |
+
/**
|
| 148 |
+
* **SidebarNavigationConversationList** - Grouped conversation list
|
| 149 |
+
*
|
| 150 |
+
* Pure-presentational list of conversations. Splits items into a Pinned
|
| 151 |
+
* section (when not in search mode) and a Recent Conversations / Search
|
| 152 |
+
* Results section with the unpinned items. Item selection, edit, delete,
|
| 153 |
+
* and stop-generation are delegated to the caller via callbacks.
|
| 154 |
+
*
|
| 155 |
+
* @example
|
| 156 |
+
* ```svelte
|
| 157 |
+
* <SidebarNavigationConversationList
|
| 158 |
+
* {filteredConversations}
|
| 159 |
+
* {currentChatId}
|
| 160 |
+
* {isSearchModeActive}
|
| 161 |
+
* {searchQuery}
|
| 162 |
+
* onSelect={...}
|
| 163 |
+
* onEdit={...}
|
| 164 |
+
* onDelete={...}
|
| 165 |
+
* onStop={...}
|
| 166 |
+
* />
|
| 167 |
+
* ```
|
| 168 |
+
*/
|
| 169 |
+
export { default as SidebarNavigationConversationList } from './SidebarNavigation/SidebarNavigationConversationList.svelte';
|
| 170 |
+
export { default as SidebarNavigationActions } from './SidebarNavigation/SidebarNavigationActions.svelte';
|
| 171 |
+
|
| 172 |
+
/**
|
| 173 |
+
* **SidebarNavigationSearchResults** - Filtered conversation list for search.
|
| 174 |
+
*
|
| 175 |
+
* Pure-presentational rendering of the search-mode subtree: "Search results"
|
| 176 |
+
* header, the matching items rendered through {@link SidebarNavigationConversationItem},
|
| 177 |
+
* and contextual empty-state messages. Used both inline inside
|
| 178 |
+
* {@link SidebarNavigationConversationList} (when search mode is active in the
|
| 179 |
+
* sidebar) and as the body of the mobile `/search` route.
|
| 180 |
+
*
|
| 181 |
+
* The caller is expected to provide an already-filtered list via
|
| 182 |
+
* `filteredConversations` and a `searchQuery` for the empty-state messages.
|
| 183 |
+
*
|
| 184 |
+
* @example
|
| 185 |
+
* ```svelte
|
| 186 |
+
* <SidebarNavigationSearchResults
|
| 187 |
+
* {searchQuery}
|
| 188 |
+
* {filteredConversations}
|
| 189 |
+
* {currentChatId}
|
| 190 |
+
* onSelect={...}
|
| 191 |
+
* onEdit={...}
|
| 192 |
+
* onDelete={...}
|
| 193 |
+
* onStop={...}
|
| 194 |
+
* />
|
| 195 |
+
* ```
|
| 196 |
+
*/
|
| 197 |
+
export { default as SidebarNavigationSearchResults } from './SidebarNavigation/SidebarNavigationSearchResults.svelte';
|
| 198 |
+
|
| 199 |
+
/**
|
| 200 |
+
* Search input for filtering conversations in sidebar. Filters conversation
|
| 201 |
+
* list by title as user types. Shows clear button when query is not empty.
|
| 202 |
+
* Integrated into sidebar header with proper styling.
|
| 203 |
+
*/
|
| 204 |
+
export { default as SidebarNavigationSearch } from './SidebarNavigation/SidebarNavigationSearch.svelte';
|
tools/ui/src/lib/components/app/server/ServerErrorSplash.svelte
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { AlertTriangle, CheckCircle, Key, RefreshCw, XCircle } from '@lucide/svelte';
|
| 3 |
+
import { goto } from '$app/navigation';
|
| 4 |
+
import { base } from '$app/paths';
|
| 5 |
+
import { Button } from '$lib/components/ui/button';
|
| 6 |
+
import { Input } from '$lib/components/ui/input';
|
| 7 |
+
import Label from '$lib/components/ui/label/label.svelte';
|
| 8 |
+
import { HEADERS, ICON_CLASS_DEFAULT, ROUTES, SETTINGS_KEYS } from '$lib/constants';
|
| 9 |
+
import { KeyboardKey } from '$lib/enums';
|
| 10 |
+
import { serverStore, settingsStore } from '$lib/stores';
|
| 11 |
+
import { fade, fly, scale } from 'svelte/transition';
|
| 12 |
+
|
| 13 |
+
interface Props {
|
| 14 |
+
class?: string;
|
| 15 |
+
error: string;
|
| 16 |
+
onRetry?: () => void;
|
| 17 |
+
showRetry?: boolean;
|
| 18 |
+
showTroubleshooting?: boolean;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
let {
|
| 22 |
+
class: className = '',
|
| 23 |
+
error,
|
| 24 |
+
onRetry,
|
| 25 |
+
showRetry = true,
|
| 26 |
+
showTroubleshooting = false
|
| 27 |
+
}: Props = $props();
|
| 28 |
+
|
| 29 |
+
let isServerLoading = $derived(serverStore.loading);
|
| 30 |
+
let isAccessDeniedError = $derived(
|
| 31 |
+
error.toLowerCase().includes('access denied') ||
|
| 32 |
+
error.toLowerCase().includes('invalid api key') ||
|
| 33 |
+
error.toLowerCase().includes('unauthorized') ||
|
| 34 |
+
error.toLowerCase().includes('401') ||
|
| 35 |
+
error.toLowerCase().includes('403')
|
| 36 |
+
);
|
| 37 |
+
|
| 38 |
+
let apiKeyInput = $state('');
|
| 39 |
+
let showApiKeyInput = $state(false);
|
| 40 |
+
let apiKeyState = $state<'idle' | 'validating' | 'success' | 'error'>('idle');
|
| 41 |
+
let apiKeyError = $state('');
|
| 42 |
+
|
| 43 |
+
function handleRetryConnection() {
|
| 44 |
+
if (onRetry) {
|
| 45 |
+
onRetry();
|
| 46 |
+
} else {
|
| 47 |
+
serverStore.fetch();
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
function handleShowApiKeyInput() {
|
| 52 |
+
showApiKeyInput = true;
|
| 53 |
+
// Pre-fill with current API key if it exists
|
| 54 |
+
const currentConfig = settingsStore.config;
|
| 55 |
+
|
| 56 |
+
apiKeyInput = currentConfig.apiKey?.toString() || '';
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
async function handleSaveApiKey() {
|
| 60 |
+
if (!apiKeyInput.trim()) return;
|
| 61 |
+
|
| 62 |
+
apiKeyState = 'validating';
|
| 63 |
+
apiKeyError = '';
|
| 64 |
+
|
| 65 |
+
try {
|
| 66 |
+
// Update the API key in settings first
|
| 67 |
+
settingsStore.updateConfig(SETTINGS_KEYS.API_KEY, apiKeyInput.trim());
|
| 68 |
+
|
| 69 |
+
// Test the API key by making a real request to the server
|
| 70 |
+
const response = await fetch(`${base}/props`, {
|
| 71 |
+
headers: {
|
| 72 |
+
'Content-Type': 'application/json',
|
| 73 |
+
[HEADERS.AUTHORIZATION]: `${HEADERS.BEARER}${apiKeyInput.trim()}`
|
| 74 |
+
}
|
| 75 |
+
});
|
| 76 |
+
|
| 77 |
+
if (response.ok) {
|
| 78 |
+
// API key is valid - User Story B
|
| 79 |
+
apiKeyState = 'success';
|
| 80 |
+
|
| 81 |
+
// Show success state briefly, then navigate to home
|
| 82 |
+
setTimeout(() => {
|
| 83 |
+
goto(ROUTES.START);
|
| 84 |
+
}, 1000);
|
| 85 |
+
} else {
|
| 86 |
+
// API key is invalid - User Story A
|
| 87 |
+
apiKeyState = 'error';
|
| 88 |
+
|
| 89 |
+
if (response.status === 401 || response.status === 403) {
|
| 90 |
+
apiKeyError = 'Invalid API key - please check and try again';
|
| 91 |
+
} else {
|
| 92 |
+
apiKeyError = `Authentication failed (${response.status})`;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
// Reset to idle state after showing error (don't reload UI)
|
| 96 |
+
setTimeout(() => {
|
| 97 |
+
apiKeyState = 'idle';
|
| 98 |
+
}, 3000);
|
| 99 |
+
}
|
| 100 |
+
} catch (error) {
|
| 101 |
+
// Network or other errors - User Story A
|
| 102 |
+
apiKeyState = 'error';
|
| 103 |
+
|
| 104 |
+
if (error instanceof Error) {
|
| 105 |
+
if (error.message.includes('fetch')) {
|
| 106 |
+
apiKeyError = 'Cannot connect to server - check if server is running';
|
| 107 |
+
} else {
|
| 108 |
+
apiKeyError = error.message;
|
| 109 |
+
}
|
| 110 |
+
} else {
|
| 111 |
+
apiKeyError = 'Connection error - please try again';
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
// Reset to idle state after showing error (don't reload UI)
|
| 115 |
+
setTimeout(() => {
|
| 116 |
+
apiKeyState = 'idle';
|
| 117 |
+
}, 3000);
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
function handleApiKeyKeydown(event: KeyboardEvent) {
|
| 122 |
+
if (event.key === KeyboardKey.ENTER) {
|
| 123 |
+
handleSaveApiKey();
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
</script>
|
| 127 |
+
|
| 128 |
+
<div class="flex h-full items-center justify-center {className}">
|
| 129 |
+
<div class="w-full max-w-md px-4 text-center">
|
| 130 |
+
<div in:fade={{ duration: 300 }} class="mb-6">
|
| 131 |
+
<div
|
| 132 |
+
class="mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-full bg-destructive/10"
|
| 133 |
+
>
|
| 134 |
+
<AlertTriangle class="h-8 w-8 text-destructive" />
|
| 135 |
+
</div>
|
| 136 |
+
|
| 137 |
+
<h2 class="mb-2 text-xl font-semibold">Server Connection Error</h2>
|
| 138 |
+
|
| 139 |
+
<p class="mb-4 text-sm text-muted-foreground">
|
| 140 |
+
{error}
|
| 141 |
+
</p>
|
| 142 |
+
</div>
|
| 143 |
+
|
| 144 |
+
{#if isAccessDeniedError && !showApiKeyInput}
|
| 145 |
+
<div in:fly={{ delay: 200, duration: 300, y: 10 }} class="mb-4">
|
| 146 |
+
<Button class="w-full" onclick={handleShowApiKeyInput} variant="outline">
|
| 147 |
+
<Key class={ICON_CLASS_DEFAULT} />
|
| 148 |
+
Enter API Key
|
| 149 |
+
</Button>
|
| 150 |
+
</div>
|
| 151 |
+
{/if}
|
| 152 |
+
|
| 153 |
+
{#if showApiKeyInput}
|
| 154 |
+
<div in:fly={{ delay: 200, duration: 300, y: 10 }} class="mb-4 space-y-3 text-left">
|
| 155 |
+
<div class="space-y-2">
|
| 156 |
+
<Label class="text-sm font-medium" for="api-key-input">API Key</Label>
|
| 157 |
+
|
| 158 |
+
<div class="relative">
|
| 159 |
+
<Input
|
| 160 |
+
bind:value={apiKeyInput}
|
| 161 |
+
autocomplete="new-password"
|
| 162 |
+
class="w-full pr-10 {apiKeyState === 'error'
|
| 163 |
+
? 'border-destructive'
|
| 164 |
+
: apiKeyState === 'success'
|
| 165 |
+
? 'border-green-500'
|
| 166 |
+
: ''}"
|
| 167 |
+
disabled={apiKeyState === 'validating'}
|
| 168 |
+
id="api-key-input"
|
| 169 |
+
onkeydown={handleApiKeyKeydown}
|
| 170 |
+
placeholder="Enter your API key..."
|
| 171 |
+
type="password"
|
| 172 |
+
/>
|
| 173 |
+
|
| 174 |
+
{#if apiKeyState === 'validating'}
|
| 175 |
+
<div class="absolute top-1/2 right-3 -translate-y-1/2">
|
| 176 |
+
<RefreshCw class="{ICON_CLASS_DEFAULT} animate-spin text-muted-foreground" />
|
| 177 |
+
</div>
|
| 178 |
+
{:else if apiKeyState === 'success'}
|
| 179 |
+
<div
|
| 180 |
+
in:scale={{ duration: 200, start: 0.8 }}
|
| 181 |
+
class="absolute top-1/2 right-3 -translate-y-1/2"
|
| 182 |
+
>
|
| 183 |
+
<CheckCircle class="{ICON_CLASS_DEFAULT} text-green-500" />
|
| 184 |
+
</div>
|
| 185 |
+
{:else if apiKeyState === 'error'}
|
| 186 |
+
<div
|
| 187 |
+
in:scale={{ duration: 200, start: 0.8 }}
|
| 188 |
+
class="absolute top-1/2 right-3 -translate-y-1/2"
|
| 189 |
+
>
|
| 190 |
+
<XCircle class="{ICON_CLASS_DEFAULT} text-destructive" />
|
| 191 |
+
</div>
|
| 192 |
+
{/if}
|
| 193 |
+
</div>
|
| 194 |
+
|
| 195 |
+
{#if apiKeyError}
|
| 196 |
+
<p in:fly={{ duration: 200, y: -10 }} class="text-sm text-destructive">
|
| 197 |
+
{apiKeyError}
|
| 198 |
+
</p>
|
| 199 |
+
{/if}
|
| 200 |
+
|
| 201 |
+
{#if apiKeyState === 'success'}
|
| 202 |
+
<p in:fly={{ duration: 200, y: -10 }} class="text-sm text-green-600">
|
| 203 |
+
✓ API key validated successfully! Connecting...
|
| 204 |
+
</p>
|
| 205 |
+
{/if}
|
| 206 |
+
</div>
|
| 207 |
+
|
| 208 |
+
<div class="flex gap-2">
|
| 209 |
+
<Button
|
| 210 |
+
class="flex-1"
|
| 211 |
+
disabled={!apiKeyInput.trim() ||
|
| 212 |
+
apiKeyState === 'validating' ||
|
| 213 |
+
apiKeyState === 'success'}
|
| 214 |
+
onclick={handleSaveApiKey}
|
| 215 |
+
>
|
| 216 |
+
{#if apiKeyState === 'validating'}
|
| 217 |
+
<RefreshCw class="{ICON_CLASS_DEFAULT} animate-spin" />
|
| 218 |
+
Validating...
|
| 219 |
+
{:else if apiKeyState === 'success'}
|
| 220 |
+
Success!
|
| 221 |
+
{:else}
|
| 222 |
+
Save & Retry
|
| 223 |
+
{/if}
|
| 224 |
+
</Button>
|
| 225 |
+
|
| 226 |
+
<Button
|
| 227 |
+
class="flex-1"
|
| 228 |
+
disabled={apiKeyState === 'validating'}
|
| 229 |
+
onclick={() => {
|
| 230 |
+
showApiKeyInput = false;
|
| 231 |
+
apiKeyState = 'idle';
|
| 232 |
+
apiKeyError = '';
|
| 233 |
+
}}
|
| 234 |
+
variant="outline"
|
| 235 |
+
>
|
| 236 |
+
Cancel
|
| 237 |
+
</Button>
|
| 238 |
+
</div>
|
| 239 |
+
</div>
|
| 240 |
+
{/if}
|
| 241 |
+
|
| 242 |
+
{#if showRetry}
|
| 243 |
+
<div in:fly={{ delay: 200, duration: 300, y: 10 }}>
|
| 244 |
+
<Button class="w-full" disabled={isServerLoading} onclick={handleRetryConnection}>
|
| 245 |
+
{#if isServerLoading}
|
| 246 |
+
<RefreshCw class="{ICON_CLASS_DEFAULT} animate-spin" />
|
| 247 |
+
|
| 248 |
+
Connecting...
|
| 249 |
+
{:else}
|
| 250 |
+
<RefreshCw class={ICON_CLASS_DEFAULT} />
|
| 251 |
+
|
| 252 |
+
Retry Connection
|
| 253 |
+
{/if}
|
| 254 |
+
</Button>
|
| 255 |
+
</div>
|
| 256 |
+
{/if}
|
| 257 |
+
|
| 258 |
+
{#if showTroubleshooting}
|
| 259 |
+
<div in:fly={{ delay: 400, duration: 300, y: 10 }} class="mt-4 text-left">
|
| 260 |
+
<details class="text-sm">
|
| 261 |
+
<summary class="cursor-pointer text-muted-foreground hover:text-foreground">
|
| 262 |
+
Troubleshooting
|
| 263 |
+
</summary>
|
| 264 |
+
|
| 265 |
+
<div class="mt-2 space-y-3 text-xs text-muted-foreground">
|
| 266 |
+
<div class="space-y-2">
|
| 267 |
+
<p class="mb-4 font-medium">Start the llama-server:</p>
|
| 268 |
+
|
| 269 |
+
<div class="rounded bg-muted/50 px-2 py-1 font-mono text-xs">
|
| 270 |
+
<p>llama-server -hf ggml-org/gemma-3-4b-it-GGUF</p>
|
| 271 |
+
</div>
|
| 272 |
+
|
| 273 |
+
<p>or</p>
|
| 274 |
+
|
| 275 |
+
<div class="rounded bg-muted/50 px-2 py-1 font-mono text-xs">
|
| 276 |
+
<p class="mt-1">llama-server -m locally-stored-model.gguf</p>
|
| 277 |
+
</div>
|
| 278 |
+
</div>
|
| 279 |
+
|
| 280 |
+
<ul class="list-disc space-y-1 pl-4">
|
| 281 |
+
<li>Check that the server is accessible at the correct URL</li>
|
| 282 |
+
|
| 283 |
+
<li>Verify your network connection</li>
|
| 284 |
+
|
| 285 |
+
<li>Check server logs for any error messages</li>
|
| 286 |
+
</ul>
|
| 287 |
+
</div>
|
| 288 |
+
</details>
|
| 289 |
+
</div>
|
| 290 |
+
{/if}
|
| 291 |
+
</div>
|
| 292 |
+
</div>
|
tools/ui/src/lib/components/app/server/ServerLoadingSplash.svelte
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { Server } from '@lucide/svelte';
|
| 3 |
+
import { ServerStatus } from '$lib/components/app';
|
| 4 |
+
import { fade } from 'svelte/transition';
|
| 5 |
+
|
| 6 |
+
interface Props {
|
| 7 |
+
class?: string;
|
| 8 |
+
message?: string;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
let { class: className = '', message = 'Initializing connection to server...' }: Props = $props();
|
| 12 |
+
</script>
|
| 13 |
+
|
| 14 |
+
<div class="flex h-full items-center justify-center {className}">
|
| 15 |
+
<div class="text-center">
|
| 16 |
+
<div in:fade={{ duration: 300 }} class="mb-4">
|
| 17 |
+
<div class="mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-full bg-muted">
|
| 18 |
+
<Server class="h-8 w-8 animate-pulse text-muted-foreground" />
|
| 19 |
+
</div>
|
| 20 |
+
|
| 21 |
+
<h2 class="mb-2 text-xl font-semibold">Connecting to Server</h2>
|
| 22 |
+
|
| 23 |
+
<p class="text-sm text-muted-foreground">
|
| 24 |
+
{message}
|
| 25 |
+
</p>
|
| 26 |
+
</div>
|
| 27 |
+
|
| 28 |
+
<div class="mt-4">
|
| 29 |
+
<ServerStatus class="justify-center" />
|
| 30 |
+
</div>
|
| 31 |
+
</div>
|
| 32 |
+
</div>
|
tools/ui/src/lib/components/app/server/ServerStatus.svelte
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { AlertTriangle, Server } from '@lucide/svelte';
|
| 3 |
+
import { Badge } from '$lib/components/ui/badge';
|
| 4 |
+
import { Button } from '$lib/components/ui/button';
|
| 5 |
+
import { ICON_CLASS_DEFAULT } from '$lib/constants';
|
| 6 |
+
import { modelsStore, serverStore } from '$lib/stores';
|
| 7 |
+
|
| 8 |
+
interface Props {
|
| 9 |
+
class?: string;
|
| 10 |
+
showActions?: boolean;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
let { class: className = '', showActions = false }: Props = $props();
|
| 14 |
+
|
| 15 |
+
let error = $derived(serverStore.error);
|
| 16 |
+
let loading = $derived(serverStore.loading);
|
| 17 |
+
let model = $derived(modelsStore.singleModelName);
|
| 18 |
+
let serverData = $derived(serverStore.props);
|
| 19 |
+
|
| 20 |
+
function getStatusColor() {
|
| 21 |
+
if (loading) return 'bg-yellow-500';
|
| 22 |
+
|
| 23 |
+
if (error) return 'bg-red-500';
|
| 24 |
+
|
| 25 |
+
if (serverData) return 'bg-green-500';
|
| 26 |
+
|
| 27 |
+
return 'bg-gray-500';
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
function getStatusText() {
|
| 31 |
+
if (loading) return 'Connecting...';
|
| 32 |
+
|
| 33 |
+
if (error) return 'Connection Error';
|
| 34 |
+
|
| 35 |
+
if (serverData) return 'Connected';
|
| 36 |
+
|
| 37 |
+
return 'Unknown';
|
| 38 |
+
}
|
| 39 |
+
</script>
|
| 40 |
+
|
| 41 |
+
<div class="flex items-center space-x-3 {className}">
|
| 42 |
+
<div class="flex items-center space-x-2">
|
| 43 |
+
<div class="h-2 w-2 rounded-full {getStatusColor()}"></div>
|
| 44 |
+
|
| 45 |
+
<span class="text-sm text-muted-foreground">{getStatusText()}</span>
|
| 46 |
+
</div>
|
| 47 |
+
|
| 48 |
+
{#if serverData && !error}
|
| 49 |
+
<Badge class="text-xs" variant="outline">
|
| 50 |
+
<Server class="mr-1 h-3 w-3" />
|
| 51 |
+
|
| 52 |
+
{model || 'Unknown Model'}
|
| 53 |
+
</Badge>
|
| 54 |
+
|
| 55 |
+
{#if serverData?.default_generation_settings?.n_ctx}
|
| 56 |
+
<Badge class="text-xs" variant="secondary">
|
| 57 |
+
ctx: {serverData.default_generation_settings.n_ctx.toLocaleString()}
|
| 58 |
+
</Badge>
|
| 59 |
+
{/if}
|
| 60 |
+
{/if}
|
| 61 |
+
|
| 62 |
+
{#if showActions && error}
|
| 63 |
+
<Button class="text-destructive" size="sm" variant="outline">
|
| 64 |
+
<AlertTriangle class={ICON_CLASS_DEFAULT} />
|
| 65 |
+
|
| 66 |
+
{error}
|
| 67 |
+
</Button>
|
| 68 |
+
{/if}
|
| 69 |
+
</div>
|
tools/ui/src/lib/components/app/server/index.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
*
|
| 3 |
+
* SERVER
|
| 4 |
+
*
|
| 5 |
+
* Components for displaying server connection state and handling
|
| 6 |
+
* connection errors. Integrates with serverStore for state management.
|
| 7 |
+
*
|
| 8 |
+
*/
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
* **ServerStatus** - Server connection status indicator
|
| 12 |
+
*
|
| 13 |
+
* Compact status display showing connection state, model name,
|
| 14 |
+
* and context size. Used in headers and loading screens.
|
| 15 |
+
*
|
| 16 |
+
* **Architecture:**
|
| 17 |
+
* - Reads state from serverStore (props, loading, error)
|
| 18 |
+
* - Displays model name from modelsStore
|
| 19 |
+
*
|
| 20 |
+
* **Features:**
|
| 21 |
+
* - Status dot: green (connected), yellow (connecting), red (error), gray (unknown)
|
| 22 |
+
* - Status text label
|
| 23 |
+
* - Model name badge with icon
|
| 24 |
+
* - Context size badge
|
| 25 |
+
* - Optional error action button
|
| 26 |
+
*
|
| 27 |
+
* @example
|
| 28 |
+
* ```svelte
|
| 29 |
+
* <ServerStatus showActions />
|
| 30 |
+
* ```
|
| 31 |
+
*/
|
| 32 |
+
export { default as ServerStatus } from './ServerStatus.svelte';
|
| 33 |
+
|
| 34 |
+
/**
|
| 35 |
+
* **ServerErrorSplash** - Full-screen connection error display
|
| 36 |
+
*
|
| 37 |
+
* Blocking error screen shown when server connection fails.
|
| 38 |
+
* Provides retry options and API key input for authentication errors.
|
| 39 |
+
*
|
| 40 |
+
* **Architecture:**
|
| 41 |
+
* - Detects access denied errors for API key flow
|
| 42 |
+
* - Validates API key against server before saving
|
| 43 |
+
* - Integrates with settingsStore for API key persistence
|
| 44 |
+
*
|
| 45 |
+
* **Features:**
|
| 46 |
+
* - Error message display with icon
|
| 47 |
+
* - Retry connection button with loading state
|
| 48 |
+
* - API key input for authentication errors
|
| 49 |
+
* - API key validation with success/error feedback
|
| 50 |
+
* - Troubleshooting section with server start commands
|
| 51 |
+
* - Animated transitions for UI elements
|
| 52 |
+
*
|
| 53 |
+
* @example
|
| 54 |
+
* ```svelte
|
| 55 |
+
* <ServerErrorSplash
|
| 56 |
+
* error={serverError}
|
| 57 |
+
* onRetry={handleRetry}
|
| 58 |
+
* showTroubleshooting
|
| 59 |
+
* />
|
| 60 |
+
* ```
|
| 61 |
+
*/
|
| 62 |
+
export { default as ServerErrorSplash } from './ServerErrorSplash.svelte';
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* **ServerLoadingSplash** - Full-screen loading display
|
| 66 |
+
*
|
| 67 |
+
* Shown during initial server connection. Displays loading animation
|
| 68 |
+
* with ServerStatus component for real-time connection state.
|
| 69 |
+
*
|
| 70 |
+
* **Features:**
|
| 71 |
+
* - Animated server icon
|
| 72 |
+
* - Customizable loading message
|
| 73 |
+
* - Embedded ServerStatus for live updates
|
| 74 |
+
*
|
| 75 |
+
* @example
|
| 76 |
+
* ```svelte
|
| 77 |
+
* <ServerLoadingSplash message="Connecting to server..." />
|
| 78 |
+
* ```
|
| 79 |
+
*/
|
| 80 |
+
export { default as ServerLoadingSplash } from './ServerLoadingSplash.svelte';
|
tools/ui/src/lib/components/app/settings/SettingsChat/SettingsChat.svelte
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { RefreshCw } from '@lucide/svelte';
|
| 3 |
+
import {
|
| 4 |
+
SettingsChatDesktopSidebar,
|
| 5 |
+
SettingsChatFields,
|
| 6 |
+
SettingsChatImportExportTab,
|
| 7 |
+
SettingsChatMobileHeader,
|
| 8 |
+
SettingsChatToolsTab,
|
| 9 |
+
SettingsFooter
|
| 10 |
+
} from '$lib/components/app/settings';
|
| 11 |
+
import { Button } from '$lib/components/ui/button';
|
| 12 |
+
import {
|
| 13 |
+
NUMERIC_FIELDS,
|
| 14 |
+
POSITIVE_INTEGER_FIELDS,
|
| 15 |
+
SETTINGS_CHAT_SECTIONS,
|
| 16 |
+
SETTINGS_SECTION_SLUGS
|
| 17 |
+
} from '$lib/constants';
|
| 18 |
+
import { ColorMode } from '$lib/enums/ui.enums';
|
| 19 |
+
import { modelsStore, serverStore, settingsStore } from '$lib/stores';
|
| 20 |
+
import type { SettingsSection, SettingsSectionTitle } from '$lib/types';
|
| 21 |
+
import { setMode } from 'mode-watcher';
|
| 22 |
+
import { fade } from 'svelte/transition';
|
| 23 |
+
interface Props {
|
| 24 |
+
initialSection?: string;
|
| 25 |
+
onSectionChange?: (section: SettingsSectionTitle) => void;
|
| 26 |
+
onClose?: () => void;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
let { initialSection, onClose, onSectionChange }: Props = $props();
|
| 30 |
+
|
| 31 |
+
let activeSlug = $derived(initialSection ?? 'general');
|
| 32 |
+
|
| 33 |
+
function handleSectionChange(section: SettingsSectionTitle) {
|
| 34 |
+
const found = SETTINGS_CHAT_SECTIONS.find((s) => s.title === section);
|
| 35 |
+
|
| 36 |
+
if (found) {
|
| 37 |
+
activeSlug = found.slug;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
onSectionChange?.(section);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
let currentSection = $derived(
|
| 44 |
+
SETTINGS_CHAT_SECTIONS.find((section) => section.slug === activeSlug) ||
|
| 45 |
+
SETTINGS_CHAT_SECTIONS[0]
|
| 46 |
+
);
|
| 47 |
+
|
| 48 |
+
let localConfig: SettingsConfigType = $state({ ...settingsStore.config });
|
| 49 |
+
|
| 50 |
+
let mobileHeader: { updateCarousel: () => void } | undefined;
|
| 51 |
+
|
| 52 |
+
let fetchInitiated = false;
|
| 53 |
+
|
| 54 |
+
$effect(() => {
|
| 55 |
+
if (serverStore.isRouterMode && currentSection.fields?.length && !fetchInitiated) {
|
| 56 |
+
fetchInitiated = true;
|
| 57 |
+
|
| 58 |
+
void modelsStore
|
| 59 |
+
.fetch()
|
| 60 |
+
.then(() => modelsStore.fetchRouterModels())
|
| 61 |
+
.then(() => modelsStore.props.fetchModalitiesForLoadedModels())
|
| 62 |
+
.then(() => modelsStore.ensureFirstModelSelected());
|
| 63 |
+
}
|
| 64 |
+
});
|
| 65 |
+
|
| 66 |
+
function handleThemeChange(newTheme: string) {
|
| 67 |
+
localConfig.theme = newTheme;
|
| 68 |
+
setMode(newTheme as ColorMode);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
function handleConfigChange(key: string, value: string | boolean) {
|
| 72 |
+
localConfig[key] = value;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
function handleReset() {
|
| 76 |
+
localConfig = { ...settingsStore.config };
|
| 77 |
+
setMode(localConfig.theme as ColorMode);
|
| 78 |
+
mobileHeader?.updateCarousel();
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
function handleSave() {
|
| 82 |
+
if (
|
| 83 |
+
localConfig.customJson &&
|
| 84 |
+
typeof localConfig.customJson === 'string' &&
|
| 85 |
+
localConfig.customJson.trim()
|
| 86 |
+
) {
|
| 87 |
+
try {
|
| 88 |
+
JSON.parse(localConfig.customJson);
|
| 89 |
+
} catch (error) {
|
| 90 |
+
alert('Invalid JSON in custom parameters. Please check the format and try again.');
|
| 91 |
+
console.error(error);
|
| 92 |
+
|
| 93 |
+
return;
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
const processedConfig = { ...localConfig };
|
| 98 |
+
|
| 99 |
+
for (const field of NUMERIC_FIELDS) {
|
| 100 |
+
if (processedConfig[field] !== undefined && processedConfig[field] !== '') {
|
| 101 |
+
const numValue = Number(processedConfig[field]);
|
| 102 |
+
|
| 103 |
+
if (!isNaN(numValue)) {
|
| 104 |
+
if ((POSITIVE_INTEGER_FIELDS as readonly string[]).includes(field)) {
|
| 105 |
+
const entryByMinMax = SETTINGS_CHAT_SECTIONS.flatMap(
|
| 106 |
+
(section) => section.fields ?? []
|
| 107 |
+
).find((entry) => entry.key === field);
|
| 108 |
+
const lo = entryByMinMax?.min ?? 1;
|
| 109 |
+
const hi = entryByMinMax?.max ?? Number.POSITIVE_INFINITY;
|
| 110 |
+
|
| 111 |
+
processedConfig[field] = Math.max(lo, Math.min(hi, Math.round(numValue)));
|
| 112 |
+
} else {
|
| 113 |
+
processedConfig[field] = numValue;
|
| 114 |
+
}
|
| 115 |
+
} else {
|
| 116 |
+
alert(`Invalid numeric value for ${field}. Please enter a valid number.`);
|
| 117 |
+
|
| 118 |
+
return;
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
settingsStore.updateMultipleConfig(processedConfig);
|
| 124 |
+
onClose?.();
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
export function reset() {
|
| 128 |
+
localConfig = { ...settingsStore.config };
|
| 129 |
+
}
|
| 130 |
+
</script>
|
| 131 |
+
|
| 132 |
+
<div in:fade={{ duration: 150 }} class="mx-auto flex h-full w-full flex-col">
|
| 133 |
+
<div class="flex flex-1 flex-col md:flex-row md:gap-4">
|
| 134 |
+
<SettingsChatDesktopSidebar
|
| 135 |
+
isActive={(section: SettingsSection) => section.slug === activeSlug}
|
| 136 |
+
onSectionChange={handleSectionChange}
|
| 137 |
+
sections={SETTINGS_CHAT_SECTIONS}
|
| 138 |
+
/>
|
| 139 |
+
|
| 140 |
+
<SettingsChatMobileHeader
|
| 141 |
+
bind:this={mobileHeader}
|
| 142 |
+
isActive={(section: SettingsSection) => section.slug === activeSlug}
|
| 143 |
+
onSectionChange={handleSectionChange}
|
| 144 |
+
sections={SETTINGS_CHAT_SECTIONS}
|
| 145 |
+
/>
|
| 146 |
+
|
| 147 |
+
<div class="mx-auto max-w-2xl px-4 flex-1 md:mt-4">
|
| 148 |
+
<div class="space-y-6 pt-3">
|
| 149 |
+
<div class="grid">
|
| 150 |
+
{#if currentSection.slug === SETTINGS_SECTION_SLUGS.TOOLS}
|
| 151 |
+
<SettingsChatToolsTab />
|
| 152 |
+
{:else if currentSection.slug === SETTINGS_SECTION_SLUGS.IMPORT_EXPORT}
|
| 153 |
+
<SettingsChatImportExportTab />
|
| 154 |
+
{:else if currentSection.fields}
|
| 155 |
+
<div class="space-y-6">
|
| 156 |
+
<SettingsChatFields
|
| 157 |
+
fields={currentSection.fields}
|
| 158 |
+
{localConfig}
|
| 159 |
+
onConfigChange={handleConfigChange}
|
| 160 |
+
onThemeChange={handleThemeChange}
|
| 161 |
+
/>
|
| 162 |
+
|
| 163 |
+
{#if currentSection.slug === SETTINGS_SECTION_SLUGS.GENERAL}
|
| 164 |
+
<div class="flex justify-end">
|
| 165 |
+
<Button onclick={() => window.location.reload()} variant="outline">
|
| 166 |
+
<RefreshCw class="h-3 w-3" />
|
| 167 |
+
Reload app
|
| 168 |
+
</Button>
|
| 169 |
+
</div>
|
| 170 |
+
{/if}
|
| 171 |
+
</div>
|
| 172 |
+
{/if}
|
| 173 |
+
</div>
|
| 174 |
+
|
| 175 |
+
<div class="mt-8 border-t border-border/30 pt-6">
|
| 176 |
+
<p class="text-xs text-muted-foreground">Settings are saved in browser's localStorage</p>
|
| 177 |
+
</div>
|
| 178 |
+
</div>
|
| 179 |
+
|
| 180 |
+
<SettingsFooter onReset={handleReset} onSave={handleSave} />
|
| 181 |
+
</div>
|
| 182 |
+
</div>
|
| 183 |
+
</div>
|
tools/ui/src/lib/components/app/settings/SettingsChat/SettingsChatFields.svelte
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { FlaskConical, RotateCcw } from '@lucide/svelte';
|
| 3 |
+
import { SettingsChatParameterSourceIndicator } from '$lib/components/app/settings';
|
| 4 |
+
import { Checkbox } from '$lib/components/ui/checkbox';
|
| 5 |
+
import { Input } from '$lib/components/ui/input';
|
| 6 |
+
import Label from '$lib/components/ui/label/label.svelte';
|
| 7 |
+
import * as RadioGroup from '$lib/components/ui/radio-group';
|
| 8 |
+
import * as Select from '$lib/components/ui/select';
|
| 9 |
+
import { Textarea } from '$lib/components/ui/textarea';
|
| 10 |
+
import { ICON_CLASS_DEFAULT, SETTING_CONFIG_INFO, SETTINGS_KEYS } from '$lib/constants';
|
| 11 |
+
import { SettingsFieldType } from '$lib/enums/settings.enums';
|
| 12 |
+
import { modelsStore, serverStore, settingsStore } from '$lib/stores';
|
| 13 |
+
import { normalizeFloatingPoint } from '$lib/utils/precision';
|
| 14 |
+
import type { Component } from 'svelte';
|
| 15 |
+
|
| 16 |
+
interface Props {
|
| 17 |
+
fields: SettingsFieldConfig[];
|
| 18 |
+
localConfig: SettingsConfigType;
|
| 19 |
+
onConfigChange: (key: string, value: string | boolean) => void;
|
| 20 |
+
onThemeChange?: (theme: string) => void;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
let { fields, localConfig, onConfigChange, onThemeChange }: Props = $props();
|
| 24 |
+
|
| 25 |
+
let currentModelParams = $derived.by(() => {
|
| 26 |
+
void modelsStore.props.cacheVersion;
|
| 27 |
+
|
| 28 |
+
if (serverStore.isRouterMode) {
|
| 29 |
+
const currentModelName = modelsStore.selectedModelName;
|
| 30 |
+
|
| 31 |
+
if (currentModelName) {
|
| 32 |
+
const currentModelProps = modelsStore.props.getModelProps(currentModelName);
|
| 33 |
+
|
| 34 |
+
return (currentModelProps?.default_generation_settings?.params ?? {}) as Record<
|
| 35 |
+
string,
|
| 36 |
+
unknown
|
| 37 |
+
>;
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
return (serverStore.defaultParams ?? {}) as Record<string, unknown>;
|
| 42 |
+
});
|
| 43 |
+
</script>
|
| 44 |
+
|
| 45 |
+
{#each fields as field (field.key)}
|
| 46 |
+
{#if !field.dependsOn || Boolean(localConfig[field.dependsOn])}
|
| 47 |
+
<div class={field.dependsOn ? 'space-y-2 pl-6' : 'space-y-2'}>
|
| 48 |
+
{#if field.type === SettingsFieldType.INPUT}
|
| 49 |
+
{@const currentValue = String(localConfig[field.key] ?? '')}
|
| 50 |
+
{@const serverDefault = currentModelParams[field.key]}
|
| 51 |
+
{@const isCustomRealTime = (() => {
|
| 52 |
+
if (serverDefault == null) return false;
|
| 53 |
+
|
| 54 |
+
if (currentValue === '') return false;
|
| 55 |
+
|
| 56 |
+
const numericInput = parseFloat(currentValue);
|
| 57 |
+
const normalizedInput = !isNaN(numericInput)
|
| 58 |
+
? Math.round(numericInput * 1000000) / 1000000
|
| 59 |
+
: currentValue;
|
| 60 |
+
const normalizedDefault =
|
| 61 |
+
typeof serverDefault === 'number'
|
| 62 |
+
? Math.round(serverDefault * 1000000) / 1000000
|
| 63 |
+
: serverDefault;
|
| 64 |
+
|
| 65 |
+
return normalizedInput !== normalizedDefault;
|
| 66 |
+
})()}
|
| 67 |
+
|
| 68 |
+
<div class="flex items-center gap-2">
|
| 69 |
+
<Label class="flex items-center gap-1.5 text-sm font-medium" for={field.key}>
|
| 70 |
+
{field.label}
|
| 71 |
+
|
| 72 |
+
{#if field.isExperimental}
|
| 73 |
+
<FlaskConical class="h-3.5 w-3.5 text-muted-foreground" />
|
| 74 |
+
{/if}
|
| 75 |
+
</Label>
|
| 76 |
+
|
| 77 |
+
{#if isCustomRealTime}
|
| 78 |
+
<SettingsChatParameterSourceIndicator />
|
| 79 |
+
{/if}
|
| 80 |
+
</div>
|
| 81 |
+
|
| 82 |
+
<div class="relative w-full">
|
| 83 |
+
<Input
|
| 84 |
+
autocomplete={field.isPrivate ? 'new-password' : undefined}
|
| 85 |
+
id={field.key}
|
| 86 |
+
type={field.isPrivate ? 'password' : field.isPositiveInteger ? 'number' : 'text'}
|
| 87 |
+
{...field.isPositiveInteger
|
| 88 |
+
? {
|
| 89 |
+
min: String(field.min ?? 1),
|
| 90 |
+
step: '1',
|
| 91 |
+
...(field.max != null ? { max: String(field.max) } : {})
|
| 92 |
+
}
|
| 93 |
+
: {}}
|
| 94 |
+
class="w-full {isCustomRealTime ? 'pr-8' : ''}"
|
| 95 |
+
oninput={(e) => onConfigChange(field.key, e.currentTarget.value)}
|
| 96 |
+
placeholder={currentModelParams[field.key] != null
|
| 97 |
+
? `Default: ${normalizeFloatingPoint(currentModelParams[field.key])}`
|
| 98 |
+
: (field.placeholder ?? '')}
|
| 99 |
+
value={currentValue}
|
| 100 |
+
/>
|
| 101 |
+
|
| 102 |
+
{#if isCustomRealTime}
|
| 103 |
+
<button
|
| 104 |
+
aria-label="Reset to default"
|
| 105 |
+
class="absolute top-1/2 right-2 inline-flex h-5 w-5 -translate-y-1/2 items-center justify-center rounded transition-colors hover:bg-muted"
|
| 106 |
+
onclick={() => {
|
| 107 |
+
settingsStore.resetParameterToServerDefault(field.key);
|
| 108 |
+
onConfigChange(field.key, '');
|
| 109 |
+
}}
|
| 110 |
+
title="Reset to default"
|
| 111 |
+
type="button"
|
| 112 |
+
>
|
| 113 |
+
<RotateCcw class="h-3 w-3" />
|
| 114 |
+
</button>
|
| 115 |
+
{/if}
|
| 116 |
+
</div>
|
| 117 |
+
|
| 118 |
+
{#if field.help || SETTING_CONFIG_INFO[field.key]}
|
| 119 |
+
<p class="mt-1 text-xs text-muted-foreground">
|
| 120 |
+
{@html field.help || SETTING_CONFIG_INFO[field.key]}
|
| 121 |
+
</p>
|
| 122 |
+
{/if}
|
| 123 |
+
{:else if field.type === SettingsFieldType.TEXTAREA}
|
| 124 |
+
{#if field.label}
|
| 125 |
+
<Label class="block flex items-center gap-1.5 text-sm font-medium" for={field.key}>
|
| 126 |
+
{field.label}
|
| 127 |
+
|
| 128 |
+
{#if field.isExperimental}
|
| 129 |
+
<FlaskConical class="h-3.5 w-3.5 text-muted-foreground" />
|
| 130 |
+
{/if}
|
| 131 |
+
</Label>
|
| 132 |
+
{/if}
|
| 133 |
+
|
| 134 |
+
<Textarea
|
| 135 |
+
class="min-h-[10rem] w-full md:max-w-3xl"
|
| 136 |
+
id={field.key}
|
| 137 |
+
onchange={(e) => onConfigChange(field.key, e.currentTarget.value)}
|
| 138 |
+
placeholder=""
|
| 139 |
+
value={String(localConfig[field.key] ?? '')}
|
| 140 |
+
/>
|
| 141 |
+
|
| 142 |
+
{#if field.help || SETTING_CONFIG_INFO[field.key]}
|
| 143 |
+
<p class="mt-1 text-xs text-muted-foreground">
|
| 144 |
+
{field.help || SETTING_CONFIG_INFO[field.key]}
|
| 145 |
+
</p>
|
| 146 |
+
{/if}
|
| 147 |
+
|
| 148 |
+
{#if field.key === SETTINGS_KEYS.SYSTEM_MESSAGE}
|
| 149 |
+
<div class="mt-3 flex items-center gap-2">
|
| 150 |
+
<Checkbox
|
| 151 |
+
checked={Boolean(localConfig.showSystemMessage ?? true)}
|
| 152 |
+
id="showSystemMessage"
|
| 153 |
+
onCheckedChange={(checked) =>
|
| 154 |
+
onConfigChange(SETTINGS_KEYS.SHOW_SYSTEM_MESSAGE, Boolean(checked))}
|
| 155 |
+
/>
|
| 156 |
+
|
| 157 |
+
<Label class="cursor-pointer text-sm font-normal" for="showSystemMessage">
|
| 158 |
+
Show system message in conversations
|
| 159 |
+
</Label>
|
| 160 |
+
</div>
|
| 161 |
+
{/if}
|
| 162 |
+
{:else if field.type === SettingsFieldType.SELECT}
|
| 163 |
+
{@const selectedOption = field.options?.find(
|
| 164 |
+
(opt: { value: string; label: string; icon?: Component }) =>
|
| 165 |
+
opt.value === localConfig[field.key]
|
| 166 |
+
)}
|
| 167 |
+
{@const currentValue = localConfig[field.key]}
|
| 168 |
+
{@const serverDefault = currentModelParams[field.key]}
|
| 169 |
+
{@const isCustomRealTime = (() => {
|
| 170 |
+
if (serverDefault == null) return false;
|
| 171 |
+
|
| 172 |
+
if (currentValue === '' || currentValue === undefined) return false;
|
| 173 |
+
|
| 174 |
+
return currentValue !== serverDefault;
|
| 175 |
+
})()}
|
| 176 |
+
|
| 177 |
+
<div class="flex items-center gap-2">
|
| 178 |
+
<Label class="flex items-center gap-1.5 text-sm font-medium" for={field.key}>
|
| 179 |
+
{field.label}
|
| 180 |
+
|
| 181 |
+
{#if field.isExperimental}
|
| 182 |
+
<FlaskConical class="h-3.5 w-3.5 text-muted-foreground" />
|
| 183 |
+
{/if}
|
| 184 |
+
</Label>
|
| 185 |
+
|
| 186 |
+
{#if isCustomRealTime}
|
| 187 |
+
<SettingsChatParameterSourceIndicator />
|
| 188 |
+
{/if}
|
| 189 |
+
</div>
|
| 190 |
+
|
| 191 |
+
<Select.Root
|
| 192 |
+
onValueChange={(value) => {
|
| 193 |
+
if (field.key === SETTINGS_KEYS.THEME && value && onThemeChange) {
|
| 194 |
+
onThemeChange(value);
|
| 195 |
+
} else {
|
| 196 |
+
onConfigChange(field.key, value);
|
| 197 |
+
}
|
| 198 |
+
}}
|
| 199 |
+
type="single"
|
| 200 |
+
value={currentValue}
|
| 201 |
+
>
|
| 202 |
+
<div class="relative w-full md:w-auto">
|
| 203 |
+
<Select.Trigger class="w-full">
|
| 204 |
+
<div class="flex items-center gap-2">
|
| 205 |
+
{#if selectedOption?.icon}
|
| 206 |
+
{@const IconComponent = selectedOption.icon}
|
| 207 |
+
<IconComponent class={ICON_CLASS_DEFAULT} />
|
| 208 |
+
{/if}
|
| 209 |
+
|
| 210 |
+
{selectedOption?.label || `Select ${field.label.toLowerCase()}`}
|
| 211 |
+
</div>
|
| 212 |
+
</Select.Trigger>
|
| 213 |
+
|
| 214 |
+
{#if isCustomRealTime}
|
| 215 |
+
<button
|
| 216 |
+
aria-label="Reset to default"
|
| 217 |
+
class="absolute top-1/2 right-8 inline-flex h-5 w-5 -translate-y-1/2 items-center justify-center rounded transition-colors hover:bg-muted"
|
| 218 |
+
onclick={() => {
|
| 219 |
+
settingsStore.resetParameterToServerDefault(field.key);
|
| 220 |
+
onConfigChange(field.key, '');
|
| 221 |
+
}}
|
| 222 |
+
title="Reset to default"
|
| 223 |
+
type="button"
|
| 224 |
+
>
|
| 225 |
+
<RotateCcw class="h-3 w-3" />
|
| 226 |
+
</button>
|
| 227 |
+
{/if}
|
| 228 |
+
</div>
|
| 229 |
+
|
| 230 |
+
<Select.Content>
|
| 231 |
+
{#if field.options}
|
| 232 |
+
{#each field.options as option (option.value)}
|
| 233 |
+
<Select.Item label={option.label} value={option.value}>
|
| 234 |
+
<div class="flex items-center gap-2">
|
| 235 |
+
{#if option.icon}
|
| 236 |
+
{@const IconComponent = option.icon}
|
| 237 |
+
<IconComponent class={ICON_CLASS_DEFAULT} />
|
| 238 |
+
{/if}
|
| 239 |
+
{option.label}
|
| 240 |
+
</div>
|
| 241 |
+
</Select.Item>
|
| 242 |
+
{/each}
|
| 243 |
+
{/if}
|
| 244 |
+
</Select.Content>
|
| 245 |
+
</Select.Root>
|
| 246 |
+
|
| 247 |
+
{#if field.help || SETTING_CONFIG_INFO[field.key]}
|
| 248 |
+
<p class="mt-1 text-xs text-muted-foreground">
|
| 249 |
+
{field.help || SETTING_CONFIG_INFO[field.key]}
|
| 250 |
+
</p>
|
| 251 |
+
{/if}
|
| 252 |
+
{:else if field.type === SettingsFieldType.RADIO && field.radioOptions}
|
| 253 |
+
{@const radioOptions = field.radioOptions}
|
| 254 |
+
{@const currentMode =
|
| 255 |
+
radioOptions.find((o: { key: string }) => Boolean(localConfig[o.key]))?.value ??
|
| 256 |
+
radioOptions[0].value}
|
| 257 |
+
|
| 258 |
+
<Label class="flex items-center gap-1.5 text-sm font-medium mb-4">
|
| 259 |
+
{field.label}
|
| 260 |
+
|
| 261 |
+
{#if field.isExperimental}
|
| 262 |
+
<FlaskConical class="h-3.5 w-3.5 text-muted-foreground" />
|
| 263 |
+
{/if}
|
| 264 |
+
</Label>
|
| 265 |
+
|
| 266 |
+
<RadioGroup.Root
|
| 267 |
+
class="gap-4"
|
| 268 |
+
onValueChange={(value) => {
|
| 269 |
+
for (const opt of radioOptions) {
|
| 270 |
+
onConfigChange(opt.key, opt.value === value);
|
| 271 |
+
}
|
| 272 |
+
}}
|
| 273 |
+
value={currentMode}
|
| 274 |
+
>
|
| 275 |
+
{#each radioOptions as opt (opt.value)}
|
| 276 |
+
{@const itemId = `${field.key}-${opt.value}`}
|
| 277 |
+
<div class="flex items-center gap-2">
|
| 278 |
+
<RadioGroup.Item id={itemId} value={opt.value} />
|
| 279 |
+
|
| 280 |
+
<Label
|
| 281 |
+
class="flex cursor-pointer items-center gap-1.5 text-sm font-normal"
|
| 282 |
+
for={itemId}
|
| 283 |
+
>
|
| 284 |
+
{opt.label}
|
| 285 |
+
|
| 286 |
+
{#if opt.isExperimental}
|
| 287 |
+
<FlaskConical class="h-3.5 w-3.5 text-muted-foreground" />
|
| 288 |
+
{/if}
|
| 289 |
+
</Label>
|
| 290 |
+
</div>
|
| 291 |
+
{/each}
|
| 292 |
+
</RadioGroup.Root>
|
| 293 |
+
|
| 294 |
+
{#if field.help || SETTING_CONFIG_INFO[field.key]}
|
| 295 |
+
<p class="text-xs text-muted-foreground">
|
| 296 |
+
{field.help || SETTING_CONFIG_INFO[field.key]}
|
| 297 |
+
</p>
|
| 298 |
+
{/if}
|
| 299 |
+
{:else if field.type === SettingsFieldType.CHECKBOX}
|
| 300 |
+
<div class="flex items-start space-x-3">
|
| 301 |
+
<Checkbox
|
| 302 |
+
checked={Boolean(localConfig[field.key])}
|
| 303 |
+
class="mt-1"
|
| 304 |
+
id={field.key}
|
| 305 |
+
onCheckedChange={(checked) => onConfigChange(field.key, checked)}
|
| 306 |
+
/>
|
| 307 |
+
|
| 308 |
+
<div class="space-y-1">
|
| 309 |
+
<label
|
| 310 |
+
class="flex cursor-pointer items-center gap-1.5 pt-1 pb-0.5 text-sm leading-none font-medium"
|
| 311 |
+
for={field.key}
|
| 312 |
+
>
|
| 313 |
+
{field.label}
|
| 314 |
+
|
| 315 |
+
{#if field.isExperimental}
|
| 316 |
+
<FlaskConical class="h-3.5 w-3.5 text-muted-foreground" />
|
| 317 |
+
{/if}
|
| 318 |
+
</label>
|
| 319 |
+
|
| 320 |
+
{#if field.help || SETTING_CONFIG_INFO[field.key]}
|
| 321 |
+
<p class="text-xs text-muted-foreground">
|
| 322 |
+
{field.help || SETTING_CONFIG_INFO[field.key]}
|
| 323 |
+
</p>
|
| 324 |
+
{/if}
|
| 325 |
+
</div>
|
| 326 |
+
</div>
|
| 327 |
+
{/if}
|
| 328 |
+
</div>
|
| 329 |
+
{/if}
|
| 330 |
+
{/each}
|
tools/ui/src/lib/components/app/settings/SettingsChat/SettingsChatImportExportSection.svelte
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { Button, type ButtonVariant } from '$lib/components/ui/button';
|
| 3 |
+
import { ICON_CLASS_DEFAULT } from '$lib/constants';
|
| 4 |
+
import type { Component } from 'svelte';
|
| 5 |
+
|
| 6 |
+
let {
|
| 7 |
+
buttonClass,
|
| 8 |
+
buttonText,
|
| 9 |
+
buttonVariant,
|
| 10 |
+
description,
|
| 11 |
+
IconComponent,
|
| 12 |
+
onclick,
|
| 13 |
+
summary,
|
| 14 |
+
title,
|
| 15 |
+
titleClass,
|
| 16 |
+
wrapperClass
|
| 17 |
+
}: {
|
| 18 |
+
title: string;
|
| 19 |
+
description: string;
|
| 20 |
+
IconComponent: Component;
|
| 21 |
+
buttonText: string;
|
| 22 |
+
onclick: () => void;
|
| 23 |
+
titleClass?: string;
|
| 24 |
+
buttonVariant?: ButtonVariant;
|
| 25 |
+
buttonClass?: string;
|
| 26 |
+
wrapperClass?: string;
|
| 27 |
+
summary?: { show: boolean; verb: string; items: DatabaseConversation[] };
|
| 28 |
+
} = $props();
|
| 29 |
+
|
| 30 |
+
let sectionButtonClass = $derived(buttonClass ?? 'justify-start justify-self-start md:w-auto');
|
| 31 |
+
let sectionButtonVariant = $derived(buttonVariant ?? 'outline');
|
| 32 |
+
</script>
|
| 33 |
+
|
| 34 |
+
<div class="grid gap-1 {wrapperClass ?? ''}">
|
| 35 |
+
<h4 class="mt-0 mb-2 text-sm font-medium {titleClass ?? ''}">{title}</h4>
|
| 36 |
+
|
| 37 |
+
<p class="mb-4 text-sm text-muted-foreground">{description}</p>
|
| 38 |
+
|
| 39 |
+
<Button class={sectionButtonClass} {onclick} variant={sectionButtonVariant}>
|
| 40 |
+
<IconComponent class="mr-2 {ICON_CLASS_DEFAULT}" />
|
| 41 |
+
|
| 42 |
+
{buttonText}
|
| 43 |
+
</Button>
|
| 44 |
+
|
| 45 |
+
{#if summary && summary.show && summary.items.length > 0}
|
| 46 |
+
<div class="mt-4 grid overflow-x-auto rounded-lg border border-border/50 bg-muted/30 p-4">
|
| 47 |
+
<h5 class="mb-2 text-sm font-medium">
|
| 48 |
+
{summary.verb}
|
| 49 |
+
{summary.items.length} conversation{summary.items.length === 1 ? '' : 's'}
|
| 50 |
+
</h5>
|
| 51 |
+
|
| 52 |
+
<ul class="space-y-1 text-sm text-muted-foreground">
|
| 53 |
+
{#each summary.items.slice(0, 10) as conv (conv.id)}
|
| 54 |
+
<li class="truncate">• {conv.name || 'Untitled conversation'}</li>
|
| 55 |
+
{/each}
|
| 56 |
+
|
| 57 |
+
{#if summary.items.length > 10}
|
| 58 |
+
<li class="italic">... and {summary.items.length - 10} more</li>
|
| 59 |
+
{/if}
|
| 60 |
+
</ul>
|
| 61 |
+
</div>
|
| 62 |
+
{/if}
|
| 63 |
+
</div>
|
tools/ui/src/lib/components/app/settings/SettingsChat/SettingsChatImportExportTab.svelte
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import SettingsChatImportExportSection from './SettingsChatImportExportSection.svelte';
|
| 3 |
+
import { Download, Trash2, Upload } from '@lucide/svelte';
|
| 4 |
+
import {
|
| 5 |
+
DialogConfirmation,
|
| 6 |
+
DialogConversationSelection,
|
| 7 |
+
DialogExportSettings
|
| 8 |
+
} from '$lib/components/app';
|
| 9 |
+
import SettingsGroup from '$lib/components/app/settings/SettingsGroup.svelte';
|
| 10 |
+
import { ConversationSelectionMode, FileExtensionText, HtmlInputType } from '$lib/enums';
|
| 11 |
+
import { ConversationTransferService } from '$lib/services';
|
| 12 |
+
import { conversationsStore, settingsStore } from '$lib/stores';
|
| 13 |
+
import { createMessageCountMap } from '$lib/utils';
|
| 14 |
+
import { fade } from 'svelte/transition';
|
| 15 |
+
import { toast } from 'svelte-sonner';
|
| 16 |
+
|
| 17 |
+
let exportedConversations = $state<DatabaseConversation[]>([]);
|
| 18 |
+
let importedConversations = $state<DatabaseConversation[]>([]);
|
| 19 |
+
let showExportSummary = $state(false);
|
| 20 |
+
let showImportSummary = $state(false);
|
| 21 |
+
|
| 22 |
+
let showExportDialog = $state(false);
|
| 23 |
+
let showImportDialog = $state(false);
|
| 24 |
+
let availableConversations = $state<DatabaseConversation[]>([]);
|
| 25 |
+
let messageCountMap = $state<Map<string, number>>(new Map());
|
| 26 |
+
let fullImportData = $state<Array<{ conv: DatabaseConversation; messages: DatabaseMessage[] }>>(
|
| 27 |
+
[]
|
| 28 |
+
);
|
| 29 |
+
|
| 30 |
+
// Delete functionality state
|
| 31 |
+
let showDeleteDialog = $state(false);
|
| 32 |
+
|
| 33 |
+
// Settings import/export state
|
| 34 |
+
let showSettingsExportSummary = $state(false);
|
| 35 |
+
let showSettingsImportSummary = $state(false);
|
| 36 |
+
let showSettingsExportDialog = $state(false);
|
| 37 |
+
let includeSensitiveData = $state(false);
|
| 38 |
+
|
| 39 |
+
function handleSettingsExport() {
|
| 40 |
+
showSettingsExportDialog = true;
|
| 41 |
+
includeSensitiveData = false;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
function handleSettingsExportConfirm() {
|
| 45 |
+
showSettingsExportDialog = false;
|
| 46 |
+
|
| 47 |
+
try {
|
| 48 |
+
const data = settingsStore.exportSettings(includeSensitiveData);
|
| 49 |
+
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
|
| 50 |
+
const url = URL.createObjectURL(blob);
|
| 51 |
+
const a = document.createElement('a');
|
| 52 |
+
|
| 53 |
+
a.href = url;
|
| 54 |
+
a.download = `llama_settings_${new Date().toISOString().split('T')[0]}.json`;
|
| 55 |
+
document.body.appendChild(a);
|
| 56 |
+
a.click();
|
| 57 |
+
document.body.removeChild(a);
|
| 58 |
+
URL.revokeObjectURL(url);
|
| 59 |
+
|
| 60 |
+
showSettingsExportSummary = true;
|
| 61 |
+
showSettingsImportSummary = false;
|
| 62 |
+
toast.success('Settings exported');
|
| 63 |
+
} catch (err) {
|
| 64 |
+
console.error('Failed to export settings:', err);
|
| 65 |
+
toast.error('Failed to export settings');
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
function handleSettingsExportCancel() {
|
| 70 |
+
showSettingsExportDialog = false;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
function handleSettingsImport() {
|
| 74 |
+
try {
|
| 75 |
+
const input = document.createElement('input');
|
| 76 |
+
|
| 77 |
+
input.type = HtmlInputType.FILE;
|
| 78 |
+
input.accept = FileExtensionText.JSON;
|
| 79 |
+
|
| 80 |
+
input.onchange = async (e) => {
|
| 81 |
+
const file = (e.target as HTMLInputElement)?.files?.[0];
|
| 82 |
+
|
| 83 |
+
if (!file) return;
|
| 84 |
+
|
| 85 |
+
try {
|
| 86 |
+
const text = await file.text();
|
| 87 |
+
const data = JSON.parse(text);
|
| 88 |
+
|
| 89 |
+
if (!data || typeof data !== 'object' || !data.config) {
|
| 90 |
+
toast.error('Invalid settings file: missing config');
|
| 91 |
+
|
| 92 |
+
return;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
settingsStore.importSettings(data);
|
| 96 |
+
|
| 97 |
+
showSettingsImportSummary = true;
|
| 98 |
+
showSettingsExportSummary = false;
|
| 99 |
+
toast.success('Settings imported successfully');
|
| 100 |
+
} catch (err) {
|
| 101 |
+
console.error('Failed to import settings:', err);
|
| 102 |
+
toast.error('Failed to import settings');
|
| 103 |
+
}
|
| 104 |
+
};
|
| 105 |
+
|
| 106 |
+
input.click();
|
| 107 |
+
} catch (err) {
|
| 108 |
+
console.error('Failed to open file picker:', err);
|
| 109 |
+
toast.error('Failed to open file picker');
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
async function handleExportClick() {
|
| 114 |
+
try {
|
| 115 |
+
const allConversations = conversationsStore.conversations;
|
| 116 |
+
|
| 117 |
+
if (allConversations.length === 0) {
|
| 118 |
+
toast.info('No conversations to export');
|
| 119 |
+
|
| 120 |
+
return;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
const conversationsWithMessages = await Promise.all(
|
| 124 |
+
allConversations.map(async (conv: DatabaseConversation) => {
|
| 125 |
+
const messages = await conversationsStore.getConversationMessages(conv.id);
|
| 126 |
+
|
| 127 |
+
return { conv, messages };
|
| 128 |
+
})
|
| 129 |
+
);
|
| 130 |
+
|
| 131 |
+
messageCountMap = createMessageCountMap(conversationsWithMessages);
|
| 132 |
+
availableConversations = allConversations;
|
| 133 |
+
showExportDialog = true;
|
| 134 |
+
} catch (err) {
|
| 135 |
+
console.error('Failed to load conversations:', err);
|
| 136 |
+
alert('Failed to load conversations');
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
async function handleExportConfirm(selectedConversations: DatabaseConversation[]) {
|
| 141 |
+
try {
|
| 142 |
+
const allData = await conversationsStore.getConversationsForExport(
|
| 143 |
+
selectedConversations.map((conv) => conv.id)
|
| 144 |
+
);
|
| 145 |
+
|
| 146 |
+
if (allData.length === 1) {
|
| 147 |
+
ConversationTransferService.downloadConversationFile(allData[0]);
|
| 148 |
+
} else {
|
| 149 |
+
ConversationTransferService.downloadConversationsArchive(allData);
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
exportedConversations = selectedConversations;
|
| 153 |
+
showExportSummary = true;
|
| 154 |
+
showImportSummary = false;
|
| 155 |
+
showExportDialog = false;
|
| 156 |
+
} catch (err) {
|
| 157 |
+
console.error('Export failed:', err);
|
| 158 |
+
alert('Failed to export conversations');
|
| 159 |
+
}
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
async function handleImportClick() {
|
| 163 |
+
try {
|
| 164 |
+
const input = document.createElement('input');
|
| 165 |
+
|
| 166 |
+
// No `accept` filter: iOS resolves each entry to a UTI and has none for
|
| 167 |
+
// `.jsonl`, which greys out exported conversations in the file picker.
|
| 168 |
+
// `parseImportFile` detects the format from the file contents instead.
|
| 169 |
+
input.type = HtmlInputType.FILE;
|
| 170 |
+
|
| 171 |
+
input.onchange = async (e) => {
|
| 172 |
+
const file = (e.target as HTMLInputElement)?.files?.[0];
|
| 173 |
+
|
| 174 |
+
if (!file) return;
|
| 175 |
+
|
| 176 |
+
try {
|
| 177 |
+
const importedData = await ConversationTransferService.parseImportFile(file);
|
| 178 |
+
|
| 179 |
+
if (importedData.length === 0) {
|
| 180 |
+
throw new Error('No conversations found in file');
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
fullImportData = importedData;
|
| 184 |
+
availableConversations = importedData.map((item) => item.conv);
|
| 185 |
+
messageCountMap = createMessageCountMap(importedData);
|
| 186 |
+
showImportDialog = true;
|
| 187 |
+
} catch (err: unknown) {
|
| 188 |
+
const message = err instanceof Error ? err.message : 'Unknown error';
|
| 189 |
+
|
| 190 |
+
console.error('Failed to parse file:', err);
|
| 191 |
+
alert(`Failed to parse file: ${message}`);
|
| 192 |
+
}
|
| 193 |
+
};
|
| 194 |
+
|
| 195 |
+
input.click();
|
| 196 |
+
} catch (err) {
|
| 197 |
+
console.error('Import failed:', err);
|
| 198 |
+
alert('Failed to import conversations');
|
| 199 |
+
}
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
async function handleImportConfirm(selectedConversations: DatabaseConversation[]) {
|
| 203 |
+
try {
|
| 204 |
+
const selectedIds = new Set(selectedConversations.map((c) => c.id));
|
| 205 |
+
const selectedData = $state
|
| 206 |
+
.snapshot(fullImportData)
|
| 207 |
+
.filter((item) => selectedIds.has(item.conv.id));
|
| 208 |
+
const { imported, skipped } = await conversationsStore.importConversationsData(selectedData);
|
| 209 |
+
|
| 210 |
+
// A conversation already in the database is left untouched, so the summary
|
| 211 |
+
// lists what was written and the toast accounts for the rest.
|
| 212 |
+
if (skipped.length > 0) {
|
| 213 |
+
toast.info(
|
| 214 |
+
`Skipped ${skipped.length} conversation${skipped.length === 1 ? '' : 's'} already in your library`
|
| 215 |
+
);
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
importedConversations = imported;
|
| 219 |
+
showImportSummary = true;
|
| 220 |
+
showExportSummary = false;
|
| 221 |
+
showImportDialog = false;
|
| 222 |
+
} catch (err) {
|
| 223 |
+
console.error('Import failed:', err);
|
| 224 |
+
alert('Failed to import conversations. Please check the file format.');
|
| 225 |
+
}
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
async function handleDeleteAllClick() {
|
| 229 |
+
try {
|
| 230 |
+
const allConversations = conversationsStore.conversations;
|
| 231 |
+
|
| 232 |
+
if (allConversations.length === 0) {
|
| 233 |
+
toast.info('No conversations to delete');
|
| 234 |
+
|
| 235 |
+
return;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
showDeleteDialog = true;
|
| 239 |
+
} catch (err) {
|
| 240 |
+
console.error('Failed to load conversations for deletion:', err);
|
| 241 |
+
toast.error('Failed to load conversations');
|
| 242 |
+
}
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
async function handleDeleteAllConfirm() {
|
| 246 |
+
try {
|
| 247 |
+
await conversationsStore.deleteAll();
|
| 248 |
+
|
| 249 |
+
showDeleteDialog = false;
|
| 250 |
+
} catch (err) {
|
| 251 |
+
console.error('Failed to delete conversations:', err);
|
| 252 |
+
}
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
function handleDeleteAllCancel() {
|
| 256 |
+
showDeleteDialog = false;
|
| 257 |
+
}
|
| 258 |
+
</script>
|
| 259 |
+
|
| 260 |
+
<div in:fade={{ duration: 150 }} class="space-y-12">
|
| 261 |
+
<SettingsGroup title="Conversations">
|
| 262 |
+
<SettingsChatImportExportSection
|
| 263 |
+
IconComponent={Download}
|
| 264 |
+
buttonText="Export conversations"
|
| 265 |
+
description="Download your conversations as a ZIP of JSONL files. This includes all messages, attachments, and conversation history."
|
| 266 |
+
onclick={handleExportClick}
|
| 267 |
+
summary={{ items: exportedConversations, show: showExportSummary, verb: 'Exported' }}
|
| 268 |
+
title="Export"
|
| 269 |
+
/>
|
| 270 |
+
|
| 271 |
+
<SettingsChatImportExportSection
|
| 272 |
+
IconComponent={Upload}
|
| 273 |
+
buttonText="Import conversations"
|
| 274 |
+
description="Import one or more conversations from a previously exported ZIP or JSONL file. This will merge with your existing conversations."
|
| 275 |
+
onclick={handleImportClick}
|
| 276 |
+
summary={{ items: importedConversations, show: showImportSummary, verb: 'Imported' }}
|
| 277 |
+
title="Import"
|
| 278 |
+
/>
|
| 279 |
+
|
| 280 |
+
<SettingsChatImportExportSection
|
| 281 |
+
IconComponent={Trash2}
|
| 282 |
+
buttonClass="text-destructive-foreground justify-start justify-self-start bg-destructive hover:bg-destructive/80 md:w-auto"
|
| 283 |
+
buttonText="Delete all conversations"
|
| 284 |
+
buttonVariant="destructive"
|
| 285 |
+
description="Permanently delete all conversations and their messages. This action cannot be undone. Consider exporting your conversations first if you want to keep a backup."
|
| 286 |
+
onclick={handleDeleteAllClick}
|
| 287 |
+
title="Delete All"
|
| 288 |
+
titleClass="text-destructive"
|
| 289 |
+
/>
|
| 290 |
+
</SettingsGroup>
|
| 291 |
+
|
| 292 |
+
<SettingsGroup title="Settings">
|
| 293 |
+
<SettingsChatImportExportSection
|
| 294 |
+
IconComponent={Download}
|
| 295 |
+
buttonText="Export settings"
|
| 296 |
+
description="Export your chat settings and preferences as a JSON file."
|
| 297 |
+
onclick={handleSettingsExport}
|
| 298 |
+
summary={{ items: [], show: showSettingsExportSummary, verb: 'Exported' }}
|
| 299 |
+
title="Export"
|
| 300 |
+
/>
|
| 301 |
+
|
| 302 |
+
<SettingsChatImportExportSection
|
| 303 |
+
IconComponent={Upload}
|
| 304 |
+
buttonText="Import settings"
|
| 305 |
+
description="Import chat settings from a previously exported JSON file. This will merge with your existing settings."
|
| 306 |
+
onclick={handleSettingsImport}
|
| 307 |
+
summary={{ items: [], show: showSettingsImportSummary, verb: 'Imported' }}
|
| 308 |
+
title="Import"
|
| 309 |
+
/>
|
| 310 |
+
</SettingsGroup>
|
| 311 |
+
</div>
|
| 312 |
+
|
| 313 |
+
<DialogExportSettings
|
| 314 |
+
bind:includeSensitiveData
|
| 315 |
+
bind:open={showSettingsExportDialog}
|
| 316 |
+
onCancel={handleSettingsExportCancel}
|
| 317 |
+
onConfirm={handleSettingsExportConfirm}
|
| 318 |
+
/>
|
| 319 |
+
|
| 320 |
+
<DialogConversationSelection
|
| 321 |
+
bind:open={showExportDialog}
|
| 322 |
+
conversations={availableConversations}
|
| 323 |
+
{messageCountMap}
|
| 324 |
+
mode={ConversationSelectionMode.EXPORT}
|
| 325 |
+
onCancel={() => (showExportDialog = false)}
|
| 326 |
+
onConfirm={handleExportConfirm}
|
| 327 |
+
/>
|
| 328 |
+
|
| 329 |
+
<DialogConversationSelection
|
| 330 |
+
bind:open={showImportDialog}
|
| 331 |
+
conversations={availableConversations}
|
| 332 |
+
{messageCountMap}
|
| 333 |
+
mode={ConversationSelectionMode.IMPORT}
|
| 334 |
+
onCancel={() => (showImportDialog = false)}
|
| 335 |
+
onConfirm={handleImportConfirm}
|
| 336 |
+
/>
|
| 337 |
+
|
| 338 |
+
<DialogConfirmation
|
| 339 |
+
bind:open={showDeleteDialog}
|
| 340 |
+
cancelText="Cancel"
|
| 341 |
+
confirmText="Delete All"
|
| 342 |
+
description="Are you sure you want to delete all conversations? This action cannot be undone and will permanently remove all your conversations and messages."
|
| 343 |
+
icon={Trash2}
|
| 344 |
+
onCancel={handleDeleteAllCancel}
|
| 345 |
+
onConfirm={handleDeleteAllConfirm}
|
| 346 |
+
title="Delete all conversations"
|
| 347 |
+
variant="destructive"
|
| 348 |
+
/>
|
tools/ui/src/lib/components/app/settings/SettingsChat/SettingsChatParameterSourceIndicator.svelte
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { Wrench } from '@lucide/svelte';
|
| 3 |
+
import { Badge } from '$lib/components/ui/badge';
|
| 4 |
+
|
| 5 |
+
interface Props {
|
| 6 |
+
class?: string;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
let { class: className = '' }: Props = $props();
|
| 10 |
+
</script>
|
| 11 |
+
|
| 12 |
+
<Badge
|
| 13 |
+
class="h-5 bg-orange-100 px-1.5 py-0.5 text-xs text-orange-800 dark:bg-orange-900 dark:text-orange-200 {className}"
|
| 14 |
+
variant="secondary"
|
| 15 |
+
>
|
| 16 |
+
<Wrench class="mr-1 h-3 w-3" />
|
| 17 |
+
|
| 18 |
+
Custom
|
| 19 |
+
</Badge>
|
tools/ui/src/lib/components/app/settings/SettingsChat/SettingsChatToolsTab.svelte
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { ChevronDown, ChevronRight } from '@lucide/svelte';
|
| 3 |
+
import { McpServerIdentity, TruncatedText } from '$lib/components/app';
|
| 4 |
+
import { Checkbox } from '$lib/components/ui/checkbox';
|
| 5 |
+
import * as Collapsible from '$lib/components/ui/collapsible';
|
| 6 |
+
import { ICON_CLASS_DEFAULT } from '$lib/constants';
|
| 7 |
+
import { ToolSource } from '$lib/enums/tools.enums';
|
| 8 |
+
import { mcpStore, permissionsStore, toolsStore } from '$lib/stores';
|
| 9 |
+
import { getToolUi } from '$lib/utils';
|
| 10 |
+
import { SvelteSet } from 'svelte/reactivity';
|
| 11 |
+
|
| 12 |
+
let expandedGroups = new SvelteSet<string>();
|
| 13 |
+
let groups = $derived(toolsStore.toolGroups);
|
| 14 |
+
|
| 15 |
+
function toggleExpanded(key: string) {
|
| 16 |
+
if (expandedGroups.has(key)) {
|
| 17 |
+
expandedGroups.delete(key);
|
| 18 |
+
} else {
|
| 19 |
+
expandedGroups.add(key);
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
</script>
|
| 23 |
+
|
| 24 |
+
{#if groups.length === 0}
|
| 25 |
+
<div class="py-8 text-center text-sm text-muted-foreground">No tools available</div>
|
| 26 |
+
{:else}
|
| 27 |
+
<div class="space-y-2">
|
| 28 |
+
<p class="text-sm text-muted-foreground">
|
| 29 |
+
Applies to new conversations. Tool picks inside a chat only affect that chat.
|
| 30 |
+
</p>
|
| 31 |
+
|
| 32 |
+
{#each groups as group (group.key)}
|
| 33 |
+
{@const isExpanded = expandedGroups.has(group.key)}
|
| 34 |
+
<Collapsible.Root onOpenChange={() => toggleExpanded(group.key)} open={isExpanded}>
|
| 35 |
+
<Collapsible.Trigger
|
| 36 |
+
class="flex w-full items-center gap-2 rounded-lg px-3 py-2 text-sm hover:bg-muted/50"
|
| 37 |
+
>
|
| 38 |
+
{#if isExpanded}
|
| 39 |
+
<ChevronDown class="h-3.5 w-3.5 shrink-0" />
|
| 40 |
+
{:else}
|
| 41 |
+
<ChevronRight class="h-3.5 w-3.5 shrink-0" />
|
| 42 |
+
{/if}
|
| 43 |
+
|
| 44 |
+
{@const isCategoryEnabled =
|
| 45 |
+
group.source !== ToolSource.MCP && toolsStore.isCategoryEnabled(group.source)}
|
| 46 |
+
|
| 47 |
+
{#if group.source !== ToolSource.MCP}
|
| 48 |
+
<Checkbox
|
| 49 |
+
checked={isCategoryEnabled}
|
| 50 |
+
onCheckedChange={() => toolsStore.toggleCategory(group.source)}
|
| 51 |
+
onclick={(e) => e.stopPropagation()}
|
| 52 |
+
/>
|
| 53 |
+
{/if}
|
| 54 |
+
|
| 55 |
+
{@const faviconUrl = group.serverId ? mcpStore.getServerFavicon(group.serverId) : null}
|
| 56 |
+
|
| 57 |
+
<span class="inline-flex min-w-0 items-center gap-1.5 font-medium">
|
| 58 |
+
{#if group.source === 'mcp'}
|
| 59 |
+
<McpServerIdentity
|
| 60 |
+
displayName={group.label}
|
| 61 |
+
{faviconUrl}
|
| 62 |
+
iconClass={ICON_CLASS_DEFAULT}
|
| 63 |
+
iconRounded="rounded-sm"
|
| 64 |
+
showVersion={false}
|
| 65 |
+
/>
|
| 66 |
+
{:else}
|
| 67 |
+
<TruncatedText class="font-medium" text={group.label} />
|
| 68 |
+
{/if}
|
| 69 |
+
</span>
|
| 70 |
+
|
| 71 |
+
<span class="ml-auto shrink-0 text-xs text-muted-foreground">
|
| 72 |
+
{group.tools.length} tool{group.tools.length !== 1 ? 's' : ''}
|
| 73 |
+
</span>
|
| 74 |
+
</Collapsible.Trigger>
|
| 75 |
+
|
| 76 |
+
<Collapsible.Content>
|
| 77 |
+
<div class="ml-4 border-l border-border/50 pl-2">
|
| 78 |
+
<!-- Header row -->
|
| 79 |
+
<div class="flex items-center gap-2 px-2 py-1 text-xs text-muted-foreground">
|
| 80 |
+
<span class="min-w-0 flex-1">Tool</span>
|
| 81 |
+
|
| 82 |
+
<span class="w-16 shrink-0 text-center">Enabled</span>
|
| 83 |
+
|
| 84 |
+
<span class="w-20 shrink-0 text-center">Always allow</span>
|
| 85 |
+
</div>
|
| 86 |
+
|
| 87 |
+
{#each group.tools as entry (entry.key)}
|
| 88 |
+
{@const toolName = entry.definition.function.name}
|
| 89 |
+
{@const toolUi =
|
| 90 |
+
entry.source === ToolSource.SERVER || entry.source === ToolSource.BROWSER
|
| 91 |
+
? getToolUi(toolName)
|
| 92 |
+
: null}
|
| 93 |
+
{@const displayLabel = toolUi?.label ?? toolName}
|
| 94 |
+
{@const IconComponent = toolUi?.icon ?? null}
|
| 95 |
+
{@const isEnabled = toolsStore.isToolEnabled(entry.key)}
|
| 96 |
+
{@const permissionKey = entry.key}
|
| 97 |
+
{@const isAlwaysAllowed = permissionsStore.hasTool(permissionKey)}
|
| 98 |
+
|
| 99 |
+
<div class="flex items-center gap-2 rounded px-2 py-1.5 text-sm hover:bg-muted/50">
|
| 100 |
+
<span class="flex min-w-0 flex-1 items-center gap-1.5">
|
| 101 |
+
{#if IconComponent}
|
| 102 |
+
<IconComponent class={ICON_CLASS_DEFAULT} />
|
| 103 |
+
{/if}
|
| 104 |
+
|
| 105 |
+
<TruncatedText class="min-w-0" showTooltip={true} text={displayLabel} />
|
| 106 |
+
</span>
|
| 107 |
+
|
| 108 |
+
<div class="flex w-16 shrink-0 justify-center">
|
| 109 |
+
<Checkbox
|
| 110 |
+
checked={isEnabled}
|
| 111 |
+
class={ICON_CLASS_DEFAULT}
|
| 112 |
+
onCheckedChange={() => toolsStore.toggleTool(entry.key)}
|
| 113 |
+
/>
|
| 114 |
+
</div>
|
| 115 |
+
|
| 116 |
+
<div class="flex w-20 shrink-0 justify-center">
|
| 117 |
+
<Checkbox
|
| 118 |
+
checked={isAlwaysAllowed}
|
| 119 |
+
class={ICON_CLASS_DEFAULT}
|
| 120 |
+
onCheckedChange={() => {
|
| 121 |
+
if (isAlwaysAllowed) {
|
| 122 |
+
permissionsStore.revokeTool(permissionKey);
|
| 123 |
+
} else {
|
| 124 |
+
permissionsStore.allowTool(permissionKey);
|
| 125 |
+
}
|
| 126 |
+
}}
|
| 127 |
+
/>
|
| 128 |
+
</div>
|
| 129 |
+
</div>
|
| 130 |
+
{/each}
|
| 131 |
+
</div>
|
| 132 |
+
</Collapsible.Content>
|
| 133 |
+
</Collapsible.Root>
|
| 134 |
+
{/each}
|
| 135 |
+
</div>
|
| 136 |
+
{/if}
|
tools/ui/src/lib/components/app/settings/SettingsChatDesktopSidebar.svelte
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { ICON_CLASS_DEFAULT } from '$lib/constants';
|
| 3 |
+
import type { SettingsSection, SettingsSectionTitle } from '$lib/types';
|
| 4 |
+
|
| 5 |
+
interface Props {
|
| 6 |
+
sections: SettingsSection[];
|
| 7 |
+
isActive: (section: SettingsSection) => boolean;
|
| 8 |
+
onSectionChange?: (section: SettingsSectionTitle) => void;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
let { isActive, onSectionChange, sections }: Props = $props();
|
| 12 |
+
</script>
|
| 13 |
+
|
| 14 |
+
<div class="sticky top-12 hidden w-64 flex-col self-start bg-background md:flex gap-6">
|
| 15 |
+
<nav class="space-y-1">
|
| 16 |
+
{#each sections as section (section.title)}
|
| 17 |
+
<button
|
| 18 |
+
class="flex w-full cursor-pointer items-center gap-3 rounded-lg px-3 py-2 text-left text-sm transition-colors hover:bg-accent {isActive(
|
| 19 |
+
section
|
| 20 |
+
)
|
| 21 |
+
? 'bg-accent text-accent-foreground'
|
| 22 |
+
: 'text-muted-foreground'}"
|
| 23 |
+
onclick={() => onSectionChange?.(section.title)}
|
| 24 |
+
>
|
| 25 |
+
<section.icon class={ICON_CLASS_DEFAULT} />
|
| 26 |
+
|
| 27 |
+
<span class="ml-2">{section.title}</span>
|
| 28 |
+
</button>
|
| 29 |
+
{/each}
|
| 30 |
+
</nav>
|
| 31 |
+
</div>
|
tools/ui/src/lib/components/app/settings/SettingsChatMobileHeader.svelte
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { ScrollCarousel } from '$lib/components/app';
|
| 3 |
+
import { ICON_CLASS_DEFAULT, UI_DATA_ATTRS } from '$lib/constants';
|
| 4 |
+
import { BooleanString } from '$lib/enums';
|
| 5 |
+
import { useScrollCarousel } from '$lib/hooks/use-scroll-carousel.svelte';
|
| 6 |
+
import type { SettingsSection, SettingsSectionTitle } from '$lib/types';
|
| 7 |
+
import { onMount, tick } from 'svelte';
|
| 8 |
+
|
| 9 |
+
interface Props {
|
| 10 |
+
sections: SettingsSection[];
|
| 11 |
+
isActive: (section: SettingsSection) => boolean;
|
| 12 |
+
onSectionChange?: (section: SettingsSectionTitle) => void;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
let { isActive, onSectionChange, sections }: Props = $props();
|
| 16 |
+
|
| 17 |
+
const carousel = useScrollCarousel();
|
| 18 |
+
|
| 19 |
+
onMount(async () => {
|
| 20 |
+
await tick();
|
| 21 |
+
|
| 22 |
+
if (carousel.scrollContainer) {
|
| 23 |
+
const activeTab = carousel.scrollContainer.querySelector(
|
| 24 |
+
`[${UI_DATA_ATTRS.ACTIVE}="${BooleanString.TRUE}"]`
|
| 25 |
+
);
|
| 26 |
+
|
| 27 |
+
if (activeTab instanceof HTMLElement) {
|
| 28 |
+
carousel.scrollToCenter(activeTab);
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
});
|
| 32 |
+
|
| 33 |
+
export function updateCarousel() {
|
| 34 |
+
setTimeout(carousel.updateScrollButtons, 100);
|
| 35 |
+
}
|
| 36 |
+
</script>
|
| 37 |
+
|
| 38 |
+
<div class="flex flex-col bg-background md:hidden sticky top-13 z-50">
|
| 39 |
+
<div class="border-b border-border/30">
|
| 40 |
+
<ScrollCarousel alwaysShowArrows {carousel} containerClass="py-2" innerClass="gap-2">
|
| 41 |
+
{#each sections as section (section.title)}
|
| 42 |
+
<button
|
| 43 |
+
class="flex cursor-pointer items-center gap-2 rounded-lg px-3 py-2 text-sm whitespace-nowrap transition-colors first:ml-4 last:mr-4 hover:bg-accent {isActive(
|
| 44 |
+
section
|
| 45 |
+
)
|
| 46 |
+
? 'bg-accent text-accent-foreground'
|
| 47 |
+
: 'text-muted-foreground'}"
|
| 48 |
+
{...{ [UI_DATA_ATTRS.ACTIVE]: isActive(section) }}
|
| 49 |
+
onclick={(e: MouseEvent) => {
|
| 50 |
+
onSectionChange?.(section.title);
|
| 51 |
+
carousel.scrollToCenter(e.currentTarget as HTMLElement);
|
| 52 |
+
}}
|
| 53 |
+
>
|
| 54 |
+
<section.icon class="{ICON_CLASS_DEFAULT} flex-shrink-0" />
|
| 55 |
+
|
| 56 |
+
<span>{section.title}</span>
|
| 57 |
+
</button>
|
| 58 |
+
{/each}
|
| 59 |
+
</ScrollCarousel>
|
| 60 |
+
</div>
|
| 61 |
+
</div>
|