feat(backend): ThtRunner.ollamaEnsure (parses tht ollama ensure --json)
This commit is contained in:
@@ -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}`),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user