"use client"; import Link from "next/link"; import { useEffect, useState } from "react"; import { api } from "@/lib/api"; import { useLive } from "@/lib/events"; import { fmtAgo, fmtDuration, fmtGB, fmtMs, fmtNum } from "@/lib/format"; import type { Model, SystemInfo } from "@/lib/types"; import { Meter, Pill, Sparkline, StatTile, StatusPill } from "@/components/ui"; interface Stats { totals: { requests: number; prompt_tokens: number; completion_tokens: number; avg_tps: number | null; avg_ttft_ms: number | null; errors: number }; per_model: { model_id: string; requests: number; completion_tokens: number; avg_tps: number | null }[]; all_time: { requests: number; completion_tokens: number; prompt_tokens: number } } export default function Dashboard() { const live = useLive(); const [sys, setSys] = useState(null); const [models, setModels] = useState([]); const [stats, setStats] = useState(null); useEffect(() => { api.get("/api/system").then(setSys).catch(() => {}); api.get<{ models: Model[] }>("/api/models").then((r) => setModels(r.models)).catch(() => {}); api.get<{ requests: Stats }>("/api/system/metrics?minutes=60&hours=24").then((r) => setStats(r.requests)).catch(() => {}); }, [live.version]); const t = live.metrics || sys?.telemetry; const hw = sys?.hardware; const mgr = live.manager || sys?.manager; const loaded = mgr?.loaded || []; const cur = loaded.find((w) => w.status === "ready"); const memHist = live.metricsHistory.map((m) => m.mem_used_gb); const gpuHist = live.metricsHistory.map((m) => m.gpu_percent ?? 0); const cpuHist = live.metricsHistory.map((m) => m.cpu_percent); const budget = sys?.policy.max_model_memory_gb ?? 45; const installed = models.filter((m) => m.installed); const recentTps = live.requests.map((r) => Number(r.tps) || 0).filter(Boolean).reverse(); return (

Dashboard

{hw ? <>{hw.chip} · {hw.memory_gb.toFixed(0)} GB unified memory · {hw.gpu_cores ?? "—"} GPU cores · {hw.cpu_cores} CPU cores · macOS {hw.os_version} : "…"}
Memory {t?.mem_pressure_level ?? "—"} Thermal {t?.thermal_state ?? "—"} {t?.swap_used_gb ? Swap {fmtGB(t.swap_used_gb)} : null}
{live.alerts.length > 0 && (
{live.alerts[live.alerts.length - 1].message}
)} {/* Current model */}
Current model
{cur ? ( <> {cur.model_id}
{cur.runtime === "mlx" ? "MLX" : "llama.cpp"} context {Math.round(cur.context / 1024)}K memory {fmtGB(cur.measured_gb || cur.estimate_gb)} loaded in {fmtMs(cur.load_ms)} warm TTFT {fmtMs(cur.warm?.ttft_ms as number)} {cur.requests} requests {cur.in_flight > 0 && {cur.in_flight} in flight} {cur.pinned && pinned}
) : Object.keys(mgr?.progress || {}).length ? (
Loading {Object.keys(mgr!.progress)[0]}… {Object.values(mgr!.progress)[0].status} · {Object.values(mgr!.progress)[0].elapsed_seconds}s
) : (
No model loaded — the next API request loads it on demand
)} {loaded.length > 1 && (
{loaded.filter((w) => w !== cur).map((w) => {w.model_id} · {fmtGB(w.measured_gb || w.estimate_gb)})}
)}
Open playground Model library
Model memory budget · {fmtGB(mgr?.resident_gb ?? 0)} resident of {fmtGB(budget, 0)} {t ? `${t.mem_used_gb.toFixed(1)} / ${t.mem_total_gb.toFixed(0)} GB system used` : ""}
budget * 0.9 ? "warn" : "accent"} />
{/* Telemetry */}
x.toFixed(1)).join(" / ")}` : ""}> p.model_id === cur.model_id)?.avg_tps ? `${stats.per_model.find((p) => p.model_id === cur.model_id)!.avg_tps!.toFixed(1)} tok/s` : "—"} sub="last requests, generation">
m.runtime === "mlx").length} MLX · ${installed.filter((m) => m.runtime === "llamacpp").length} GGUF`} />
{/* Models + activity */}
Models
All models →
{installed.slice().sort((a, b) => Number(b.loaded) - Number(a.loaded) || Number(b.favorite) - Number(a.favorite) || (b.last_used_at || 0) - (a.last_used_at || 0)).slice(0, 8).map((m) => ( (location.href = `/models/${m.id}`)}> ))} {!installed.length && }
ModelRuntimeEst. RAMTok/sStatus
{m.favorite && ★}{m.name}
{m.family} · {m.quantization}
{m.runtime === "mlx" ? "MLX" : "GGUF"} {fmtGB(m.estimated_ram_gb)} {m.avg_tps ? m.avg_tps.toFixed(1) : "—"}
No models yet — download one
Live activity
    {live.requests.slice(0, 20).map((r, i) => (
  • {String(r.model_id)}
    {String(r.endpoint).replace("/v1/", "")}{r.stream ? " · stream" : ""}
    = 400 ? "text-bad" : "text-ink-2"}>{Number(r.status) >= 400 ? `error ${r.status}` : `${fmtNum(Number(r.completion_tokens) || 0)} tok · ${r.tps ? Number(r.tps).toFixed(1) : "—"} tok/s`}
    TTFT {fmtMs(Number(r.ttft_ms))} · {fmtMs(Number(r.total_ms))}
  • ))} {!live.requests.length &&
  • Requests appear here in real time{cur ? "" : ` · last used ${fmtAgo(installed[0]?.last_used_at)}`}
  • }
); }