2026-03-05 08:52:22 +01:00
|
|
|
<script lang="ts">
|
2026-03-16 15:38:11 +01:00
|
|
|
import {
|
|
|
|
|
CircleAlert,
|
|
|
|
|
Heart,
|
|
|
|
|
HeartOff,
|
|
|
|
|
Info,
|
|
|
|
|
Loader2,
|
|
|
|
|
Power,
|
|
|
|
|
PowerOff,
|
|
|
|
|
RotateCw
|
|
|
|
|
} from '@lucide/svelte';
|
2026-03-05 08:52:22 +01:00
|
|
|
import { ActionIcon, ModelId } from '$lib/components/app';
|
|
|
|
|
import type { ModelOption } from '$lib/types/models';
|
|
|
|
|
import { ServerModelStatus } from '$lib/enums';
|
|
|
|
|
import { modelsStore, routerModels } from '$lib/stores/models.svelte';
|
|
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
option: ModelOption;
|
|
|
|
|
isSelected: boolean;
|
|
|
|
|
isHighlighted: boolean;
|
|
|
|
|
isFav: boolean;
|
2026-04-28 14:35:49 +03:00
|
|
|
hideOrgName?: boolean;
|
2026-03-05 08:52:22 +01:00
|
|
|
onSelect: (modelId: string) => void;
|
|
|
|
|
onMouseEnter: () => void;
|
|
|
|
|
onKeyDown: (e: KeyboardEvent) => void;
|
2026-03-16 15:38:11 +01:00
|
|
|
onInfoClick?: (modelName: string) => void;
|
2026-03-05 08:52:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let {
|
|
|
|
|
option,
|
|
|
|
|
isSelected,
|
|
|
|
|
isHighlighted,
|
|
|
|
|
isFav,
|
2026-04-28 14:35:49 +03:00
|
|
|
hideOrgName = false,
|
2026-03-05 08:52:22 +01:00
|
|
|
onSelect,
|
|
|
|
|
onMouseEnter,
|
2026-03-16 15:38:11 +01:00
|
|
|
onKeyDown,
|
|
|
|
|
onInfoClick
|
2026-03-05 08:52:22 +01:00
|
|
|
}: Props = $props();
|
|
|
|
|
|
|
|
|
|
let currentRouterModels = $derived(routerModels());
|
|
|
|
|
let serverStatus = $derived.by(() => {
|
|
|
|
|
const model = currentRouterModels.find((m) => m.id === option.model);
|
|
|
|
|
return (model?.status?.value as ServerModelStatus) ?? null;
|
|
|
|
|
});
|
|
|
|
|
let isOperationInProgress = $derived(modelsStore.isModelOperationInProgress(option.model));
|
|
|
|
|
let isFailed = $derived(serverStatus === ServerModelStatus.FAILED);
|
2026-03-25 11:02:32 +01:00
|
|
|
let isSleeping = $derived(serverStatus === ServerModelStatus.SLEEPING);
|
|
|
|
|
let isLoaded = $derived(
|
|
|
|
|
(serverStatus === ServerModelStatus.LOADED || isSleeping) && !isOperationInProgress
|
|
|
|
|
);
|
2026-03-05 08:52:22 +01:00
|
|
|
let isLoading = $derived(serverStatus === ServerModelStatus.LOADING || isOperationInProgress);
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<div
|
2026-05-01 18:36:29 +02:00
|
|
|
class={[
|
2026-03-05 08:52:22 +01:00
|
|
|
'group flex w-full items-center gap-2 rounded-sm p-2 text-left text-sm transition focus:outline-none',
|
|
|
|
|
'cursor-pointer hover:bg-muted focus:bg-muted',
|
2026-05-01 18:36:29 +02:00
|
|
|
(isSelected || isHighlighted) && 'bg-accent text-accent-foreground',
|
|
|
|
|
!(isSelected || isHighlighted) && 'hover:bg-accent hover:text-accent-foreground',
|
2026-03-05 08:52:22 +01:00
|
|
|
isLoaded ? 'text-popover-foreground' : 'text-muted-foreground'
|
2026-05-01 18:36:29 +02:00
|
|
|
]}
|
2026-03-05 08:52:22 +01:00
|
|
|
role="option"
|
|
|
|
|
aria-selected={isSelected || isHighlighted}
|
|
|
|
|
tabindex="0"
|
|
|
|
|
onclick={() => onSelect(option.id)}
|
|
|
|
|
onmouseenter={onMouseEnter}
|
|
|
|
|
onkeydown={onKeyDown}
|
|
|
|
|
>
|
|
|
|
|
<ModelId
|
|
|
|
|
modelId={option.model}
|
2026-04-28 14:35:49 +03:00
|
|
|
{hideOrgName}
|
2026-03-05 08:52:22 +01:00
|
|
|
aliases={option.aliases}
|
|
|
|
|
tags={option.tags}
|
|
|
|
|
class="flex-1"
|
|
|
|
|
/>
|
|
|
|
|
|
2026-03-16 15:38:11 +01:00
|
|
|
<div class="flex shrink-0 items-center gap-1">
|
2026-03-05 08:52:22 +01:00
|
|
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
|
|
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
|
|
|
<div
|
2026-03-16 15:38:11 +01:00
|
|
|
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"
|
2026-03-05 08:52:22 +01:00
|
|
|
onclick={(e) => e.stopPropagation()}
|
|
|
|
|
>
|
|
|
|
|
{#if isFav}
|
|
|
|
|
<ActionIcon
|
|
|
|
|
iconSize="h-2.5 w-2.5"
|
|
|
|
|
icon={HeartOff}
|
2026-03-25 11:02:32 +01:00
|
|
|
tooltip="Remove from favorites"
|
2026-03-05 08:52:22 +01:00
|
|
|
class="h-3 w-3 hover:text-foreground"
|
2026-03-25 11:02:32 +01:00
|
|
|
onclick={() => modelsStore.toggleFavorite(option.model)}
|
2026-03-05 08:52:22 +01:00
|
|
|
/>
|
|
|
|
|
{:else}
|
|
|
|
|
<ActionIcon
|
|
|
|
|
iconSize="h-2.5 w-2.5"
|
|
|
|
|
icon={Heart}
|
2026-03-25 11:02:32 +01:00
|
|
|
tooltip="Add to favorites"
|
2026-03-05 08:52:22 +01:00
|
|
|
class="h-3 w-3 hover:text-foreground"
|
2026-03-25 11:02:32 +01:00
|
|
|
onclick={() => modelsStore.toggleFavorite(option.model)}
|
2026-03-05 08:52:22 +01:00
|
|
|
/>
|
|
|
|
|
{/if}
|
2026-03-16 15:38:11 +01:00
|
|
|
|
|
|
|
|
<!-- info button: only shown when model is loaded and callback is provided -->
|
|
|
|
|
{#if isLoaded && onInfoClick}
|
|
|
|
|
<ActionIcon
|
|
|
|
|
iconSize="h-2.5 w-2.5"
|
|
|
|
|
icon={Info}
|
|
|
|
|
tooltip="Model information"
|
|
|
|
|
class="h-3 w-3 hover:text-foreground"
|
|
|
|
|
onclick={() => onInfoClick(option.model)}
|
|
|
|
|
/>
|
|
|
|
|
{/if}
|
2026-03-05 08:52:22 +01:00
|
|
|
</div>
|
2026-03-16 15:38:11 +01:00
|
|
|
|
2026-03-05 08:52:22 +01:00
|
|
|
{#if isLoading}
|
|
|
|
|
<Loader2 class="h-4 w-4 animate-spin text-muted-foreground" />
|
|
|
|
|
{:else if isFailed}
|
|
|
|
|
<div class="flex w-4 items-center justify-center">
|
|
|
|
|
<CircleAlert class="h-3.5 w-3.5 text-red-500 group-hover:hidden" />
|
|
|
|
|
|
2026-05-01 18:36:29 +02:00
|
|
|
<div class="hidden group-hover:flex">
|
2026-03-05 08:52:22 +01:00
|
|
|
<ActionIcon
|
|
|
|
|
iconSize="h-2.5 w-2.5"
|
|
|
|
|
icon={RotateCw}
|
|
|
|
|
tooltip="Retry loading model"
|
|
|
|
|
class="h-3 w-3 text-red-500 hover:text-foreground"
|
|
|
|
|
onclick={() => modelsStore.loadModel(option.model)}
|
2026-05-01 18:36:29 +02:00
|
|
|
stopPropagationOnClick
|
2026-03-05 08:52:22 +01:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-03-25 11:02:32 +01:00
|
|
|
{:else if isSleeping}
|
|
|
|
|
<div class="flex w-4 items-center justify-center">
|
|
|
|
|
<span class="h-2 w-2 rounded-full bg-orange-400 group-hover:hidden"></span>
|
|
|
|
|
|
|
|
|
|
<div class="hidden group-hover:flex">
|
|
|
|
|
<ActionIcon
|
|
|
|
|
iconSize="h-2.5 w-2.5"
|
|
|
|
|
icon={PowerOff}
|
|
|
|
|
tooltip="Unload model"
|
|
|
|
|
class="h-3 w-3 text-red-500 hover:text-red-600"
|
|
|
|
|
onclick={(e) => {
|
|
|
|
|
e?.stopPropagation();
|
|
|
|
|
modelsStore.unloadModel(option.model);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-03-05 08:52:22 +01:00
|
|
|
{:else if isLoaded}
|
|
|
|
|
<div class="flex w-4 items-center justify-center">
|
|
|
|
|
<span class="h-2 w-2 rounded-full bg-green-500 group-hover:hidden"></span>
|
|
|
|
|
|
2026-05-01 18:36:29 +02:00
|
|
|
<div class="hidden group-hover:flex">
|
2026-03-05 08:52:22 +01:00
|
|
|
<ActionIcon
|
|
|
|
|
iconSize="h-2.5 w-2.5"
|
|
|
|
|
icon={PowerOff}
|
|
|
|
|
tooltip="Unload model"
|
|
|
|
|
class="h-3 w-3 text-red-500 hover:text-red-600"
|
|
|
|
|
onclick={() => modelsStore.unloadModel(option.model)}
|
2026-05-01 18:36:29 +02:00
|
|
|
stopPropagationOnClick
|
2026-03-05 08:52:22 +01:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{:else}
|
|
|
|
|
<div class="flex w-4 items-center justify-center">
|
|
|
|
|
<span class="h-2 w-2 rounded-full bg-muted-foreground/50 group-hover:hidden"></span>
|
|
|
|
|
|
2026-05-01 18:36:29 +02:00
|
|
|
<div class="hidden group-hover:flex">
|
2026-03-05 08:52:22 +01:00
|
|
|
<ActionIcon
|
|
|
|
|
iconSize="h-2.5 w-2.5"
|
|
|
|
|
icon={Power}
|
|
|
|
|
tooltip="Load model"
|
|
|
|
|
class="h-3 w-3"
|
|
|
|
|
onclick={() => modelsStore.loadModel(option.model)}
|
2026-05-01 18:36:29 +02:00
|
|
|
stopPropagationOnClick
|
2026-03-05 08:52:22 +01:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|