"use client"; import { GaugeIcon, GitCompareIcon } from "lucide-react"; import Link from "next/link"; import { useEffect, useState } from "react"; import { BenchmarkStateBadge } from "@/components/benchmark-state"; import { LocalTime } from "@/components/local-time"; import { buttonVariants } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { Checkbox } from "@/components/ui/checkbox"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import type { BenchmarkRow } from "@/lib/benchmarks"; import { configChips, describeSettings, headline } from "@/lib/benchmark-view"; import { cn } from "@/lib/utils"; export type ListRow = Omit & { createdAt: string; startedAt: string | null; finishedAt: string | null; cancelRequestedAt: string | null; }; const MAX_COMPARE = 6; const fmt = (v: number | null | undefined, digits = 1) => (v == null ? "–" : v.toFixed(digits)); /** All runs with their headline numbers; polls while something is queued or running. */ export function BenchmarkList({ rows: initial, compact }: { rows: ListRow[]; compact?: boolean }) { const [rows, setRows] = useState(initial); const [selected, setSelected] = useState([]); const busy = rows.some((r) => r.state === "queued" || r.state === "running"); useEffect(() => { if (!busy || compact) return; const t = setInterval(async () => { const res = await fetch("/api/benchmarks", { cache: "no-store" }).catch(() => null); if (res?.ok) setRows(await res.json()); }, 3_000); return () => clearInterval(t); }, [busy, compact]); if (rows.length === 0) { return (

No benchmarks yet. Open a running{" "} deployment {" "} and start one there.

); } const toggle = (id: string) => setSelected((s) => (s.includes(id) ? s.filter((x) => x !== id) : s.length < MAX_COMPARE ? [...s, id] : s)); const comparable = rows.filter((r) => r.state === "completed"); return (
{!compact && comparable.length > 1 && (
{selected.length === 0 ? "Select completed runs to compare them." : `${selected.length} selected (up to ${MAX_COMPARE}).`} Compare
)} {!compact && } Run Settings Decode t/s TTFT Prefill t/s Peak t/s State {rows.map((r) => { const h = headline(r.summary); const s = r.snapshot; return ( {!compact && ( toggle(r.id)} aria-label={`Select ${r.label ?? s.deploymentName} for comparison`} /> )} {r.label ?? s.deploymentName}
{r.label && `${s.deploymentName} · `} {s.repoId} ·
{s.runtimeName} {configChips(s).map((c) => ( {c} ))}
{describeSettings(r.settings)}
{fmt(h.decode)} {h.ttftMs != null ? `${Math.round(h.ttftMs)} ms` : "–"} {fmt(h.prefill?.tps, 0)} {fmt(h.peak?.tps)}
); })}
); }