import { errorResponse, readPolicy, readToday, writePolicy } from "@/lib/articles/generation"; export const dynamic = "force-dynamic"; // THE GENERATION POLICY (release 27 S8): settings.generation, read from and // written through the editor's settings action (POST /api/ops/settings) — // routes per task, the models, the caps. Never the API key: the key FILE's // path and whether a file is there. // // GET -> { policy, today } // POST { routes?, models?, caps?, cacheTtl? } -> { policy } (a preset is its routes) export async function GET() { try { const policy = await readPolicy(); const today = await readToday(policy.generation.caps.daily); return Response.json({ policy, today }, { headers: { "cache-control": "no-store" } }); } catch (err) { return errorResponse(err); } } export async function POST(request: Request) { try { const body = (await request.json().catch(() => null)) as Record | null; if (!body || typeof body !== "object" || Array.isArray(body)) return Response.json({ error: "send the policy's changes as an object" }, { status: 400 }); return Response.json({ ok: true, policy: await writePolicy(body) }, { headers: { "cache-control": "no-store" } }); } catch (err) { return errorResponse(err); } }