fix(cli): surfaced tiny model download errors

Preserved worker-side download errors through TinyTitleClient and included them in tiny-models text and JSON failures.

Fixes #3839
This commit is contained in:
roboomp
2026-06-29 22:56:40 +00:00
parent 0ba736f5bc
commit f5be8953c4
5 changed files with 89 additions and 20 deletions
@@ -28,12 +28,21 @@ interface ProgressReporter {
interface DownloadResult {
model: TinyLocalModelKey;
ok: boolean;
error?: string;
}
function writeLine(text = ""): void {
process.stdout.write(`${text}\n`);
}
function downloadErrorSummary(error: string | undefined): string | undefined {
return error
?.split(/\r?\n/)
.map(line => line.trim())
.find(line => line.length > 0)
?.replace(/^Error:\s*/, "");
}
export function resolveModels(model: string | undefined): TinyLocalModelKey[] {
if (!model) return [DEFAULT_TINY_TITLE_LOCAL_MODEL_KEY];
// `all` is a prefetch convenience: skip models that fail before load (unsupported
@@ -101,10 +110,15 @@ async function downloadOne(modelKey: TinyLocalModelKey, json: boolean | undefine
const label = getTinyLocalModelSpec(modelKey)?.label ?? modelKey;
if (!json && !process.stdout.isTTY) writeLine(`Downloading ${label} (${modelKey})...`);
const progress = makeProgressReporter(modelKey, json);
const ok = await tinyTitleClient.downloadModel(modelKey, { onProgress: progress.onProgress });
progress.finish(ok);
if (!json && !process.stdout.isTTY) writeLine(ok ? `Downloaded ${label}.` : `Failed to download ${label}.`);
return { model: modelKey, ok };
const result = await tinyTitleClient.downloadModel(modelKey, { onProgress: progress.onProgress });
progress.finish(result.ok);
const error = downloadErrorSummary(result.error);
if (!json && !process.stdout.isTTY) {
writeLine(result.ok ? `Downloaded ${label}.` : `Failed to download ${label}${error ? `: ${error}` : ""}.`);
} else if (!json && !result.ok && error) {
writeLine(`${label} failed: ${error}`);
}
return result.error ? { model: modelKey, ok: result.ok, error: result.error } : { model: modelKey, ok: result.ok };
}
export async function runTinyModelsCommand(command: TinyModelsCommandArgs): Promise<void> {