import { errorResponse } from "@/lib/articles/generation"; import { clearPiecesCache } from "@/lib/pieces"; import { clearRailCounts } from "@/lib/rail"; import { readSchedules, scheduleAsk } from "@/lib/schedules"; export const dynamic = "force-dynamic"; const NO_STORE = { "cache-control": "no-store" }; const ACTIONS = ["create", "update", "pause", "resume", "delete", "tick-now", "learn", "unlearn", "promote-alias", "add-spelling"]; // RECURRING REPORTS (plans/umtool-redesign.md, R5). // // GET every schedule, read from the article store (no editor call) // POST { action: create | update | pause | resume | delete | tick-now | // learn | unlearn | promote-alias | add-spelling, … } // -- the editor's `report-schedule` ops action, forwarded as sent: the // editor keeps the schedules and is their one writer (a create with // `dryRun: true` is its plan; a delete without `confirm: true` is its // plan; R6.3: a learn with `dryRun: true` and a promote-alias without // `confirm: true` are plans; release 32: add-spelling, a spelling // added by hand). Answers the editor's JSON, or its // refusal in its words. export async function GET() { try { return Response.json(await readSchedules(), { headers: NO_STORE }); } catch (err) { return errorResponse(err); } } export async function POST(request: Request) { const body = (await request.json().catch(() => null)) as Record | null; if (!body || typeof body !== "object" || Array.isArray(body)) return Response.json({ error: "send the schedule's action as an object" }, { status: 400, headers: NO_STORE }); if (typeof body.action !== "string" || !ACTIONS.includes(body.action)) { return Response.json({ error: `"action" is one of ${ACTIONS.join(", ")}` }, { status: 400, headers: NO_STORE }); } try { const out = await scheduleAsk(body); // A write changes what Work, the Inbox and the rail show. const planOnly = ((body.action === "create" || body.action === "learn") && body.dryRun === true) || ((body.action === "delete" || body.action === "promote-alias") && body.confirm !== true); if (!planOnly) { clearPiecesCache(); clearRailCounts(); } return Response.json(out, { headers: NO_STORE }); } catch (err) { return errorResponse(err); } }