import { useEffect, useRef, useState } from 'react'; import { tr } from '../lib/i18n'; import { Icon } from './ui'; import { FloatingMenu } from './FloatingMenu'; import { cx } from '../lib/format'; import { versionNote, type CatalogVersion } from '../lib/native-catalog'; import { nvfp4Version } from '../lib/native-names'; import { fitOn, recommendedVersions, versionFit, versionGroups, type CacheChoice, type FitHardware, type PcPick } from '../lib/native-fit'; /** The name a version goes by in the list: the quantization, with the maker only where the quantization alone would be ambiguous. */ export function versionName(v: CatalogVersion): string { switch (v.sourceFamily) { case 'swift': return `Swift ${v.model}`; case 'unsloth': return `Unsloth ${v.model}`; case 'nvfp4': return tr(nvfp4Version(v.model)?.name ?? v.model); case 'coder': return `Coder ${v.model}`; default: return v.model; } } /** Who made a version (Details only): the family name of the quantization, a proper name in every language. */ const MAKERS: Record = { qwen: 'GSQ-RCO', coder: 'GSQ-RCO', swift: 'Swift', unsloth: 'Unsloth', gyro: 'Gyro', nvfp4: 'NVFP4' }; const gb = (n: number) => `${Number.isInteger(n) ? n : n.toFixed(1)} GB`; const whole = (n: number) => `${Math.round(n)} GB`; /** * Where the versions of the chosen base model are listed, each exactly once. At the top: the versions we recommend (the pick for this PC first; no "Recommended" tag since 11-02, the order says it) and the versions already downloaded (tagged "Downloaded"). Below, folded under "More * versions": all the others. A row is the name, small tags, a word only where one is needed ("may run slower" for a version that does * not fit in memory; a version that fits says nothing: see `versionFit`) and the size. The maker and the * memory it needs are behind "Show details" (open from the start in Expert mode). The other base models are not in this list: they * appear when picked at the top of the page. */ export function VersionPicker({ versions, selectedId, hardware, onSelect, onOwnGguf, downloaded, showRecommended = true, moreLabel, pick, cache, details: detailsOpen = false }: { /** The versions of the chosen base model. */ versions: CatalogVersion[]; selectedId: string; hardware: FitHardware | null | undefined; onSelect: (id: string) => void; onOwnGguf: () => void; /** The versions already on this computer (ready to load): each gets a small "Downloaded" tag. */ downloaded?: ReadonlySet; /** False where the recommended ones are shown elsewhere (the first-run page): the menu then holds only the others. */ showRecommended?: boolean; /** What the button says while the selected version is one of the recommended ones shown elsewhere. */ moreLabel?: string; /** The engine's own pick for this PC (catalog.recommendation). */ pick?: PcPick | null; /** The conversation context and cache format the person chose: the fit words follow them, as the This computer card does. */ cache?: CacheChoice | null; /** Start with the technical detail shown (Expert mode). */ details?: boolean; }) { const trigger = useRef(null); const [open, setOpen] = useState(false); const [details, setDetails] = useState(detailsOpen); useEffect(() => setDetails(detailsOpen), [detailsOpen]); const selected = versions.find(v => v.id === selectedId); // Where the recommended ones are shown outside the menu, the menu holds only the others. const rows = recommendedVersions(versions, pick); const apart = new Set(showRecommended ? [] : rows.map(x => x.v.id)); const recommendedIds = rows.map(x => x.v.id); const { top, more } = versionGroups(versions, apart, downloaded, recommendedIds); const shown = selected && !apart.has(selected.id) ? selected : undefined; // The folded part opens by itself when it holds the chosen version or when there is nothing above it. const [moreOpen, setMoreOpen] = useState(false); const foldedOpen = moreOpen || !top.length || more.some(v => v.id === selectedId); const need = (v: CatalogVersion, technical: boolean) => { const size = typeof v.fit_gb === 'number' && Number.isFinite(v.fit_gb) ? v.fit_gb : fitOn(v, hardware, true, cache).memoryGb; // the files without the lookup table: the figure the label uses if (technical) return tr("{0} RAM + VRAM", [gb(size)]); return tr("Needs {0} of memory", [whole(size)]); }; const row = (v: CatalogVersion) => { const on = v.id === selectedId, have = !!downloaded?.has(v.id); const state = versionFit(v, hardware, cache); const technical = [MAKERS[v.sourceFamily], need(v, true)].filter(Boolean).join(' · '); const note = versionNote(v.model); return ; }; // The open menu opens on the chosen version, not at the top of a long list. const menu = useRef(null); useEffect(() => { if (open) menu.current?.querySelector('.is-on')?.scrollIntoView({ block: 'nearest' }); }, [open]); return <> {tr(open ? setOpen(false)}>
{tr(top.length ?
{tr(top.map(row))}
: null)} {tr(more.length ?
{tr(top.length ? : null)} {tr(foldedOpen ?
{tr(more.map(row))}
: null)}
: null)}
: null)} ; }