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
build: harden vercel — fail-fast bundle-api, retry-individually, more externals, heartbeat
nirholas41ef2fb53fef
diff --git a/public/features.json b/public/features.jsonindex f96642bd1..612e9e30e 100644--- a/public/features.json+++ b/public/features.json@@ -1,5 +1,5 @@{- "generated_at": "2026-05-29T01:17:20.019Z",+ "generated_at": "2026-05-29T01:24:41.241Z","generated_by": "scripts/build-page-index.mjs from data/pages.json","site": {"name": "three.ws",diff --git a/scripts/build-vercel.mjs b/scripts/build-vercel.mjsindex 4fb31f571..c6b8326c7 100644--- a/scripts/build-vercel.mjs+++ b/scripts/build-vercel.mjs@@ -15,8 +15,22 @@ import { isCached, writeStamp } from './build-cache.mjs';const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');+const running = new Set();++// Heartbeat: every 30s, print which sub-builds are still in flight. If Vercel's+// build hangs, the log makes it obvious which stage is stuck instead of leaving+// us to guess from a silent 45-minute timeout.+const heartbeat = setInterval(() => {+ if (running.size === 0) return;+ const labels = [...running].map(([l, t]) => `${l} (${((Date.now() - t) / 1000).toFixed(0)}s)`).join(', ');+ console.log(`\n[build:vercel] still running: ${labels}`);+}, 30_000);+heartbeat.unref();+function run(label, cmd, opts = {}) {const start = Date.now();+ const entry = [label, start];+ running.add(entry);return new Promise((res, rej) => {console.log(`\n[${label}] starting: ${cmd}`);const child = spawn('sh', ['-c', cmd], {@@ -25,6 +39,7 @@ function run(label, cmd, opts = {}) {env: { ...process.env, ...opts.env },});child.on('close', (code) => {+ running.delete(entry);const elapsed = ((Date.now() - start) / 1000).toFixed(1);if (code === 0) {console.log(`[${label}] done in ${elapsed}s`);@@ -92,12 +107,10 @@ async function postBuild() {}const totalStart = Date.now();+const phase = (n, label) => console.log(`\n=== build:vercel phase ${n}: ${label} (t+${((Date.now() - totalStart) / 1000).toFixed(1)}s) ===`);try {- // Phase 1: prebuild + build:lib + independent sub-builds — all in parallel- // prebuild generates data files the app vite build reads (pages.json, skill metadata, news)- // build:lib is independent of prebuild — produces dist-lib/agent-3d.js- // avatar-studio, chat, bundle-api are fully independent+ phase(1, 'prebuild + lib + avatar-studio + chat + bundle-api (parallel)');await Promise.all([prebuild(),buildLib(),@@ -106,15 +119,22 @@ try {bundleApi(),]);- // Phase 2: app vite build (needs prebuild outputs + same node_modules)+ phase(2, 'app vite build');await buildApp();- // Phase 3: post-build steps (depend on Phase 1+2 outputs)+ phase(3, 'post-build (copy-avatar-studio + publish-lib + r2-cors)');await postBuild();+ clearInterval(heartbeat);const totalElapsed = ((Date.now() - totalStart) / 1000).toFixed(1);console.log(`\n✓ build:vercel complete in ${totalElapsed}s`);} catch (err) {- console.error(`\n✗ build:vercel failed: ${err.message}`);+ clearInterval(heartbeat);+ const totalElapsed = ((Date.now() - totalStart) / 1000).toFixed(1);+ console.error(`\n✗ build:vercel failed after ${totalElapsed}s: ${err.message}`);+ if (running.size > 0) {+ const labels = [...running].map(([l, t]) => `${l} (${((Date.now() - t) / 1000).toFixed(0)}s)`).join(', ');+ console.error(` still running when build failed: ${labels}`);+ }process.exit(1);}diff --git a/scripts/bundle-api.mjs b/scripts/bundle-api.mjsindex 154652cf0..0bb465014 100644--- a/scripts/bundle-api.mjs+++ b/scripts/bundle-api.mjs@@ -11,11 +11,12 @@* JS file BEFORE Vercel sees them. The bundled files have all deps inlined;* nft finds nothing external to trace — drops from ~45 min to under 3 min.*/-import { readdir, stat } from 'fs/promises';+import { readdir, stat, readFile } from 'fs/promises';import { resolve, join, dirname, relative } from 'path';import { fileURLToPath } from 'url';import { existsSync } from 'fs';import { execFileSync } from 'child_process';+import { createHash } from 'crypto';const __dirname = dirname(fileURLToPath(import.meta.url));const ROOT = resolve(__dirname, '..');@@ -71,25 +72,43 @@ const EXTERNALS = ['@metaplex-foundation/*','@bonfida/*','@pump-fun/*',+ '@nirholas/*',+ '@coral-xyz/*','@aws-sdk/*','@sentry/*','@opentelemetry/*','@asamuzakjp/*','@csstools/*',+ '@neynar/*',+ '@upstash/*','jsdom','ethers',+ 'elevenlabs',+ 'playwright',+ 'playwright-core',+ 'puppeteer',+ 'puppeteer-core',+ 'puppeteer-extra',+ 'puppeteer-extra-plugin-stealth',+ 'puppeteer-extra-plugin-*',];-const start = Date.now();-const routeFiles = await collectRouteFiles(API_DIR);-const BATCH_SIZE = 20;-const totalBatches = Math.ceil(routeFiles.length / BATCH_SIZE);-console.log(`[bundle-api] Bundling ${routeFiles.length} route files in ${totalBatches} batches...`);+// Hash every source file BEFORE bundling. After bundling, any file whose+// content still matches its pre-bundle hash was untouched by esbuild — Vercel's+// NFT would then trace it against the full ~2 GB node_modules tree, blowing the+// 45 min build timeout. Fail the build instead so the next deploy points at the+// real cause within minutes instead of after a 45-minute hang.+async function hashFile(path) {+ try {+ const buf = await readFile(path);+ return createHash('sha256').update(buf).digest('hex');+ } catch {+ return null;+ }+}-let errors = 0;-for (let i = 0; i < routeFiles.length; i += BATCH_SIZE) {- const batch = routeFiles.slice(i, i + BATCH_SIZE);- const args = [+function esbuildArgs(files) {+ return ['--bundle','--platform=node','--target=node20',@@ -104,29 +123,95 @@ for (let i = 0; i < routeFiles.length; i += BATCH_SIZE) {'--log-override:duplicate-object-key=silent','--log-override:equals-negative-zero=silent',...EXTERNALS.map((e) => `--external:${e}`),- ...batch,+ ...files,];+}++function runEsbuild(files, timeoutMs) {+ execFileSync(resolve(ROOT, 'node_modules/.bin/esbuild'), esbuildArgs(files), {+ cwd: ROOT,+ stdio: ['ignore', 'pipe', 'pipe'],+ timeout: timeoutMs,+ maxBuffer: 10 * 1024 * 1024,+ });+}++const start = Date.now();+const routeFiles = await collectRouteFiles(API_DIR);+const BATCH_SIZE = 20;+const totalBatches = Math.ceil(routeFiles.length / BATCH_SIZE);+console.log(`[bundle-api] Bundling ${routeFiles.length} route files in ${totalBatches} batches...`);++const preHashes = new Map();+await Promise.all(routeFiles.map(async (f) => preHashes.set(f, await hashFile(f))));++let batchErrors = 0;+let individualRetries = 0;+const individualFailures = [];++for (let i = 0; i < routeFiles.length; i += BATCH_SIZE) {+ const batch = routeFiles.slice(i, i + BATCH_SIZE);+ const batchIdx = Math.floor(i / BATCH_SIZE) + 1;try {- execFileSync(resolve(ROOT, 'node_modules/.bin/esbuild'), args, {- cwd: ROOT,- stdio: ['ignore', 'pipe', 'pipe'],- timeout: 60_000,- maxBuffer: 10 * 1024 * 1024,- });+ runEsbuild(batch, 90_000);process.stdout.write('.');} catch (err) {process.stdout.write('!');- errors++;- const stderr = err.stderr?.toString().trim();- const short = stderr- ? stderr.split('\n').filter((l) => l.includes('ERROR')).slice(0, 3).join('\n ') || stderr.slice(0, 200)- : err.message;- console.error(`\n[bundle-api] Batch ${i}–${i + BATCH_SIZE} failed:\n ${short}`);+ batchErrors++;+ const stderr = err.stderr?.toString().trim() || err.message || '';+ const short = stderr.split('\n').filter((l) => l.includes('ERROR')).slice(0, 5).join('\n ') || stderr.slice(0, 400);+ console.error(`\n[bundle-api] Batch ${batchIdx}/${totalBatches} failed — retrying individually:\n ${short}`);+ // Retry each file in the failed batch on its own so one bad file+ // doesn't poison the other 19. Anything still failing is definitively+ // unbundled and will block the build below.+ for (const file of batch) {+ individualRetries++;+ try {+ runEsbuild([file], 30_000);+ } catch (singleErr) {+ const ss = singleErr.stderr?.toString().trim() || singleErr.message || '';+ const sshort = ss.split('\n').filter((l) => l.includes('ERROR')).slice(0, 3).join('\n ') || ss.slice(0, 300);+ individualFailures.push({ file: relative(ROOT, file), error: sshort });+ }+ }+ }+}++const stillRaw = [];+for (const f of routeFiles) {+ const before = preHashes.get(f);+ const after = await hashFile(f);+ if (before && after && before === after) {+ stillRaw.push(relative(ROOT, f));}}const elapsed = ((Date.now() - start) / 1000).toFixed(1);const sizes = await Promise.all(routeFiles.map(async (f) => (await stat(f)).size));const totalKB = (sizes.reduce((s, n) => s + n, 0) / 1024).toFixed(0);-console.log(`\n[bundle-api] Done in ${elapsed}s — ${routeFiles.length} files, ${totalKB} KB total${errors ? ` (${errors}/${totalBatches} batch errors — unbundled files traced by NFT normally)` : ''}`);-if (errors > totalBatches / 2) process.exit(1);+console.log(+ `\n[bundle-api] Done in ${elapsed}s — ${routeFiles.length} files, ${totalKB} KB` ++ (batchErrors ? `, ${batchErrors}/${totalBatches} batch errors (${individualRetries} individual retries)` : '') ++ (individualFailures.length ? `, ${individualFailures.length} routes still failing` : '') ++ (stillRaw.length ? `, ${stillRaw.length} routes left as raw source` : '')+);++if (individualFailures.length) {+ console.error(`\n[bundle-api] FAILED — ${individualFailures.length} routes could not be bundled:`);+ for (const { file, error } of individualFailures.slice(0, 25)) {+ console.error(` ${file}\n ${error}`);+ }+ if (individualFailures.length > 25) console.error(` …and ${individualFailures.length - 25} more`);+}++if (stillRaw.length) {+ console.error(`\n[bundle-api] FAILED — ${stillRaw.length} routes left as raw source (NFT would scan full node_modules):`);+ for (const f of stillRaw.slice(0, 25)) console.error(` ${f}`);+ if (stillRaw.length > 25) console.error(` …and ${stillRaw.length - 25} more`);+}++// Fail fast on the build container instead of letting Vercel time out at 45 min+// trying to NFT-trace raw route files against the 2 GB node_modules tree.+if (individualFailures.length > 0 || stillRaw.length > 0) {+ process.exit(1);+}