diff --git a/apps/host/server/folder-dialog.mjs b/apps/host/server/folder-dialog.mjs index 2d07594d..1785d86b 100644 --- a/apps/host/server/folder-dialog.mjs +++ b/apps/host/server/folder-dialog.mjs @@ -182,13 +182,16 @@ export function chooserUnavailable(picked) { return { message: picked.reason, code: 'folder-chooser-unavailable', details: picked.detail }; } -/** A typed path stands in for the dialog: it must be an absolute directory that exists. */ -export async function typedFolder(value, { isAbsolute }) { - const text = typeof value === 'string' ? value.trim() : ''; +/** A typed path stands in for the dialog: it must be an absolute directory that exists. `fileType` (a RegExp on the name) also lets a + * file of that kind through (the model page takes a folder or one .gguf file). Quotes around the path (Windows "Copy as path") go. */ +export async function typedFolder(value, { isAbsolute, fileType = null }) { + let text = typeof value === 'string' ? value.trim() : ''; + if (text.length > 1 && /^(["'])[\s\S]*\1$/.test(text)) text = text.slice(1, -1).trim(); if (!text || text.includes('\0')) return null; - if (!isAbsolute(text)) throw new Error('Enter the full path of the folder.'); + if (!isAbsolute(text)) throw new Error(fileType ? 'Enter the full path of the folder or the file.' : 'Enter the full path of the folder.'); let info; - try { info = await stat(text); } catch { throw new Error('That folder does not exist.'); } - if (!info.isDirectory()) throw new Error('Choose a folder, not a file.'); + try { info = await stat(text); } catch { throw new Error(fileType ? 'That folder or file does not exist.' : 'That folder does not exist.'); } + if (info.isFile() && fileType?.test(text)) return text; + if (!info.isDirectory()) throw new Error(fileType ? 'Choose a folder, or a .gguf file.' : 'Choose a folder, not a file.'); return cleanChosenPath(text); } diff --git a/apps/host/server/index.mjs b/apps/host/server/index.mjs index fc3b1e86..0482c759 100644 --- a/apps/host/server/index.mjs +++ b/apps/host/server/index.mjs @@ -979,7 +979,7 @@ async function api(req, res, path, method, url) { return json(res,200,{path:file});} if(path==='/api/native/local/preview'&&method==='POST'){ /* "Use a local GGUF": pick (or type) the folder, and Control says what is in it. Nothing is copied or changed. */ - const typed=await typedFolder((await readBody(req)).path,{isAbsolute}); + const typed=await typedFolder((await readBody(req)).path,{isAbsolute,fileType:/\.gguf$/i}); const picked=typed?{path:typed}:await chooseFolder('Choose the folder that holds your GGUF files'); if(picked.unavailable){const u=chooserUnavailable(picked);return error(res,501,u.message,{code:u.code});}; if(picked.cancelled)return json(res,200,{cancelled:true}); diff --git a/apps/host/src/components/NativeLocalModel.tsx b/apps/host/src/components/NativeLocalModel.tsx index 7c68d038..2aea8555 100644 --- a/apps/host/src/components/NativeLocalModel.tsx +++ b/apps/host/src/components/NativeLocalModel.tsx @@ -8,18 +8,20 @@ import { nativeCatalogModels, catalogVersionLabel } from '../lib/native-catalog' import { sizeGb } from '../lib/format'; import { NativeProgress } from './NativeModels'; -interface Preview { path: string; preview: { file_count: number; total_bytes: number; file_set_status: string; issues: string[]; messages?: string[]; projectors?: { name: string; status: string; pinned: boolean; plain: string }[]; reads_pictures?: boolean; candidate_selection: { family: string; model: string } | null } } +interface Preview { path: string; preview: { model_dir?: string; plain_issues?: string[]; already_set_up?: { data_dir?: string | null; pack?: string | null } | null; file_count: number; total_bytes: number; file_set_status: string; issues: string[]; messages?: string[]; projectors?: { name: string; status: string; pinned: boolean; plain: string }[]; reads_pictures?: boolean; candidate_selection: { family: string; model: string } | null } } /** The words for why a folder of GGUF files cannot be used: a sentence and what to do, the checker's own codes under Details. */ function problem(issues: string[]): { message: string; next: string } { const has = (re: RegExp) => issues.some(i => re.test(i)); - if (has(/incomplete_or_invalid_shard_set|multiple_model_groups/)) - return { message: 'Some parts of this model are missing, or the folder holds more than one model.', next: 'Put every part of one model in one folder, then check again.' }; + if (has(/multiple_model_groups/)) + return { message: 'This folder holds more than one model.', next: 'Type the full path of the .gguf file of the one you want, or choose the folder of that model.' }; + if (has(/incomplete_or_invalid_shard_set/)) + return { message: 'Some parts of this model are missing.', next: 'Put every part of one model (all the -0000N-of-0000M files) in one folder, then check again.' }; if (has(/unsupported_architecture|unsupported_or_missing_architecture/)) return { message: 'This model type isn’t supported by the Strata engine.', next: 'Add it as a Custom model API instead: start it with llama-server, then open Settings > Models > Add model provider > Custom model API.' }; if (has(/unrecognized_or_unsupported_model_variant|expert_quantization|tokenizer/)) return { message: 'Strata can’t run these files yet.', next: 'Strata runs the Qwen3.8-Flash-Next models. Download one from Models, or choose a folder with its files.' }; - return { message: 'These files could not be checked.', next: 'Check that the folder holds complete GGUF files, then try again.' }; + return { message: 'These files could not be checked.', next: 'Check that the folder holds complete GGUF files, then try again. The file named under Details says what is wrong with it.' }; } /** "Use a local GGUF": choose the folder of a model you already have, Strata checks it, and prepares and loads it without copying @@ -47,13 +49,16 @@ export function NativeLocalModel({ onBack }: { onBack: () => void }) { catch (e) { setError(e instanceof Error ? e.message : String(e)); } finally { setPending(false); } } + /* Files that sit in a Strata data folder (/models/) with their prepared model data beside them: that folder is used as the data + * folder, so the prepared data is not made a second time. A folder the installer would not accept as a data folder is not passed. */ + const ownDataFolder = (() => { const d = checked?.preview.already_set_up?.pack ? checked.preview.already_set_up.data_dir : null; return d && /strata/i.test(d.split(/[\\/]/).filter(Boolean).pop() ?? '') ? d : null; })(); async function prepare() { if (!usable || !selection || !checked) return; setPending(true); setError(''); try { - const result = await nativeAction('operations', { kind: 'install', args: { family: selection.family, model: selection.model, gguf_dir: checked.path, context: native?.catalog?.recommendation?.context ?? 32768, vision: checked.preview.projectors?.some(p => p.status === 'ok' && p.pinned) && native?.visionReader ? 'yes' : 'no', kv: 'int8', loadAfter: true } }); + const result = await nativeAction('operations', { kind: 'install', args: { family: selection.family, model: selection.model, gguf_dir: checked.preview.model_dir ?? checked.path, ...(ownDataFolder ? { data_dir: ownDataFolder } : {}), context: native?.catalog?.recommendation?.context ?? 32768, vision: checked.preview.projectors?.some(p => p.status === 'ok' && p.pinned) && native?.visionReader ? 'yes' : 'no', kv: 'int8', loadAfter: true } }); setJobId(result.id); } catch (e) { setError(e instanceof Error ? e.message : String(e)); } @@ -64,8 +69,8 @@ export function NativeLocalModel({ onBack }: { onBack: () => void }) {

{tr("Use a local GGUF…")}

-

{tr("Already have a supported model on this computer? Choose the folder that holds its files. Strata checks them, prepares the model and loads it. Nothing is copied or downloaded.")}

- +

{tr("Already have a supported model on this computer? Choose the folder that holds its files, or one of its .gguf files. Strata checks them, prepares the model and loads it. Nothing is copied or downloaded.")}

+
void check('')}>{tr("Choose folder")} void check(typed)}>{tr(pending && !jobId ? 'Checking…' : 'Check files')}
{tr(checked ?
{tr(usable ? <> @@ -77,6 +82,8 @@ export function NativeLocalModel({ onBack }: { onBack: () => void }) { : <>

{tr(found!.message)}

{tr(found!.next)}

+ {tr(checked.preview.plain_issues?.map(m =>

{tr(m)}

))} + {tr(checked.preview.messages?.map(m =>

{tr(m)}

))} {tr(checked.preview.issues.length ?
{tr("Details")}
{checked.preview.issues.join(String.fromCharCode(10))}
: null)} )}
: null)} {tr(active ? : job?.state === 'error' ? : job?.state === 'done' ?

{tr(job.summary)}

: null)} diff --git a/apps/host/tests/folder-dialog.test.mjs b/apps/host/tests/folder-dialog.test.mjs index 0fde55a3..f92d7a9d 100644 --- a/apps/host/tests/folder-dialog.test.mjs +++ b/apps/host/tests/folder-dialog.test.mjs @@ -77,6 +77,23 @@ test('a typed path must be an absolute existing directory', async () => { } finally { await rm(dir, { recursive: true, force: true }); } }); +test('the model page takes a folder or one .gguf file, with or without quotes around the path', async () => { + const dir = await mkdtemp(join(tmpdir(), 'strata-gguf-typed-')); + try { + await writeFile(join(dir, 'model-00001-of-00002.gguf'), 'x'); + await writeFile(join(dir, 'notes.txt'), 'x'); + const only = { isAbsolute, fileType: /\.gguf$/i }; + assert.equal(await typedFolder(dir, only), dir); + assert.equal(await typedFolder(join(dir, 'model-00001-of-00002.gguf'), only), join(dir, 'model-00001-of-00002.gguf')); + assert.equal(await typedFolder(`"${join(dir, 'model-00001-of-00002.gguf')}"`, only), join(dir, 'model-00001-of-00002.gguf')); + assert.equal(await typedFolder(` "${dir}" `, only), dir); + await assert.rejects(typedFolder(join(dir, 'notes.txt'), only), /folder, or a \.gguf file/); + await assert.rejects(typedFolder(join(dir, 'missing.gguf'), only), /does not exist/); + // the other pickers still refuse a file + await assert.rejects(typedFolder(join(dir, 'model-00001-of-00002.gguf'), { isAbsolute }), /not a file/); + } finally { await rm(dir, { recursive: true, force: true }); } +}); + async function startHost() { const home = await mkdtemp(join(tmpdir(), 'strata-folder-home-')); const net = await import('node:net');