SPB Git forge

spb/ai-atlas

Public
41commits 1branches 0releases
4.6 MBsize
maindefault branch
12 days agolast push
HTML 77.2% TypeScript 10.5% Python 9.6% JavaScript 2.5%
2.3 KB · 39 lines typescript
Raw Blame History
1import type { GraphExploreMode } from '@/lib/types';23/** The seven `/graph/explore` modes, as preset chips. Server-safe. */4export const GRAPH_MODES: { mode: GraphExploreMode; label: string; hint: string; rootTypes: string[] }[] = [5  { mode: 'lineage', label: 'Model lineage', hint: 'base → fine-tune → quantization, families, supersessions', rootTypes: ['model', 'artifact', 'model_family', 'quantization'] },6  { mode: 'research', label: 'Research network', hint: 'papers, authors, the models and datasets they describe', rootTypes: ['paper', 'researcher'] },7  { mode: 'company', label: 'Company ecosystem', hint: 'what an organization develops, owns, operates', rootTypes: ['company', 'organization', 'lab', 'university'] },8  { mode: 'benchmark', label: 'Benchmark graph', hint: 'benchmarks and the models evaluated on them', rootTypes: ['benchmark'] },9  { mode: 'dataset', label: 'Dataset graph', hint: 'datasets and the models trained or evaluated on them', rootTypes: ['dataset'] },10  { mode: 'provider', label: 'Provider graph', hint: 'providers and the models they serve', rootTypes: ['provider'] },11  { mode: 'hardware', label: 'Hardware ecosystem', hint: 'hardware, manufacturers, runtimes', rootTypes: ['hardware'] },12];13export const GRAPH_MODE_SET = new Set<string>(GRAPH_MODES.map((m) => m.mode));1415export function isGraphMode(v: string | undefined | null): v is GraphExploreMode {16  return !!v && GRAPH_MODE_SET.has(v);17}18/** Best default mode for a root entity type. */19export function defaultModeFor(entityType: string | undefined | null): GraphExploreMode {20  const m = GRAPH_MODES.find((x) => entityType && x.rootTypes.includes(entityType));21  return m?.mode ?? 'lineage';22}23export function graphHref(node: string | null, mode: GraphExploreMode, depth: 1 | 2): string {24  const p = new URLSearchParams();25  if (node) p.set('node', node);26  if (mode !== 'lineage') p.set('mode', mode);27  if (depth === 2) p.set('depth', '2');28  const s = p.toString();29  return s ? `/graph?${s}` : '/graph';30}31/** `/graph/<slug>?mode=&depth=` URLs for the per-entity page. */32export function graphSlugHref(node: string, mode: GraphExploreMode, depth: 1 | 2): string {33  const p = new URLSearchParams();34  if (mode !== 'lineage') p.set('mode', mode);35  if (depth === 2) p.set('depth', '2');36  const s = p.toString();37  return `/graph/${encodeURIComponent(node)}${s ? `?${s}` : ''}`;38}39