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

This file was deleted.

85 changes: 82 additions & 3 deletions ui/apps/chat/src/lib/components/app/dialogs/DialogSearch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@
import { ArrowDown, ArrowUp, CornerDownLeft, MessageSquare, Pin, X } from '@lucide/svelte';
import { ActionIcon, KeyboardShortcutInfo } from '#lib/components/app/index.ts';
import {
DISCOVER_ICON,
ICON_CLASS_DEFAULT,
ICON_CLASS_SM,
ICON_CLASS_XS,
MODELS_DISCOVER_SEARCH_DEBOUNCE_MS,
PROJECT_ICON,
SIDEBAR_ACTIONS_ITEMS
} from '#lib/constants/index.ts';
import { KeyboardKey, SidebarAction } from '#lib/enums/index.ts';
import { extensions, type NavigationItem } from '#lib/extensions/index.ts';
import { HuggingFaceService } from '#lib/services/index.ts';
import { RouterService } from '#lib/services/router.service.ts';
import { conversationsStore, deviceStore, projectsStore, uiStore } from '#lib/stores/index.ts';
import {
conversationsStore,
deviceStore,
modelsDiscoverStore,
projectsStore,
uiStore
} from '#lib/stores/index.ts';
import type { HfModelInfo } from '#lib/types/huggingface.js';
import { formatRelativeTime, isIMEComposing, sidebarFooterItems } from '#lib/utils/index.ts';
import { goto } from '$app/navigation';
import type { Component } from 'svelte';
Expand All @@ -39,13 +49,17 @@

interface SearchSection {
entries: SearchEntry[];
/** Shown in place of the entries a section is still waiting for, or failed to get. */
note?: string;
title: string;
}

/** Recent chats shown before typing, so the actions stay in view below them. */
const RECENT_LIMIT = 5;
/** Matches kept while typing; the rest stays reachable by typing more. */
const MATCH_LIMIT = 50;
/** Hub models listed; the models page shows the whole search. */
const HUB_LIMIT = 6;

let query = $state('');
let highlighted = $state(0);
Expand Down Expand Up @@ -118,19 +132,80 @@
.filter((entry) => matches(entry.label))
);

// Hub models answer the typed term wherever the models page searches the Hub
const searchesHub = $derived(open && uiStore.isDiscoverEnabled && needle.length > 0);

let hubModels = $state<HfModelInfo[]>([]);
let hubNote = $state<string | undefined>();

$effect(() => {
hubModels = [];
hubNote = undefined;

if (!searchesHub) return;

const term = needle;

let cancelled = false;

hubNote = 'Searching Hugging Face...';

// the same debounce the models page waits for after the last keystroke
const timer = setTimeout(async () => {
try {
// the models page's own search, so the first matches here lead its list too
const models = await modelsDiscoverStore.searchHub(term);

if (cancelled) return;

hubModels = models.slice(0, HUB_LIMIT);
hubNote = undefined;
} catch {
if (!cancelled) hubNote = 'Could not search Hugging Face';
}
}, MODELS_DISCOVER_SEARCH_DEBOUNCE_MS);

return () => {
cancelled = true;
clearTimeout(timer);
};
});

const hubEntries = $derived.by((): SearchEntry[] =>
hubModels.map((model) => ({
icon: DISCOVER_ICON,
id: `hub-${model.id}`,
label: model.id,
meta: `${HuggingFaceService.formatDownloads(model.downloads)} downloads`,
run: () => close(() => openHubModel(model.id))
}))
);

// last, so matches arriving from the Hub never move the rows above them
const sections = $derived<SearchSection[]>(
[
{ entries: chatEntries, title: needle ? 'Chats' : 'Recents' },
{ entries: projectEntries, title: 'Projects' },
{ entries: actionEntries, title: 'Actions' }
].filter((section) => section.entries.length > 0)
{ entries: actionEntries, title: 'Actions' },
{ entries: hubEntries, note: hubNote, title: 'Models on Hugging Face' }
].filter((section) => section.entries.length > 0 || section.note)
);

const entries = $derived(sections.flatMap((section) => section.entries));
const activeIndex = $derived(Math.min(highlighted, entries.length - 1));

const emptyMessage = $derived(needle ? 'No results found' : 'No chats yet');

/**
* Shows a Hub model's details over the models page; a phone, which has no models
* page in its navigation, opens them over the page it is on.
*/
function openHubModel(repo: string) {
if (!deviceStore.isMobile) uiStore.openModelsManager();

uiStore.openHubModelDetails(repo);
}

/** Closes the search first, so a dialog opened by `next` takes the focus. */
function close(next: () => void) {
handleOpenChange(false);
Expand Down Expand Up @@ -270,6 +345,10 @@
: 'opacity-0'}"
/>
</button>
{:else}
<p class="px-2.5 py-2 text-sm text-muted-foreground max-md:py-3 max-md:text-base">
{section.note}
</p>
{/each}
</div>
{:else}
Expand Down
9 changes: 3 additions & 6 deletions ui/apps/chat/src/lib/components/app/dialogs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ export { default as DialogExportSettings } from './DialogExportSettings.svelte';
export { default as DialogConfirmation } from './DialogConfirmation.svelte';

/**
* **DialogSearch** - Spotlight-style search over chats and sidebar actions
* **DialogSearch** - Spotlight-style search over chats, projects, sidebar actions and Hub models
*
* Opens over the app with a focused input and a keyboard-driven result list:
* arrow keys move the highlight, Enter opens, Escape closes. A phone shows it full screen, like
* every dialog.
* arrow keys move the highlight, Enter opens, Escape closes. With Discover on, the typed
* term also searches Hugging Face. A phone shows it full screen, like every dialog.
*/
export { default as DialogSearch } from './DialogSearch.svelte';

Expand Down Expand Up @@ -479,6 +479,3 @@ export { default as DialogConversationSelection } from './DialogConversationSele
* ```
*/
export { default as DialogMermaidPreview } from './DialogMermaidPreview.svelte';

/** **DialogDiscoverModels** - shell for the Hugging Face model discovery view. */
export { default as DialogDiscoverModels } from './DialogDiscoverModels.svelte';
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
} from '#lib/utils/index.ts';

interface Props {
/** Name every capability in an outline badge instead of a bare icon. */
asBadges?: boolean;
class?: string;
/** Hide the modality icons, keeping the capability ones. */
hideModalities?: boolean;
option: ModelOption;
}

let { class: className = '', hideModalities = false, option }: Props = $props();
let { asBadges = false, class: className = '', hideModalities = false, option }: Props = $props();

// a listing that declares its capabilities (Ollama-compatible servers) needs no lookup
let declared = $derived(option.capabilities);
Expand Down Expand Up @@ -61,6 +63,7 @@

<span {@attach nearViewport(() => (isNearViewport = true))} class={className}>
<ModelCapabilityIcons
{asBadges}
{hideModalities}
modalities={option.modalities}
{supportsThinking}
Expand Down
98 changes: 98 additions & 0 deletions ui/apps/chat/src/lib/components/app/models/ModelCard.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<script lang="ts">
import * as Card from '@ggml-org/llama-ui/ui/card';
import type { Snippet } from 'svelte';

interface Props {
/** Avatar at the card's top left. */
avatar: Snippet;
/** The model's name and badges, beside the avatar; the card's one button. */
title: Snippet;
/** Controls at the top right, e.g. an actions menu. */
actions?: Snippet;
/** Body between the header and the footer: capabilities, a description. */
children?: Snippet;
class?: string;
/** Faded, e.g. a hidden model. */
dimmed?: boolean;
/** Muted facts at the bottom left. */
footer?: Snippet;
/** Bottom right of the footer, e.g. a load control. */
footerEnd?: Snippet;
onSelect: () => void;
/** Laid over the card's edge, e.g. a download progress bar. */
overlay?: Snippet;
/** `aria-pressed` of the card's button; undefined leaves it a plain button. */
pressed?: boolean;
selected?: boolean;
/** Native title of the card's button, e.g. the full model id. */
tooltip?: string;
}

let {
actions,
avatar,
children,
class: className = '',
dimmed = false,
footer,
footerEnd,
onSelect,
overlay,
pressed,
selected = false,
title,
tooltip
}: Props = $props();
</script>

<!-- The surface of the MCP server cards. The title button stretches over the whole card,
so a click anywhere opens the model, while the controls stack above it: a button
nested in a button is invalid. -->
<Card.Root
class={[
'relative min-w-0 gap-3! overflow-hidden bg-muted/30 p-4 transition-colors hover:bg-muted/50',
selected && 'ring-1 ring-primary/40',
dimmed && 'opacity-60',
className
]}
>
<div class="flex min-w-0 items-start gap-3">
<button
aria-pressed={pressed}
class="flex min-w-0 flex-1 cursor-pointer items-center gap-3 text-left before:absolute before:inset-0 before:content-[''] focus-visible:outline-none focus-visible:before:rounded-xl focus-visible:before:ring-2 focus-visible:before:ring-ring/50"
onclick={onSelect}
title={tooltip}
type="button"
>
{@render avatar()}

<span class="min-w-0 flex-1">
{@render title()}
</span>
</button>

{#if actions}
<div class="relative z-10 -mt-1 -mr-1.5 shrink-0">
{@render actions()}
</div>
{/if}
</div>

{@render children?.()}

{#if footer || footerEnd}
<div class="mt-auto flex min-h-6 items-center justify-between gap-3 text-xs">
<div class="min-w-0 text-muted-foreground">
{@render footer?.()}
</div>

{#if footerEnd}
<div class="relative z-10 flex shrink-0 items-center">
{@render footerEnd()}
</div>
{/if}
</div>
{/if}

{@render overlay?.()}
</Card.Root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<script lang="ts">
import * as Card from '@ggml-org/llama-ui/ui/card';
import { Skeleton } from '@ggml-org/llama-ui/ui/skeleton';

interface Props {
class?: string;
/** Leave room for a description, the way a Hub card carries one. */
description?: boolean;
}

let { class: className = '', description = false }: Props = $props();
</script>

<!-- Static skeleton of ModelCard: avatar, name over its subline, capability icons, footer facts. -->
<Card.Root class={['gap-3! bg-muted/30 p-4', className]}>
<div class="flex items-center gap-3">
<Skeleton class="size-9 shrink-0 rounded-md" />

<div class="min-w-0 flex-1 space-y-1.5">
<Skeleton class="h-4 w-36" />

<Skeleton class="h-3 w-20" />
</div>

<Skeleton class="h-3 w-12 shrink-0 self-start" />
</div>

{#if description}
<div class="space-y-1.5">
<Skeleton class="h-3 w-full" />

<Skeleton class="h-3 w-3/4" />
</div>
{/if}

<div class="mt-auto flex items-center justify-between">
<Skeleton class="h-3 w-24" />

<Skeleton class="h-3 w-16" />
</div>
</Card.Root>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import { isLocalOption } from './ModelsManager/utils';
import { cn } from '@ggml-org/llama-ui/utils';
import { MODEL_ID } from '#lib/constants/index.ts';
import { HuggingFaceService } from '#lib/services/index.ts';
import type { ModelOption } from '#lib/types/models.js';
Expand Down Expand Up @@ -53,7 +54,7 @@

<span
{@attach nearViewport(() => (isNearViewport = true))}
class={['text-sm text-muted-foreground', className]}
class={cn('text-sm text-muted-foreground', className)}
>
{formatContextLength(values)}
</span>
Loading
Loading