import type { Metadata } from 'next'; import Link from 'next/link'; import { AdminTitle, JsonPre, KindChip, Mono, Notice, StatusChip } from '@/components/admin/ui'; import { DataTable, EmptyRow, Td, Th } from '@/components/ui/data-table'; import { Note } from '@/components/ui/section'; import { Unavailable } from '@/components/ui/unavailable'; import { adminApi, load, requireAdmin } from '@/lib/admin/admin-api'; import type { AdminQuality, CountSample } from '@/lib/admin/types'; import { cn } from '@/lib/cn'; import { fmtAgo, fmtInt, num } from '@/lib/format'; import { routes } from '@/lib/site'; export const metadata: Metadata = { title: 'Data quality', robots: { index: false, follow: false } }; export const dynamic = 'force-dynamic'; type Tile = { key: string; label: string; count: number | null; sample: unknown[]; href?: string; tone: 'neutral' | 'warn' | 'danger'; hint: string }; function tile(key: string, label: string, cs: CountSample | undefined, hint: string, opts: { href?: string; danger?: number } = {}): Tile { const count = num(cs?.count); const tone: Tile['tone'] = count === null || count === 0 ? 'neutral' : opts.danger !== undefined && count >= opts.danger ? 'danger' : 'warn'; return { key, label, count, sample: (cs?.sample ?? []) as unknown[], href: opts.href, tone, hint }; } function SampleRow({ s }: { s: unknown }) { if (typeof s === 'string') return {s}; const o = (s ?? {}) as Record; const slug = typeof o.slug === 'string' ? o.slug : null; const type = typeof o.entity_type === 'string' ? o.entity_type : 'model'; const name = typeof o.name === 'string' ? o.name : typeof o.model === 'string' ? o.model : typeof o.reason === 'string' ? o.reason : typeof o.raw === 'string' ? `${String(o.domain ?? '')}: ${o.raw}` : null; return ( {slug ? ( {name ?? slug} ) : ( {name ?? {JSON.stringify(o).slice(0, 80)}} )} {typeof o.provider === 'string' && · {o.provider}} {typeof o.provider_model_id === 'string' && {o.provider_model_id}} {Array.isArray(o.quant_formats) && o.quant_formats.length > 0 && {(o.quant_formats as unknown[]).join(', ')}} {typeof o.health === 'string' && } {typeof o.last_success_at === 'string' && last success {fmtAgo(o.last_success_at)}} {typeof o.count === 'number' && × {o.count}} {typeof o.id === 'string' && !slug && {o.id}} ); } export default async function AdminQualityPage({ searchParams }: { searchParams: Promise> }) { await requireAdmin(); const sp = await searchParams; const res = await load(adminApi.quality()); const q: AdminQuality | null = res.ok ? res.data : null; const tiles: Tile[] = q ? [ tile('pending_decisions', 'Pending resolution decisions', q.duplicate_candidates?.pending_decisions, 'Candidate pairs awaiting a decision in Entity resolution.', { href: '/admin/entity-resolution' }), tile('review_merge_candidates', 'Merge candidates (review queue)', q.duplicate_candidates?.review_merge_candidates, 'merge_candidate items in the v1 review queue.', { href: '/admin/review?kind=merge_candidate' }), tile('unmapped_taxonomy_rows', 'Unmapped taxonomy rows', q.taxonomy_violations?.unmapped_taxonomy_rows, 'Raw labels the ontology could not map (domain: raw).'), tile('openness_unknown_vocab', 'Openness outside vocabulary', q.taxonomy_violations?.openness_unknown_vocab, 'Openness values not in open-source | open-weights | restricted-weights | proprietary | unknown.', { danger: 1 }), tile('status_unknown_vocab', 'Status outside vocabulary', q.taxonomy_violations?.status_unknown_vocab, 'Status values not in the status vocabulary.', { danger: 1 }), tile('license_unclassified', 'Unclassified licences', q.taxonomy_violations?.license_unclassified, 'Licence labels without a canonical key.'), tile('impossible_values', 'Impossible values (anomalies)', { count: q.impossible_values?.count, sample: q.impossible_values?.sample ?? [] }, 'Open anomaly flags by check — see Anomalies for resolve / ignore.', { href: '/admin/anomalies' }), tile('conflicting_t1_claims', 'Conflicting tier-1 claims', q.conflicting_t1_claims, 'Two official sources disagree on a current value.', { danger: 1, href: '/admin/review?kind=conflict' }), tile('models_without_organization', 'Models without organization', q.models_without_organization, 'Canonical models with no developer relation.'), tile('models_without_release_source', 'Models without release source', q.models_without_release_source, 'Canonical models whose release date has no sourced claim.'), tile('models_without_parameters', 'Models without parameters', q.models_without_parameters, 'Canonical models with no parameter_count claim (proprietary models are expected here).'), tile('orphan_benchmark_results', 'Orphan benchmark results', q.orphan_benchmark_results, 'Current results whose model was merged or is an artifact.', { danger: 1 }), tile('benchmarks_without_results', 'Benchmarks without results', q.benchmarks_without_results, 'Registered benchmarks no connector feeds yet.'), tile('unresolved_provider_deployments', 'Unresolved provider deployments', q.unresolved_provider_deployments, 'Price rows whose provider_model_id matches no identifier.'), tile('quantisations_typed_as_models', 'Quantisations typed as models', q.quantisations_typed_as_models, 'Name analysis says artifact but the row is a model.', { href: '/admin/entity-resolution?type=model' }), tile('stale_sources', 'Stale sources', q.stale_sources, 'Last success older than 3× the connector interval.', { href: '/admin/connectors' }), tile('empty_public_categories', 'Empty public categories', q.empty_public_categories, 'Entity types with a public listing but zero rows.'), tile('quarantined_runs_pending', 'Quarantined runs pending', q.quarantined_runs_pending, 'Held connector runs awaiting release or discard.', { href: '/admin/quarantine', danger: 1 }), ] : []; const queue = q?.review_queue_priority ?? []; const byCheck = q?.impossible_values?.by_check ?? []; return ( <> Anomaly checks → {!res.ok ? ( ) : ( <>
    {tiles.map((t) => (
  • {t.label}

    {t.count === null ? '—' : fmtInt(t.count)}

    {t.hint}

    {t.sample.length === 0 ? (

    No sample.

    ) : (
      {t.sample.slice(0, 8).map((s, i) => (
    • ))}
    )} {t.href && ( Open review action → )}
  • ))}
{byCheck.length > 0 && (

{byCheck.map((c) => ( {c.severity} {c.check_name} {fmtInt(c.n)} ))}

)}

Prioritized review queue {fmtInt(queue.length)}

Frontier models, benchmark leaders, the largest parameter / context claims, price anomalies, major organizations and duplicates of frontier models come first. Kind Item Reasons Detail Action {queue.length === 0 && Nothing prioritized.} {queue.map((it) => { const slug = typeof it.slug === 'string' ? it.slug : null; const type = typeof it.entity_type === 'string' ? it.entity_type : 'model'; const href = it.kind === 'anomaly' ? `/admin/anomalies?check=${encodeURIComponent(String(it.check ?? ''))}` : it.kind === 'duplicate' || it.kind === 'merge_candidate' || it.kind === 'resolution' ? '/admin/entity-resolution' : it.kind === 'conflict' ? '/admin/review?kind=conflict' : '/admin/review'; return ( {typeof it.severity === 'string' && {it.severity}} {slug ? ( {typeof it.name === 'string' ? it.name : slug} ) : ( {it.id} )} {typeof it.check === 'string' && {it.check}} {it.reasons?.join(' · ') || '—'} {typeof it.message === 'string' ? it.message : !['kind', 'id', 'reasons', 'slug', 'entity_id', 'check', 'severity', 'name', 'entity_type'].includes(k)))} maxHeight="6rem" />} Review → ); })} {q?.note && {q.note}} )} ); }