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
chore: scan/home polish, sentry + api-bundle updates
nirholase222999b5887
diff --git a/api/_lib/sentry.js b/api/_lib/sentry.jsindex ac5b25047..c351b061f 100644--- a/api/_lib/sentry.js+++ b/api/_lib/sentry.js@@ -3,64 +3,143 @@// Optional env: SENTRY_ENVIRONMENT (defaults to VERCEL_ENV), SENTRY_RELEASE (defaults to VERCEL_GIT_COMMIT_SHA)//// Usage: import { captureException } from './_lib/sentry.js'-// wrap() in http.js calls this automatically for 5xx errors.+// serverError() in http.js calls this automatically for 5xx errors.//-// @sentry/node pulls in the full OpenTelemetry instrumentation tree at import-// time (~30s of cold-start cost per process). Defer the SDK behind a lazy-// import that only fires when SENTRY_DSN is set AND an error needs reporting.-// Endpoints without errors never pay the cost; CI / local tests that-// transitively import http.js no longer time out.+// WHY NO @sentry/node SDK HERE — DO NOT "FIX" THIS BY ADDING IT BACK.+// This module is imported (via http.js) by ~360 of our serverless functions.+// The @sentry/node SDK statically pulls in the full OpenTelemetry instrumentation+// tree (@sentry + @opentelemetry ≈ 50 MB / thousands of files). On Vercel that+// tree is marked external in scripts/bundle-api.mjs, so @vercel/nft traces it+// once PER FUNCTION at build time — ~360 traversals of a 50 MB graph. That alone+// pushed the deploy past Vercel's 45-minute build timeout (deploy 5vphtZz6S).+// Reporting straight to Sentry's public envelope-ingestion HTTP API removes the+// dependency entirely: nothing for NFT to trace, no SDK init / OTel cold-start+// cost, and one fire-and-forget fetch on the (rare) error path. Same envelope+// Sentry's own SDK would POST — just without shipping the SDK to every function.+// Spec: https://develop.sentry.dev/sdk/envelopes/-let _sdkPromise = null;-let _initialised = false;+import { webcrypto } from 'node:crypto';-function loadSdk() {- if (!_sdkPromise) _sdkPromise = import('@sentry/node');- return _sdkPromise;+const crypto = globalThis.crypto || webcrypto;++// Parse the DSN once. Shape: {PROTOCOL}://{PUBLIC_KEY}@{HOST}{PATH}/{PROJECT_ID}+// Returns null (→ reporting is a no-op) when SENTRY_DSN is unset or malformed.+function parseDsn(rawDsn) {+ if (!rawDsn) return null;+ let url;+ try {+ url = new URL(rawDsn);+ } catch {+ return null;+ }+ const publicKey = url.username;+ const segments = url.pathname.split('/').filter(Boolean);+ const projectId = segments.pop();+ if (!publicKey || !projectId) return null;+ const pathPrefix = segments.length ? `/${segments.join('/')}` : '';+ return {+ publicKey,+ envelopeUrl: `${url.protocol}//${url.host}${pathPrefix}/api/${projectId}/envelope/`,+ };+}++let _dsn;+function dsn() {+ if (_dsn === undefined) _dsn = parseDsn(process.env.SENTRY_DSN);+ return _dsn;+}++function eventId() {+ return crypto.randomUUID().replace(/-/g, '');}-async function ensureInit() {- const Sentry = await loadSdk();- if (!_initialised) {- Sentry.init({- dsn: process.env.SENTRY_DSN,- environment: process.env.SENTRY_ENVIRONMENT || process.env.VERCEL_ENV || 'development',- release: process.env.SENTRY_RELEASE || process.env.VERCEL_GIT_COMMIT_SHA || undefined,- tracesSampleRate: 0.1,- sendDefaultPii: false,+// V8 stack → Sentry frames. Sentry orders frames oldest-first (the crashing+// frame LAST), the reverse of how V8 prints them. Lines we can't parse are+// dropped; a partial trace still groups better than none.+function parseStack(stack) {+ if (typeof stack !== 'string') return [];+ const frames = [];+ for (const line of stack.split('\n')) {+ const m = line.match(/^\s*at (?:(.+?) )?\(?(.+?):(\d+):(\d+)\)?\s*$/);+ if (!m) continue;+ const [, fn, filename, lineno, colno] = m;+ frames.push({+ function: fn || '<anonymous>',+ filename,+ lineno: Number(lineno),+ colno: Number(colno),+ in_app: !filename.includes('node_modules') && !filename.startsWith('node:'),});- _initialised = true;}- return Sentry;+ return frames.reverse();+}++function baseEvent(level) {+ return {+ event_id: eventId(),+ timestamp: Date.now() / 1000,+ platform: 'node',+ level,+ logger: 'three.ws',+ environment: process.env.SENTRY_ENVIRONMENT || process.env.VERCEL_ENV || 'development',+ release: process.env.SENTRY_RELEASE || process.env.VERCEL_GIT_COMMIT_SHA || undefined,+ server_name: process.env.VERCEL_REGION || undefined,+ sdk: { name: 'threews.fetch', version: '1.0.0' },+ };+}++// Build the 3-line NDJSON envelope (envelope header, item header, event) and+// POST it. Fire-and-forget with a hard timeout so a slow/blocked ingest never+// delays — or hangs — the function it was reporting an error from.+function send(event) {+ const cfg = dsn();+ if (!cfg) return;+ const envelope =+ JSON.stringify({ event_id: event.event_id, sent_at: new Date().toISOString() }) ++ '\n' ++ JSON.stringify({ type: 'event' }) ++ '\n' ++ JSON.stringify(event);++ const controller = new AbortController();+ const timer = setTimeout(() => controller.abort(), 2500);+ fetch(cfg.envelopeUrl, {+ method: 'POST',+ headers: {+ 'content-type': 'application/x-sentry-envelope',+ 'x-sentry-auth': `Sentry sentry_version=7, sentry_client=threews.fetch/1.0.0, sentry_key=${cfg.publicKey}`,+ },+ body: envelope,+ signal: controller.signal,+ keepalive: true,+ })+ .catch(() => {})+ .finally(() => clearTimeout(timer));}export function captureException(err, context = {}) {- if (!process.env.SENTRY_DSN) return;- // Fire-and-forget — error reporting must not block the response path. If- // Sentry's loader / init throws, swallow it; the handler already replied.- ensureInit()- .then((Sentry) => {- Sentry.withScope((scope) => {- for (const [key, value] of Object.entries(context)) {- scope.setExtra(key, value);- }- Sentry.captureException(err);- });- })- .catch(() => {});+ if (!dsn()) return;+ const error = err instanceof Error ? err : new Error(typeof err === 'string' ? err : JSON.stringify(err));+ send({+ ...baseEvent('error'),+ exception: {+ values: [+ {+ type: error.name || 'Error',+ value: error.message || String(error),+ stacktrace: { frames: parseStack(error.stack) },+ },+ ],+ },+ extra: context,+ });}export function captureMessage(message, level = 'info', context = {}) {- if (!process.env.SENTRY_DSN) return;- ensureInit()- .then((Sentry) => {- Sentry.withScope((scope) => {- scope.setLevel(level);- for (const [key, value] of Object.entries(context)) {- scope.setExtra(key, value);- }- Sentry.captureMessage(message);- });- })- .catch(() => {});+ if (!dsn()) return;+ send({+ ...baseEvent(level),+ message: { formatted: String(message) },+ extra: context,+ });}diff --git a/pages/home.html b/pages/home.htmlindex b977cfc9f..2ee073b3d 100644--- a/pages/home.html+++ b/pages/home.html@@ -2697,24 +2697,19 @@<div class="hero-text"><div class="eyebrow">Open beta · live now</div><h1 class="hero-h">- Make a 3D AI agent<br/>- from a selfie.<br/>- <em>Embed it anywhere.</em>+ The 3D agent<br/>+ layer of the<br/>+ <em>internet.</em></h1><ul class="hero-bullets"><li><strong>Create</strong> a 3D AI agent from a selfie in 60 seconds</li><li><strong>Embed</strong> it on any website with two lines of HTML</li>- <li><strong>Earn</strong> <span data-term="usdc">USDC (a $1 digital dollar)</span> per chat with <span data-term="pay-per-call">pay-per-call micropayments</span></li>+ <li><strong>Earn</strong> USDC per chat with x402 micropayments</li></ul><div class="hero-cta-row"><a class="btn btn--primary" href="/create">Build your agent <span class="arrow">→</span></a>- <a class="btn" href="/what-is">What is this? <span class="arrow">→</span></a><a class="btn" href="#embed">See the embed</a></div>- <p class="hero-reassure">- <svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M13.5 4.5L6 12L2.5 8.5"/></svg>- <span><strong>No crypto needed to start.</strong> Build, embed, and chat with your agent for free. Owning it on-chain or charging for it is <a href="/pricing#no-crypto">an optional layer</a>.</span>- </p></div><div class="hero-stage" id="hero-stage"><span class="stage-marker">live</span>diff --git a/pages/scan.html b/pages/scan.htmlindex 84ef64213..69568019b 100644--- a/pages/scan.html+++ b/pages/scan.html@@ -232,6 +232,8 @@.done-viewer::after { content: ''; position: absolute; inset: -2px; border-radius: 18px; background: conic-gradient(from 0deg, var(--scan), rgba(136, 136, 136, 0.3), var(--scan), rgba(136, 136, 136, 0.3)); z-index: -1; animation: done-glow 6s linear infinite; opacity: 0.45; }@keyframes done-glow { to { transform: rotate(360deg); } }.done-viewer model-viewer { width: 100%; height: 100%; --poster-color: transparent; }+ .viewer-error { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 22px; text-align: center; font-size: 13px; line-height: 1.5; color: var(--muted); background: var(--panel); }+ .viewer-error.show { display: flex; }.name-row { margin: 0 0 18px; }.name-input { width: 100%; padding: 12px 14px; background: var(--panel); border: 1px solid var(--border-strong); border-radius: 10px; color: var(--text); font: 15px/1 inherit; outline: none; transition: border-color 120ms; }.name-input:focus { border-color: var(--scan); }@@ -630,6 +632,25 @@let _docTitleBase = document.title;let _notifyPermission = (typeof Notification !== 'undefined') ? Notification.permission : 'denied';+ function showViewerError(message) {+ const viewer = document.querySelector('.done-viewer');+ if (!viewer) return;+ let el = viewer.querySelector('.viewer-error');+ if (!el) {+ el = document.createElement('div');+ el.className = 'viewer-error';+ el.setAttribute('role', 'alert');+ viewer.appendChild(el);+ }+ el.textContent = message;+ el.classList.add('show');+ }++ // Surface model-viewer decode/load failures instead of leaving a black box.+ document.getElementById('done-model')?.addEventListener('error', () => {+ showViewerError('This scan couldn’t be displayed. Try downloading the .GLB instead.');+ });+document.addEventListener('selfie:preview', (e) => {const dataUrl = e.detail?.dataUrl;if (!dataUrl) return;@@ -667,15 +688,27 @@try {const res = await fetch(`/api/avatars/${encodeURIComponent(_avatarId)}`, { credentials: 'include' });if (res.ok) {- const avatar = await res.json();- _modelUrl = avatar.model_url || null;+ const data = await res.json();+ // GET /api/avatars/:id wraps the record in { avatar }. Private+ // scans expose the playable model as a presigned `url`; the public+ // CDN field `model_url` is null until the scan is made public.+ const avatar = data.avatar || data;+ _modelUrl = avatar.url || avatar.model_url || null;_avatarName = avatar.name || _avatarName;const modelEl = document.getElementById('done-model');- if (modelEl && _modelUrl) modelEl.setAttribute('src', _modelUrl);+ if (modelEl && _modelUrl) {+ modelEl.setAttribute('src', _modelUrl);+ } else {+ showViewerError('Your scan finished, but the model is still finalizing. Refresh in a moment.');+ }const nameEl = document.getElementById('done-name');if (nameEl && avatar.name) nameEl.value = avatar.name;+ } else {+ showViewerError('Couldn’t load your scan. Refresh to try again.');}- } catch (_) {}+ } catch (_) {+ showViewerError('Couldn’t load your scan. Check your connection and refresh.');+ }notifyDone();showStep('done');diff --git a/scripts/bundle-api.mjs b/scripts/bundle-api.mjsindex a8b46a4c3..0910f172d 100644--- a/scripts/bundle-api.mjs+++ b/scripts/bundle-api.mjs@@ -75,8 +75,12 @@ const EXTERNALS = ['@nirholas/*','@coral-xyz/*','@aws-sdk/*',- '@sentry/*',- '@opentelemetry/*',+ // NOTE: @sentry/* and @opentelemetry/* are intentionally NOT externalized —+ // nothing imports them anymore. api/_lib/sentry.js reports to Sentry's HTTP+ // envelope API via fetch instead of the @sentry/node SDK, specifically so NFT+ // no longer traces that ~50 MB tree once per function across the ~360 routes+ // that import http.js (the 45-min build timeout, deploy 5vphtZz6S). If you+ // re-add the SDK, read api/_lib/sentry.js's header first.'@asamuzakjp/*','@csstools/*','@neynar/*',