"use client"; import type { DiscoverEntry, DiscoverHardware, DiscoverResult, GPUInfo } from "@/lib/modelfit"; import { verdictMeta } from "@/components/modelfit/verdict"; // ── Small building blocks ───────────────────────────────────────────────────── function Chip({ label, tone = "zinc" }: { label: string; tone?: "zinc" | "green" | "sky" | "amber" }) { const tones = { zinc: "bg-zinc-800 text-zinc-300", green: "bg-emerald-900/50 text-emerald-300", sky: "bg-sky-900/50 text-sky-300", amber: "bg-amber-900/50 text-amber-300", }; return {label}; } function Stat({ label, value, accent }: { label: string; value: React.ReactNode; accent?: string }) { return (
{label}
{value}
); } function backendTone(b: string) { return b === "cuda" ? "bg-emerald-900/50 text-emerald-300 ring-emerald-600/40" : b === "metal" ? "bg-sky-900/50 text-sky-300 ring-sky-600/40" : b === "rocm" ? "bg-purple-900/50 text-purple-300 ring-purple-600/40" : "bg-zinc-800 text-zinc-300 ring-zinc-600/40"; } /** Per-GPU VRAM bar: used (other processes) + free. */ function GpuBar({ gpu }: { gpu: GPUInfo }) { const total = gpu.vram_gb || 0; const free = gpu.vram_free_gb ?? null; const usedPct = total > 0 && free != null ? Math.max(0, Math.min(100, ((total - free) / total) * 100)) : 0; return (
{gpu.name} {total} GB{gpu.integrated ? " unified" : ""}
{free != null && ( <>
{free} GB free · {(total - free).toFixed(1)} GB in use
)}
); } /** Usage gauge for the recommended model vs available memory, with 80% marker. */ function UsageGauge({ entry, hardware }: { entry: DiscoverEntry; hardware: DiscoverHardware }) { const re = entry.resource_estimate; if (!re) return null; const onGpu = hardware.total_vram_gb > 0; const capacity = onGpu ? hardware.total_vram_gb : hardware.ram_gb; const model = re.estimated_vram_gb; const pct = capacity > 0 ? Math.min(100, (model / capacity) * 100) : 0; const meta = verdictMeta(re.verdict); const freeNow = onGpu ? hardware.total_vram_free_gb ?? null : null; return (
Estimated {onGpu ? "VRAM" : "RAM"} use {model} / {capacity} GB
{/* 80% headroom marker */}
{re.headroom_gb != null && re.headroom_gb >= 0 ? `${re.headroom_gb} GB headroom` : "exceeds capacity"} {freeNow != null && ` · ${freeNow} GB free right now`} {" · dashed line = 80% target"}
); } // ── Plain-language summary ──────────────────────────────────────────────────── function gpuSummary(gpus: GPUInfo[], totalVram: number): string { if (gpus.length === 0) return "no GPU"; const first = gpus[0].name.replace(/NVIDIA GeForce |NVIDIA /i, ""); const prefix = gpus.length > 1 ? `${gpus.length}× ${first}` : first; return `${prefix} (${totalVram} GB VRAM)`; } function buildSummary(hardware: DiscoverHardware, entry: DiscoverEntry): string { const re = entry.resource_estimate; const name = (entry.model_meta.display_name || entry.model_id).replace(/^(ollama:|hf:|local:)/, ""); const hw = hardware.total_vram_gb > 0 ? gpuSummary(hardware.gpus, hardware.total_vram_gb) : `${hardware.ram_gb} GB RAM (CPU)`; if (!re) return `${name} is the best match for your ${hw}.`; const v = re.verdict; const use = `~${re.estimated_vram_gb} GB at ${entry.best_quantization}`; if (v === "runs_great") return `Your ${hw} runs ${name} comfortably — ${use}, ${re.headroom_gb} GB to spare.`; if (v === "runs_ok") return `Your ${hw} runs ${name} — ${use}, a tight but workable fit.`; if (v === "runs_offload") return `${name} needs ${use} — more than your ${hw}. It runs by offloading layers to system RAM (slower). A smaller model or lower quant would run fully on the GPU.`; if (v === "runs_cpu") return `${name} runs on your CPU — ${use} in RAM, ${re.headroom_gb} GB to spare.`; if (v === "runs_cpu_tight") return `${name} runs on your CPU but leaves little RAM headroom (${use}).`; return `${name} needs ${use} — too large for this machine. Pick a smaller model below.`; } // ── Main report ─────────────────────────────────────────────────────────────── export function SystemReport({ result, onPull, onRefresh, loading, hosted = false, }: { result: DiscoverResult; onPull: (entry: DiscoverEntry) => void; onRefresh: () => void; loading: boolean; /** True on a hosted demo (HF Space): the probe reads the SERVER, not the visitor's device. */ hosted?: boolean; }) { const hw = result.hardware; const top = result.recommendations[0] as DiscoverEntry | undefined; const onGpu = hw.total_vram_gb > 0; const meta = top?.resource_estimate ? verdictMeta(top.resource_estimate.verdict) : null; return (
{/* Header */}

Your System Report

Detected hardware and the best-fitting model, ranked for {result.task ?? "your tasks"}.

{/* Hosted-demo notice: the probe reads the Space's server, not the visitor's device. */} {hosted && (
You're on the hosted demo.{" "} This report profiles the Space's server{" "} ({hw.os} {hw.arch ? ` · ${hw.arch}` : ""}) — not your own device. Models shown here would run on the server, not on your machine. To profile your Mac/PC and pull models onto it, run Auralynq locally ( one command ).
)}
{/* ── This machine ── */}
{hosted ? "Server (hosted demo)" : "This machine"} {hw.best_backend.toUpperCase()}
{hw.cpu_cores_physical != null && ( )} {hw.avx2 && } {hw.avx512 && }
{/* GPUs */}
{onGpu ? `GPU${hw.gpus.length > 1 ? `s · ${hw.gpus.length}` : ""}` : "GPU"} {onGpu && ( {hw.total_vram_gb} GB total {hw.total_vram_free_gb != null && ` · ${hw.total_vram_free_gb} free`} )}
{hw.gpus.length === 0 ? (

None detected — inference will use the CPU. {hw.in_container && " (Running in a container; host GPUs may be hidden.)"}

) : (
{hw.gpus.slice(0, 4).map((g, i) => ( ))}
)}
{/* ── Top pick ── */}
{hosted ? "Best pick for this server" : "Best pick for you"} {!top ? (

No models matched this machine and task.

) : ( <> {/* Model identity */}
{(top.model_meta.display_name || top.model_id).replace(/^(ollama:|hf:|local:)/, "")}
{top.source} {top.model_meta.parameter_count_b != null && · {top.model_meta.parameter_count_b}B} · {top.best_quantization} · score {Math.round(top.overall_score)}
{top.already_installed && ( Installed )}
{/* Verdict badge */} {meta && (
{meta.label}
)} {/* Usage gauge */} {/* Quick stats */}
{top.resource_estimate && ( <> )}
{/* Plain-language summary */}

{buildSummary(hw, top)}

{/* CTA */} {!top.already_installed && top.pull_command && ( )} )}
{/* Footer */}
{result.total_candidates} models scored against {hosted ? " the server's hardware" : " your hardware"} · full ranking below ↓
); }