Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,56 @@
<script lang="ts">
import { Checkbox } from '@ggml-org/llama-ui/ui/checkbox';
import * as Collapsible from '@ggml-org/llama-ui/ui/collapsible';
import * as DropdownMenu from '@ggml-org/llama-ui/ui/dropdown-menu';
import * as Tooltip from '@ggml-org/llama-ui/ui/tooltip';
import { Check, ChevronDown, ChevronRight, Info, Loader2, PencilRuler } from '@lucide/svelte';
import { ATTACHMENT_MENU_TEXT, CLI_FLAGS, ICON_CLASS_DEFAULT } from '#lib/constants/index.ts';
import { useToolsPanel } from '#lib/hooks/use-tools-panel.svelte.ts';
import { toolsStore } from '#lib/stores/index.ts';
import type { ToolGroup } from '#lib/types/index.ts';
import type { Attachment } from 'svelte/attachments';
import { SvelteMap } from 'svelte/reactivity';

const toolsPanel = useToolsPanel();

// measured-px height transition for the tool groups (same technique as
// ModelsSelectorReasoningPanel): two plain lengths interpolate in every
// browser, no calc-size() support needed
const GROUP_TRANSITION_MS = 200;
const groupHeights = new SvelteMap<string, number>();
const groupEls = new SvelteMap<string, HTMLDivElement>();

function heightFor(group: ToolGroup): number {
return toolsPanel.expandedGroups.has(group.key) ? (groupHeights.get(group.key) ?? 0) : 0;
}

// the rows are plain buttons (not menu items), so they stay mounted always;
// visibility keeps collapsed rows out of the tab order
function groupEl(key: string): Attachment<HTMLDivElement> {
return (el) => {
groupEls.set(key, el);

return () => groupEls.delete(key);
};
}

$effect(() => {
for (const group of [...toolsPanel.categoryGroups, ...toolsPanel.providerGroups]) {
const isExpanded = toolsPanel.expandedGroups.has(group.key);

if (isExpanded && !groupHeights.has(group.key)) {
// newly expanded: measure after the rows are laid out
requestAnimationFrame(() => {
const el = groupEls.get(group.key);

if (el && toolsPanel.expandedGroups.has(group.key)) {
groupHeights.set(group.key, el.scrollHeight);
}
});
} else if (!isExpanded && groupHeights.has(group.key)) {
groupHeights.delete(group.key);
}
}
});
</script>

<DropdownMenu.Sub onOpenChange={(open) => open && toolsPanel.handleOpen()}>
Expand Down Expand Up @@ -82,13 +123,13 @@
{@const favicon = toolsPanel.getFavicon(group)}
{@const groupDisabled = toolsPanel.isGroupDisabled(group)}

<Collapsible.Root
onOpenChange={() => toolsPanel.toggleGroupExpanded(group.key)}
open={isExpanded}
>
<div>
<div class="flex items-center gap-1 {groupDisabled ? 'pointer-events-none opacity-50' : ''}">
<Collapsible.Trigger
<button
aria-expanded={isExpanded}
class="flex min-w-0 flex-1 items-center gap-2 rounded px-2 py-1.5 text-sm hover:bg-muted/50"
onclick={() => toolsPanel.toggleGroupExpanded(group.key)}
type="button"
>
{#if isExpanded}
<ChevronDown class="size-icon-sm shrink-0" />
Expand All @@ -114,7 +155,7 @@
<span class="ml-auto shrink-0 text-xs text-muted-foreground">
{toolsPanel.getEnabledToolCount(group)}/{group.tools.length}
</span>
</Collapsible.Trigger>
</button>

<Tooltip.Root>
<Tooltip.Trigger>
Expand All @@ -138,7 +179,13 @@
</Tooltip.Root>
</div>

<Collapsible.Content>
<div
{@attach groupEl(group.key)}
class="overflow-hidden"
style={`height: ${heightFor(group)}px; visibility: ${
isExpanded ? 'visible' : 'hidden'
}; transition: height ${GROUP_TRANSITION_MS}ms cubic-bezier(0.23, 1, 0.32, 1), visibility ${GROUP_TRANSITION_MS}ms;`}
>
<div class="ml-4 flex flex-col gap-0.5 border-l border-border/50 pl-2">
{#each group.tools as entry (entry.key)}
{@const enabled = toolsPanel.isToolEnabled(entry)}
Expand Down Expand Up @@ -166,6 +213,6 @@
</button>
{/each}
</div>
</Collapsible.Content>
</Collapsible.Root>
</div>
</div>
{/snippet}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<script lang="ts">
import { downloadProgressFor } from '../utils';
import { downloadProgressFor, type ModelOverride } from '../utils';
import ModelsManagerModelConfigurationActions from './ModelsManagerModelConfigurationActions.svelte';
import ModelsManagerModelConfigurationHeader from './ModelsManagerModelConfigurationHeader.svelte';
import ModelsManagerModelConfigurationInference from './ModelsManagerModelConfigurationInference.svelte';
import ModelsManagerModelConfigurationInformation from './ModelsManagerModelConfigurationInformation.svelte';
import ModelsManagerModelConfigurationLoad from './ModelsManagerModelConfigurationLoad.svelte';
import { ModelDownloadProgressBar } from '@ggml-org/llama-ui/models';
import { Button } from '@ggml-org/llama-ui/ui/button';
import * as Tabs from '@ggml-org/llama-ui/ui/tabs';
import * as Tooltip from '@ggml-org/llama-ui/ui/tooltip';
import { Trash2 } from '@lucide/svelte';
import { DialogConfirmDownload } from '#lib/components/app/dialogs/index.ts';
import { LOAD_DEFAULTS, MODEL_ID } from '#lib/constants/index.ts';
import { ModelDownloadConfirmAction, ServerModelStatus } from '#lib/enums/index.ts';
import { HuggingFaceService } from '#lib/services/index.ts';
import { deviceStore, modelsStore, uiStore } from '#lib/stores/index.ts';
Expand All @@ -16,17 +20,35 @@
import { repoOf } from '#lib/utils/index.ts';

interface Props {
isCustomized: boolean;
onClose: () => void;
onSave: (override: ModelOverride) => void;
onToggleLoad: () => void;
onUseInChat: () => void;
onUseInNewChat: () => void;
option: ModelOption;
override?: ModelOverride;
}

let { onClose, onToggleLoad, onUseInChat, onUseInNewChat, option }: Props = $props();
let {
isCustomized,
onClose,
onSave,
onToggleLoad,
onUseInChat,
onUseInNewChat,
option,
override
}: Props = $props();

let tab = $state('information');
// edits in this pane, cleared on reset; the stored override is the baseline
let edits = $state<ModelOverride | null>(null);
let draft = $derived(edits ?? override ?? {});

// the same removal the table row offers, confirmed by the same dialog
let deleteOpen = $state(false);

// a model the router did not take from its HF cache is not its own to delete
let removeBlockedReason = $derived(modelsStore.removeBlockedReason(option.model));

Expand All @@ -37,7 +59,11 @@
return modelsStore.props.getModelProps(option.model);
});
let status = $derived(modelsStore.getModelStatus(option.model));
let isOperationInProgress = $derived(modelsStore.status.isOperationInProgress(option.model));
let isLoaded = $derived(modelsStore.isModelRunning(option.model));
let loadProgress = $derived(
isOperationInProgress ? modelsStore.status.getLoadProgress(option.model) : null
);

// an in-flight download has no configuration: the pane shows its progress and
// the download actions, everything a loaded or downloaded model offers waits
Expand All @@ -56,9 +82,17 @@
// the same cancellation the table's rows confirm, owned by this pane
let cancelDownloadOpen = $state(false);

// The server reports the full metadata only once a model is loaded, which loads it.
// With the Hub enabled, it fills those gaps instead.
// The server only reports the full metadata once a model is loaded, which loads
// it. When discovery is on, the Hub fills those gaps instead.
let hubDetails = $state<HfModelDetailInfo | null>(null);
// the window the model can take, from the listing or the Hub; a loaded model's runtime
// context only bounds it when nothing else says otherwise
let contextMax = $derived(
option.contextLength ??
hubDetails?.gguf?.context_length ??
serverProps?.default_generation_settings?.n_ctx ??
LOAD_DEFAULTS.contextLength
);

$effect(() => {
const repo = repoOf(option.model);
Expand All @@ -67,7 +101,7 @@

hubDetails = null;

if (!HuggingFaceService.isEnabled() || !repo.includes('/')) {
if (!HuggingFaceService.isEnabled() || !repo.includes(MODEL_ID.ORG_SEPARATOR)) {
return;
}

Expand All @@ -81,10 +115,15 @@
cancelled = true;
};
});

function resetDraft(): void {
edits = null;
}
</script>

<div class="flex h-full min-h-0 flex-col">
<ModelsManagerModelConfigurationHeader
{isCustomized}
{isDownload}
{isDownloadPaused}
{isLoaded}
Expand All @@ -101,9 +140,9 @@
{status}
/>

<div class="min-h-0 flex-1 overflow-y-auto p-4">
{#if isDownload}
<!-- nothing is on disk yet, so the pane keeps to the download itself -->
{#if isDownload}
<!-- nothing is on disk yet, so the pane keeps to the download itself -->
<div class="min-h-0 flex-1 overflow-y-auto p-4">
<div class="space-y-2 py-1">
<div class="flex items-baseline justify-between gap-3 text-sm">
<span class="text-muted-foreground">
Expand All @@ -129,36 +168,81 @@
/>
{/if}
</div>
{:else}
<ModelsManagerModelConfigurationInformation hub={hubDetails} {option} {serverProps} />

<div class="mt-4 border-t border-border/30 pt-3 pb-2">
{#if removeBlockedReason}
<!-- a disabled button takes no pointer events, so the wrapper holds the hover -->
<Tooltip.Root>
<Tooltip.Trigger>
{#snippet child({ props })}
<div {...props}>
{@render deleteButton()}
</div>
{/snippet}
</Tooltip.Trigger>

<Tooltip.Content class="max-w-64">
<p>{removeBlockedReason}</p>
</Tooltip.Content>
</Tooltip.Root>

<!-- a phone has no hover, so the reason sits under the button -->
{#if deviceStore.isMobile}
<p class="px-3 pt-1 text-xs text-muted-foreground">{removeBlockedReason}</p>
</div>
{:else}
<Tabs.Root
class="mt-3 min-h-0 flex-1 gap-0"
onValueChange={(value) => (tab = value)}
value={tab}
>
<div class="px-4">
<Tabs.List class="w-full">
<Tabs.Trigger value="information">Information</Tabs.Trigger>

<Tabs.Trigger value="load">Load</Tabs.Trigger>

<Tabs.Trigger value="inference">Inference</Tabs.Trigger>
</Tabs.List>
</div>

<div class="min-h-0 flex-1 overflow-y-auto p-4">
<Tabs.Content value="information">
<ModelsManagerModelConfigurationInformation
draftSetting={override?.load?.speculativeDecoding ?? null}
hub={hubDetails}
{option}
{serverProps}
/>
</Tabs.Content>

<Tabs.Content value="load">
<ModelsManagerModelConfigurationLoad
{contextMax}
{draft}
{loadProgress}
onChange={(next) => (edits = next)}
onReset={resetDraft}
onSave={() => onSave(draft)}
/>
</Tabs.Content>

<Tabs.Content value="inference">
<ModelsManagerModelConfigurationInference
{draft}
onChange={(next) => (edits = next)}
onReset={resetDraft}
onSave={() => onSave(draft)}
/>
</Tabs.Content>

<div class="mt-4 border-t border-border/30 pt-3 pb-2">
{#if removeBlockedReason}
<!-- a disabled button takes no pointer events, so the wrapper holds the hover -->
<Tooltip.Root>
<Tooltip.Trigger>
{#snippet child({ props })}
<div {...props}>
{@render deleteButton()}
</div>
{/snippet}
</Tooltip.Trigger>

<Tooltip.Content class="max-w-64">
<p>{removeBlockedReason}</p>
</Tooltip.Content>
</Tooltip.Root>

<!-- a phone has no hover, so the reason sits under the button -->
{#if deviceStore.isMobile}
<p class="px-3 pt-1 text-xs text-muted-foreground">{removeBlockedReason}</p>
{/if}
{:else}
{@render deleteButton()}
{/if}
{:else}
{@render deleteButton()}
{/if}
</div>
</div>
{/if}
</div>
</Tabs.Root>
{/if}

<!-- a phone keeps the actions at the bottom of its screen, in reach of the thumb -->
{#if deviceStore.isMobile}
Expand Down
Loading
Loading