import { ActionError, applyIndex, isIndexAction, planIndex } from "@/lib/system/actions"; import { bodyOf, fail, ok } from "../_respond"; export const dynamic = "force-dynamic"; // THE PROJECT INDEX, from Settings ยท system (P5): `umtool index --rebuild | // --prune` behind a plan (lib/system/actions.ts). // // POST { action: "rebuild" | "prune", dryRun: true } -> { plan } writes nothing // POST { action: "rebuild" | "prune" } -> { applied, message, job? } // rebuild runs as a umtool job (the CLI); prune drops the records in // process. A confirm the plan now refuses is 409 with the plan. export async function POST(request: Request) { try { const b = await bodyOf(request); if (!isIndexAction(b.action)) throw new ActionError('action is "rebuild" or "prune"'); if (b.dryRun === true) return ok({ plan: await planIndex(b.action) }); return ok({ applied: true, ...(await applyIndex(b.action)) }); } catch (e) { return fail(e); } }