import { projectRef } from "@/lib/projects"; import { kindMakesTakes } from "@/lib/projects/kinds.mjs"; import { proposeTightWindows } from "@/lib/report/tightPropose.mjs"; export const dynamic = "force-dynamic"; // PROPOSE TIGHT WINDOWS (UI notes 2026-10-30, item 4; lib/report/tightPropose.mjs): // every clip of the cut tightened to its sentence and each edge into its pause, // before and after, for review. READS ONLY -- nothing is fetched and nothing // is written; a row is applied by its own Apply, through the window writer // (PUT /api/report/window with the token this answers). // // GET ?project=[&clip=…][&measure=0] // -> { token, rows: [{ id, before, after, changed, how, said, why, fetched, locked, words, clear }], counts } // measure=0: no silences (the words alone) -- nothing is measured const headers = { "cache-control": "no-store" }; export async function GET(request: Request) { const url = new URL(request.url); const project = await projectRef(String(url.searchParams.get("project") ?? "")); if (!project) return Response.json({ error: "no such project" }, { status: 404, headers }); if (!kindMakesTakes(project.kind)) return Response.json({ error: "tight windows are a report video's" }, { status: 400, headers }); const clips = url.searchParams.getAll("clip").filter(Boolean); try { const got = await proposeTightWindows(project, { clips: clips.length ? clips : null, measure: url.searchParams.get("measure") !== "0" }); return Response.json(got, { headers }); } catch (e) { return Response.json({ error: e instanceof Error ? e.message : String(e) }, { status: 422, headers }); } }