import Link from 'next/link'; import { Legend, LineChart } from '@/components/charts/charts'; import { CompareButton } from '@/components/compare/compare-button'; import { ConfidenceBadge } from '@/components/ui/badges'; import { DataTable, EmptyRow, Td, Th } from '@/components/ui/data-table'; import { EntityLink } from '@/components/ui/entity'; import { Pagination } from '@/components/ui/pagination'; import { SourceCell } from '@/components/ui/provenance'; import { Note } from '@/components/ui/section'; import { EmptyState } from '@/components/ui/unavailable'; import { cn } from '@/lib/cn'; import { fmtDate, fmtInt, fmtScore } from '@/lib/format'; import { routes } from '@/lib/site'; import type { BenchmarkResult } from '@/lib/types'; /** Per-model identifiers (one row each) are useless as filters; everything else becomes a chip candidate. */ const PER_ROW_KEYS = new Set(['aa_slug', 'model_tag', 'model_id', 'run_id', 'submission_id', 'date', 'submitted_at', 'url']); /** Distinct config values seen on the page (value → count), skipping per-row identifiers and singletons. */ export function configChips(results: BenchmarkResult[], max = 10): { value: string; key: string; count: number }[] { const counts = new Map(); for (const r of results) { for (const [k, v] of Object.entries(r.config ?? {})) { if (PER_ROW_KEYS.has(k) || v === null || v === undefined || v === '') continue; const s = typeof v === 'object' ? JSON.stringify(v) : String(v); if (s.length > 40) continue; const cur = counts.get(s); if (cur) cur.count += 1; else counts.set(s, { key: k, count: 1 }); } } return [...counts.entries()] .map(([value, x]) => ({ value, key: x.key, count: x.count })) .filter((c) => c.count > 1 && c.count < results.length) .sort((a, b) => b.count - a.count || a.value.localeCompare(b.value)) .slice(0, max); } export function configSummary(c: Record): string { return Object.entries(c ?? {}) .filter(([, v]) => v !== null && v !== undefined && v !== '') .slice(0, 4) .map(([k, v]) => `${k}=${typeof v === 'object' ? JSON.stringify(v) : String(v)}`) .join(' · '); } export function ConfigChips({ slug, chips, active, model }: { slug: string; chips: ReturnType; active?: string; model?: string }) { if (!chips.length && !active) return null; const cls = (on: boolean) => cn('inline-flex h-8 items-center gap-1.5 border px-2.5 text-xs whitespace-nowrap', on ? 'border-ink bg-ink text-canvas' : 'border-rule text-ink-2 hover:border-rule-strong hover:text-ink'); return ( ); } /** * Leaderboard table: rank · model (+org) · score with a relative bar · config · evaluated · source · compare/history. * Bars are relative to the best score of the page (per direction) — a reading aid, not a normalisation. */ export function Leaderboard({ slug, results, total, limit, offset, config, model, unit, makeHref }: { slug: string; results: BenchmarkResult[]; total: number; limit: number; offset: number; config?: string; model?: string; unit?: string | null; makeHref: (offset: number) => string }) { if (!results.length) return {config ? Clear the filter : 'Results appear when a tier 1–3 source publishes them; we never copy scores without a source.'}; const hib = results[0]?.higher_is_better !== false; const scores = results.map((r) => r.score).filter((s) => Number.isFinite(s)); const max = Math.max(...scores); const min = Math.min(...scores); const width = (s: number) => { if (!Number.isFinite(s) || max <= 0) return 0; const v = hib ? s / max : min > 0 ? min / s : 0; return Math.max(2, Math.min(100, v * 100)); }; const u = unit ?? results[0]?.unit ?? null; return ( <> # Model Score Config Evaluated Source Actions {results.length === 0 && } {results.map((r, i) => { const rank = offset + i + 1; const isModel = model && r.model.slug === model; return ( {fmtInt(rank)} #{fmtInt(rank)} {r.model.organization && {r.model.organization.name}} {fmtScore(r.score)} {u === '%' ? '%' : u ? {u} : null} {configSummary(r.config) || '—'} {r.evaluated_at ? fmtDate(r.evaluated_at) : — (obs. {fmtDate(r.observed_at)})} History ); })} Scores are reported as published, with their evaluation configuration (harness, prompting, judge). The bar is relative to the best score on this page{hib ? '' : ' (lower is better)'}. Results with different configs are not directly comparable — see methodology. ); } /** Score history for one model on this benchmark (all rows incl. superseded), as a time series. */ export function HistoryChart({ items, model, unit }: { items: BenchmarkResult[]; model: string; unit?: string | null }) { const name = items[0]?.model.name ?? model; const pts = items .map((r) => ({ x: new Date(r.evaluated_at ?? r.observed_at), y: r.score, r })) .filter((p) => !Number.isNaN(p.x.getTime()) && Number.isFinite(p.y)) .sort((a, b) => a.x.getTime() - b.x.getTime()); const u = unit ?? items[0]?.unit ?? null; const fmt = (v: number) => `${fmtScore(v)}${u === '%' ? '%' : ''}`; const days = new Set(pts.map((p) => p.x.toISOString().slice(0, 10))); return (

Score history · {name} {fmtInt(items.length)} {items.length === 1 ? 'row' : 'rows'}

{pts.length < 2 || days.size < 2 ? ( Not enough history to chart — {pts.length === 0 ? 'no result recorded for this model' : pts.length === 1 ? `a single observation (${fmt(pts[0]?.y ?? 0)} on ${fmtDate(pts[0]?.r.evaluated_at ?? pts[0]?.r.observed_at)})` : `${fmtInt(pts.length)} observations, all dated ${fmtDate(pts[0]?.r.evaluated_at ?? pts[0]?.r.observed_at)}`}. Rows under different configurations count separately; the list below shows each one. ) : ( <> ({ x: p.x, y: p.y })) }]} height={200} yFormat={fmt} showDots yLabel={`Score history for ${name}`} /> )} {pts.length > 0 && (
    {[...pts].reverse().slice(0, 12).map((p) => (
  • {fmt(p.y)} {configSummary(p.r.config) || '—'} {fmtDate(p.r.evaluated_at ?? p.r.observed_at)}
  • ))}
)}
); }