"use client"; import { ExternalLinkIcon, PencilIcon, PlayIcon, SendIcon, SquareIcon, Trash2Icon } from "lucide-react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import { CopyButton } from "@/components/copy-button"; import { DeploymentStateBadge } from "@/components/deployment-state"; import { LiveLog } from "@/components/live-log"; import { LocalTime } from "@/components/local-time"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; import { Button, buttonVariants } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Progress } from "@/components/ui/progress"; import { useHostname, webUiUrl } from "@/hooks/use-hostname"; import { ENGINE_PORT } from "@/lib/deploy-command"; import { ACCELERATOR_LABEL } from "@/lib/runtimes-shared"; import type { DeploymentRow } from "@/lib/deployments"; import { formatBytes, percent } from "@/lib/format"; import { quantGroup } from "@/lib/selection"; import { cn } from "@/lib/utils"; import { deleteDeployment, startDeployment, stopDeployment } from "../actions"; import type { ListRow } from "../../benchmarks/benchmark-list"; import { BenchmarkCard } from "./benchmark-card"; type Deployment = Omit & { startedAt: string | null; readyAt: string | null; stoppedAt: string | null; createdAt: string; }; function Stat({ label, value, children }: { label: string; value: React.ReactNode; children?: React.ReactNode }) { return (
{label} {value} {children}
); } export function DeploymentDetail({ initial, benchmarks }: { initial: Deployment; benchmarks: ListRow[] }) { const router = useRouter(); const [d, setD] = useState(initial); const [now, setNow] = useState(() => Date.now()); const active = d.desiredState === "running" || d.state === "starting" || d.state === "running" || d.state === "stopping"; useEffect(() => { const t = setInterval(async () => { setNow(Date.now()); const res = await fetch(`/api/deployments/${d.id}`, { cache: "no-store" }).catch(() => null); if (res?.status === 404) router.push("/deployments"); else if (res?.ok) setD(await res.json()); }, 2_000); return () => clearInterval(t); }, [d.id, router]); const file = d.options.modelFile ? (quantGroup(d.options.modelFile) ?? d.options.modelFile) : null; const loadSecs = d.readyAt && d.startedAt ? (new Date(d.readyAt).getTime() - new Date(d.startedAt).getTime()) / 1000 : null; const startingSecs = d.state === "starting" && d.startedAt ? Math.max(0, (now - new Date(d.startedAt).getTime()) / 1000) : null; const port = ENGINE_PORT[d.engine]; const internal = d.containerName ? `http://${d.containerName}:${port}/v1` : null; const hostname = useHostname(); const published = d.hostPort && hostname ? `http://${hostname}:${d.hostPort}/v1` : null; const webUi = webUiUrl(d, hostname); return (

{d.name}

{d.repoId} {file && ` · ${file}`} {d.options.mmproj && " · vision"} {d.options.draftFile && ` · ${d.options.draftType === "draft-mtp" ? "MTP" : "draft"}`} · {d.runtimeName}

{d.runtimeImage}
{webUi && ( Web UI )} {active ? ( ) : ( )} Edit }> Delete Delete {d.name}? The container is stopped and removed. The model files stay in the library. Cancel { if (await deleteDeployment(d.id)) router.push("/deployments"); }} > Delete
{d.state === "failed" && d.error && (
{d.error}
)}
{d.cpus ? `limit ${d.cpus}` : "no limit"} {d.stats && d.state === "running" && d.memoryMb ? ( ) : ( {d.memoryMb ? `limit ${formatBytes(d.memoryMb * 2 ** 20)}` : "no limit"} )} until /health answered {d.engine === "vllm" ? `seqs ${d.options.maxNumSeqs ?? "default"}` : `slots ${d.options.parallel ?? "auto"}`}
Endpoint {internal ? (
{internal}
) : ( Not started yet. )} On the Docker network, for Kaname and other containers. {published && (
{published}
)} OpenAI-compatible; model name {d.repoId}. {d.options.requireApiKey && ( <> {" "} Requires one of the{" "} API keys {" "} as Authorization: Bearer. )}
Details
Container
{d.containerName ?? "–"}
Runs on
{ACCELERATOR_LABEL[d.accelerator]} {d.accelerator === "nvidia" && ` · ${d.options.gpus?.length ? `${d.options.gpus.length} selected GPU${d.options.gpus.length === 1 ? "" : "s"}` : "all GPUs"}`}
Started
Stopped
{d.command && ( <>
Arguments
{d.command.join(" ")}
)}
); } /** Live container log (polls new lines every 1.5 s). */ /** Smoke test over the OpenAI API: streams the answer and measures time to first token and speed. */ function Chat({ id, running }: { id: string; running: boolean }) { const [prompt, setPrompt] = useState("Write one sentence about the sea."); const [answer, setAnswer] = useState(""); const [busy, setBusy] = useState(false); const [stats, setStats] = useState<{ ttft: number | null; total: number; tokens: number | null; promptTokens: number | null } | null>(null); const [error, setError] = useState(null); async function send() { setBusy(true); setAnswer(""); setError(null); setStats(null); const t0 = performance.now(); let first: number | null = null; let usage: { completion_tokens?: number; prompt_tokens?: number } | null = null; let chunks = 0; try { const res = await fetch(`/api/deployments/${id}/chat`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ messages: [{ role: "user", content: prompt }], maxTokens: 256 }), }); if (!res.ok || !res.body) { const body = await res.json().catch(() => ({})); throw new Error(body.error?.message ?? `HTTP ${res.status}`); } const reader = res.body.pipeThrough(new TextDecoderStream()).getReader(); let buf = ""; for (;;) { const { value, done } = await reader.read(); if (done) break; buf += value; let nl: number; while ((nl = buf.indexOf("\n")) >= 0) { const line = buf.slice(0, nl).trim(); buf = buf.slice(nl + 1); if (!line.startsWith("data:")) continue; const data = line.slice(5).trim(); if (data === "[DONE]") continue; const j = JSON.parse(data); if (j.usage) usage = j.usage; const delta: string = j.choices?.[0]?.delta?.content ?? j.choices?.[0]?.delta?.reasoning_content ?? ""; if (delta) { first ??= performance.now(); chunks++; setAnswer((a) => a + delta); } } } const total = (performance.now() - t0) / 1000; setStats({ ttft: first ? (first - t0) / 1000 : null, total, tokens: usage?.completion_tokens ?? chunks, promptTokens: usage?.prompt_tokens ?? null }); } catch (err) { setError(err instanceof Error ? err.message : String(err)); } finally { setBusy(false); } } const genSecs = stats && stats.ttft != null ? stats.total - stats.ttft : null; return ( Try it