diff --git a/tools/ui/src/lib/components/app/chat/ChatForm/ChatForm.svelte b/tools/ui/src/lib/components/app/chat/ChatForm/ChatForm.svelte index 397ddc322..91edac1d8 100644 --- a/tools/ui/src/lib/components/app/chat/ChatForm/ChatForm.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatForm/ChatForm.svelte @@ -477,12 +477,9 @@ queueMicrotask(() => inputRef?.focus()); } - // A flow outside the chat, e.g. the models manager closing onto it, asks for the - // composer back. The dialog's focus scope is still tearing down, so focus on a - // frame of its own. + // A flow outside the chat, e.g. the models page returning to it, asks for the + // composer back. Focus on a frame of its own, once the route has settled. $effect(() => { - if (uiStore.manageModelsOpen) return; - if (!uiStore.composerFocusRequested) return; uiStore.composerFocusRequested = false; diff --git a/tools/ui/src/lib/components/app/dialogs/DialogDiscoverModels.svelte b/tools/ui/src/lib/components/app/dialogs/DialogDiscoverModels.svelte new file mode 100644 index 000000000..ed3d651d2 --- /dev/null +++ b/tools/ui/src/lib/components/app/dialogs/DialogDiscoverModels.svelte @@ -0,0 +1,53 @@ + + + + event.preventDefault()} + > + + + + + Discover + + + + Find models on Hugging Face and download them to the server. + + + +
+ +
+
+
diff --git a/tools/ui/src/lib/components/app/dialogs/DialogManageModels.svelte b/tools/ui/src/lib/components/app/dialogs/DialogManageModels.svelte deleted file mode 100644 index fbe711c25..000000000 --- a/tools/ui/src/lib/components/app/dialogs/DialogManageModels.svelte +++ /dev/null @@ -1,207 +0,0 @@ - - - - event.preventDefault()} - > - - - - - - - - - - - - - {title} - - - - Browse, load and delete the models the server can serve. - - - -
- {#if shownView === ModelsDialogView.MANAGE} - - {#snippet toolbarEnd()} - {#if discoverEnabled} - - {/if} - {/snippet} - - {:else if shownView === ModelsDialogView.DISCOVER} -
- -
- {/if} -
-
-
- - diff --git a/tools/ui/src/lib/components/app/dialogs/index.ts b/tools/ui/src/lib/components/app/dialogs/index.ts index 45cc9b2e6..5c6a56f00 100644 --- a/tools/ui/src/lib/components/app/dialogs/index.ts +++ b/tools/ui/src/lib/components/app/dialogs/index.ts @@ -500,5 +500,5 @@ export { default as DialogMcpResourcePreview } from './DialogMcpResourcePreview. */ export { default as DialogMermaidPreview } from './DialogMermaidPreview.svelte'; -/** **DialogManageModels** - shell for the models manager. */ -export { default as DialogManageModels } from './DialogManageModels.svelte'; +/** **DialogDiscoverModels** - shell for the Hugging Face model discovery view. */ +export { default as DialogDiscoverModels } from './DialogDiscoverModels.svelte'; diff --git a/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManager.svelte b/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManager.svelte index 9853bafe5..002b283fb 100644 --- a/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManager.svelte +++ b/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManager.svelte @@ -10,9 +10,10 @@ type ModelsTableGroup, splitHiddenQuants } from './utils'; + import * as Drawer from '$lib/components/ui/drawer'; import { LOCAL_BACKEND_ID, type ModalityKey, MODELS_TABLE_GROUP_LABELS } from '$lib/constants'; import { ModelCapability, ModelsTableGroupKind } from '$lib/enums'; - import { conversationsStore, modelsStore, serverStore, uiStore } from '$lib/stores'; + import { conversationsStore, deviceStore, modelsStore, serverStore, uiStore } from '$lib/stores'; import type { ModelOption } from '$lib/types/models'; import { filterModelOptions } from '$lib/utils'; import { type Snippet, untrack } from 'svelte'; @@ -48,8 +49,8 @@ downloads.find((group) => group.base.id === selectedId)?.base ?? null ); - // The pane is laid out before it is ever opened, so the first open only slides a - // finished panel in. It renders the selection, else the model it last showed. + // The pane renders the selection, else the model it last showed, so its copy stays + // in place while it closes. let lastPicked = $state(null); let target = $derived(selected ?? lastPicked ?? allModels[0] ?? null); let shownId = $state(null); @@ -254,10 +255,31 @@ await modelsStore.status.load(option.model); } - /** The chat sits behind the dialog, so the dialog closes and the composer takes focus. */ + /** Leave the models page for the chat it was opened from, with the composer focused. */ function returnToChat(): void { - uiStore.manageModelsOpen = false; uiStore.requestComposerFocus(); + void uiStore.closeModelsManager(); + } + + /** Overlays that handle their own Escape, so the page leaves them alone. */ + const OPEN_OVERLAY_SELECTOR = [ + '[role="dialog"][data-state="open"]', + '[role="alertdialog"][data-state="open"]', + '[role="menu"][data-state="open"]', + '[role="listbox"][data-state="open"]' + ].join(', '); + + // Escape steps back the way the dialog's did: the pane's drawer closes itself, then + // the next Escape leaves the page + function handleKeydown(event: KeyboardEvent): void { + if (event.key !== 'Escape' || event.defaultPrevented) return; + + if (document.querySelector(OPEN_OVERLAY_SELECTOR)) return; + + // a typed filter is not thrown away by a stray Escape + if (event.target instanceof HTMLInputElement && event.target.value) return; + + returnToChat(); } /** Load the model when the server can take load requests, without waiting for it. */ @@ -292,6 +314,8 @@ } + +
+
- -
+ { + if (!open) selectedId = null; + }} + open={selected !== null} + shouldScaleBackground={false} +> + - + Model details + + + Configuration, actions and metadata of the selected model. + +
@@ -331,33 +368,10 @@ {/key} {/if}
-
- + + diff --git a/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerFilters.svelte b/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerFilters.svelte index 8b4c3bf37..99fe92072 100644 --- a/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerFilters.svelte +++ b/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerFilters.svelte @@ -5,6 +5,7 @@ import { CAPABILITY_ICONS, CAPABILITY_LABELS, + FILTER_TOGGLE_GROUP_CLASS, FILTER_TOGGLE_ITEM_CLASS, FILTER_TRIGGER_CLASS, MODALITY_FLAG_KEYS, @@ -89,10 +90,12 @@ + action would otherwise squeeze the filters out of sight. The scroll box clips on + both axes, so it gets room for the controls' shadows and gives it back outside --> @@ -115,11 +118,10 @@ {#each toggles as toggle (toggle.value)} -
+
{#if isDownload}
diff --git a/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerModelConfiguration/ModelsManagerModelConfigurationActions.svelte b/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerModelConfiguration/ModelsManagerModelConfigurationActions.svelte index affab3421..30b3becdf 100644 --- a/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerModelConfiguration/ModelsManagerModelConfigurationActions.svelte +++ b/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerModelConfiguration/ModelsManagerModelConfigurationActions.svelte @@ -11,8 +11,7 @@ Trash2 } from '@lucide/svelte'; import { Button } from '$lib/components/ui/button'; - import { SETTINGS_KEYS } from '$lib/constants'; - import { conversationsStore, deviceStore, settingsStore } from '$lib/stores'; + import { conversationsStore, deviceStore, uiStore } from '$lib/stores'; interface Props { /** A provider that cannot load or unload has no button to offer. */ @@ -48,10 +47,7 @@ size = 'sm' }: Props = $props(); - // the discover view exists only while its setting is on - let discoverEnabled = $derived( - Boolean(settingsStore.getConfig(SETTINGS_KEYS.ENABLE_DISCOVER_MODELS)) - ); + let discoverEnabled = $derived(uiStore.isDiscoverEnabled); // a chat with anything in it takes the model, a new chat is not what its user asked for let hasChat = $derived( diff --git a/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerModelConfiguration/ModelsManagerModelConfigurationHeader.svelte b/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerModelConfiguration/ModelsManagerModelConfigurationHeader.svelte index d2cc2d5b8..5cb3bad91 100644 --- a/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerModelConfiguration/ModelsManagerModelConfigurationHeader.svelte +++ b/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerModelConfiguration/ModelsManagerModelConfigurationHeader.svelte @@ -74,7 +74,7 @@ -
+
@@ -108,15 +108,18 @@
- + + {#if !isMobile} + + {/if}
diff --git a/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerModelRow.svelte b/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerModelRow.svelte index 204d746d8..8383d418a 100644 --- a/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerModelRow.svelte +++ b/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerModelRow.svelte @@ -7,7 +7,7 @@ import ModelId from '../ModelId.svelte'; import ModelsManagerStatusCell from './ModelsManagerStatusCell.svelte'; import { modelRowActions } from './row-actions'; - import { configuredContext, downloadProgressFor } from './utils'; + import { configuredContext, downloadProgressFor, isRowControlClick } from './utils'; import { Heart, MoreHorizontal } from '@lucide/svelte'; import { DropdownMenuActions } from '$lib/components/app'; import { MODEL_ROW_GRID_CLASS, MODEL_ROW_TRAILING_CELL_CLASS } from '$lib/constants'; @@ -55,13 +55,20 @@ } + + +
{ + if (!isRowControlClick(event)) activate(); + }} >
+
+ entry.key} + more={showMore} + onCollapsedChange={(key, collapsed) => + modelsStore.setGroupCollapsed(group.key, key, collapsed)} + sectionWindow={MODEL_ROW_WINDOW} + stickyClass="rounded-lg bg-muted/25 backdrop-blur-lg" + stickyStyle={MODELS_TABLE_GROUP_STICKY_OFFSET} + weightOf={(entry) => entry.quants.length} + /> +
{/if} {/each} {#if isEmpty} -

- {hasFilters ? 'No models match these filters.' : 'No models found.'} -

+ + + + + + + {hasFilters ? 'No matching models' : 'No models yet'} + + + {hasFilters + ? 'Try a different search or clear the filters.' + : 'Models the server can run show up here.'} + + + {/if}
diff --git a/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerQuantRow.svelte b/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerQuantRow.svelte index 6d76251cd..6838a85da 100644 --- a/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerQuantRow.svelte +++ b/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerQuantRow.svelte @@ -3,7 +3,7 @@ import ModelDraftSidecars from '../ModelDraftSidecars.svelte'; import ModelsManagerStatusCell from './ModelsManagerStatusCell.svelte'; import { modelRowActions } from './row-actions'; - import { configuredContext } from './utils'; + import { configuredContext, isRowControlClick } from './utils'; import { MoreHorizontal } from '@lucide/svelte'; import { DropdownMenuActions } from '$lib/components/app'; import { Badge } from '$lib/components/ui/badge'; @@ -28,13 +28,20 @@ let quant = $derived(option.parsedId?.quantization ?? option.model); + + +
{ + if (!isRowControlClick(event)) onSelect(option); + }} > diff --git a/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerTableToolbar.svelte b/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerTableToolbar.svelte index fef282fcc..b2b10f58e 100644 --- a/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerTableToolbar.svelte +++ b/tools/ui/src/lib/components/app/models/ModelsManager/ModelsManagerTableToolbar.svelte @@ -6,7 +6,7 @@ import { Button } from '$lib/components/ui/button'; import { type ModalityKey } from '$lib/constants'; import { ModelCapability } from '$lib/enums'; - import { deviceStore, uiStore } from '$lib/stores'; + import { deviceStore } from '$lib/stores'; import type { Snippet } from 'svelte'; interface Props { @@ -32,12 +32,10 @@ let hasFilters = $derived(hasActiveFilters(contextLimit, modalities, capabilities)); let filterInput = $state(null); - // The search takes the focus the dialog would give its first control: the input - // mounts a frame or two after the dialog opens (the toolbar renders below the - // table in the DOM), so the poll retries until the ref lands or gives up. + // The search takes the focus when the models page opens: the input mounts a frame + // or two after the page (the toolbar renders below the table in the DOM), so the + // poll retries until the ref lands or gives up. $effect(() => { - if (!uiStore.manageModelsOpen) return; - let frames = 0; let handle = requestAnimationFrame(function focusFilter() { if (filterInput) { diff --git a/tools/ui/src/lib/components/app/models/ModelsManager/row-actions.ts b/tools/ui/src/lib/components/app/models/ModelsManager/row-actions.ts index 3407634ec..f3c4363c7 100644 --- a/tools/ui/src/lib/components/app/models/ModelsManager/row-actions.ts +++ b/tools/ui/src/lib/components/app/models/ModelsManager/row-actions.ts @@ -13,13 +13,18 @@ export function modelRowActions( /** Download state, when the row stands for a tracked download. */ download?: ModelRowDownloadState | null ) { - const viewInDiscover = { - icon: Compass, - label: 'See in Discover', - // the details pane is keyed by repo, not by `:` - onclick: () => uiStore.openModelsDiscover(repoOf(option.model)), - separator: true - }; + // the details pane is keyed by repo, not by `:`; the entry exists only + // while Discover is on + const viewInDiscover = uiStore.isDiscoverEnabled + ? [ + { + icon: Compass, + label: 'See in Discover', + onclick: () => uiStore.openModelsDiscover(repoOf(option.model)), + separator: true + } + ] + : []; // a tracked download is paused, resumed or dropped: it is not loaded, hidden or // drafted. An in-flight row cancels, which stops the download and removes the @@ -40,7 +45,7 @@ export function modelRowActions( separator: true, variant: 'destructive' as const }, - viewInDiscover + ...viewInDiscover ]; } @@ -63,6 +68,6 @@ export function modelRowActions( onclick: () => modelsStore.toggleHidden(option.id), separator: true }, - viewInDiscover + ...viewInDiscover ]; } diff --git a/tools/ui/src/lib/components/app/models/ModelsManager/utils.ts b/tools/ui/src/lib/components/app/models/ModelsManager/utils.ts index 435700a10..ccbe226c0 100644 --- a/tools/ui/src/lib/components/app/models/ModelsManager/utils.ts +++ b/tools/ui/src/lib/components/app/models/ModelsManager/utils.ts @@ -81,6 +81,14 @@ export interface ModelsTableGroup { label: string; } +/** Controls in a model row that act on their own, so a row click passes them by. */ +const ROW_CONTROL_SELECTOR = 'button, a, input, [role="menuitem"]'; + +/** Whether a click on a model row landed on one of its own controls. */ +export function isRowControlClick(event: MouseEvent): boolean { + return event.target instanceof Element && event.target.closest(ROW_CONTROL_SELECTOR) !== null; +} + /** Context the model runs with: what a loaded model reports. */ export function configuredContext(option: ModelOption): number | null { return modelsStore.isModelRunning(option.model) diff --git a/tools/ui/src/lib/components/app/models/ModelsSelector/ModelsSelectorDropdown.svelte b/tools/ui/src/lib/components/app/models/ModelsSelector/ModelsSelectorDropdown.svelte index 750e5f6a7..d9e6be298 100644 --- a/tools/ui/src/lib/components/app/models/ModelsSelector/ModelsSelectorDropdown.svelte +++ b/tools/ui/src/lib/components/app/models/ModelsSelector/ModelsSelectorDropdown.svelte @@ -91,7 +91,7 @@ function handleManageModels() { open = false; - // let the menu finish closing before the dialog takes focus + // let the menu finish closing before the models page takes focus setTimeout(() => (onManageModels ? onManageModels() : uiStore.openModelsManager()), 0); } diff --git a/tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigation.svelte b/tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigation.svelte index 2ce4824cf..828c63623 100644 --- a/tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigation.svelte +++ b/tools/ui/src/lib/components/app/navigation/SidebarNavigation/SidebarNavigation.svelte @@ -5,7 +5,7 @@ import { ActionIcon, DialogConversationRename, - DialogManageModels, + DialogDiscoverModels, DialogMcpServers, DialogModelInformation, DialogSettingsChat, @@ -469,7 +469,7 @@ - + diff --git a/tools/ui/src/lib/constants/css-classes.constants.ts b/tools/ui/src/lib/constants/css-classes.constants.ts index 045dce6ac..a8f00df4c 100644 --- a/tools/ui/src/lib/constants/css-classes.constants.ts +++ b/tools/ui/src/lib/constants/css-classes.constants.ts @@ -54,9 +54,17 @@ export const FILTER_TRIGGER_CLASS = ` ${INPUT_CLASSES} `; -/** One filter toggle of the models manager toolbar. */ +/** The filter toggles' shared box: the same fill, border and shadow as a filter trigger. */ +export const FILTER_TOGGLE_GROUP_CLASS = ` + h-8 + overflow-hidden + divide-x divide-border/30 dark:divide-border/20 + ${INPUT_CLASSES} +`; + +/** One filter toggle of the models manager toolbar; its group draws the box. */ export const FILTER_TOGGLE_ITEM_CLASS = - 'bg-muted! border-border/30! shadow-none! dark:border-border/20! data-[state=on]:bg-muted-foreground/15! data-[state=on]:text-foreground! dark:data-[state=on]:bg-muted-foreground/25!'; + 'h-full rounded-none hover:bg-muted/80 dark:hover:bg-muted data-[state=on]:bg-muted-foreground/15 data-[state=on]:text-foreground dark:data-[state=on]:bg-muted-foreground/25'; /** Column grid shared by every row of the models manager table. Below md the context, * status and actions columns are dropped, so a phone gives the whole width to the diff --git a/tools/ui/src/lib/constants/routes.constants.ts b/tools/ui/src/lib/constants/routes.constants.ts index 1f518a758..9a475a118 100644 --- a/tools/ui/src/lib/constants/routes.constants.ts +++ b/tools/ui/src/lib/constants/routes.constants.ts @@ -13,8 +13,13 @@ export const ROUTES = { CHAT: '#/chat', /** MCP servers. */ MCP_SERVERS: '#/mcp-servers', + /** Models manager. */ + MODELS: '#/models', /** Search — mobile-only full-page conversation search. */ SEARCH: '#/search', /** Root — start of the app. */ START: '#/' } as const; + +/** SvelteKit route id of the models manager, as `page.route.id` reports it. */ +export const MODELS_ROUTE_ID = '/models'; diff --git a/tools/ui/src/lib/constants/ui.constants.ts b/tools/ui/src/lib/constants/ui.constants.ts index 946793978..9af1424fa 100644 --- a/tools/ui/src/lib/constants/ui.constants.ts +++ b/tools/ui/src/lib/constants/ui.constants.ts @@ -1,4 +1,5 @@ import { MODEL_ICON } from './icons.constants'; +import { MODELS_ROUTE_ID } from './routes.constants'; import { Search, Settings, SquarePen } from '@lucide/svelte'; import McpLogo from '$lib/components/app/mcp/McpLogo.svelte'; import { SidebarAction, ToolSource } from '$lib/enums'; @@ -7,9 +8,6 @@ import type { DesktopIconStripItem } from '$lib/types'; /** Delay before a copied affordance resets from its check to the copy icon. */ export const COPY_FEEDBACK_RESET_MS = 1500; -/** How long a models dialog view fades out before the next one fades in. */ -export const MODELS_DIALOG_VIEW_FADE_MS = 150; - export const FORK_TREE_DEPTH_PADDING = 8; export const SYSTEM_MESSAGE_PLACEHOLDER = 'System message'; @@ -83,6 +81,7 @@ export const SIDEBAR_ACTIONS_ITEMS: DesktopIconStripItem[] = [ { icon: Search, keys: ['cmd', 'k'], tooltip: 'Search' }, { action: SidebarAction.MANAGE_MODELS, + activeRouteId: MODELS_ROUTE_ID, icon: MODEL_ICON, tooltip: 'Models' }, diff --git a/tools/ui/src/lib/enums/index.ts b/tools/ui/src/lib/enums/index.ts index 9ab0be32e..142962826 100644 --- a/tools/ui/src/lib/enums/index.ts +++ b/tools/ui/src/lib/enums/index.ts @@ -95,7 +95,6 @@ export { ColorMode, HtmlInputType, McpPromptVariant, - ModelsDialogView, ScrollCarouselVariant, SidebarAction, TooltipSide, diff --git a/tools/ui/src/lib/enums/ui.enums.ts b/tools/ui/src/lib/enums/ui.enums.ts index 599fc2128..20cfe47ff 100644 --- a/tools/ui/src/lib/enums/ui.enums.ts +++ b/tools/ui/src/lib/enums/ui.enums.ts @@ -32,12 +32,6 @@ export enum SidebarAction { /** * MCP prompt display variant */ -/** View the models dialog renders. */ -export enum ModelsDialogView { - DISCOVER = 'discover', - MANAGE = 'manage' -} - export enum McpPromptVariant { ATTACHMENT = 'attachment', MESSAGE = 'message' diff --git a/tools/ui/src/lib/hooks/use-models-selector.svelte.ts b/tools/ui/src/lib/hooks/use-models-selector.svelte.ts index 35a85dcd8..844a7d4fb 100644 --- a/tools/ui/src/lib/hooks/use-models-selector.svelte.ts +++ b/tools/ui/src/lib/hooks/use-models-selector.svelte.ts @@ -114,13 +114,6 @@ export function useModelsSelector(opts: UseModelsSelectorOptions): UseModelsSele ); const emptyMessage = $derived(searchTerm ? 'No models found.' : 'No models yet.'); - // the manager takes the focus, so the selector closes instead of sitting behind it - $effect(() => { - if (!uiStore.manageModelsOpen) return; - - opts.onOpenChange?.(false); - }); - onMount(() => { modelsStore.fetch().catch((error) => { console.error('Unable to load models:', error); diff --git a/tools/ui/src/lib/stores/init.ts b/tools/ui/src/lib/stores/init.ts index 37ea87b17..ce2dcfbd0 100644 --- a/tools/ui/src/lib/stores/init.ts +++ b/tools/ui/src/lib/stores/init.ts @@ -7,6 +7,7 @@ import { toolsStore } from './tools.svelte'; import { versionStore } from './version.svelte'; import { browser } from '$app/environment'; import { MigrationService } from '$lib/services/migration.service'; +import { validateApiKey } from '$lib/utils/api-key-validation'; let startup: Promise | null = null; @@ -30,3 +31,11 @@ export function initStores(): Promise { return startup; } + +/** Load shared by the app's pages: start the stores, then check the API key. */ +export async function loadAppRoute(fetch: typeof globalThis.fetch): Promise { + // loads run before the root layout script, so the stored API key reaches + // the probe only once the settings store has read localStorage + await initStores(); + await validateApiKey(fetch); +} diff --git a/tools/ui/src/lib/stores/ui.svelte.ts b/tools/ui/src/lib/stores/ui.svelte.ts index bd9e40323..49ac2fbff 100644 --- a/tools/ui/src/lib/stores/ui.svelte.ts +++ b/tools/ui/src/lib/stores/ui.svelte.ts @@ -6,40 +6,74 @@ * controls and the chat tab bar reacts to). */ +import { goto } from '$app/navigation'; +import { page } from '$app/state'; +import { MODELS_ROUTE_ID, ROUTES, SETTINGS_KEYS } from '$lib/constants'; +import { settingsStore } from '$lib/stores/settings/index.svelte'; import type { ModelOption } from '$lib/types/models'; class UiStore { /** Set when a flow outside the chat wants the composer focused once it can take it. */ composerFocusRequested = $state(false); - /** Repo the Discover view selects when it opens, set by a model row. */ + /** Repo the Discover dialog selects when it opens, set by a model row. */ discoverModelFocus = $state(null); + /** Open state of the Discover dialog. */ discoverModelsOpen = $state(false); /** Whether the desktop sidebar is expanded (open). */ isSidebarExpanded = $state(false); /** Model the manager reveals when it opens, a qualified id or a raw model name. */ manageModelFocus = $state(null); - /** Open state of the models manager, driven from the sidebar and from model rows. */ - manageModelsOpen = $state(false); /** Model the information dialog shows; a phone opens it instead of the manager. */ modelInformation = $state(null); + /** Route the models page returns to: the last page visited before it. */ + modelsReturnRoute: string = ROUTES.START; + + /** Whether Discover is turned on; every Discover entry point hides without it. */ + get isDiscoverEnabled(): boolean { + return Boolean(settingsStore.getConfig(SETTINGS_KEYS.ENABLE_DISCOVER_MODELS)); + } + + /** Whether the models manager route is the current page. */ + get isModelsPageOpen(): boolean { + return page.route.id === MODELS_ROUTE_ID; + } + + /** Leave the models page for the route it was opened from. */ + async closeModelsManager(): Promise { + if (!this.isModelsPageOpen) return; + + await goto(this.modelsReturnRoute); + } /** Open the model information dialog, a phone's stand-in for the manager pane. */ openModelInformation(option: ModelOption): void { this.modelInformation = option; } - /** Open the models dialog on Discover, focused on one repo. */ + /** Open the Discover dialog, focused on one repo; a no-op while Discover is off. */ openModelsDiscover(focus?: string): void { + if (!this.isDiscoverEnabled) return; + this.discoverModelFocus = focus ?? null; this.discoverModelsOpen = true; } - /** Open the models manager, optionally focused on one model. */ + /** Navigate to the models manager, optionally focused on one model. */ openModelsManager(focus?: string): void { this.manageModelFocus = focus ?? null; - this.manageModelsOpen = true; + + if (this.isModelsPageOpen) return; + + void goto(ROUTES.MODELS); + } + + /** Remember the current route as the models page's way back, unless it is that page. */ + rememberModelsReturnRoute(): void { + if (this.isModelsPageOpen) return; + + this.modelsReturnRoute = page.url.hash || ROUTES.START; } /** Ask the composer to take focus, e.g. after a dialog closes onto the chat. */ diff --git a/tools/ui/src/routes/(chat)/+page.ts b/tools/ui/src/routes/(chat)/+page.ts index 0c46aaa8a..3be3d5a95 100644 --- a/tools/ui/src/routes/(chat)/+page.ts +++ b/tools/ui/src/routes/(chat)/+page.ts @@ -1,10 +1,4 @@ import type { PageLoad } from './$types'; -import { initStores } from '$lib/stores/init'; -import { validateApiKey } from '$lib/utils'; +import { loadAppRoute } from '$lib/stores/init'; -export const load: PageLoad = async ({ fetch }) => { - // loads run before the root layout script, so the stored API key reaches - // the probe only once the settings store has read localStorage - await initStores(); - await validateApiKey(fetch); -}; +export const load: PageLoad = ({ fetch }) => loadAppRoute(fetch); diff --git a/tools/ui/src/routes/(chat)/chat/[id]/+page.ts b/tools/ui/src/routes/(chat)/chat/[id]/+page.ts index 0c46aaa8a..3be3d5a95 100644 --- a/tools/ui/src/routes/(chat)/chat/[id]/+page.ts +++ b/tools/ui/src/routes/(chat)/chat/[id]/+page.ts @@ -1,10 +1,4 @@ import type { PageLoad } from './$types'; -import { initStores } from '$lib/stores/init'; -import { validateApiKey } from '$lib/utils'; +import { loadAppRoute } from '$lib/stores/init'; -export const load: PageLoad = async ({ fetch }) => { - // loads run before the root layout script, so the stored API key reaches - // the probe only once the settings store has read localStorage - await initStores(); - await validateApiKey(fetch); -}; +export const load: PageLoad = ({ fetch }) => loadAppRoute(fetch); diff --git a/tools/ui/src/routes/+layout.svelte b/tools/ui/src/routes/+layout.svelte index 5de4f82c1..70d3b7d8b 100644 --- a/tools/ui/src/routes/+layout.svelte +++ b/tools/ui/src/routes/+layout.svelte @@ -1,7 +1,7 @@ + + + Models - {APP_NAME} + + +
+
+
+

Models

+ +

+ Load, configure and remove the models this server can run. +

+
+ + {#if uiStore.isDiscoverEnabled} + + {/if} +
+ + +
diff --git a/tools/ui/src/routes/models/+page.ts b/tools/ui/src/routes/models/+page.ts new file mode 100644 index 000000000..3be3d5a95 --- /dev/null +++ b/tools/ui/src/routes/models/+page.ts @@ -0,0 +1,4 @@ +import type { PageLoad } from './$types'; +import { loadAppRoute } from '$lib/stores/init'; + +export const load: PageLoad = ({ fetch }) => loadAppRoute(fetch); diff --git a/tools/ui/tests/client/models-manager-sort-filter.svelte.test.ts b/tools/ui/tests/client/models-manager-sort-filter.svelte.test.ts index 9e9e0c246..65c8c7812 100644 --- a/tools/ui/tests/client/models-manager-sort-filter.svelte.test.ts +++ b/tools/ui/tests/client/models-manager-sort-filter.svelte.test.ts @@ -218,7 +218,7 @@ it('filters by search', async () => { await screen.getByPlaceholder('Search your models').fill('beta'); - await expect.element(screen.getByText(/alpha\s+8B/)).not.toBeVisible(); + await expect.element(screen.getByText(/alpha\s+8B/)).not.toBeInTheDocument(); await expect.element(screen.getByText(/beta\s+8B/)).toBeVisible(); }); @@ -231,7 +231,7 @@ it('filters by context and sorts from the Hub details cache', async () => { await screen.getByText('Context:').click(); await screen.getByText('32K or more').click(); - await expect.element(screen.getByText(/alpha\s+8B/)).not.toBeVisible(); + await expect.element(screen.getByText(/alpha\s+8B/)).not.toBeInTheDocument(); await expect.element(screen.getByText(/gamma\s+8B/)).toBeVisible(); // sorting re-runs once the cache answers