import { NextResponse } from "next/server"; import { withAuth } from "@/lib/api-auth"; import { apiError, handleApiError } from "@/lib/api-errors"; import { BenchmarkBody, BenchmarkError, createBenchmark, listBenchmarks } from "@/lib/benchmarks"; export const dynamic = "force-dynamic"; /** All runs, newest first; `?deployment=` or `?model=` narrows them. */ export const GET = withAuth(async (req) => { const sp = new URL(req.url).searchParams; return NextResponse.json(await listBenchmarks({ deploymentId: sp.get("deployment") ?? undefined, modelId: sp.get("model") ?? undefined })); }); /** Queue a BetterBench run against a running deployment. */ export const POST = withAuth(async (req) => { try { return NextResponse.json(await createBenchmark(BenchmarkBody.parse(await req.json())), { status: 201 }); } catch (err) { if (err instanceof BenchmarkError) return apiError(err.status, err.code, err.message); return handleApiError(err); } });