diff --git a/apps/host/server/engine-step.mjs b/apps/host/server/engine-step.mjs index da774247..1274c7b5 100644 --- a/apps/host/server/engine-step.mjs +++ b/apps/host/server/engine-step.mjs @@ -75,8 +75,11 @@ export function createEngineStep({ control, signal = null, onChange = () => {} } const modelRemaining = Number.isFinite(model?.remaining_gb) ? model.remaining_gb : null; const active = !['done', 'current', 'skipped', 'failed'].includes(part.state); const engineRemaining = active || part.state === 'done' ? Math.max(0, part.total_gb - part.done_gb) : 0; + /* The install knows its files (strata_mcp files_progress): the model's parts and the picture reader, each counted. Without that, one + model part from the combined figures. The engine is added either way. */ + const own = Array.isArray(install.parts) && install.parts.some(p => p?.kind === 'model') ? install.parts.filter(p => p?.kind !== 'engine') : null; const parts = [ - { kind: 'model', name: model?.file ?? install.model ?? 'Model', state: install.running === false ? 'done' : 'downloading', done_gb: modelDone ?? 0, total_gb: round((modelDone ?? 0) + (modelRemaining ?? 0)) }, + ...(own ?? [{ kind: 'model', name: model?.file ?? install.model ?? 'Model', state: install.running === false ? 'done' : 'downloading', done_gb: modelDone ?? 0, total_gb: round((modelDone ?? 0) + (modelRemaining ?? 0)) }]), { ...part }, ]; const merged = { ...install, engine: { ...part }, parts }; diff --git a/apps/host/server/native-control.mjs b/apps/host/server/native-control.mjs index a7c1c8f9..1a99dbba 100644 --- a/apps/host/server/native-control.mjs +++ b/apps/host/server/native-control.mjs @@ -355,7 +355,7 @@ return {summary:result.summary??'Deleted',removed:result.plan?.gb??null};} const room=args.resourceProfile==='work'; return autotuner.start(job,job.kind==='recheck'?'recheck':'tune',{configPath:path,presetId:args.presetId,mode:args.mode,use:args.use,goal:room?'room':'speed',leaveRam:room?20:0,allowSmallDifferences:args.allowSmallDifferences===true,name:args.name},{onProgress:p=>{job.summary=p.text??job.summary;emit();}}); } - function operation(kind,args={}){if(!['install','load','benchmark','tune','autotune','recheck','calibrate','update-engine','update-strata','rollback','remove'].includes(kind))throw new Error('Choose a supported native operation.');if(!snapshot.available)throw new Error(snapshot.error??'Connect the native Strata installation first.');if(kind==='install'||kind==='load'){const refusal=engineRefusal(snapshot.catalog,args.model,snapshot.engineInfo);if(refusal)throw new Error(refusal);}return begin(kind,job=>kind==='install'?install(job,args):kind==='load'?loadEngine(job,args):kind==='benchmark'?benchmark(job,args):kind==='tune'?tune(job,args):kind==='autotune'||kind==='recheck'?autotune(job,args):kind==='remove'?removeModel(job,args):program(job,args),{guided:args.guided===true,model:args.model});} + function operation(kind,args={}){if(!['install','load','benchmark','tune','autotune','recheck','calibrate','update-engine','update-strata','rollback','remove'].includes(kind))throw new Error('Choose a supported native operation.');if(!snapshot.available)throw new Error(snapshot.error??'Connect the native Strata installation first.');if(kind==='install'||kind==='load'){const refusal=engineRefusal(snapshot.catalog,args.model,snapshot.engineInfo);if(refusal)throw new Error(refusal);}return begin(kind,job=>kind==='install'?install(job,args):kind==='load'?loadEngine(job,args):kind==='benchmark'?benchmark(job,args):kind==='tune'?tune(job,args):kind==='autotune'||kind==='recheck'?autotune(job,args):kind==='remove'?removeModel(job,args):program(job,args),{guided:args.guided===true,model:args.model,...(args.family?{family:args.family}:{})});} async function cancel(id){const job=jobs.get(id);if(!job||job.state!=='running')throw new Error('This operation is no longer running.');if(job.kind==='install'){job.engineAbort?.abort();await tool('strata_install',{cancel:true});}else if(job.abort)job.abort.abort();else if(job.process){if(!['tune','calibrate','autotune','recheck'].includes(job.kind))throw new Error('File updates cannot be cancelled safely while files are being replaced.');job.state='cancelled';await stopProcess(job.process);}job.state='cancelled';job.summary=job.kind==='install'?'Stopped. Completed downloads are kept.':'Stopped.';emit();return state();} async function close(){closing=true;clearInterval(timer);const installing=packaged&&child&&[...jobs.values()].some(j=>j.kind==='install'&&j.state==='running');if(installing)await send('tools/call',{name:'strata_install',arguments:{cancel:true}},15000).catch(()=>{});const operations=[];for(const job of jobs.values()){job.abort?.abort();if(job.process)operations.push(stopProcess(job.process));if(job.state==='running')job.state='cancelled';}await Promise.all(operations);await Promise.all([...instances.keys()].map(id=>unload(id,true).catch(()=>{})));disconnect();} // Remove nonserializable process references from public jobs. diff --git a/apps/host/src/components/DownloadParts.tsx b/apps/host/src/components/DownloadParts.tsx new file mode 100644 index 00000000..0827ad02 --- /dev/null +++ b/apps/host/src/components/DownloadParts.tsx @@ -0,0 +1,17 @@ +import { tr } from '../lib/i18n'; + +export interface InstallPart { kind?: string; name?: string; state?: string; done_gb?: number; total_gb?: number; files_done?: number; files_total?: number } + +/** + * The parts of a download, one line each: the model (with "2/4" when it comes in parts), the picture reader, the engine. A model in several + * parts is only downloaded when every line says Done, so a person can see which part is under way instead of one bar that restarts. + */ +export function DownloadParts({ parts }: { parts: InstallPart[] | undefined }) { + if (!parts || parts.length < 2) return null; + return ; +} diff --git a/apps/host/src/components/GuidedSetup.tsx b/apps/host/src/components/GuidedSetup.tsx index 15682632..a8586cee 100644 --- a/apps/host/src/components/GuidedSetup.tsx +++ b/apps/host/src/components/GuidedSetup.tsx @@ -12,7 +12,10 @@ import { nativeAction, useNative, type NativeJob } from '../lib/native'; import { completeSetup, completeSetupStep, go, newSession, openSetup, selectRemoteModel, setSettingsSection, useStore } from '../lib/store'; import type { LocalModelFolder, SetupState } from '../lib/types'; import { downloadCounter, modelFolderLabel, onboardingError } from '../lib/onboarding-download'; -import { installProgress, useDownloadEta } from '../lib/download-eta'; +import { installProgress, installStage, stageText, useDownloadEta } from '../lib/download-eta'; +import { VersionPicker } from './VersionPicker'; +import { DownloadParts } from './DownloadParts'; +import { recommendedVersions } from '../lib/native-fit'; import { nativeCatalogModels, catalogVersionLabel } from '../lib/native-catalog'; type Choices = NonNullable['onboarding']>; function radioKeys(event: KeyboardEvent) { if (!['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Home', 'End'].includes(event.key)) @@ -161,6 +164,12 @@ export function GuidedSetup() { } }); return () => { cancelled = true; }; }, [step, plan, preparing, native?.available, version?.id, context, directory]); + const recommendedCards = recommendedVersions(selectedFamily?.sizes ?? []).map(x => x.v); + // The recommended four first, then a list with every other version (the Models page's version list); a family without a recommended set shows them all. + const cards = recommendedCards.length ? recommendedCards : selectedFamily?.sizes ?? []; + const others = recommendedCards.length ? (selectedFamily?.sizes ?? []).filter(v => !recommendedCards.includes(v)) : []; + const readyIds = new Set((native?.installed?.models ?? []).filter(m => m.ready).map(m => m.model)); + const versionCard = (v: NonNullable) => ; const counter = downloadCounter(plan?.plan?.download_gb ?? version?.download_gb, progress, preparing); const eta = useDownloadEta(preparing ? progress : undefined, installJob?.id); const title = step === 1 ? 'State of the art. At home.' : step === 2 ? 'Select the model you want to run.' : step === 3 ? 'Downloading the model...' : tuneJob?.state === 'running' ? 'A little tuning. A better fit.' : 'How you would like to work with Strata?'; @@ -179,13 +188,14 @@ export function GuidedSetup() {
{tr("Model")}
({ value: String(n), label: `${n / 1024}K` }))} onChange={value => setContext(Number(value))}/>
{tr(!version || version.needsNewerEngine ?

{tr("This model needs a newer engine. Update your engine or import a local GGUF for this model.")}

: null)}
{tr("Choose a version")}{tr(version ? `${catalogVersionLabel(version)} selected` : '')}
-
{tr(selectedFamily.sizes.map(v => ))}
+
{tr(cards.map(v => versionCard(v)))}
+ {tr(others.length ?
g.usable !== false).map(g => g.vram_gb)) } : null} downloaded={readyIds} showRecommended={false} moreLabel="More versions" onSelect={id => { setSize(id); setPlan(null); }} onOwnGguf={() => setFolderOpen(true)}/>
: null)}
{tr(directory ? 'Your model folder' : 'Already downloaded the model?')}{tr(directory || "Choose the folder and we'll start your models with Strata.")}
setFolderOpen(v => !v)}>{tr(folderOpen ? 'Close' : directory ? 'Change' : 'Choose folder')}
{tr(folderOpen ? void perform(async () => { await nativeAction('directory', { directory: path }); setDirectory(path); setFolderOpen(false); setPlan(null); })}/> : null)} :
{tr("Connect your Strata installation")} void skip(false, 'Engine')}>{tr("Connect engine")}
)}
: step === 3 ?
{tr(selectedFamily?.title)}{tr(version ? catalogVersionLabel(version) : '')}{tr(version?.model)}
- {tr(preparing ?
{tr(progress ? 'Downloading model files…' : 'Preparing your model…')}
{tr(progress ? : )}
{tr(progress ? `${progress.percent ?? 0}%${Number.isFinite(progress.done_gb) && Number.isFinite(progress.total_gb) ? ` · ${progress.done_gb!.toFixed(1)} / ${progress.total_gb!.toFixed(1)} GB` : ''}` : 'Getting files ready…')}
{tr(eta ? {eta} : null)}
: <>{tr(stopped ? : null)}{tr(plan?.plan?.disk_short ? : null)})} + {tr(preparing ?
{tr(progress ? stageText(installStage(installJob?.result?.install)) : 'Preparing your model…')}
{tr(progress ? : )}
{tr(progress ? `${progress.percent ?? 0}%${Number.isFinite(progress.done_gb) && Number.isFinite(progress.total_gb) ? ` · ${progress.done_gb!.toFixed(1)} / ${progress.total_gb!.toFixed(1)} GB` : ''}` : 'Getting files ready…')}
{tr(eta ? {eta} : null)}
: <>{tr(stopped ? : null)}{tr(plan?.plan?.disk_short ? : null)})} {tr("Save to")}{tr(modelFolderLabel(folder))}{tr(!preparing ? : null)}
:
diff --git a/apps/host/src/components/NativeModels.tsx b/apps/host/src/components/NativeModels.tsx index b852f935..42ef8c09 100644 --- a/apps/host/src/components/NativeModels.tsx +++ b/apps/host/src/components/NativeModels.tsx @@ -6,7 +6,9 @@ import { FamilySwitch } from './FamilySwitch'; import { PcFitCard } from './PcFitCard'; import { fitOn } from '../lib/native-fit'; import { Btn, Dialog, ErrorNotice, Icon, Select } from './ui'; -import { installProgress, useDownloadEta } from '../lib/download-eta'; +import { installProgress, installStage, stageText, useDownloadEta } from '../lib/download-eta'; +import { useKept } from '../lib/kept-state'; +import { DownloadParts } from './DownloadParts'; import { sizeGb } from '../lib/format'; import { NativeDeleteDialog } from './NativeDelete'; import { plainFailureText } from '../lib/plain-errors'; @@ -31,12 +33,14 @@ export function NativeModels({ onOtherModels, onReady, onImport, onConnectEngine onReady?: () => void; }) { const native = useNative(), imageLibrary = useStore(s => s.imageModels), hardware = useStore(s => s.hardware); - const [family, setFamily] = useState(''), [size, setSize] = useState(''), [context, setContext] = useState(32768), [vision, setVision] = useState('yes'); + // The choices are kept while the page is closed (Models -> Monitor -> Models used to start them over and a person lost track of what was downloading). + const [family, setFamily] = useKept('models.family', ''), [size, setSize] = useKept('models.size', ''), [context, setContext] = useKept('models.context', 32768), [vision, setVision] = useKept('models.vision', 'yes'); const manual = useStore(s => s.setup?.choices?.onboarding?.manual ?? false); - const [expert, setExpert] = useState(manual), [multiple, setMultiple] = useState(false), [gpus, setGpus] = useState([]), [kv, setKv] = useState('int8'), [lowRam, setLowRam] = useState('auto'), [split, setSplit] = useState('auto'), [deviceChoice, setDeviceChoice] = useState('auto'); - const [cardsKey, setCardsKey] = useState(null); - const [resourceProfile, setResourceProfile] = useState<'work' | 'performance'>('work'); - const [pending, setPending] = useState(false), [error, setError] = useState(''), [plan, setPlan] = useState | null>(null), [loadedError, setLoadedError] = useState(''), [tuneOpen, setTuneOpen] = useState(false), [jobId, setJobId] = useState(''), [manage, setManage] = useState(false); + const [expert, setExpert] = useKept('models.expert', manual), [multiple, setMultiple] = useKept('models.multiple', false), [gpus, setGpus] = useKept('models.gpus', []), [kv, setKv] = useKept('models.kv', 'int8'), [lowRam, setLowRam] = useKept('models.lowRam', 'auto'), [split, setSplit] = useKept('models.split', 'auto'), [deviceChoice, setDeviceChoice] = useKept('models.device', 'auto'); + const [cardsKey, setCardsKey] = useKept('models.cards', null); + const [resourceProfile, setResourceProfile] = useKept<'work' | 'performance'>('models.profile', 'work'); + const [pending, setPending] = useState(false), [error, setError] = useState(''), [plan, setPlan] = useState | null>(null), [loadedError, setLoadedError] = useState(''), [tuneOpen, setTuneOpen] = useState(false), [jobId, setJobId] = useKept('models.job', ''), [manage, setManage] = useState(false); + const [toastedJob, setToastedJob] = useKept('models.toasted', ''), [appliedSig, setAppliedSig] = useKept('models.applied', ''); const presetPending = useRef(false); const [deleting, setDeleting] = useState(null); const families = nativeCatalogModels(native?.catalog?.families ?? []); @@ -56,15 +60,11 @@ export function NativeModels({ onOtherModels, onReady, onImport, onConnectEngine const keptUse = keptModels.map(i => { const s = sizeOf(i.model); const card = pcGpus.find(g => g.index === i.gpus[0]); const f = s && pcRam ? fitOn(s, { ram_gb: pcRam, vram_gb: card?.vram_gb ?? pcVram }) : null; return { gpus: i.gpus, ram: f?.ramUseGb ?? 0, vram: f?.vramUseGb ?? 0 }; }); const keptRam = keptUse.reduce((n, u) => n + u.ram, 0); const keptVramOn = (cards: number[]) => keptUse.filter(u => u.gpus.some(g => cards.includes(g))).reduce((n, u) => n + u.vram, 0); + // The versions that are really on this computer: a config whose files are all there (every part of a model in parts). + const readyIds = useMemo(() => new Set(downloaded.filter(m => m.ready).map(m => m.model)), [downloaded]); + // What a running job works on, by its name in the list: "Qwen3.8-Flash-Next · Gyro · Smallest". + const jobLabel = (j: NativeJob) => { const v = allSizes.find(s => s.id === j.model || (s.model === j.model && (!j.family || s.sourceFamily === j.family))); const f = v && families.find(x => x.sizes.includes(v)); return v ? [f?.title, catalogVersionLabel(v)].filter(Boolean).join(' · ') : ''; }; const loadedSelected = native?.instances.find(i => i.model === selectedSize?.id && i.status === 'ready'); - // A model that is already on this PC loads as it was prepared: the page shows its settings, so loading it never asks to download. - useEffect(() => { if (installed?.ready) { - if (installed.context) - setContext(installed.context); - if (installed.kv) - setKv(installed.kv as typeof kv); - setLowRam((installed.lowRamMode ?? 'auto') as typeof lowRam); - } }, [installed?.model, installed?.ready, installed?.context, installed?.kv, installed?.lowRamMode]); // What the running model was really started with is what the page shows: after Load the highlight must still be the profile that was applied. useEffect(() => { if (loadedSelected?.resourceProfile) setResourceProfile(loadedSelected.resourceProfile); }, [loadedSelected?.id, loadedSelected?.resourceProfile]); @@ -93,7 +93,8 @@ export function NativeModels({ onOtherModels, onReady, onImport, onConnectEngine const gpuNumbers = (text: string) => text.replace(/\(card (\d+)\)/g, (_m, n) => `(GPU ${Number(n) + 1})`); // The fit sentence for a card choice, less what the kept models take of RAM and of that card's memory. const lessKept = (words: string, cards: number[]) => { const gone = Math.round(keptRam + keptVramOn(cards)); return gone > 0 ? words.replace(/of the (\d+) GB available/, (_m, n) => `of the ${Math.max(0, Number(n) - gone)} GB available`) : words; }; - useEffect(() => { setCardsKey(null); }, [selectedSize?.id]); + const shownSize = useRef(selectedSize?.id); + useEffect(() => { if (shownSize.current !== selectedSize?.id) { shownSize.current = selectedSize?.id; setCardsKey(null); } }, [selectedSize?.id]); const values = useMemo(() => ({ family: selectedSize?.sourceFamily, model: selectedSize?.model, context, vision: selectedSize?.images ? vision : 'no', kv, low_ram: lowRam, resourceProfile, ...(expert && gpus.length ? { gpus: gpus.join(',') } : cardsGpus.length > 1 ? { gpus: cardsGpus.join(',') } : cardsGpus.length === 1 ? { gpu: cardsGpus[0] } : {}), loadAfter: true, multiple: expert && multiple }), [selectedSize?.sourceFamily, selectedSize?.model, context, vision, kv, lowRam, resourceProfile, gpus.join(','), cardsGpus.join(','), expert, multiple]); const downloadValues = { ...values, vision: selectedSize?.images ? 'yes' : 'no', loadVision: selectedSize?.images ? vision : 'no' }; useEffect(() => { if (!native?.catalog || family) @@ -102,19 +103,35 @@ export function NativeModels({ onOtherModels, onReady, onImport, onConnectEngine setSize(f.sizes.find(s => s.id === current?.model)?.id ?? f.sizes.find(s => have.has(s.id))?.id ?? f.sizes.find(s => s.model === rec.model)?.id ?? f.sizes[0]?.id ?? ''); setContext(('context' in rec ? rec.context : undefined) ?? 32768); } }, [native?.catalog]); - useEffect(() => { if (presetPending.current) { - presetPending.current = false; - return; - } if (installed) { - setContext(installed.context ?? 32768); - setVision(installed.visionEnabled === false || installed.images === 'off' ? 'no' : installed.visionDevice ?? installed.images ?? 'yes'); - setKv(installed.kv ?? 'int8'); - setLowRam(installed.lowRamMode ?? 'auto'); - // A model never tuned has no saved choice: keep the page's own (Leave 20%) rather than flipping to Full performance. - if (installed.resourceProfile && !loadedSelected?.resourceProfile) - setResourceProfile(installed.resourceProfile); - } }, [installed?.model, installed?.context, installed?.kv, installed?.images, installed?.visionEnabled, installed?.visionDevice, installed?.lowRamMode, installed?.resourceProfile]); - useEffect(() => { if (jobId && job?.state === 'done' && (job.kind === 'load' || job.kind === 'install')) { + // The version that is selected: a model already on this PC shows the settings it was prepared with (so loading it never asks to download); + // a model that is not yet downloaded starts with Read pictures ON (owner rule: pictures on by default). This runs when the SELECTION or the + // installed settings change, not when the page opens again: coming back from another tab keeps what was chosen. + useEffect(() => { + if (presetPending.current) { + presetPending.current = false; + return; + } + if (!selectedSize) + return; + const sig = installed ? ['have', installed.model, installed.ready, installed.context, installed.kv, installed.images, installed.visionEnabled, installed.visionDevice, installed.lowRamMode, installed.resourceProfile].join('|') : `new|${selectedSize.id}`; + if (sig === appliedSig) + return; + setAppliedSig(sig); + if (installed) { + if (installed.context) + setContext(installed.context); + setVision(installed.visionEnabled === false || installed.images === 'off' ? 'no' : installed.visionDevice ?? installed.images ?? 'yes'); + setKv(installed.kv ?? 'int8'); + setLowRam(installed.lowRamMode ?? 'auto'); + // A model never tuned has no saved choice: keep the page's own (Leave 20%) rather than flipping to Full performance. + if (installed.resourceProfile && !loadedSelected?.resourceProfile) + setResourceProfile(installed.resourceProfile); + } + else + setVision('yes'); + }, [selectedSize?.id, installed?.model, installed?.ready, installed?.context, installed?.kv, installed?.images, installed?.visionEnabled, installed?.visionDevice, installed?.lowRamMode, installed?.resourceProfile]); + useEffect(() => { if (jobId && job?.state === 'done' && job.id !== toastedJob && (job.kind === 'load' || job.kind === 'install')) { + setToastedJob(job.id); selectRemoteModel(null); pushToast('success', 'Model ready', 'Start a new chat when you’re ready.'); } }, [job?.state]); @@ -153,7 +170,7 @@ export function NativeModels({ onOtherModels, onReady, onImport, onConnectEngine {tr(selectedSize ? <>
{tr("Version")} { const f = families.find(f => f.family === v.family || f.sizes.some(s => s.sourceFamily === v.family)); if (!f) return; presetPending.current = true; setFamily(f.family); setSize(f.sizes.find(s => s.model === v.model && (s.sourceFamily === v.family || f.family === v.family))?.id ?? ''); setContext(v.context ?? 32768); setVision(v.vision ?? 'no'); setKv(v.kv ?? 'int8'); setLowRam(v.low_ram ?? 'auto'); }}/> setManage(true)}>{tr("Manage models")}
-
{ const f = families.find(f => f.sizes.some(s => s.id === id)); if (f) { setFamily(f.family); setSize(id); setError(''); } }} onOwnGguf={() => (onImport ?? onOtherModels)()}/>
+
{ const f = families.find(f => f.sizes.some(s => s.id === id)); if (f) { setFamily(f.family); setSize(id); setError(''); } }} onOwnGguf={() => (onImport ?? onOtherModels)()}/>
{tr(noFit ?

{tr("May run slower \u00B7 Model data can be read from SSD.")}

: null)}
{tr("Conversation context")} setVision(e.target.checked ? 'yes' : 'no')}/>{tr("Read pictures ")}{tr("On by default")}{tr("Understand photos, screenshots and charts. The picture files download automatically. Turn it off to save memory.")}{tr(expert && vision !== 'no' ?