"use client"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import { passesBar, type ModelScore, type VerdictBar } from "yt-dlp-transcript-common/lib/report/draft/bench/score"; import type { GenerationVerdicts } from "yt-dlp-transcript-common/lib/generationSettings"; // THE BAR (release 28 M7): the least agreement, CONTRADICTED recall and // NOT_FOUND recall a model must reach on this run, and the passing models the // operator ticks for the verdict proposals — settings.generation.verdicts, // written whole through /api/bench/bar (the editor's settings action). A // model is never ticked automatically, and one that fails the bar as typed // cannot be ticked. const KEYS: { key: keyof VerdictBar; label: string }[] = [ { key: "agreement", label: "minimum agreement" }, { key: "contradictedRecall", label: "minimum CONTRADICTED recall" }, { key: "notFoundRecall", label: "minimum NOT_FOUND recall" }, ]; const field = "w-16 rounded border border-[var(--color-line)] bg-[var(--color-ink)] px-1.5 py-0.5 text-[12px] text-[var(--color-text)]"; const toPct = (v: number) => String(Math.round(v * 1000) / 10); // The window proposals read is the run's the bar is set on: saved with it // (settings.generation.verdicts.window, release 29). const windowWords = (w: { mode: string; seconds: number }) => (w.mode === "turn" ? `the speaker's turn within ${w.seconds} s` : `±${w.seconds} s`); export default function BarForm({ initial, models, window }: { initial: GenerationVerdicts; models: ModelScore[]; window: GenerationVerdicts["window"] }) { const [typed, setTyped] = useState(() => Object.fromEntries(KEYS.map((k) => [k.key, toPct(initial.bar[k.key])])) as Record); const [ticked, setTicked] = useState(initial.models); const [status, setStatus] = useState<{ ok: boolean; text: string } | null>(null); const [busy, setBusy] = useState(false); const bar = Object.fromEntries(KEYS.map((k) => [k.key, Math.min(100, Math.max(0, Number(typed[k.key]) || 0)) / 100])) as VerdictBar; // A model ticked in settings but not in this run is kept as it is. const here = new Set(models.map((m) => m.model)); async function save(e: React.FormEvent) { e.preventDefault(); setBusy(true); setStatus(null); const keep = ticked.filter((m) => !here.has(m) || passesBar(models.find((x) => x.model === m)!, bar).pass); try { const r = await fetch("/api/bench/bar", { method: "POST", body: JSON.stringify({ bar, models: keep, window }) }); const body = await r.json(); if (!r.ok) throw new Error(body.error ?? `HTTP ${r.status}`); const v = body.verdicts as GenerationVerdicts; setTyped(Object.fromEntries(KEYS.map((k) => [k.key, toPct(v.bar[k.key])])) as Record); setTicked(v.models); setStatus({ ok: true, text: "Saved." }); } catch (err) { setStatus({ ok: false, text: (err as Error).message }); } finally { setBusy(false); } } return (
the bar {KEYS.map((k) => ( ))}
verdict proposals on {models.map((m) => { const check = passesBar(m, bar); const on = ticked.includes(m.model) && check.pass; return ( ); })} {`proposals read ${windowWords(window)} (this run's window)`} {initial.window && (initial.window.mode !== window.mode || initial.window.seconds !== window.seconds) ? ` · now ${windowWords(initial.window)}` : ""} {status && ( {status.text} )}
); }