Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree (570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base = the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main). Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details, conflict table and left-out files are in docs/upstream.md. Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61), docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out. scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run"). Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR macros on. No GPU run, no quality gate. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
102 lines
7.2 KiB
TypeScript
102 lines
7.2 KiB
TypeScript
import {localeTag} from '../lib/i18n';
|
||
import { tr } from '../lib/i18n';
|
||
import { useEffect, useState } from 'react';
|
||
import { Btn, Dialog, ErrorNotice, Icon } from './ui';
|
||
import { api } from '../lib/client';
|
||
import { addLocalModel } from '../lib/store';
|
||
import { sizeGb } from '../lib/format';
|
||
import type { LocalModelFolder, LocalModelPreview } from '../lib/types';
|
||
const fileSize = (bytes: number) => bytes < 1024 ** 2 ? `${Math.max(1, Math.round(bytes / 1024))} KB` : bytes < 1024 ** 3 ? `${Math.round(bytes / 1024 ** 2)} MB` : sizeGb(bytes / 1024 ** 3);
|
||
export function LocalModelImport({ open, directory, onClose, onChoose }: {
|
||
open: boolean;
|
||
directory: string;
|
||
onClose: () => void;
|
||
onChoose: (id: string) => void;
|
||
}) {
|
||
const [folder, setFolder] = useState<LocalModelFolder | null>(null), [path, setPath] = useState(''), [preview, setPreview] = useState<LocalModelPreview | null>(null);
|
||
const [name, setName] = useState(''), [pending, setPending] = useState(false), [error, setError] = useState('');
|
||
useEffect(() => {
|
||
if (open) {
|
||
setPreview(null);
|
||
setError('');
|
||
void browse(directory);
|
||
}
|
||
}, [open]);
|
||
async function browse(input: string) {
|
||
setPending(true);
|
||
setError('');
|
||
try {
|
||
const next = await api.get<LocalModelFolder>(`/api/local-models/browse?directory=${encodeURIComponent(input)}`);
|
||
setFolder(next);
|
||
setPath(next.directory);
|
||
setPreview(null);
|
||
}
|
||
catch (e) {
|
||
setPath(input);
|
||
setError(e instanceof Error ? e.message : String(e));
|
||
}
|
||
finally {
|
||
setPending(false);
|
||
}
|
||
}
|
||
async function inspect(file: string) {
|
||
setPending(true);
|
||
setError('');
|
||
try {
|
||
const next = await api.post<LocalModelPreview>('/api/local-models/inspect', { path: file });
|
||
setPreview(next);
|
||
setName(next.variant.name);
|
||
}
|
||
catch (e) {
|
||
setError(e instanceof Error ? e.message : String(e));
|
||
}
|
||
finally {
|
||
setPending(false);
|
||
}
|
||
}
|
||
async function useModel() {
|
||
if (!preview)
|
||
return;
|
||
setPending(true);
|
||
setError('');
|
||
try {
|
||
const id = await addLocalModel(preview.variant.local!.path, name);
|
||
onChoose(id);
|
||
onClose();
|
||
}
|
||
catch (e) {
|
||
setError(e instanceof Error ? e.message : String(e));
|
||
}
|
||
finally {
|
||
setPending(false);
|
||
}
|
||
}
|
||
const close = () => {
|
||
if (!pending)
|
||
onClose();
|
||
};
|
||
return <Dialog open={open} title={tr("Use a local model")} className="local-model-dialog" onClose={close} actions={<><Btn disabled={pending} onClick={preview ? () => { setPreview(null); setError(''); } : close}>{tr(preview ? 'Choose another file' : 'Cancel')}</Btn>{tr(preview ? <Btn variant="primary" icon="models" disabled={pending || !name.trim()} onClick={() => void useModel()}>{tr(pending ? 'Adding…' : 'Use this model')}</Btn> : null)}</>}>
|
||
{preview ? <div className="local-model-review">
|
||
<div className="local-model-review__identity"><Icon name="model-file" size={25}/><div><strong>{preview.variant.name}</strong><small>{tr("Local GGUF \u00B7 ")}{tr(preview.variant.local!.shards === 1 ? 'One file' : `${preview.variant.local!.shards} files found`)}</small></div></div>
|
||
<dl className="local-model-facts"><div><dt>{tr("Architecture")}</dt><dd>{tr(preview.variant.local!.architecture)}</dd></div><div><dt>{tr("Quantization")}</dt><dd>{tr(preview.variant.quant)}</dd></div><div><dt>{tr("Size")}</dt><dd>{tr(fileSize(preview.variant.local!.files.reduce((n, f) => n + f.bytes, 0)))}</dd></div><div><dt>{tr("Context limit")}</dt><dd>{tr(Math.floor(preview.variant.local!.contextLength / 1024).toLocaleString(localeTag()))}{tr("K tokens")}</dd></div></dl>
|
||
<label className="local-model-name">{tr("Display name")}<input className="st-input" value={name} maxLength={160} onChange={e => setName(e.target.value)} disabled={pending}/></label>
|
||
<details className="local-model-files"><summary>{tr(preview.variant.local!.shards === 1 ? 'File location' : 'Model files')}</summary><code>{preview.variant.local!.path}</code>{tr(preview.files.length > 1 ? <ul>{tr(preview.files.map(file => <li key={file}>{tr(file)}</li>))}</ul> : null)}</details>
|
||
<p className="small muted">{tr("Strata uses these files in place. You can load the model after adding it.")}</p>
|
||
<p className="local-model-compatibility small"><Icon name="info" size={16}/><span>{tr("Custom model \u00B7 engine compatibility is checked when loading. Memory estimates use the file\u2019s metadata.")}</span></p>
|
||
{tr(!preview.variant.local!.hasChatTemplate ? <p className="small muted">{tr("No chat template is declared; response formatting depends on the engine.")}</p> : null)}
|
||
</div> : <div className="local-model-browser">
|
||
<p className="small muted">{tr("Choose the model’s .gguf file. For a split model, choose any shard; Strata finds the first and checks the full set.")}</p>
|
||
<form className="local-model-browser__path" onSubmit={e => {
|
||
e.preventDefault();
|
||
if (!pending)
|
||
void (/\.gguf$/i.test(path.trim()) ? inspect(path) : browse(path));
|
||
}}><input className="st-input" aria-label={tr("Model file or folder path")} placeholder={tr("Model file or folder path")} value={path} disabled={pending} onChange={e => setPath(e.target.value)}/><Btn type="submit" disabled={pending || !path.trim()}>{tr("Go")}</Btn></form>
|
||
<div className="local-model-browser__navigation"><div>{folder?.shortcuts.map(shortcut => <Btn key={shortcut.path} size="sm" icon="folder" disabled={pending} onClick={() => void browse(shortcut.path)}>{tr(shortcut.name)}</Btn>)}</div><Btn size="sm" disabled={pending || !folder?.parent} onClick={() => folder?.parent && void browse(folder.parent)}>{tr("Up a folder")}</Btn></div>
|
||
<div className="local-model-browser__list" aria-label={tr("Local model files")} aria-busy={pending}>{pending ? <p className="small muted" role="status">{tr("Reading files\u2026")}</p> : folder?.entries.length ? folder.entries.map(entry => <button key={entry.path} className="local-model-file" aria-label={tr("{0} {1}", [entry.kind === 'folder' ? tr('Open folder') : tr('Choose file'), entry.name])} onClick={() => void (entry.kind === 'folder' ? browse(entry.path) : inspect(entry.path))}><Icon name={entry.kind === 'folder' ? 'folder' : 'model-file'} size={19}/><span title={entry.name}>{entry.name}</span>{tr(entry.kind === 'folder' ? <Icon name="chevron" size={15}/> : <small>{tr(fileSize(entry.bytes ?? 0))}</small>)}</button>) : <div className="local-model-browser__empty"><Icon name="folder" size={26}/><strong>{tr("No GGUF files here")}</strong><p className="small muted">{tr("Open another folder or enter a model\u2019s full path above.")}</p></div>}</div>
|
||
{tr(folder?.truncated ? <p className="small muted">{tr("Showing the first 1,000 items. Enter a path to open a specific file.")}</p> : null)}
|
||
<p className="xs muted">{tr("Only folders and GGUF files are shown. LoRA adapters and image projectors need separate support.")}</p>
|
||
</div>}
|
||
{tr(error ? <ErrorNotice message={error} next={tr("Choose a complete text model GGUF file.")}/> : null)}
|
||
</Dialog>;
|
||
}
|