Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(api): static barrel makes catalog entries unconditional in production
fudjia477aada1a465
diff --git a/api/_lib/3d-catalog/index.js b/api/_lib/3d-catalog/index.jsindex 08a3b7e68..4460bd691 100644--- a/api/_lib/3d-catalog/index.js+++ b/api/_lib/3d-catalog/index.js@@ -5,20 +5,17 @@// to edit (and collide on), each endpoint drops ITS OWN descriptor file in this// directory — `api/_lib/3d-catalog/<slug>.js` — and this assembler merges them.//-// Serverless-safe enumeration-// ----------------------------// Vercel's function bundler (node-file-trace) only bundles files it can see via-// STATIC imports. A computed `import('./' + file)` off a `readdirSync` result is-// invisible to the tracer, so the sibling descriptors would be missing from the-// deployed lambda. Two things make the runtime read work regardless:-// 1. `vercel.json` → `functions["api/3d/*.js"].includeFiles` ships the whole-// `api/_lib/3d-catalog/**` tree into every `/api/3d/*` lambda, so the files-// exist on disk at runtime.-// 2. we enumerate with `fs.readdirSync(__dirname)` and `import(pathToFileURL())`-// each `*.js` (except this index), which resolves against those bundled-// files.-// This is the documented Vercel escape hatch for data-dir reads; it's the same-// `includeFiles` mechanism other functions in this repo use (see vercel.json).+// Serverless-safe enumeration: static barrel first, glob as a dev-time extra+// ---------------------------------------------------------------------------+// Vercel's function bundler only reliably ships what STATIC imports reach. A+// computed `import('./' + file)` off a `readdirSync` result is invisible to the+// tracer — the first deployed version relied on the runtime glob (plus+// vercel.json's `includeFiles` pin and a cwd fallback) and served+// `endpoints: []` in production while finding every entry locally. So the+// STATIC_ENTRIES barrel below is the production source of truth, and the+// runtime glob survives only as an additive convenience: a descriptor dropped+// in this directory appears in `npm run dev` / vitest before its import line+// lands, and fixture dirs passed by tests still assemble pure-glob.//// Robustness: a malformed or throwing descriptor is skipped and logged — the// assembler NEVER throws and NEVER lets one bad entry take down the whole index.@@ -30,6 +27,23 @@ import { pathToFileURL } from 'node:url';import { basename, dirname, join } from 'node:path';import { fileURLToPath } from 'node:url';+import generateEntry from './generate.js';+import inspectEntry from './inspect.js';++// Static barrel — the PRODUCTION source of truth for the catalog. Vercel's+// bundler only reliably ships what static imports reach: the first deployed+// version enumerated this directory at runtime and served `endpoints: []` live+// while finding every entry locally. The directory glob below still runs, but+// only as an ADDITIVE dev-time pickup so a freshly dropped descriptor shows up+// before its import line lands.+//+// >>> Adding an endpoint: drop `api/_lib/3d-catalog/<slug>.js` AND add its+// >>> import + line here. The import is what makes it exist in production.+const STATIC_ENTRIES = [+ { mod: generateEntry, source: 'generate.js' },+ { mod: inspectEntry, source: 'inspect.js' },+];+// In dev/tests `import.meta.url` is this source file, so its own directory is// the descriptor dir. In production Vercel esbuild-bundles this module INTO the// `api/3d/*.js` handler, so `import.meta.url` resolves to `api/3d/` — full of@@ -121,26 +135,49 @@ const cache = new Map();export async function loadCatalog({ dir = __dirname, fresh = false } = {}) {if (!fresh && cache.has(dir)) return cache.get(dir);+ const entries = [];+ const seen = new Set();+ const staticSources = new Set();++ // The static barrel seeds the real catalog (never fixture dirs passed by+ // tests). It goes through the same normalize + dedup gauntlet as globbed+ // files — a malformed barrel entry is skipped, not fatal.+ if (dir === __dirname) {+ for (const { mod, source } of STATIC_ENTRIES) {+ staticSources.add(source);+ const normalized = normalizeEntry(mod, source);+ if (!normalized) {+ console.warn(`[3d-catalog] skipping malformed static entry: ${source}`);+ continue;+ }+ const key = `${normalized.methods.join(',')} ${normalized.path}`;+ if (seen.has(key)) continue;+ seen.add(key);+ entries.push(normalized);+ }+ }+let files = [];try {files = readdirSync(dir).filter((f) =>f.endsWith('.js') &&!NON_ENTRY.has(f) &&+ !staticSources.has(f) &&!f.startsWith('_') &&!f.startsWith('.') &&!f.endsWith('.test.js'),);} catch (err) {- // Directory unreadable (should never happen once bundled) — degrade to an- // empty, valid catalog rather than throwing.- console.warn(`[3d-catalog] could not read catalog dir ${dir}:`, err?.message || err);- cache.set(dir, []);+ // Directory unreadable (expected inside the serverless bundle, where the+ // static barrel above has already populated the catalog) — never throw.+ if (entries.length === 0) {+ console.warn(`[3d-catalog] could not read catalog dir ${dir}:`, err?.message || err);+ }+ cache.set(dir, entries);return cache.get(dir);}- const entries = [];- const seen = new Set();for (const file of files) {try {const mod = await import(pathToFileURL(join(dir, file)).href);diff --git a/api/_lib/crypto-catalog/index.js b/api/_lib/crypto-catalog/index.jsindex 5ddd0377d..9b8975c45 100644--- a/api/_lib/crypto-catalog/index.js+++ b/api/_lib/crypto-catalog/index.js@@ -9,14 +9,11 @@// `GET /api/crypto` (the human/agent index) and `/api/crypto/openapi.json` (the// machine-readable spec). Add an endpoint → it appears in both automatically.//-// Why a runtime directory read instead of a hand-maintained barrel: a barrel-// would force every sibling prompt to edit one shared file, reintroducing the-// merge conflicts the per-file convention exists to avoid. Vercel's file tracer-// won't follow this dynamic `import()` on its own, so `api/crypto/index.js` and-// `api/crypto/openapi.js` pin `includeFiles: "api/_lib/crypto-catalog/**"` in-// vercel.json — that copies every entry file into the serverless bundle so the-// `readdir` below finds them in production exactly as it does in local dev and-// under vitest.+// Production enumerates via the STATIC_ENTRIES barrel below (see its comment+// for why: the runtime glob assembled empty in the deployed lambda). The+// directory read still runs as an additive dev/test convenience, so the+// drop-a-file convention keeps working locally before a descriptor's import+// line lands, and test fixture dirs assemble pure-glob.//// Robustness contract (per the endpoint spec): a malformed or throwing entry is// skipped and logged, never fatal. Zero entries is a valid state — the index@@ -26,6 +23,33 @@ import { readdirSync } from 'node:fs';import { fileURLToPath, pathToFileURL } from 'node:url';import { basename, dirname, join } from 'node:path';+import bondingEntry from './bonding.js';+import launchesEntry from './launches.js';+import symbolEntry from './symbol.js';+import tokenEntry from './token.js';+import trendingEntry from './trending.js';+import walletEntry from './wallet.js';+import whalesEntry from './whales.js';++// Static barrel — the PRODUCTION source of truth for the catalog. Vercel's+// bundler only reliably ships what static imports reach: the runtime glob+// (even with the includeFiles pin and the cwd fallback below) assembled empty+// in the deployed lambda while finding every entry locally. The glob still+// runs, but only as an ADDITIVE dev-time pickup for descriptors whose import+// line hasn't landed yet.+//+// >>> Adding an endpoint: drop `api/_lib/crypto-catalog/<slug>.js` AND add its+// >>> import + line here. The import is what makes it exist in production.+const STATIC_ENTRIES = [+ { mod: bondingEntry, source: 'bonding.js' },+ { mod: launchesEntry, source: 'launches.js' },+ { mod: symbolEntry, source: 'symbol.js' },+ { mod: tokenEntry, source: 'token.js' },+ { mod: trendingEntry, source: 'trending.js' },+ { mod: walletEntry, source: 'wallet.js' },+ { mod: whalesEntry, source: 'whales.js' },+];+// In dev/tests `import.meta.url` is this source file, so its own directory is// the entry dir. In production Vercel esbuild-bundles this module INTO the// `api/crypto/*.js` handler, so `import.meta.url` resolves to the handler's@@ -113,28 +137,50 @@ const cache = new Map();export async function loadCatalog({ dir = HERE, fresh = false } = {}) {if (!fresh && cache.has(dir)) return cache.get(dir);+ /** @type {Array<ReturnType<typeof normalize>>} */+ const entries = [];+ const seen = new Set();+ const staticSources = new Set();++ // The static barrel seeds the real catalog (never fixture dirs passed by+ // tests). Barrel entries face the same validation + dedup as globbed files.+ if (dir === HERE) {+ for (const { mod, source } of STATIC_ENTRIES) {+ staticSources.add(source);+ if (!isValidEntry(mod)) {+ console.warn(`[crypto-catalog] skipping ${source}: malformed static descriptor`);+ continue;+ }+ const entry = normalize(mod);+ const key = `${entry.method} ${entry.path}`;+ if (seen.has(key)) continue;+ seen.add(key);+ entries.push(entry);+ }+ }+let files = [];try {files = readdirSync(dir).filter((f) =>f.endsWith('.js') &&!NON_ENTRY.has(f) &&+ !staticSources.has(f) &&!f.startsWith('_') &&!f.startsWith('.') &&!f.endsWith('.test.js'),);} catch (err) {- // Directory unreadable (shouldn't happen given includeFiles, but never- // throw from the assembler — an empty catalog is a valid served state).- console.warn(`[crypto-catalog] could not read entry dir ${dir}: ${err.message}`);- cache.set(dir, []);- return [];+ // Directory unreadable (expected inside the serverless bundle, where the+ // static barrel above already populated the catalog) — never throw.+ if (entries.length === 0) {+ console.warn(`[crypto-catalog] could not read entry dir ${dir}: ${err.message}`);+ }+ entries.sort((a, b) => a.path.localeCompare(b.path) || a.method.localeCompare(b.method));+ cache.set(dir, entries);+ return entries;}- /** @type {Array<ReturnType<typeof normalize>>} */- const entries = [];- const seen = new Set();-for (const file of files.sort()) {try {// eslint-disable-next-line no-await-in-loop