import type { GraphExploreMode } from '@/lib/types'; /** The seven `/graph/explore` modes, as preset chips. Server-safe. */ export const GRAPH_MODES: { mode: GraphExploreMode; label: string; hint: string; rootTypes: string[] }[] = [ { mode: 'lineage', label: 'Model lineage', hint: 'base → fine-tune → quantization, families, supersessions', rootTypes: ['model', 'artifact', 'model_family', 'quantization'] }, { mode: 'research', label: 'Research network', hint: 'papers, authors, the models and datasets they describe', rootTypes: ['paper', 'researcher'] }, { mode: 'company', label: 'Company ecosystem', hint: 'what an organization develops, owns, operates', rootTypes: ['company', 'organization', 'lab', 'university'] }, { mode: 'benchmark', label: 'Benchmark graph', hint: 'benchmarks and the models evaluated on them', rootTypes: ['benchmark'] }, { mode: 'dataset', label: 'Dataset graph', hint: 'datasets and the models trained or evaluated on them', rootTypes: ['dataset'] }, { mode: 'provider', label: 'Provider graph', hint: 'providers and the models they serve', rootTypes: ['provider'] }, { mode: 'hardware', label: 'Hardware ecosystem', hint: 'hardware, manufacturers, runtimes', rootTypes: ['hardware'] }, ]; export const GRAPH_MODE_SET = new Set(GRAPH_MODES.map((m) => m.mode)); export function isGraphMode(v: string | undefined | null): v is GraphExploreMode { return !!v && GRAPH_MODE_SET.has(v); } /** Best default mode for a root entity type. */ export function defaultModeFor(entityType: string | undefined | null): GraphExploreMode { const m = GRAPH_MODES.find((x) => entityType && x.rootTypes.includes(entityType)); return m?.mode ?? 'lineage'; } export function graphHref(node: string | null, mode: GraphExploreMode, depth: 1 | 2): string { const p = new URLSearchParams(); if (node) p.set('node', node); if (mode !== 'lineage') p.set('mode', mode); if (depth === 2) p.set('depth', '2'); const s = p.toString(); return s ? `/graph?${s}` : '/graph'; } /** `/graph/?mode=&depth=` URLs for the per-entity page. */ export function graphSlugHref(node: string, mode: GraphExploreMode, depth: 1 | 2): string { const p = new URLSearchParams(); if (mode !== 'lineage') p.set('mode', mode); if (depth === 2) p.set('depth', '2'); const s = p.toString(); return `/graph/${encodeURIComponent(node)}${s ? `?${s}` : ''}`; }