import { NextResponse } from "next/server"; import { z } from "zod"; import { APPROVAL_MODES } from "@/lib/agent-guardrails"; import { withAuth } from "@/lib/api-auth"; import { apiError, handleApiError } from "@/lib/api-errors"; import { getTuning, saveTuning, SettingsError } from "@/lib/settings"; export const dynamic = "force-dynamic"; /** Guardrails for deployments and benchmarks requested through the API. */ export const GET = withAuth(async () => NextResponse.json(await getTuning())); const Body = z .object({ approvalMode: z.enum(APPROVAL_MODES), maxAgentDeployments: z.number().int(), maxRunMinutes: z.number().int(), maxSweepMinutes: z.number().int(), maxSweepVariants: z.number().int(), allowedRuntimeIds: z.array(z.string().max(64)).max(100), allowedArgs: z.object({ "llama.cpp": z.array(z.string().max(80)).max(500), vllm: z.array(z.string().max(80)).max(500) }), hostPortRange: z.object({ from: z.number().int(), to: z.number().int() }).nullable(), maxMemoryMb: z.number().nullable(), maxCpus: z.number().nullable(), }) .partial(); export const PUT = withAuth(async (req) => { try { return NextResponse.json(await saveTuning(Body.parse(await req.json()))); } catch (err) { if (err instanceof SettingsError) return apiError(err.status, err.code, err.message); return handleApiError(err); } });