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 { getGuardrails, saveGuardrails, SettingsError } from "@/lib/settings"; export const dynamic = "force-dynamic"; /** Guardrails for downloads requested through the API. */ export const GET = withAuth(async () => NextResponse.json(await getGuardrails())); const Body = z .object({ approvalMode: z.enum(APPROVAL_MODES), maxRequestBytes: z.number(), minFreeBytes: z.number(), maxOpenJobs: z.number().int(), allowedAuthors: z.array(z.string()).max(100), }) .partial(); export const PUT = withAuth(async (req) => { try { return NextResponse.json(await saveGuardrails(Body.parse(await req.json()))); } catch (err) { if (err instanceof SettingsError) return apiError(err.status, err.code, err.message); return handleApiError(err); } });