import { ExternalLink } from 'lucide-react';
import { ScrollX } from '@/components/models/scroll-x';
import Link from 'next/link';
import { Evidence } from '@/components/evidence/evidence';
import { ComparabilityBadge, ConfigChipEl, TrustBadge } from '@/components/models/badges';
import { configChipsOf, fmtScoreUnit, scoreDelta } from '@/components/models/shared';
import { Estimated } from '@/components/ui/badges';
import { DataTable, Td, Th } from '@/components/ui/data-table';
import { EntityLink } from '@/components/ui/entity';
import { Hint } from '@/components/ui/hint';
import { SourceCell } from '@/components/ui/provenance';
import { Note } from '@/components/ui/section';
import { EmptyState } from '@/components/ui/unavailable';
import { cn } from '@/lib/cn';
import { DASH, fmtAgo, fmtDate, fmtGb, fmtInt, fmtTokens, fmtUsdPerM, fmtValue, hostOf, num } from '@/lib/format';
import { propertyLabel, routes } from '@/lib/site';
import type { BenchmarkListItem, Deployment, HardwareFitRow, ModelDetail, ProvenanceEntry, VersionHistoryItem } from '@/lib/types';
/* ------------------------------------------------------------------------------------------------------ identity panel */
/** Canonical model · official checkpoints · third-party artifacts (by kind) · provider deployments · API aliases · folded variants. */
export function IdentityPanel({ d }: { d: ModelDetail }) {
const id = d.identity;
const kinds = d.artifacts?.items ?? [];
if (!id) return
Identity block not returned by the API for this entity.
;
// The definition hint sits at the far right of the value cell (right-aligned bubble): in the narrow label column the 18rem bubble would widen the page.
const Row = ({ k, hint, children }: { k: string; hint?: string; children: React.ReactNode }) => (
{r.status}
{r.valid_to && until {fmtDate(r.valid_to)}}
{fmtAgo(r.observed_at)}
since {fmtDate(r.valid_from)}
);
})}
{rows[0]?.prices.unit ?? 'USD per 1M tokens'} as published by each provider; native units (per-request fees, flex/priority tiers) are kept verbatim. Rows are append-only — every price change is kept in the history below.
{delisted > 0 && ` ${fmtInt(delisted)} delisted deployment${delisted === 1 ? '' : 's'} shown greyed.`} Cost of a workload →
>
);
}
/* ------------------------------------------------------------------------------------------------------ version history */
function fmtVersionValue(property: string, v: unknown): string {
if (v === null || v === undefined) return 'unknown';
if (/context_length|max_output_tokens/.test(property)) return `${fmtTokens(v)}`;
return fmtValue(v, property);
}
/** property → "128K → 200K → 1M" with dates; every hop is an evidence trigger (claim id, source, tier). */
export function VersionHistoryBlock({ items, d }: { items: VersionHistoryItem[]; d: ModelDetail }) {
const shown = items.filter((v) => v.transitions.length > 0);
if (!shown.length) return
);
})}
Each hop is a claim: click a value for its source, tier and observation time. Nothing is overwritten — a new observation closes the previous claim.
);
}
/* ------------------------------------------------------------------------------------------------------ benchmarks grouped */
/** Benchmark → metric / comparability group → best current row (trust, comparability note, n results, vs leader, leaderboard link). */
export function ModelBenchmarksBlock({ d, leaders }: { d: ModelDetail; leaders: BenchmarkListItem[] | null }) {
const b = d.benchmarks;
if (!b || !b.items.length) return Results appear when a tier 1–3 source publishes them; we never copy scores without a source.;
const leaderMap = new Map();
for (const l of leaders ?? []) leaderMap.set(l.slug, l);
const items = [...b.items].sort((x, y) => (x.category ?? '').localeCompare(y.category ?? '') || x.name.localeCompare(y.name));
const rows: React.ReactNode[] = [];
for (const bm of items) {
const li = leaderMap.get(bm.slug);
for (const m of bm.metrics) {
for (const g of m.groups) {
const isPrimary = li?.primary_group?.config_key === g.config_key && li?.primary_group?.metric === m.metric;
const leader = isPrimary ? li?.leader : null;
const leaderIsSelf = leader?.model.slug === d.slug;
const delta = leader && !leaderIsSelf ? scoreDelta(g.best.score, leader.score, g.best.unit) : null;
const chips = configChipsOf(g.best.config, null, 4);
const conditions = chips.filter((c) => c.kind === 'condition');
rows.push(
{rows}
{b.note ?? 'Current rows only, grouped by benchmark → canonical metric → comparability group.'} {fmtInt(b.total_rows)} current rows in total. “vs leader” compares with the current leader of the benchmark's primary group only; other groups are not directly comparable. Comparability rules →
>
);
}
/* ------------------------------------------------------------------------------------------------------ hardware fit */
export function HardwareFitBlock({ rows, assumptions, modelSlug }: { rows: HardwareFitRow[]; assumptions?: string[]; modelSlug: string }) {
if (!rows.length) return Estimates need a parameter count; this model has none recorded from a source.;
const sorted = [...rows].sort((a, b) => Number(b.fits) - Number(a.fits) || (num(a.hardware.attributes?.memory_gb) ?? 0) - (num(b.hardware.attributes?.memory_gb) ?? 0));
const fits = sorted.filter((r) => r.fits).length;
return (
<>
{fmtInt(fits)} of {fmtInt(sorted.length)} device × quantization combinations fit.
Run locally: your machine →
Hardware
Quantization
Device memory
Est. memory
Fits
{sorted.map((r, i) => (
{r.quantization}
{fmtGb(r.hardware.attributes?.memory_gb as never)}