"use client"; import { ExternalLinkIcon, PlayIcon, RocketIcon, SquareIcon } from "lucide-react"; import Link from "next/link"; import { useEffect, useState } from "react"; import { DeploymentStateBadge } from "@/components/deployment-state"; import { Button, buttonVariants } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { useHostname, webUiUrl } from "@/hooks/use-hostname"; import type { DeploymentRow } from "@/lib/deployments"; import { formatBytes } from "@/lib/format"; import { quantGroup } from "@/lib/selection"; import { startDeployment, stopDeployment } from "./actions"; type Row = Omit & { startedAt: string | null; readyAt: string | null; stoppedAt: string | null; createdAt: string; }; const isActive = (r: Row) => r.desiredState === "running" || r.state === "starting" || r.state === "running" || r.state === "stopping"; /** Live list (polls every 2 s while something is starting/stopping, else every 5 s). */ export function DeploymentList({ rows: initial }: { rows: Row[] }) { const [rows, setRows] = useState(initial); const hostname = useHostname(); const busy = rows.some((r) => r.state === "starting" || r.state === "stopping" || (r.desiredState === "running") !== (r.state === "running")); async function reload() { const res = await fetch("/api/deployments", { cache: "no-store" }).catch(() => null); if (res?.ok) setRows(await res.json()); } useEffect(() => { const t = setInterval(reload, busy ? 2_000 : 5_000); return () => clearInterval(t); }, [busy]); if (rows.length === 0) { return (

No deployments yet. Pick a runtime and a downloaded model to start one.

New deployment
); } return (
{rows.map((r) => { const file = r.options.modelFile ? (quantGroup(r.options.modelFile) ?? r.options.modelFile) : null; const loadSecs = r.readyAt && r.startedAt ? (new Date(r.readyAt).getTime() - new Date(r.startedAt).getTime()) / 1000 : null; return (
{r.name} {r.repoId} {file && ` · ${file}`} {r.options.mmproj && " · vision"} {r.options.draftFile && " · MTP/draft"} {r.runtimeName}
{r.state === "running" && r.stats ? `CPU ${(r.stats.cpuPercent / 100).toFixed(1)} cores · RAM ${formatBytes(r.stats.memoryBytes)}${r.memoryMb ? ` / ${formatBytes(r.memoryMb * 2 ** 20)}` : ""}` : r.state === "failed" ? (r.error?.split("\n")[0] ?? "failed") : `ctx ${r.options.contextSize}${r.memoryMb ? ` · ${formatBytes(r.memoryMb * 2 ** 20)} RAM` : ""}`} {r.state === "running" && loadSecs != null && ` · loaded in ${loadSecs.toFixed(1)} s`} {r.state === "running" && webUiUrl(r, hostname) && ( Web UI )} {isActive(r) ? ( ) : ( )}
); })}
); }