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
test(audit): share one noise filter across the browser sweeps, and render accessory thumbs
nirholasac3c97cdcce0
diff --git a/scripts/audit-console.mjs b/scripts/audit-console.mjsindex 7c02214e5..52aaf4d51 100644--- a/scripts/audit-console.mjs+++ b/scripts/audit-console.mjs@@ -33,6 +33,7 @@ import { createServer } from 'node:net';import { spawn } from 'node:child_process';import { get as httpGet } from 'node:http';import { chromium } from 'playwright';+import { isIgnorableConsole, isDevOnlyAsset } from './lib/console-noise.mjs';const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');@@ -51,97 +52,6 @@ const VIEWPORTS = {mobile: { width: 390, height: 844, isMobile: true, label: 'mobile 390×844' },};-// ── Noise filters ────────────────────────────────────────────────────────────-// Console text that is never a real defect from our code (dev infra, browser-// policy, third-party telemetry, auth-gated API statuses, external CDN CORS).-const IGNORE_CONSOLE = [- // Vite HMR / dev infra. In Codespaces the HMR wss handshake 302s through the- // proxy — documented environment noise, not a page bug.- /\[vite\]/i,- /@vite\/client/i,- /WebSocket closed without opened/i,- /WebSocket connection to .* failed/i,- /Error during WebSocket handshake/i,- /failed to connect to websocket/i,- /\[HMR\]/i,- // Browser policy / environment- /the AudioContext was not allowed to start/i,- /Tracking Prevention/i,- /autoplay/i,- /Permissions policy violation/i,- /Unrecognized feature:/i,- // Third-party analytics / telemetry (never our code)- /posthog/i,- /sentry/i,- /segment\.com/i,- /google-analytics/i,- /cdn\.vercel-insights/i,- /vercel\.live/i,- // API calls judged by HTTP status, not console — auth/payment-gate is expected- /Failed to load resource.*\/api\//i,- /\b(401|402|403|429|503)\b.*\/api\//i,- /Failed to load resource: the server responded with a status of 40[0-3]/i,- /Failed to load resource: the server responded with a status of 429/i,- /Failed to load resource: the server responded with a status of 5(02|03)/i,- // Walk multiplayer / live socket servers not running in dev (graceful fallback)- /Failed to load resource: net::ERR_CONNECTION_REFUSED/i,- /net::ERR_CONNECTION_REFUSED/i,- /\[walk-net\]/i,- // R2/CDN CORS from dev origins (localhost) — only blocks in dev, not production- /r2\.dev.*Access-Control/i,- /r2\.dev.*CORS policy/i,- /CORS policy.*r2\.dev/i,- /Access-Control-Allow-Origin.*r2\.dev/i,- /pub-[a-f0-9]+\.r2\.dev.*blocked/i,- /blocked by CORS policy.*r2\.dev/i,- // User-generated data with expired signed URLs — not our code- /private-user-images\.githubusercontent\.com.*404/i,- /X-Amz-Signature.*404/i,- // Three.js / WebGL expected notices- /THREE\.WebGLRenderer: WebGL 1 is not supported/i,- /THREE\.BufferGeometry\.computeBoundingSphere/i,- /WebGL.*swiftshader/i,- /Automatic fallback to software WebGL/i,- // Content-Security-Policy noise from third-party embeds- /content security policy/i,- /Refused to (load|connect|execute|frame)/i,- // Solana / wallet adapter expected console output- /StandardWalletAdapter/i,- /wallet adapter/i,- // dev tooling- /Download the React DevTools/i,- // iframe sandbox noise- /Allow attribute/i,- /Blocked.*frame/i,- // Font loading via CSS (browser-level, not our JS)- /OTS parsing error/i,- /downloadable font/i,- // Colyseus/socket deprecation warnings- /using deprecated parameters for the initialization/i,- // Vite dep-optimizer race: when the optimizer re-bundles mid-navigation,- // in-flight requests for the old dep hash 504 and Vite auto-reloads the page.- // Purely a dev-server artifact — production ships pre-bundled deps, never 504s.- /504 \(Outdated Optimize Dep\)/i,- /Outdated Optimize Dep/i,-];--function isIgnorableConsole(text) {- return IGNORE_CONSOLE.some((re) => re.test(text));-}--// First-party URLs whose 4xx/5xx is a dev-server artifact, never a prod defect:-// • /.vite/deps/* — optimizer re-bundle race (504), Vite auto-reloads-// • /agent-3d/.../agent-3d.js — the <agent-3d> custom-element bundle. In dev a-// plugin serves it from dist-lib/ (needs `npm run build:lib`); in production-// it's a real CDN asset at https://three.ws/agent-3d/latest/agent-3d.js.-// • *.map — source maps; browsers probe them, 404 is harmless-function isDevOnlyAsset(u) {- if (/\/.vite\/deps\//.test(u)) return true;- if (/\/agent-3d\/[^/]+\/agent-3d\.(js|umd\.cjs)(\?|$)/.test(u)) return true;- if (/\.map(\?|$)/.test(u)) return true;- return false;-}-// ── Route manifest from data/pages.json ──────────────────────────────────────function loadRoutes({ includeBlog }) {const data = JSON.parse(readFileSync(join(ROOT, 'data/pages.json'), 'utf8'));diff --git a/scripts/lib/console-noise.mjs b/scripts/lib/console-noise.mjsnew file mode 100644index 000000000..f1666f7fb--- /dev/null+++ b/scripts/lib/console-noise.mjs@@ -0,0 +1,99 @@+// Shared console/network noise filters for the browser audit harnesses.+//+// A headless sweep sees plenty of output that is never a defect in our code:+// Vite HMR chatter, browser autoplay policy, third-party telemetry, auth-gated+// API statuses, and dev-only asset paths that only exist as real CDN files in+// production. Both `npm run audit:console` (every route) and+// `npm run audit:play-failures` (deliberate failure injection on /play) judge+// findings against this one list, so a filter fixed in one is fixed in both.++// ── Noise filters ────────────────────────────────────────────────────────────+// Console text that is never a real defect from our code (dev infra, browser+// policy, third-party telemetry, auth-gated API statuses, external CDN CORS).+export const IGNORE_CONSOLE = [+ // Vite HMR / dev infra. In Codespaces the HMR wss handshake 302s through the+ // proxy — documented environment noise, not a page bug.+ /\[vite\]/i,+ /@vite\/client/i,+ /WebSocket closed without opened/i,+ /WebSocket connection to .* failed/i,+ /Error during WebSocket handshake/i,+ /failed to connect to websocket/i,+ /\[HMR\]/i,+ // Browser policy / environment+ /the AudioContext was not allowed to start/i,+ /Tracking Prevention/i,+ /autoplay/i,+ /Permissions policy violation/i,+ /Unrecognized feature:/i,+ // Third-party analytics / telemetry (never our code)+ /posthog/i,+ /sentry/i,+ /segment\.com/i,+ /google-analytics/i,+ /cdn\.vercel-insights/i,+ /vercel\.live/i,+ // API calls judged by HTTP status, not console — auth/payment-gate is expected+ /Failed to load resource.*\/api\//i,+ /\b(401|402|403|429|503)\b.*\/api\//i,+ /Failed to load resource: the server responded with a status of 40[0-3]/i,+ /Failed to load resource: the server responded with a status of 429/i,+ /Failed to load resource: the server responded with a status of 5(02|03)/i,+ // Walk multiplayer / live socket servers not running in dev (graceful fallback)+ /Failed to load resource: net::ERR_CONNECTION_REFUSED/i,+ /net::ERR_CONNECTION_REFUSED/i,+ /\[walk-net\]/i,+ // R2/CDN CORS from dev origins (localhost) — only blocks in dev, not production+ /r2\.dev.*Access-Control/i,+ /r2\.dev.*CORS policy/i,+ /CORS policy.*r2\.dev/i,+ /Access-Control-Allow-Origin.*r2\.dev/i,+ /pub-[a-f0-9]+\.r2\.dev.*blocked/i,+ /blocked by CORS policy.*r2\.dev/i,+ // User-generated data with expired signed URLs — not our code+ /private-user-images\.githubusercontent\.com.*404/i,+ /X-Amz-Signature.*404/i,+ // Three.js / WebGL expected notices+ /THREE\.WebGLRenderer: WebGL 1 is not supported/i,+ /THREE\.BufferGeometry\.computeBoundingSphere/i,+ /WebGL.*swiftshader/i,+ /Automatic fallback to software WebGL/i,+ // Content-Security-Policy noise from third-party embeds+ /content security policy/i,+ /Refused to (load|connect|execute|frame)/i,+ // Solana / wallet adapter expected console output+ /StandardWalletAdapter/i,+ /wallet adapter/i,+ // dev tooling+ /Download the React DevTools/i,+ // iframe sandbox noise+ /Allow attribute/i,+ /Blocked.*frame/i,+ // Font loading via CSS (browser-level, not our JS)+ /OTS parsing error/i,+ /downloadable font/i,+ // Colyseus/socket deprecation warnings+ /using deprecated parameters for the initialization/i,+ // Vite dep-optimizer race: when the optimizer re-bundles mid-navigation,+ // in-flight requests for the old dep hash 504 and Vite auto-reloads the page.+ // Purely a dev-server artifact — production ships pre-bundled deps, never 504s.+ /504 \(Outdated Optimize Dep\)/i,+ /Outdated Optimize Dep/i,+];++export function isIgnorableConsole(text) {+ return IGNORE_CONSOLE.some((re) => re.test(text));+}++// First-party URLs whose 4xx/5xx is a dev-server artifact, never a prod defect:+// • /.vite/deps/* — optimizer re-bundle race (504), Vite auto-reloads+// • /agent-3d/.../agent-3d.js — the <agent-3d> custom-element bundle. In dev a+// plugin serves it from dist-lib/ (needs `npm run build:lib`); in production+// it's a real CDN asset at https://three.ws/agent-3d/latest/agent-3d.js.+// • *.map — source maps; browsers probe them, 404 is harmless+export function isDevOnlyAsset(u) {+ if (/\/.vite\/deps\//.test(u)) return true;+ if (/\/agent-3d\/[^/]+\/agent-3d\.(js|umd\.cjs)(\?|$)/.test(u)) return true;+ if (/\.map(\?|$)/.test(u)) return true;+ return false;+}diff --git a/scripts/render-accessory-thumbs.mjs b/scripts/render-accessory-thumbs.mjsnew file mode 100644index 000000000..8f3b14797--- /dev/null+++ b/scripts/render-accessory-thumbs.mjs@@ -0,0 +1,167 @@+#!/usr/bin/env node+// Accessory thumbnail renderer.+//+// The /play wardrobe (src/game/cosmetics-wardrobe.js) and the character-studio+// preset picker both show a poster PNG per worn accessory. This renders one from+// the accessory's own GLB, so a thumbnail can never drift from the asset it+// stands for: whoever regenerates the GLB regenerates the poster from it.+//+// It draws with the repo's own Three.js (node_modules/three) inside headless+// Chromium via Playwright — no CDN, no external service, no network. The page is+// served from a throwaway local HTTP server rooted at the repo so the module+// graph and the GLB are same-origin.+//+// Output is a 512x512 PNG with a transparent background, three-point studio+// lighting and a soft neutral fill, matching the framing of the thumbs already+// in public/accessories/thumbs/.+//+// Usage:+// node scripts/render-accessory-thumbs.mjs laurel-meetup+// node scripts/render-accessory-thumbs.mjs # every accessory GLB++import { createServer } from 'node:http';+import { readFile, writeFile, readdir, mkdir } from 'node:fs/promises';+import { createReadStream } from 'node:fs';+import path from 'node:path';+import { fileURLToPath } from 'node:url';+import { chromium } from 'playwright';++const HERE = path.dirname(fileURLToPath(import.meta.url));+const REPO = path.resolve(HERE, '..');+const GLB_DIR = path.join(REPO, 'public', 'accessories');+const THUMB_DIR = path.join(GLB_DIR, 'thumbs');+const SIZE = 512;++const MIME = {+ '.js': 'text/javascript', '.mjs': 'text/javascript', '.html': 'text/html',+ '.json': 'application/json', '.glb': 'model/gltf-binary', '.wasm': 'application/wasm',+};++// Serve the repo read-only on an ephemeral port, with the harness page itself at+// HARNESS_PATH so the page, the Three.js module graph and the GLB all share one+// origin (an `about:blank` page gets a null origin and every module import fails+// CORS). Paths are resolved and then checked to still live under the repo, so a+// `..` in a URL can't escape it.+const HARNESS_PATH = '/__accessory-thumb.html';++function serveRepo(harnessHtml) {+ return new Promise((resolve) => {+ const server = createServer(async (req, res) => {+ const rel = decodeURIComponent((req.url || '/').split('?')[0]);+ if (rel === HARNESS_PATH) {+ res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' });+ res.end(harnessHtml);+ return;+ }+ const file = path.resolve(REPO, '.' + rel);+ if (!file.startsWith(REPO)) { res.writeHead(403).end(); return; }+ try {+ const body = await readFile(file);+ res.writeHead(200, {+ 'content-type': MIME[path.extname(file)] || 'application/octet-stream',+ 'content-length': body.length,+ });+ res.end(body);+ } catch {+ res.writeHead(404).end();+ }+ });+ server.listen(0, '127.0.0.1', () => resolve({ server, port: server.address().port }));+ });+}++const PAGE = `<!doctype html>+<html><head><meta charset="utf-8">+<script type="importmap">+{"imports":{"three":"/node_modules/three/build/three.module.js",+"three/addons/":"/node_modules/three/examples/jsm/"}}+</script>+<style>html,body{margin:0;background:transparent}canvas{display:block}</style>+</head><body>+<script type="module">+import * as THREE from 'three';+import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';++const SIZE = ${SIZE};+const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true, preserveDrawingBuffer: true });+renderer.setSize(SIZE, SIZE);+renderer.setClearColor(0x000000, 0);+renderer.toneMapping = THREE.ACESFilmicToneMapping;+renderer.toneMappingExposure = 1.15;+document.body.appendChild(renderer.domElement);++const scene = new THREE.Scene();+// Three-point studio rig: a warm key from the front-left, a cool rim from+// behind-right to separate the silhouette against a transparent background, and+// a hemisphere fill so downward faces never go to pure black.+const key = new THREE.DirectionalLight(0xfff4e2, 3.1); key.position.set(-2.2, 2.6, 3.2);+const rim = new THREE.DirectionalLight(0xdce8ff, 2.0); rim.position.set(2.4, 1.2, -2.8);+scene.add(key, rim, new THREE.HemisphereLight(0xffffff, 0x2a2a30, 1.35));++window.renderAccessory = async (url) => {+ const gltf = await new GLTFLoader().loadAsync(url);+ const model = gltf.scene;+ // Drop any previous subject so one page can render the whole batch.+ for (const child of [...scene.children]) if (child.userData.subject) scene.remove(child);+ model.userData.subject = true;+ scene.add(model);++ // Frame the model: recentre on its bounding box, then pull the camera back+ // far enough that the largest dimension fills ~78% of the frame at any scale.+ const box = new THREE.Box3().setFromObject(model);+ const size = box.getSize(new THREE.Vector3());+ const center = box.getCenter(new THREE.Vector3());+ model.position.sub(center);+ const radius = Math.max(size.x, size.y, size.z) * 0.5 || 0.1;+ const camera = new THREE.PerspectiveCamera(35, 1, radius * 0.01, radius * 100);+ const dist = (radius / Math.sin((35 * Math.PI / 180) / 2)) * 0.78;+ // Three-quarter view from slightly above: reads volume better than a flat+ // front-on shot and matches the existing thumbs.+ camera.position.set(dist * 0.52, dist * 0.42, dist * 0.74);+ camera.lookAt(0, 0, 0);+ renderer.render(scene, camera);+ return renderer.domElement.toDataURL('image/png');+};+window.rendererReady = true;+</script></body></html>`;++async function main() {+ const wanted = process.argv.slice(2).filter((a) => !a.startsWith('-')).map((n) => n.replace(/\.glb$/, ''));+ const names = (await readdir(GLB_DIR))+ .filter((f) => f.endsWith('.glb'))+ .map((f) => f.replace(/\.glb$/, ''))+ .filter((n) => !wanted.length || wanted.includes(n));+ const missing = wanted.filter((n) => !names.includes(n));+ if (missing.length) throw new Error(`No GLB for ${missing.join(', ')} in ${GLB_DIR}`);+ if (!names.length) { console.log('No accessory GLBs to render.'); return; }++ await mkdir(THUMB_DIR, { recursive: true });+ const { server, port } = await serveRepo();+ const browser = await chromium.launch({ args: ['--use-gl=swiftshader', '--enable-unsafe-swiftshader'] });+ try {+ const page = await browser.newPage({ viewport: { width: SIZE, height: SIZE } });+ page.on('pageerror', (err) => { throw err; });+ await page.setContent(PAGE(port), { waitUntil: 'load' });+ await page.waitForFunction('window.rendererReady === true', null, { timeout: 30_000 });++ for (const name of names) {+ const dataUrl = await page.evaluate(+ ([url]) => window.renderAccessory(url),+ [`http://127.0.0.1:${port}/public/accessories/${name}.glb`],+ );+ const png = Buffer.from(dataUrl.split(',')[1], 'base64');+ const out = path.join(THUMB_DIR, `${name}.png`);+ await writeFile(out, png);+ console.log(` ${(name + '.png').padEnd(28)} ${png.length.toString().padStart(7)} bytes`);+ }+ } finally {+ await browser.close();+ server.close();+ }+ console.log(`Rendered ${names.length} accessory thumbnail(s) to ${THUMB_DIR}`);+}++main().catch((err) => {+ console.error(err);+ process.exit(1);+});