feat(backend): ThtRunner.ollamaEnsure (parses tht ollama ensure --json)

This commit is contained in:
2026-06-29 19:31:49 +02:00
parent deb8081bc2
commit a0af089d00
2 changed files with 49 additions and 0 deletions
+24
View File
@@ -26,6 +26,15 @@ export interface SessionDocument {
content: string;
}
export interface OllamaEnsureResult {
ok: boolean;
stage?: string;
error?: string;
server?: string;
model?: string;
model_name?: string;
}
export class ThtRunner {
constructor(private cfg: ThtConfig) {}
@@ -129,4 +138,19 @@ export class ThtRunner {
unarchive(id: string) { return this.ok(["session", "unarchive", id]); }
deleteSession(id: string) { return this.ok(["session", "delete", id]); }
documents(id: string) { return this.json<SessionDocument[]>(["session", "documents", id, "--json"]); }
async ollamaEnsure(workspace: string, timeoutSec: number): Promise<OllamaEnsureResult> {
const { code, stdout, stderr } = await this.run(
["ollama", "ensure", "--json", "--timeout", String(timeoutSec)],
workspace,
);
let parsed: Partial<OllamaEnsureResult> = {};
try { parsed = JSON.parse(stdout.trim() || "{}"); } catch { /* leave {} */ }
if (code === 0) return { ok: true, ...parsed };
return {
ok: false,
stage: parsed.stage,
error: parsed.error ?? (stderr.trim() || `tht ollama ensure exit ${code}`),
};
}
}