import { NextResponse } from "next/server"; import { readModelLog } from "yt-dlp-transcript-common/lib/llm/callLog-server"; import { modelLogView, viewQueryOf } from "yt-dlp-transcript-common/lib/llm/callLogView"; import { getRegistry } from "yt-dlp-transcript-common/jobs/registry"; import { JOB_ID, locate } from "./_locate"; export const dynamic = "force-dynamic"; // A JOB'S MODEL LOG (demo epic D3; the record is common's lib/llm/callLog.ts): // every model call the job made — what was asked (first lines), what came // back, what code did with it — grouped by phase, one page a group, for the // job page's panel. Ungated like the job's log beside it (./../log/route.ts // says why); it carries no key, no header and no host path (the records are // scrubbed when written). // GET /api/jobs//model-log[?outcome=&phase=&offset=&limit=] // -> { status, where: {article, n} | null, view: ModelLogView | null } export async function GET(request: Request, { params }: { params: Promise<{ id: string }> }) { const { id } = await params; if (!JOB_ID.test(id)) return NextResponse.json({ error: "Invalid id" }, { status: 400 }); let q; try { q = viewQueryOf(new URL(request.url).searchParams); } catch (e) { return NextResponse.json({ error: (e as Error).message }, { status: 400 }); } const status = getRegistry().get(id)?.status ?? null; const at = await locate(id); if (!at) return NextResponse.json({ status, where: null, view: null }, { headers: { "cache-control": "no-store" } }); // An iteration's log holds other runs: this job's only. const view = modelLogView(await readModelLog(at.files), { ...q, ...(at.where ? { jobId: id } : {}) }); return NextResponse.json({ status, where: at.where, view }, { headers: { "cache-control": "no-store" } }); }