## User-reported issues addressed
### 1. Logs show literal \\n (and don't update live)
- Old impl: GET /api/services/[role] returned a JSON snapshot {logs: '...'}
with embedded \\n escape sequences that the UI rendered as plain text.
Plus it wasn't actually streaming — fetch returned the whole body at once.
- New: GET /api/services/[role]/stream — proper Server-Sent Events endpoint.
Emits one `log` event per line with {stream: stdout|stderr, line, ts}.
Uses a line buffer so partial chunks don't get split mid-line.
Client opens `new EventSource(...)` instead of fetch — gets genuine live
updates (docker logs -f --tail 300 --timestamps).
- Added keep-alive comment every 15s for proxies that kill idle SSE.
### 2. 'Llama Dashboard' → 'GPU Node Dashboard'
- Renamed everywhere (browser title, header, footer)
- The dashboard now manages llama + comfy + system + services, so the old
name was misleading.
### 3. Models not visible (llama + comfy)
- Root cause hypothesis: empty HOST_PROJECT_PATH → compose resolves
${HOST_PROJECT_PATH:-./} to './' relative to compose CWD inside the
dashboard container, so volume mounts point to a path that doesn't exist
on the host.
- Added /api/debug endpoint that returns:
* All env vars the dashboard sees (PROJECT_DIR, HOST_PROJECT_PATH,
LLAMA_MODELS_DIR, NODE_INSTANCE, SSH_ROLE, TAILSCALE_HOSTNAME)
* Which paths exist (PROJECT_DIR, LLAMA_MODELS_DIR, comfy models dir)
* Directory listings of each (so you can see what's actually there)
* Contents of .env (so you can verify HOST_PROJECT_PATH was set)
* Existence of dashboard-config.json
- This endpoint is for diagnosing 'models not visible' issues — call
`curl http://gpu-node:8090/api/debug` after deployment.
### 4. Comfy models parsing
- worker.py `list` and `queue` commands output human-readable text, not
JSON. The dashboard was trying to JSON.parse the output and silently
returning empty arrays.
- Added --json flag to both commands (worker.py):
* `worker.py list [type] --json` → {models: [{type, filename, sizeBytes}], total, totalBytes}
* `worker.py queue --json` → {jobs: [...]}
* `worker.py types` → ["checkpoints", "loras", ...] (new command)
- Updated dashboard to use --json everywhere.
### 5. Comfy model types — couldn't pick all available types
- Was hardcoded list of 9 types (checkpoints, loras, vae, etc.)
- Now fetched dynamically from /api/comfy/types, which calls the new
`worker.py types` command — lists actual subdirectories of
gpu/comfy/models.
- Falls back to hardcoded list if worker is offline or older version.
## Files changed
- model-worker/worker.py:
* Added json import
* Added command_list_json(model_type) — JSON variant of command_list
* Added command_queue_json() — JSON variant of command_queue
* Added `types` command (outputs JSON array of subdir names)
* `list` command now accepts --json flag
* `queue` command now accepts --json flag
* print_usage() updated
- dashboard/src/app/api/services/[role]/stream/route.ts — new SSE endpoint
- dashboard/src/app/api/comfy/types/route.ts — new (proxy to worker.py types)
- dashboard/src/app/api/debug/route.ts — new (diagnostic endpoint)
- dashboard/src/lib/docker.ts:
* listComfyModels uses --json flag
* getComfyQueue uses --json flag
* Added getComfyTypes() — calls worker.py types
* Better error handling for type-not-found case
- dashboard/src/app/page.tsx:
* Renamed 'Llama Dashboard' → 'GPU Node Dashboard'
* LiveLogs type changed from string[] to {stream, line, ts}[]
* startLogsStream uses EventSource instead of fetch+readablestream
* Added comfyTypes state, refreshComfyTypes callback
* ComfyTab receives dynamic types list (with fallback)
- dashboard/src/app/layout.tsx: title renamed
126 lines
3.3 KiB
TypeScript
126 lines
3.3 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { promises as fs } from "node:fs";
|
|
import path from "node:path";
|
|
import {
|
|
PROJECT_DIR,
|
|
HOST_PROJECT_PATH,
|
|
LLAMA_MODELS_DIR,
|
|
NODE_INSTANCE,
|
|
ENV_FILE_PATH,
|
|
DASHBOARD_CONFIG_PATH,
|
|
} from "@/lib/docker";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
export const runtime = "nodejs";
|
|
|
|
/**
|
|
* GET /api/debug
|
|
*
|
|
* Returns what the dashboard container actually sees:
|
|
* - Environment variables (PROJECT_DIR, HOST_PROJECT_PATH, LLAMA_MODELS_DIR, etc.)
|
|
* - Whether key paths exist
|
|
* - Directory listings of PROJECT_DIR and LLAMA_MODELS_DIR
|
|
* - Contents of .env (if present) — useful for verifying HOST_PROJECT_PATH was set
|
|
*
|
|
* Useful for diagnosing "models not visible" type issues.
|
|
*/
|
|
export async function GET() {
|
|
const checks: {
|
|
path: string;
|
|
exists: boolean;
|
|
isDir?: boolean;
|
|
entries?: string[];
|
|
error?: string;
|
|
}[] = [];
|
|
|
|
// 1. PROJECT_DIR (usually /project)
|
|
checks.push({
|
|
path: PROJECT_DIR,
|
|
exists: true,
|
|
isDir: true,
|
|
entries: await listDirSafe(PROJECT_DIR),
|
|
});
|
|
|
|
// 2. LLAMA_MODELS_DIR (PROJECT_DIR/gpu/llama_models)
|
|
checks.push({
|
|
path: LLAMA_MODELS_DIR,
|
|
exists: await existsSafe(LLAMA_MODELS_DIR),
|
|
isDir: await isDirSafe(LLAMA_MODELS_DIR),
|
|
entries: await listDirSafe(LLAMA_MODELS_DIR),
|
|
});
|
|
|
|
// 3. Comfy models dir
|
|
const comfyModelsDir = path.join(PROJECT_DIR, "gpu", "comfy", "models");
|
|
checks.push({
|
|
path: comfyModelsDir,
|
|
exists: await existsSafe(comfyModelsDir),
|
|
isDir: await isDirSafe(comfyModelsDir),
|
|
entries: await listDirSafe(comfyModelsDir),
|
|
});
|
|
|
|
// 4. .env file
|
|
const envExists = await existsSafe(ENV_FILE_PATH);
|
|
let envContents: string | null = null;
|
|
if (envExists) {
|
|
try {
|
|
envContents = await fs.readFile(ENV_FILE_PATH, "utf-8");
|
|
} catch (err) {
|
|
envContents = `[read error: ${(err as Error).message}]`;
|
|
}
|
|
}
|
|
|
|
// 5. Dashboard config
|
|
const configExists = await existsSafe(DASHBOARD_CONFIG_PATH);
|
|
|
|
return NextResponse.json({
|
|
env: {
|
|
PROJECT_DIR,
|
|
HOST_PROJECT_PATH,
|
|
LLAMA_MODELS_DIR,
|
|
NODE_INSTANCE,
|
|
ENV_FILE_PATH,
|
|
DASHBOARD_CONFIG_PATH,
|
|
// Also expose relevant process.env for debugging
|
|
process: {
|
|
HOST_PROJECT_PATH: process.env.HOST_PROJECT_PATH,
|
|
PROJECT_DIR: process.env.PROJECT_DIR,
|
|
LLAMA_MODELS_DIR: process.env.LLAMA_MODELS_DIR,
|
|
NODE_INSTANCE: process.env.NODE_INSTANCE,
|
|
SSH_ROLE: process.env.SSH_ROLE,
|
|
TAILSCALE_HOSTNAME: process.env.TAILSCALE_HOSTNAME,
|
|
},
|
|
},
|
|
checks,
|
|
envFile: envExists ? { exists: true, contents: envContents } : { exists: false },
|
|
dashboardConfig: { exists: configExists, path: DASHBOARD_CONFIG_PATH },
|
|
timestamp: new Date().toISOString(),
|
|
});
|
|
}
|
|
|
|
async function existsSafe(p: string): Promise<boolean> {
|
|
try {
|
|
await fs.access(p);
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
async function isDirSafe(p: string): Promise<boolean | undefined> {
|
|
try {
|
|
const stat = await fs.stat(p);
|
|
return stat.isDirectory();
|
|
} catch {
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
async function listDirSafe(p: string): Promise<string[] | undefined> {
|
|
try {
|
|
const entries = await fs.readdir(p);
|
|
return entries.slice(0, 50);
|
|
} catch (err) {
|
|
return [`[error: ${(err as Error).message}]`];
|
|
}
|
|
}
|