"use client"; import { ChevronDownIcon, CopyIcon, DownloadCloudIcon, PencilIcon, PlusIcon, ServerIcon, Trash2Icon } from "lucide-react"; import { useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import { toast } from "sonner"; import { LocalTime } from "@/components/local-time"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; import { Button } from "@/components/ui/button"; import { Card, CardAction, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Progress } from "@/components/ui/progress"; import type { DockerHostInfo, runtimes } from "@/lib/db/schema"; import { formatBytes, percent } from "@/lib/format"; import { ACCELERATOR_LABEL, RUNTIME_PRESETS, type RuntimeInput } from "@/lib/runtimes-shared"; import { cn } from "@/lib/utils"; import { RuntimeForm } from "./runtime-form"; type Runtime = typeof runtimes.$inferSelect; const FEATURE_LABEL: Record = { avx2: "AVX2", avx512f: "AVX-512", avx512_bf16: "AVX-512 BF16", avx512_vnni: "AVX-512 VNNI", avx512bw: "AVX-512 BW", amx_bf16: "AMX BF16", amx_int8: "AMX INT8", f16c: "F16C", fma: "FMA", }; async function send(url: string, method: string, body?: unknown): Promise { const res = await fetch(url, { method, headers: body ? { "Content-Type": "application/json" } : undefined, body: body ? JSON.stringify(body) : undefined, }); if (res.ok) return true; const json = await res.json().catch(() => ({})); toast.error(json.error?.message ?? `Request failed (${res.status})`); return false; } const toInput = (r: Runtime): RuntimeInput => ({ name: r.name, engine: r.engine, accelerator: r.accelerator, image: r.image, description: r.description, env: r.env, extraArgs: r.extraArgs, devices: r.devices, shmSizeMb: r.shmSizeMb, numaTuning: r.numaTuning, }); export function RuntimesView({ runtimes, docker, workerOnline }: { runtimes: Runtime[]; docker: DockerHostInfo | null; workerOnline: boolean }) { const router = useRouter(); const [creating, setCreating] = useState<(RuntimeInput & { preset?: string }) | null>(null); const [editing, setEditing] = useState(null); const anyPulling = runtimes.some((r) => r.imageState === "pulling" || (r.pullRequestedAt && (!r.pullStartedAt || r.pullRequestedAt > r.pullStartedAt))); // While a pull runs, refresh the server data every 2 s for its progress. useEffect(() => { if (!anyPulling) return; const t = setInterval(() => router.refresh(), 2_000); return () => clearInterval(t); }, [anyPulling, router]); return (
Runtimes Container images that serve models: official llama.cpp and vLLM builds, or your own forks from any registry. Kaname only starts images registered here, with the models mounted read-only. }> Add runtime From a preset {RUNTIME_PRESETS.map((p) => ( setCreating({ ...p, name: p.name, preset: p.id })} className="flex-col items-start gap-0"> {p.name} {p.summary} ))} setCreating({ name: "", engine: "vllm", image: "" })}>Custom image (fork)… {creating && (
setCreating(null)} onSubmit={async (value) => { const ok = await send("/api/runtimes", "POST", { ...value, preset: creating.preset }); if (ok) { toast.success(`Runtime "${value.name}" added`); setCreating(null); router.refresh(); } return ok; }} />
)} {runtimes.length === 0 && !creating &&

No runtimes yet. Add one from a preset.

} {runtimes.map((r) => editing === r.id ? (
setEditing(null)} onSubmit={async (value) => { const ok = await send(`/api/runtimes/${r.id}`, "PUT", value); if (ok) { setEditing(null); router.refresh(); } return ok; }} />
) : ( setEditing(r.id)} onDuplicate={() => setCreating({ ...toInput(r), name: `${r.name} (copy)` })} /> ), )}
); } function HostCard({ docker, workerOnline }: { docker: DockerHostInfo | null; workerOnline: boolean }) { return ( Docker host {!workerOnline ? "The worker is offline; these facts may be outdated." : !docker ? "Not connected. Runtimes need the worker to reach Docker through the socket proxy (DOCKER_HOST)." : docker.connected ? `Docker ${docker.serverVersion} on ${docker.os} (${docker.architecture})` : `Can't reach Docker: ${docker.error}`} {docker && (
CPU
{docker.cpuModel ?? "unknown"} {docker.cpus != null && · {docker.cpus} threads}
Features
{docker.cpuFeatures.length === 0 ? ( unknown ) : ( docker.cpuFeatures.map((f) => ( {FEATURE_LABEL[f] ?? f} )) )}
Memory
{docker.memoryBytes != null ? formatBytes(docker.memoryBytes) : "unknown"}
GPUs
{docker.gpus && docker.gpus.length > 0 ? ( docker.gpus.map((g) => ( {g.index}: {g.name} · {formatBytes(g.memoryMb * 2 ** 20)} · driver {g.driver} )) ) : docker.nvidia ? ( {docker.gpuError ? `NVIDIA runtime found, but listing GPUs failed: ${docker.gpuError}` : "NVIDIA runtime found, no GPUs listed."} ) : ( No NVIDIA GPUs (no NVIDIA runtime in Docker). Intel/AMD GPUs aren't listed; pass /dev/dri to a runtime to use them. )}
Network
{docker.network ?? "not detected (set KANAME_DOCKER_NETWORK)"}
Models
{docker.modelsSource ? `${docker.modelsSource.source} (${docker.modelsSource.type}, mounted read-only)` : "not detected (set KANAME_MODELS_SOURCE)"}
Checked
)}
); } function ImageState({ r }: { r: Runtime }) { const requested = !!r.pullRequestedAt && (!r.pullStartedAt || r.pullRequestedAt > r.pullStartedAt); if (r.imageState === "pulling" || requested) { const p = r.pullProgress; return (
{p ? `${p.status} · ${formatBytes(p.doneBytes)}${p.totalBytes ? ` / ${formatBytes(p.totalBytes)}` : ""}` : "Pull queued…"}
); } if (r.imageState === "present") { return ( Pulled · {r.imageSize != null ? formatBytes(r.imageSize) : "?"} {r.imageCreated && ( {" "} · built )} ); } if (r.imageState === "failed") return Pull failed: {r.pullError}; if (r.imageState === "missing") return Not pulled yet; return Not checked yet; } function RuntimeRow({ runtime: r, dockerReady, onEdit, onDuplicate, }: { runtime: Runtime; dockerReady: boolean; onEdit: () => void; onDuplicate: () => void; }) { const router = useRouter(); const pulling = r.imageState === "pulling"; const envCount = Object.keys(r.env).length; return (
{r.name} {r.engine === "vllm" ? "vLLM" : "llama.cpp"} {r.accelerator !== "cpu" && ( {ACCELERATOR_LABEL[r.accelerator]} )} {r.numaTuning && NUMA tuning}
{r.image} {r.description &&

{r.description}

}
}> Delete runtime “{r.name}”? The pulled image stays in Docker; remove it there if you need the space. Cancel { if (await send(`/api/runtimes/${r.id}`, "DELETE")) router.refresh(); }} > Delete
{envCount > 0 && `${envCount} env var${envCount === 1 ? "" : "s"}`} {r.extraArgs.length > 0 && `${envCount > 0 ? " · " : ""}${r.extraArgs.join(" ")}`} {r.shmSizeMb != null && ` · shm ${r.shmSizeMb} MiB`} {r.devices.length > 0 && ` · ${r.devices.join(", ")}`}
); }