import { NextResponse } from "next/server"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { RESEARCH_APPROVE_BODY_KEYS, approveResearch } from "yt-dlp-transcript-common/controller/researchRuns"; import { opsFail, ops } from "../_lib"; import { researchEditor } from "../_researchEditor"; export const dynamic = "force-dynamic"; // POST { article, iteration, ids?, approve?, note? } // -> { ok: true, outcomes: [{id, status?, jobId?, note?, error?}], research } // // A research run's acquisitions (release 27 S11), after its job: // - first, always, the run is REFRESHED: an enqueued acquisition whose // editor jobs have all ended is done (or failed, naming the job), and // the run's phase follows (wait → ready); // - `ids` with `approve: true` runs each proposal's editor action — past // the run's autonomy and caps, never past a standing rule (no site for a // new channel, no Twitch VOD) — through this editor's own ops actions, // their doors and queues; `approve: false` rejects them (`note`: why); // - no `ids`: the run's state now (the umtool queue polls this). // `research` is {article, iteration, status, phase, autonomy, limits, spent, // proposals, waitingOn: {approval, jobs}, continuedBy, autoContinue?}. A run // whose job is still going is refused. The CONTINUATION is report-draft // {task: "sweep", iteration: }; an `auto` run's is asked by the // editor itself (release 28 F1, controller/researchAutoContinue.ts). // // AN ADAPTER: the rules are the controller's (controller/researchRuns.ts). export async function POST(request: Request) { return ops(request, RESEARCH_APPROVE_BODY_KEYS, async (body) => { const out = await approveResearch(body, { paths: getPaths(), editor: researchEditor }); if (!out.ok) return opsFail(out.error); return NextResponse.json({ ok: true, outcomes: out.outcomes, research: out.view }); }); }