import { runSettled, runView } from "@/lib/agent-runs"; import { withToken } from "@/lib/api-tokens"; import { v1Catch, v1Error, v1Json } from "@/lib/api-v1"; import { getBenchmark } from "@/lib/benchmarks"; import { parseWait, waitFor } from "@/lib/wait"; export const dynamic = "force-dynamic"; /** * A run's state and compact result (headline numbers, setup, resources). ?wait= (max 900) blocks * until it is finished or waits for approval; ?full=1 adds BetterBench's full summary. */ export const GET = withToken>("benchmarks:read", async (req, { params, token }) => { try { const id = (await params).id; const q = new URL(req.url).searchParams; const { value: run, waitedS, timedOut } = await waitFor(() => getBenchmark(id), (r) => !r || runSettled(r.state), parseWait(q), { signal: req.signal }); if (!run) return v1Error(404, "not_found", "No benchmark run with this id."); return v1Json({ ...runView(run, token, q.get("full") === "1"), ...(waitedS ? { waitedSeconds: waitedS, timedOut } : {}) }); } catch (err) { return v1Catch(err); } });