Compare commits
4 Commits
fix/dashbo
...
fix/dashbo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
93bf5cdc88 | ||
| ff180be9b5 | |||
|
|
15892cf0d1 | ||
| 41da236ee6 |
@@ -1,4 +1,4 @@
|
|||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { getComfyQueue } from "@/lib/docker";
|
import { getComfyQueue } from "@/lib/docker";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
@@ -6,12 +6,20 @@ export const runtime = "nodejs";
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* GET /api/comfy/queue
|
* GET /api/comfy/queue
|
||||||
* Returns current download queue via `docker exec model-worker python3 /app/worker.py queue`.
|
*
|
||||||
|
* Returns current download queue via `docker exec model-worker python3
|
||||||
|
* /app/worker.py queue --json`.
|
||||||
|
*
|
||||||
|
* Returns 200 even when model-worker is offline (queue is empty in that
|
||||||
|
* case) — frontend polls this every 5s, returning 500 on every poll when
|
||||||
|
* worker isn't running would spam the browser console.
|
||||||
*/
|
*/
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
const result = await getComfyQueue();
|
const result = await getComfyQueue();
|
||||||
return NextResponse.json(
|
return NextResponse.json({
|
||||||
{ ok: result.ok, queue: result.queue, raw: result.raw, error: result.error },
|
ok: result.ok,
|
||||||
{ status: result.ok ? 200 : 500 }
|
queue: result.queue,
|
||||||
);
|
raw: result.raw,
|
||||||
|
error: result.error,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,13 +17,17 @@ export async function POST(req: NextRequest) {
|
|||||||
config?: Partial<DashboardConfig>;
|
config?: Partial<DashboardConfig>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log("[/api/llama] action:", body.action, "config.model:", body.config?.model);
|
||||||
|
|
||||||
if (body.action === "start") {
|
if (body.action === "start") {
|
||||||
const current = await loadConfig();
|
const current = await loadConfig();
|
||||||
const cfg: DashboardConfig = {
|
const cfg: DashboardConfig = {
|
||||||
...current,
|
...current,
|
||||||
...(body.config || {}),
|
...(body.config || {}),
|
||||||
} as DashboardConfig;
|
} as DashboardConfig;
|
||||||
|
console.log("[/api/llama] merged cfg.model:", cfg.model);
|
||||||
const result = await startLlama(cfg);
|
const result = await startLlama(cfg);
|
||||||
|
console.log("[/api/llama] startLlama result ok:", result.ok);
|
||||||
return NextResponse.json(result, { status: result.ok ? 200 : 500 });
|
return NextResponse.json(result, { status: result.ok ? 200 : 500 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,17 @@ import { deleteModel, listModels } from "@/lib/docker";
|
|||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
export const runtime = "nodejs";
|
export const runtime = "nodejs";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/models
|
||||||
|
*
|
||||||
|
* Lists all .gguf files in gpu/llama_models/. Returns:
|
||||||
|
* { models: [{ name, sizeBytes, sizeHuman, modifiedAt }] }
|
||||||
|
*/
|
||||||
|
export async function GET() {
|
||||||
|
const models = await listModels();
|
||||||
|
return NextResponse.json({ models });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DELETE /api/models?name=foo.gguf
|
* DELETE /api/models?name=foo.gguf
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -254,11 +254,14 @@ export default function DashboardPage() {
|
|||||||
const refreshModels = React.useCallback(async () => {
|
const refreshModels = React.useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/models", { cache: "no-store" });
|
const res = await fetch("/api/models", { cache: "no-store" });
|
||||||
if (!res.ok) return;
|
if (!res.ok) {
|
||||||
|
console.error("[refreshModels] HTTP", res.status, await res.text().catch(() => ""));
|
||||||
|
return;
|
||||||
|
}
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
setModels(data.models || []);
|
setModels(data.models || []);
|
||||||
} catch {
|
} catch (err) {
|
||||||
/* ignore */
|
console.error("[refreshModels] error:", err);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -268,8 +271,8 @@ export default function DashboardPage() {
|
|||||||
if (!res.ok) return;
|
if (!res.ok) return;
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
setConfig(data.config || DEFAULT_CONFIG);
|
setConfig(data.config || DEFAULT_CONFIG);
|
||||||
} catch {
|
} catch (err) {
|
||||||
/* ignore */
|
console.error("[refreshConfig] error:", err);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -296,8 +299,8 @@ export default function DashboardPage() {
|
|||||||
// If current selection isn't in the new list, switch to first available
|
// If current selection isn't in the new list, switch to first available
|
||||||
setComfyAddType((cur) => (types.includes(cur) ? cur : types[0]));
|
setComfyAddType((cur) => (types.includes(cur) ? cur : types[0]));
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (err) {
|
||||||
/* keep fallback list */
|
console.error("[refreshComfyTypes] error:", err);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -309,7 +312,8 @@ export default function DashboardPage() {
|
|||||||
const res = await fetch(url, { cache: "no-store" });
|
const res = await fetch(url, { cache: "no-store" });
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
setComfyModels(data.models || []);
|
setComfyModels(data.models || []);
|
||||||
} catch {
|
} catch (err) {
|
||||||
|
console.error("[refreshComfyModels] error:", err);
|
||||||
setComfyModels([]);
|
setComfyModels([]);
|
||||||
}
|
}
|
||||||
}, [comfyFilter]);
|
}, [comfyFilter]);
|
||||||
@@ -319,7 +323,8 @@ export default function DashboardPage() {
|
|||||||
const res = await fetch("/api/comfy/queue", { cache: "no-store" });
|
const res = await fetch("/api/comfy/queue", { cache: "no-store" });
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
setComfyQueue(data.queue || []);
|
setComfyQueue(data.queue || []);
|
||||||
} catch {
|
} catch (err) {
|
||||||
|
// Queue refresh runs every 5s — don't spam console on network blips
|
||||||
setComfyQueue([]);
|
setComfyQueue([]);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
@@ -328,9 +333,16 @@ export default function DashboardPage() {
|
|||||||
refreshConfig();
|
refreshConfig();
|
||||||
refreshModels();
|
refreshModels();
|
||||||
refreshComfyTypes();
|
refreshComfyTypes();
|
||||||
|
refreshComfyModels();
|
||||||
const id = setInterval(refreshComfyQueue, 5000);
|
const id = setInterval(refreshComfyQueue, 5000);
|
||||||
return () => clearInterval(id);
|
return () => clearInterval(id);
|
||||||
}, [refreshConfig, refreshModels, refreshComfyTypes, refreshComfyQueue]);
|
}, [
|
||||||
|
refreshConfig,
|
||||||
|
refreshModels,
|
||||||
|
refreshComfyTypes,
|
||||||
|
refreshComfyModels,
|
||||||
|
refreshComfyQueue,
|
||||||
|
]);
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Live logs streaming via Server-Sent Events (replaces fetch+readablestream)
|
// Live logs streaming via Server-Sent Events (replaces fetch+readablestream)
|
||||||
@@ -440,6 +452,7 @@ export default function DashboardPage() {
|
|||||||
|
|
||||||
async function handleStartLlama() {
|
async function handleStartLlama() {
|
||||||
await runAction("start-llama", async () => {
|
await runAction("start-llama", async () => {
|
||||||
|
// Persist config first so reloads restore it.
|
||||||
const res = await fetch("/api/config", {
|
const res = await fetch("/api/config", {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
@@ -451,7 +464,17 @@ export default function DashboardPage() {
|
|||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ action: "start", config }),
|
body: JSON.stringify({ action: "start", config }),
|
||||||
});
|
});
|
||||||
return await startRes.json();
|
const result = await startRes.json();
|
||||||
|
// If start failed, include compose logs in the message so the user can
|
||||||
|
// see what went wrong (common cause: model-worker still on old image
|
||||||
|
// without --json flag, or env not set, etc).
|
||||||
|
if (!result.ok && result.logs) {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
message: `${result.message}\n\n${result.logs.slice(-500)}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return result;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2113,10 +2136,13 @@ function Toast({
|
|||||||
toast: { type: "success" | "error" | "info"; message: string };
|
toast: { type: "success" | "error" | "info"; message: string };
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
}) {
|
}) {
|
||||||
|
// If message has multiple lines, render as pre-formatted text (so logs are
|
||||||
|
// readable); otherwise normal flow.
|
||||||
|
const isMultiLine = toast.message.includes("\n");
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
"fixed bottom-4 right-4 z-50 max-w-sm rounded-md border bg-card shadow-lg p-3 pr-9 text-sm",
|
"fixed bottom-4 right-4 z-50 max-w-md rounded-md border bg-card shadow-lg p-3 pr-9 text-sm",
|
||||||
toast.type === "success" && "border-success/30",
|
toast.type === "success" && "border-success/30",
|
||||||
toast.type === "error" && "border-destructive/30",
|
toast.type === "error" && "border-destructive/30",
|
||||||
toast.type === "info" && "border-border"
|
toast.type === "info" && "border-border"
|
||||||
@@ -2131,7 +2157,13 @@ function Toast({
|
|||||||
toast.type === "info" && "bg-muted-foreground"
|
toast.type === "info" && "bg-muted-foreground"
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<span className="text-foreground">{toast.message}</span>
|
{isMultiLine ? (
|
||||||
|
<pre className="text-foreground whitespace-pre-wrap break-all font-mono text-[11px] leading-tight max-h-60 overflow-y-auto scrollbar-thin">
|
||||||
|
{toast.message}
|
||||||
|
</pre>
|
||||||
|
) : (
|
||||||
|
<span className="text-foreground">{toast.message}</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
onClick={onClose}
|
onClick={onClose}
|
||||||
|
|||||||
@@ -124,6 +124,14 @@ export const TAILSCALE_HOSTNAME = envOrFile("TAILSCALE_HOSTNAME", "gpu-node");
|
|||||||
export const LLAMA_MODELS_DIR =
|
export const LLAMA_MODELS_DIR =
|
||||||
process.env.LLAMA_MODELS_DIR || path.join(PROJECT_DIR, "gpu", "llama_models");
|
process.env.LLAMA_MODELS_DIR || path.join(PROJECT_DIR, "gpu", "llama_models");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal mount of the comfy models directory (mirrors the host path that
|
||||||
|
* the model-worker container mounts as /models).
|
||||||
|
*/
|
||||||
|
export const COMFY_MODELS_DIR =
|
||||||
|
process.env.COMFY_MODELS_DIR ||
|
||||||
|
path.join(PROJECT_DIR, "gpu", "comfy", "models");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Node instance name (used for filtering containers by label).
|
* Node instance name (used for filtering containers by label).
|
||||||
*/
|
*/
|
||||||
@@ -626,6 +634,12 @@ export async function startLlama(
|
|||||||
await saveConfig(config);
|
await saveConfig(config);
|
||||||
await writeEnvLlamaConfig(config.model, extraArgs);
|
await writeEnvLlamaConfig(config.model, extraArgs);
|
||||||
|
|
||||||
|
// Log what we're actually starting with — helps diagnose "model didn't
|
||||||
|
// change" issues (the most common cause is the request body not including
|
||||||
|
// the new model, or compose picking up an old LLAMA_MODEL from .env).
|
||||||
|
console.log("[startLlama] model:", config.model);
|
||||||
|
console.log("[startLlama] extraArgs:", extraArgs);
|
||||||
|
|
||||||
const res = await runCompose(
|
const res = await runCompose(
|
||||||
[
|
[
|
||||||
"--profile",
|
"--profile",
|
||||||
@@ -642,9 +656,14 @@ export async function startLlama(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const combined = res.stdout + (res.stderr ? `\n${res.stderr}` : "");
|
const combined = res.stdout + (res.stderr ? `\n${res.stderr}` : "");
|
||||||
|
console.log("[startLlama] compose exit:", res.code);
|
||||||
|
console.log("[startLlama] compose output:\n", combined);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ok: res.code === 0,
|
ok: res.code === 0,
|
||||||
message: res.code === 0 ? "Llama instance started" : "Failed to start",
|
message: res.code === 0
|
||||||
|
? `Llama started (model: ${config.model})`
|
||||||
|
: `Failed to start (exit ${res.code})`,
|
||||||
logs: combined,
|
logs: combined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -937,10 +956,10 @@ async function modelWorkerExec(
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const quoted = args.map((a) => `'${a.replace(/'/g, "'\\''")}'`).join(" ");
|
const quoted = args.map((a) => `'${a.replace(/'/g, "'\\''")}'`).join(" ");
|
||||||
const { stdout, stderr } = await execAsync(
|
const cmd = `docker exec ${container} python3 /app/worker.py ${quoted}`;
|
||||||
`docker exec ${container} python3 /app/worker.py ${quoted}`,
|
const { stdout, stderr } = await execAsync(cmd, {
|
||||||
{ maxBuffer: 8 * 1024 * 1024 }
|
maxBuffer: 8 * 1024 * 1024,
|
||||||
);
|
});
|
||||||
return {
|
return {
|
||||||
ok: true,
|
ok: true,
|
||||||
output: String(stdout),
|
output: String(stdout),
|
||||||
@@ -951,7 +970,12 @@ async function modelWorkerExec(
|
|||||||
stdout?: string | Buffer;
|
stdout?: string | Buffer;
|
||||||
stderr?: string | Buffer;
|
stderr?: string | Buffer;
|
||||||
message: string;
|
message: string;
|
||||||
|
code?: number;
|
||||||
};
|
};
|
||||||
|
// Log the failure so it's visible in dashboard container logs
|
||||||
|
console.error(
|
||||||
|
`[modelWorkerExec] args=${JSON.stringify(args)} container=${container} exitCode=${e.code} stderr=${e.stderr ? String(e.stderr).slice(0, 500) : "(empty)"} message=${e.message}`
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
ok: false,
|
ok: false,
|
||||||
output: e.stdout ? String(e.stdout) : "",
|
output: e.stdout ? String(e.stdout) : "",
|
||||||
@@ -967,43 +991,127 @@ export interface ComfyModelEntry {
|
|||||||
sizeHuman?: string;
|
sizeHuman?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read comfy model types directly from the filesystem (subdirs of
|
||||||
|
* /project/gpu/comfy/models). Used as a fallback when the model-worker
|
||||||
|
* container isn't running.
|
||||||
|
*
|
||||||
|
* Returns the same shape as `worker.py types`.
|
||||||
|
*/
|
||||||
|
async function listComfyTypesFromFs(): Promise<string[]> {
|
||||||
|
try {
|
||||||
|
const entries = await fs.readdir(COMFY_MODELS_DIR, { withFileTypes: true });
|
||||||
|
return entries
|
||||||
|
.filter((e) => e.isDirectory() && !e.isSymbolicLink())
|
||||||
|
.map((e) => e.name)
|
||||||
|
.sort();
|
||||||
|
} catch {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read comfy models directly from the filesystem. Walks each subdirectory
|
||||||
|
* (one per model type) and lists all files inside. Used as a fallback when
|
||||||
|
* the model-worker container isn't running.
|
||||||
|
*
|
||||||
|
* Returns the same shape as `worker.py list --json`.
|
||||||
|
*/
|
||||||
|
async function listComfyModelsFromFs(
|
||||||
|
type?: string
|
||||||
|
): Promise<ComfyModelEntry[]> {
|
||||||
|
const out: ComfyModelEntry[] = [];
|
||||||
|
try {
|
||||||
|
if (type) {
|
||||||
|
// Single type — list its contents
|
||||||
|
const typeDir = path.join(COMFY_MODELS_DIR, type);
|
||||||
|
const stat = await fs.stat(typeDir).catch(() => null);
|
||||||
|
if (!stat || !stat.isDirectory()) return [];
|
||||||
|
const entries = await fs.readdir(typeDir, { withFileTypes: true });
|
||||||
|
for (const entry of entries) {
|
||||||
|
if (!entry.isFile()) continue;
|
||||||
|
if (entry.name.startsWith(".")) continue;
|
||||||
|
const full = path.join(typeDir, entry.name);
|
||||||
|
const size = await fs.stat(full).then((s) => s.size).catch(() => 0);
|
||||||
|
out.push({
|
||||||
|
type,
|
||||||
|
filename: entry.name,
|
||||||
|
sizeBytes: size,
|
||||||
|
sizeHuman: size > 0 ? humanSize(size) : undefined,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// All types — walk each subdir
|
||||||
|
const types = await listComfyTypesFromFs();
|
||||||
|
for (const t of types) {
|
||||||
|
const typeDir = path.join(COMFY_MODELS_DIR, t);
|
||||||
|
const entries = await fs.readdir(typeDir, { withFileTypes: true });
|
||||||
|
for (const entry of entries) {
|
||||||
|
if (!entry.isFile()) continue;
|
||||||
|
if (entry.name.startsWith(".")) continue;
|
||||||
|
const full = path.join(typeDir, entry.name);
|
||||||
|
const size = await fs.stat(full).then((s) => s.size).catch(() => 0);
|
||||||
|
out.push({
|
||||||
|
type: t,
|
||||||
|
filename: entry.name,
|
||||||
|
sizeBytes: size,
|
||||||
|
sizeHuman: size > 0 ? humanSize(size) : undefined,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
export async function listComfyModels(
|
export async function listComfyModels(
|
||||||
type?: string
|
type?: string
|
||||||
): Promise<{ ok: boolean; models: ComfyModelEntry[]; raw: string; error?: string }> {
|
): Promise<{ ok: boolean; models: ComfyModelEntry[]; raw: string; error?: string }> {
|
||||||
// Use the new --json flag so we get structured output instead of having to
|
// Try the model-worker first — it knows which files are real models vs
|
||||||
// parse the human-readable table.
|
// metadata files (.txt etc.) and follows ComfyUI's naming conventions.
|
||||||
const args = ["list"];
|
const args = ["list"];
|
||||||
if (type) args.push(type);
|
if (type) args.push(type);
|
||||||
args.push("--json");
|
args.push("--json");
|
||||||
const res = await modelWorkerExec(...args);
|
const res = await modelWorkerExec(...args);
|
||||||
if (!res.ok) {
|
|
||||||
return { ok: false, models: [], raw: res.output, error: res.error };
|
if (res.ok) {
|
||||||
}
|
try {
|
||||||
try {
|
const parsed = JSON.parse(res.output);
|
||||||
const parsed = JSON.parse(res.output);
|
if (parsed.error) {
|
||||||
// worker.py outputs {"models": [...], "total": N, "totalBytes": N}
|
return {
|
||||||
// or {"error": "...", "available_types": [...]} on type-not-found
|
ok: false,
|
||||||
if (parsed.error) {
|
models: [],
|
||||||
return {
|
raw: res.output,
|
||||||
ok: false,
|
error: parsed.error,
|
||||||
models: [],
|
};
|
||||||
raw: res.output,
|
}
|
||||||
error: parsed.error,
|
const arr: ComfyModelEntry[] = (parsed.models || []).map(
|
||||||
};
|
(m: { type: string; filename: string; sizeBytes?: number }) => ({
|
||||||
|
type: m.type,
|
||||||
|
filename: m.filename,
|
||||||
|
sizeBytes: m.sizeBytes,
|
||||||
|
sizeHuman: m.sizeBytes ? humanSize(m.sizeBytes) : undefined,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return { ok: true, models: arr, raw: res.output };
|
||||||
|
} catch {
|
||||||
|
// Fall through to fs fallback
|
||||||
}
|
}
|
||||||
const arr: ComfyModelEntry[] = (parsed.models || []).map(
|
|
||||||
(m: { type: string; filename: string; sizeBytes?: number }) => ({
|
|
||||||
type: m.type,
|
|
||||||
filename: m.filename,
|
|
||||||
sizeBytes: m.sizeBytes,
|
|
||||||
sizeHuman: m.sizeBytes ? humanSize(m.sizeBytes) : undefined,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
return { ok: true, models: arr, raw: res.output };
|
|
||||||
} catch {
|
|
||||||
// Probably worker.py without --json support (older version)
|
|
||||||
return { ok: true, models: [], raw: res.output };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fallback: read directly from the filesystem. Useful when:
|
||||||
|
// - model-worker container isn't running (e.g. during sleep mode)
|
||||||
|
// - worker.py doesn't support --json flag (older version)
|
||||||
|
// - docker exec fails for any reason
|
||||||
|
const models = await listComfyModelsFromFs(type);
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
models,
|
||||||
|
raw: res.output || "",
|
||||||
|
error: res.ok ? undefined : res.error,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getComfyTypes(): Promise<{
|
export async function getComfyTypes(): Promise<{
|
||||||
@@ -1012,17 +1120,30 @@ export async function getComfyTypes(): Promise<{
|
|||||||
raw: string;
|
raw: string;
|
||||||
error?: string;
|
error?: string;
|
||||||
}> {
|
}> {
|
||||||
// Uses the new `worker.py types` command — outputs JSON array of strings.
|
// Try the model-worker first.
|
||||||
// Falls back to an empty list if the worker version doesn't support it yet.
|
|
||||||
const res = await modelWorkerExec("types");
|
const res = await modelWorkerExec("types");
|
||||||
if (!res.ok) return { ok: false, types: [], raw: res.output, error: res.error };
|
if (res.ok) {
|
||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(res.output);
|
const parsed = JSON.parse(res.output);
|
||||||
const arr: string[] = Array.isArray(parsed) ? parsed : [];
|
const arr: string[] = Array.isArray(parsed) ? parsed : [];
|
||||||
return { ok: true, types: arr, raw: res.output };
|
if (arr.length > 0) {
|
||||||
} catch {
|
return { ok: true, types: arr, raw: res.output };
|
||||||
return { ok: true, types: [], raw: res.output };
|
}
|
||||||
|
} catch {
|
||||||
|
/* fall through */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fallback: read subdirectories of gpu/comfy/models directly.
|
||||||
|
// The model-worker container might not be running (sleep mode), but the
|
||||||
|
// directory is mounted into the dashboard container at /project/gpu/comfy.
|
||||||
|
const types = await listComfyTypesFromFs();
|
||||||
|
return {
|
||||||
|
ok: types.length > 0,
|
||||||
|
types,
|
||||||
|
raw: res.output || "",
|
||||||
|
error: types.length > 0 ? undefined : res.error || "no types found",
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ComfyQueueEntry {
|
export interface ComfyQueueEntry {
|
||||||
|
|||||||
Reference in New Issue
Block a user