HTML 77.2%
TypeScript 10.5%
Python 9.6%
JavaScript 2.5%
1import { ImageResponse } from 'next/og';2import type { NextRequest } from 'next/server';3import { Wallpaper } from '@/components/brand/og';4import { defaultModeFor, GRAPH_MODES, isGraphMode } from '@/components/graph/modes';5import { api, apiD3, safe } from '@/lib/api';6import { fmtInt } from '@/lib/format';7import { typeLabel } from '@/lib/site';89export const runtime = 'nodejs';10export const revalidate = 3600;1112/** Dynamic Open Graph image for /graph?node=&mode=&depth= (query routes cannot use the opengraph-image convention). */13export async function GET(req: NextRequest): Promise<Response> {14 const sp = req.nextUrl.searchParams;15 const node = sp.get('node');16 const size = { width: 1200, height: 630 };17 const d = node ? await safe(api.entity(node)) : null;18 if (!d) return new ImageResponse(<Wallpaper eyebrow="Knowledge graph" title="Every entity, every relation" subtitle="Model lineage · research networks · company ecosystems · benchmark, dataset, provider and hardware graphs" />, size);19 const mode = isGraphMode(sp.get('mode')) ? (sp.get('mode') as ReturnType<typeof defaultModeFor>) : defaultModeFor(d.entity_type);20 const depth: 1 | 2 = sp.get('depth') === '2' ? 2 : 1;21 const g = await safe(apiD3.graphExplore(d.slug, mode, depth, 150));22 const label = GRAPH_MODES.find((m) => m.mode === mode)?.label ?? 'Graph';23 const counters: [string, string][] = g ? [['Nodes', fmtInt(g.counts?.nodes ?? g.nodes.length)], ['Edges', fmtInt(g.counts?.edges ?? g.edges.length)], ['Depth', String(g.depth)], ...(g.truncated ? ([['Truncated', 'yes']] as [string, string][]) : [])] : [];24 return new ImageResponse(<Wallpaper eyebrow={`${label} · ${typeLabel(d.entity_type)}`} title={d.name} subtitle={`${label} around ${d.name}${d.organization ? ` (${d.organization.name})` : ''} — every edge is a stated relation with a source.`} counters={counters} footer={`www.ai-atlas.co/graph?node=${d.slug}`} markPx={220} />, size);25}26