import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { lastRunsByTask, readGenerationUsage, utcDay } from "yt-dlp-transcript-common/controller/generationUsage"; import PolicyPanel from "@/components/articles/PolicyPanel"; import AppShell from "@/components/shell/AppShell"; import { Panel } from "@/components/ui/panel"; import { readPolicy, type PolicyView } from "@/lib/articles/generation"; import { policyChip } from "@/lib/create/policy.mjs"; import { articleHref, settingsHref } from "@/lib/hrefs"; import { daySpend, recentDays } from "@/lib/settings/spend.mjs"; import Link from "next/link"; export const dynamic = "force-dynamic"; // --------------------------------------------------------------------------- // SETTINGS · GENERATION (plans/umtool-redesign.md, P5): the generation policy // -- where each task runs (Claude Code, the API, the local model), the presets, // the models (the extractor an API sweep reads its batches with among them), // the caps, and whether the API key's FILE is there (its path; never the key) // -- written through the editor's settings action (PolicyPanel, release 27 // S8, moved here from the new-article form). Under it, the day's spend, job by // job, from the editor's usage ledger (the total P2b's rail says). // // Read from the editor; an editor that does not answer is said, and the // ledger is still read (it is a file). // --------------------------------------------------------------------------- const usd = (v: number) => `$${v.toFixed(2)}`; const hhmm = (iso: string) => iso.slice(11, 16); export default async function GenerationPage() { let policy: PolicyView | null = null; let policyError: string | null = null; try { policy = await readPolicy(); } catch (e) { policyError = e instanceof Error ? e.message : String(e); } const rows = await readGenerationUsage(getPaths().generationUsageFile).catch(() => []); const day = utcDay(); const spend = daySpend(rows, day); const daily = policy?.generation.caps.daily ?? 0; const today = { day, usd: spend.usd, jobs: spend.jobs.length, daily }; const week = recentDays(rows, day, 7); const weekMax = Math.max(...week.map((d) => d.usd), 0.01); return (
{policyChip(policy?.generation ?? null, policy?.tasks)}} />
{policy ? ( ) : (

The editor did not answer ({policyError}), so the policy is unknown. Start it, then reload.

)} {`${day} UTC · the editor's ledger`} } data-spend-today={spend.usd.toFixed(2)} >

{usd(spend.usd)} {daily > 0 ? `of the ${usd(daily)} daily cap` : "no daily cap"} · {spend.jobs.length} {spend.jobs.length === 1 ? "job" : "jobs"}

{spend.jobs.length > 0 ? (
    {spend.jobs.map((j) => (
  • {hhmm(j.at)} {j.task} ·{" "} {j.article} i{j.iteration} {j.models.join(", ")} {usd(j.usd)}
  • ))}
) : (

Nothing spent on the API today.

)}

Last 7 days

    {week.map((d) => (
  • {d.day} {usd(d.usd)}
  • ))}
); }