"use client"; import { DownloadIcon, ExternalLinkIcon, RotateCcwIcon, SquareIcon, Trash2Icon, TriangleAlertIcon, } from "lucide-react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import { toast } from "sonner"; import { BenchmarkStateBadge } from "@/components/benchmark-state"; import { CopyButton } from "@/components/copy-button"; 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 { Input } from "@/components/ui/input"; import { reportSummary, weightsLabel } from "@/lib/benchmark-report"; import { CONFIG_ROWS, describeSettings } from "@/lib/benchmark-view"; import type { ListRow } from "../benchmark-list"; import { AgentApprovalBar } from "@/components/approval-bar"; import { RequestedByBadge } from "@/components/requested-by-badge"; import { RunMetaCard } from "@/components/run-meta"; import { cancelBenchmark, deleteBenchmark, describeBenchmark, renameBenchmark } from "../actions"; import { AbReport } from "./ab-report"; import { QualityReport } from "./quality-report"; import { BenchmarkReport } from "./benchmark-report"; import { PublishCard } from "./publish-card"; function duration(a: string | null, b: string | null, now: number) { if (!a) return null; const s = Math.max( 0, ((b ? new Date(b).getTime() : now) - new Date(a).getTime()) / 1000, ); const h = Math.floor(s / 3600); const m = Math.floor((s % 3600) / 60); return h ? `${h} h ${m} min` : m ? `${m} min ${Math.round(s % 60)} s` : `${Math.round(s)} s`; } export function BenchmarkDetail({ initial }: { initial: ListRow }) { const router = useRouter(); const [r, setR] = useState(initial); const [now, setNow] = useState(() => Date.now()); const [label, setLabel] = useState(initial.label ?? ""); const [description, setDescription] = useState(initial.description ?? ""); const active = r.state === "pending_approval" || r.state === "queued" || r.state === "running"; useEffect(() => { if (!active) return; const t = setInterval(async () => { setNow(Date.now()); const res = await fetch(`/api/benchmarks/${r.id}`, { cache: "no-store", }).catch(() => null); if (res?.ok) setR(await res.json()); }, 2_000); return () => clearInterval(t); }, [active, r.id]); async function again() { if (!r.deploymentId) return; const res = await fetch("/api/benchmarks", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ deploymentId: r.deploymentId, deploymentBId: r.kind === "ab" ? r.deploymentBId : null, kind: r.kind, label: r.label, description: r.description, ...r.settings, }), }); const json = await res.json().catch(() => ({})); if (!res.ok) return toast.error( json.error?.message ?? `Could not start (${res.status})`, ); router.push(`/benchmarks/${json.id}`); } const s = r.snapshot; const sum = r.summary; const took = duration(r.startedAt, r.finishedAt, now); return (
{r.deploymentId ? ( {s.deploymentName} ) : ( `${s.deploymentName} (deleted)` )}{" "} ·{" "} {r.modelId ? ( {s.repoId} ) : ( s.repoId )}{" "} · {s.runtimeName} {r.kind === "ab" && r.snapshotB && ( <> {" "} · B:{" "} {r.deploymentBId ? ( {r.snapshotB.deploymentName} ) : ( r.snapshotB.deploymentName )} > )} {r.sweepId && ( <> {" "} ·{" "} part of a sweep > )}
{r.kind === "eval" ? "Kaname" : "BetterBench"} ·{" "}
{r.kind === "ab"
? `paired A/B, target ±${r.settings.mdePct ?? 1}%, up to ${r.settings.maxPairs ?? 200} pairs`
: describeSettings(r.settings)}{" "}
· created
{r.error}
Waiting: benchmarks run one at a time.
)} {r.state === "running" && r.phase && (Now: {r.phase}
)}