import { act } from "@/lib/agent-activity"; import { AgentSweepBody, requestSweep } from "@/lib/agent-runs"; import { withToken } from "@/lib/api-tokens"; import { v1Catch, v1Json } from "@/lib/api-v1"; export const dynamic = "force-dynamic"; /** * Queue a sweep: one or two settings varied from the token's own base deployment. Each variant is * deployed, benchmarked and removed again, one after another. */ export const POST = withToken("benchmarks:run", async (req, { token }) => { try { const body = AgentSweepBody.parse(await req.json()); const r = await act(token, "sweep.create", { type: "sweep" }, () => requestSweep(token, body)); return v1Json( { ...r, message: r.state === "pending_approval" ? "Requested; it waits for the user's approval in Kaname. Don't retry or poll; tell the user and stop." : `Queued (${r.variants} variants, stopped after ${r.timeLimitMinutes} min); GET /api/v1/sweeps/${r.id}?wait=900 for progress.`, }, 201, ); } catch (err) { return v1Catch(err); } });