import type { ResearchOutcome, ResearchView } from "yt-dlp-transcript-common/controller/researchRuns"; import { askEditor, EditorError } from "./generation"; // A RESEARCH RUN, AS UMTOOL SEES IT (release 27 S11): its acquisitions and // their state, from the EDITOR's `research-approve` action — which refreshes // every enqueued acquisition from its jobs first, so each read is the run as // it is now. The operator's yes or no is the same action with `ids`. Umtool // writes nothing here: the editor runs an approved acquisition through its own // ops action and rewrites the run's proposals.json. // // SERVER-ONLY. // The editor's answer's shape is common's (type-only imports: nothing of the // controller is bundled here). export type { ResearchOutcome, ResearchView }; export type { Proposal as ResearchProposal } from "yt-dlp-transcript-common/lib/report/draft/research/decide"; const ID = /^p\d+$/; /** The run now (refreshed by the editor). */ export async function readResearch(article: string, n: number): Promise { const answer = await askEditor<{ research: ResearchView }>("/api/ops/research-approve", { method: "POST", body: { article, iteration: n } }); return answer.research; } /** The operator's yes (`approve: true`) or no to proposals of a run. */ export async function settleResearch( article: string, n: number, ids: string[], approve: boolean, note?: string, ): Promise<{ research: ResearchView; outcomes: ResearchOutcome[] }> { if (!ids.length || !ids.every((id) => ID.test(id))) throw new EditorError("ids are proposal ids (p01, p02, …)", 400); const answer = await askEditor<{ research: ResearchView; outcomes: ResearchOutcome[] }>("/api/ops/research-approve", { method: "POST", body: { article, iteration: n, ids, approve, ...(note?.trim() ? { note: note.trim() } : {}) }, }); return { research: answer.research, outcomes: answer.outcomes ?? [] }; }