"use client"; import { useMemo, useState } from "react"; import { ArrowDown, ArrowUp, ArrowUpDown, Search } from "lucide-react"; import { Switch, Tip, Badge } from "@/components/ui/primitives"; import { Input } from "@/components/ui/input"; import { cn } from "@/lib/utils"; import { hasBench, kTok, ms, pct, perM, PROBES, providerTone, score, usd, type ModelRow } from "./format"; type Key = "provider" | "id" | "enabled" | "contextWindow" | "maxOutput" | "inputPrice" | "outputPrice" | "pass" | "score" | "judged" | "ttft" | "latency" | "tps" | "cost"; const COLS: { key: Key; label: string; num?: boolean; title?: string }[] = [ { key: "provider", label: "Provider" }, { key: "id", label: "Model" }, { key: "enabled", label: "On", title: "Enabled for automatic routing" }, { key: "contextWindow", label: "Context", num: true }, { key: "maxOutput", label: "Max out", num: true }, { key: "inputPrice", label: "$/M in", num: true }, { key: "outputPrice", label: "$/M out", num: true }, { key: "pass", label: "Pass", num: true, title: "Deterministic pass rate (measured)" }, { key: "score", label: "Score", num: true, title: "Mean deterministic score 0–1" }, { key: "judged", label: "Judged", num: true, title: "LLM-judge mean 1–5 (writing & synthesis only)" }, { key: "ttft", label: "TTFT", num: true, title: "Median time to first token" }, { key: "latency", label: "Latency", num: true, title: "Median total latency" }, { key: "tps", label: "tok/s", num: true }, { key: "cost", label: "$/run", num: true, title: "Mean estimated cost per benchmark run" }, ]; const val = (m: ModelRow, k: Key): number | string | null => { const b = m.benchmark ?? {}; switch (k) { case "provider": return m.provider; case "id": return m.id; case "enabled": return m.enabled ? 1 : 0; case "contextWindow": return m.contextWindow; case "maxOutput": return m.maxOutput; case "inputPrice": return m.inputPrice; case "outputPrice": return m.outputPrice; case "pass": return b.pass_rate ?? null; case "score": return b.mean_score ?? null; case "judged": return b.judged_mean ?? null; case "ttft": return b.ttft_median_ms ?? null; case "latency": return b.total_median_ms ?? null; case "tps": return b.tps_median ?? null; case "cost": return b.cost_mean ?? null; } }; export function CatalogueTable({ models, onToggle }: { models: ModelRow[]; onToggle: (id: string, enabled: boolean) => void }) { const [sort, setSort] = useState<{ key: Key; dir: 1 | -1 }>({ key: "score", dir: -1 }); const [provider, setProvider] = useState("all"); const [tested, setTested] = useState(true); const [textOnly, setTextOnly] = useState(true); const [q, setQ] = useState(""); const rows = useMemo(() => models.filter((m) => (provider === "all" || m.provider === provider) && (!tested || hasBench(m)) && (!textOnly || m.category === "text" || m.category === "text-specialized") && (!q || m.id.toLowerCase().includes(q.toLowerCase()) || (m.displayName ?? "").toLowerCase().includes(q.toLowerCase()))) .sort((a, b) => { const x = val(a, sort.key), y = val(b, sort.key); if (x == null && y == null) return a.id.localeCompare(b.id); if (x == null) return 1; if (y == null) return -1; return (typeof x === "string" ? x.localeCompare(String(y)) : x - Number(y)) * sort.dir || a.id.localeCompare(b.id); }), [models, provider, tested, textOnly, q, sort]); const head = (c: (typeof COLS)[number]) => setSort((s) => ({ key: c.key, dir: s.key === c.key ? (s.dir === 1 ? -1 : 1) : c.num ? -1 : 1 }))}>{c.label}{sort.key === c.key ? (sort.dir === 1 ? : ) : }; return (
setQ(e.target.value)} placeholder="Filter models" className="h-8 w-48 pl-7 text-[13px]" />
{[["all", "All"], ["openai", "OpenAI"], ["anthropic", "Anthropic"]].map(([id, l]) => )}
{rows.length} / {models.length}
{COLS.map(head)}{rows.map((m) => { const b = m.benchmark ?? {}; return ( ); })} {!rows.length && }
Probes
{m.provider}
{m.id}{!m.available && gone}{m.category === "embedding" && embed}
{m.displayName && m.displayName !== m.id &&
{m.displayName}
}
onToggle(m.id, v)} aria-label={`Enable ${m.id}`} /> {kTok(m.contextWindow)}{kTok(m.maxOutput)} {perM(m.inputPrice)}{perM(m.outputPrice)} {pct(b.pass_rate)} {score(b.mean_score)}{score(b.judged_mean, 2)} {ms(b.ttft_median_ms)}{ms(b.total_median_ms)}{b.tps_median == null ? "–" : Math.round(b.tps_median)}{usd(b.cost_mean)}
{PROBES.map((p) => { const s = m.probes?.[p.key]?.status; return {p.short}; })}
No model matches these filters.
); }