Compare commits
2 Commits
fix/dashbo
...
fix/dashbo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
93bf5cdc88 | ||
| ff180be9b5 |
@@ -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 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -452,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" },
|
||||||
@@ -463,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;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2125,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"
|
||||||
@@ -2143,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}
|
||||||
|
|||||||
@@ -634,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",
|
||||||
@@ -650,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,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -945,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),
|
||||||
@@ -959,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) : "",
|
||||||
|
|||||||
Reference in New Issue
Block a user