"use client" import type { CSSProperties } from "react" import { useMemo } from "react" import { useAudienceMode } from "@/components/audience-mode-provider" import { useRouter } from "next/navigation" import { AlertTriangle, Award, ChevronDown, ChevronRight, ExternalLink, Eye, MoreHorizontal, } from "lucide-react" import type { CategoryType } from "@/lib/benchmark-schema" import type { SignalSummaries } from "@/lib/backend-artifacts" import { getCategoryColor } from "@/lib/benchmark-schema" import type { BenchmarkCard } from "@/lib/benchmark-schema" import { lookupBenchmarkCard } from "@/lib/benchmark-metadata-utils" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu" export type BenchmarkEvaluationCardData = { id: string route_id: string model_name: string model_id: string canonical_model_name: string developer: string evaluations_count: number benchmarks_count: number variant_count: number categories: CategoryType[] category_stats: Record latest_timestamp: string evaluator_count: number evaluator_names: string[] source_type_count: number source_types: string[] evidence_count: number missing_generation_config_count: number third_party_eval_count: number independent_verification_ratio: number reproducibility_status: "complete" | "partial" | "missing" eval_libraries: Array<{ name: string version?: string fork?: string }> latest_source_name?: string params_billions?: number | null benchmark_names?: string[] score_summary?: { count: number min: number max: number average: number | null } reproducibility_summary?: SignalSummaries["reproducibility_summary"] provenance_summary?: SignalSummaries["provenance_summary"] comparability_summary?: SignalSummaries["comparability_summary"] top_scores: Array<{ benchmark: string score: number metric: string unit?: string }> source_urls: string[] detail_urls: string[] model_url?: string release_date?: string input_modalities?: string[] output_modalities?: string[] architecture?: string params?: string inference_engine?: string inference_platform?: string } interface BenchmarkEvaluationCardProps { data: BenchmarkEvaluationCardData benchmarkCards?: Record onDelete?: (id: string) => void delayMs?: number selectedForCompare?: boolean onToggleCompare?: (id: string) => void } function formatDate(isoString: string) { const numeric = Number(isoString) const parsedDate = !Number.isNaN(numeric) && !isoString.includes("-") ? new Date(numeric * 1000) : new Date(isoString) try { return parsedDate.toLocaleDateString("en-US", { year: "numeric", month: "short", day: "numeric", }) } catch { return isoString } } function formatParamsBillions(value: number | null | undefined) { if (value == null || Number.isNaN(value)) return null if (value >= 100) return `${Math.round(value)}B` return `${value.toFixed(1)}B` } function formatScoreValue(value: number | null | undefined) { if (value == null || !Number.isFinite(value)) { return null } if (value >= 0 && value <= 1) { return `${(value * 100).toFixed(1)}%` } if (Math.abs(value) >= 100) { return value.toFixed(0) } return value.toFixed(2) } function getCoverageSummaryLabel(data: BenchmarkEvaluationCardData) { if (data.benchmarks_count > 0) { return `${data.benchmarks_count} benchmark suite${data.benchmarks_count === 1 ? "" : "s"} surfaced` } if (data.latest_source_name) { return data.latest_source_name } return "Coverage summary" } function getTopBenchmarks(data: BenchmarkEvaluationCardData) { const surfaced = Array.from(new Set(data.top_scores.map((score) => score.benchmark))) if (surfaced.length > 0) { return surfaced } if (data.benchmark_names?.length) { return Array.from(new Set(data.benchmark_names)) } return [] } const CATEGORY_PLOT_COLORS: Record = { "General": "#2563eb", "Reasoning": "#7c3aed", "Agentic": "#ea580c", "Safety": "#16a34a", "Knowledge": "#0f766e", } function getCategoryPlotColor(category: string) { return CATEGORY_PLOT_COLORS[category] ?? "#64748b" } function CategoryCoveragePlot({ coverage, }: { coverage: Array<{ category: CategoryType; count: number }> }) { if (coverage.length === 0) { return (
No category coverage recorded.
) } const totalCount = coverage.reduce((sum, item) => sum + item.count, 0) return (
{coverage.map((item) => (
))}
{coverage.slice(0, 4).map((item) => ( {item.category} {item.count} ))}
) } export function BenchmarkEvaluationCard({ data, benchmarkCards, onDelete, delayMs = 0, selectedForCompare = false, onToggleCompare, }: BenchmarkEvaluationCardProps) { const router = useRouter() const { mode } = useAudienceMode() const isResearchView = mode === "research" // Collect unique domains from this model's benchmarks using metadata cards const modelDomains = useMemo(() => { if (!benchmarkCards) return [] const domainCounts = new Map() for (const { benchmark } of data.top_scores) { const card = lookupBenchmarkCard(benchmarkCards, benchmark) for (const domain of card?.benchmark_details?.domains ?? []) { domainCounts.set(domain, (domainCounts.get(domain) ?? 0) + 1) } } return Array.from(domainCounts.entries()) .sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])) .map(([domain]) => domain) }, [benchmarkCards, data.top_scores]) const categoryCoverage = useMemo( () => Object.entries(data.category_stats) .filter(([, count]) => count > 0) .sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])) .map(([category, count]) => ({ category: category as CategoryType, count, })), [data.category_stats] ) const paramsBillions = formatParamsBillions(data.params_billions) const coverageSummaryLabel = getCoverageSummaryLabel(data) const topBenchmarks = getTopBenchmarks(data) const scoreRange = [formatScoreValue(data.score_summary?.min), formatScoreValue(data.score_summary?.max)] .filter((value): value is string => Boolean(value)) .join(" to ") const reproducibilityGapCount = data.reproducibility_summary?.has_reproducibility_gap_count ?? 0 const reproducibilityTotal = data.reproducibility_summary?.results_total ?? data.evaluations_count return ( router.push(`/models/${data.route_id}`)} >
Model Summary
{coverageSummaryLabel} / {formatDate(data.latest_timestamp)}
{data.model_name}
{data.developer || "Unknown developer"}
{data.variant_count > 1 && ( {data.variant_count} versions )} {paramsBillions && {paramsBillions} parameters} {data.benchmarks_count} benchmark suites {data.evaluations_count} reported results {reproducibilityGapCount > 0 && ( {isResearchView ? `${reproducibilityGapCount} reproducibility gaps` : `${reproducibilityGapCount} re-run gaps`} )}
{onToggleCompare ? ( ) : null} router.push(`/models/${data.route_id}`)}> View Details {data.source_urls.length > 0 && ( window.open(data.source_urls[0], "_blank")}> View Source )} {onDelete && ( onDelete(data.id)} className="text-destructive"> Remove )}
Category coverage
{categoryCoverage.length} {categoryCoverage.length === 1 ? "category" : "categories"}
{data.evaluations_count}
reported results
{modelDomains.length > 0 && (
Top domain coverage
{modelDomains.slice(0, 5).map((domain) => ( {domain} ))} {modelDomains.length > 5 && ( +{modelDomains.length - 5} more )}
)} {topBenchmarks.length > 0 && (
Covered benchmarks
{topBenchmarks.slice(0, 6).map((benchmark) => ( {benchmark} ))} {topBenchmarks.length > 6 && ( See the full list in details )}
)} event.stopPropagation()} className="border-t border-border/60 px-4 py-4">
{topBenchmarks.length > 0 && ( )} {scoreRange && ( )} {data.architecture && isResearchView && ( )} {data.source_types.length > 0 && ( s.replace(/_/g, " ")).join(", ")} /> )} {reproducibilityGapCount > 0 && ( )}
Full record
Open for the full benchmark list, provenance, and comparison detail.
) } function KeyValueRow({ label, value }: { label: string; value: string }) { return (
{label} {value}
) }