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
vite + widget verify script tweaks
nirholas0762b21369aa
diff --git a/scripts/_snap-modals.tmp.mjs b/scripts/_snap-modals.tmp.mjsdeleted file mode 100644index d3d735c48..000000000--- a/scripts/_snap-modals.tmp.mjs+++ /dev/null@@ -1,65 +0,0 @@-import { chromium } from 'playwright';-import { readFile } from 'node:fs/promises';--const glb = await readFile('/workspaces/three.ws/public/avatars/default.glb');-const browser = await chromium.launch();-const ctx = await browser.newContext({ viewport: { width: 1440, height: 1100 }, deviceScaleFactor: 2 });-const page = await ctx.newPage();-page.on('pageerror', (e) => console.error('PE:', e.message));--const b64 = Buffer.from(glb).toString('base64');-await page.addInitScript((b64) => {- if (location.pathname !== '/create-review') return;- window.__seed = (async () => {- const bin = atob(b64), bytes = new Uint8Array(bin.length);- for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i);- const blob = new Blob([bytes], { type: 'model/gltf-binary' });- const id = '19b160abcdef';- const db = await new Promise((res, rej) => {- const r = indexedDB.open('three-ws-guest', 1);- r.onupgradeneeded = () => { if (!r.result.objectStoreNames.contains('avatars')) r.result.createObjectStore('avatars'); };- r.onsuccess = () => res(r.result); r.onerror = () => rej(r.error);- });- await new Promise((res, rej) => {- const tx = db.transaction('avatars', 'readwrite');- tx.objectStore('avatars').put({ blob, meta: { source: 'avaturn' }, id, name: `Avatar #${id.slice(0,6)}`, size: blob.size, createdAt: Date.now() }, 'pending');- tx.oncomplete = res; tx.onerror = () => rej(tx.error);- });- db.close();- return true;- })();-}, b64);--await page.goto('http://localhost:3000/create-review', { waitUntil: 'load' });-try { await page.evaluate(() => window.__seed); } catch {}--// Wait longer so the page settles before any reload-await page.waitForTimeout(1500);-await page.reload({ waitUntil: 'load' });--await page.waitForSelector('#mv-container canvas', { timeout: 20000 });-await page.waitForFunction(() => document.getElementById('viewer-loading')?.classList.contains('is-hidden'));-await page.waitForTimeout(3500);--await page.fill('#f-name', 'Nicholas');--async function shot(feat, file, dwell = 700) {- await page.click(`[data-feature="${feat}"]`);- await page.waitForSelector('.fm-backdrop');- await page.waitForTimeout(dwell);- const b = await page.locator('.fm-dialog').boundingBox();- await page.screenshot({ path: file, clip: { x: Math.max(0, b.x - 24), y: Math.max(0, b.y - 24), width: b.width + 48, height: b.height + 48 } });- await page.keyboard.press('Escape');- await page.waitForSelector('.fm-backdrop', { state: 'detached' });-}--await shot('identity', '/tmp/cr-final-identity.png', 1000);-await shot('paid', '/tmp/cr-final-paid.png');-await shot('embed', '/tmp/cr-final-embed.png', 1000);-await shot('reputation', '/tmp/cr-final-reputation.png');-await shot('download', '/tmp/cr-final-download.png');--await page.screenshot({ path: '/tmp/cr-final-page.png' });--await browser.close();-console.log('saved');diff --git a/scripts/verify-widget-shell.mjs b/scripts/verify-widget-shell.mjsindex 5793019f4..4b9c7effa 100644--- a/scripts/verify-widget-shell.mjs+++ b/scripts/verify-widget-shell.mjs@@ -1,6 +1,6 @@-// Verify the slim /widget shell renders a 3D avatar without flashing site-// chrome — and that the parent surfaces (studio preview, public embed URL,-// legacy /app#kiosk=true) all behave correctly. Run while `npm run dev` is up.+// Verify the slim /widget shell behaves correctly across every surface:+// FOUC guard, no chrome, reveal=interaction click-to-boot, JSON-RPC API,+// poster pass-through, and studio/legacy parity. Run while `npm run dev` is up.//// node scripts/verify-widget-shell.mjs//@@ -49,12 +49,10 @@ async function waitForFirstFrame(page) {await withPage('/widget#model=<glb>&kiosk=true (direct embed)', async (page) => {const url = `${BASE}/widget?_=${Date.now()}#model=${encodeURIComponent(DEMO_GLB)}&kiosk=true`;await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30000 });- // Body should be invisible until first-frame event fires.const initialVisibility = await page.evaluate(() => getComputedStyle(document.body).visibility);if (initialVisibility === 'hidden') ok('body starts visibility:hidden (FOUC guard)');else fail('body starts visibility:hidden (FOUC guard)', `got ${initialVisibility}`);- // Confirm no <header>/<footer> ever exists in the DOM.const chromeCount = await page.evaluate(() =>document.querySelectorAll(@@ -78,7 +76,6 @@ await withPage('/widget#model=<glb>&kiosk=true (direct embed)', async (page) =>// targets /widget (not /app) and renders the model.await withPage('/studio preview iframe targets /widget', async (page) => {await page.goto(`${BASE}/studio/`, { waitUntil: 'domcontentloaded', timeout: 30000 });- // Wait for the preview iframe to receive a src.await page.waitForFunction(() => document.getElementById('preview-iframe')?.src?.includes('/widget'),{ timeout: 20000 },@@ -88,7 +85,6 @@ await withPage('/studio preview iframe targets /widget', async (page) => {ok(`preview iframe → /widget (src=${previewSrc.slice(0, 120)}…)`);else fail('preview iframe → /widget', `unexpected src: ${previewSrc}`);- // Drop into the iframe and confirm chrome isn't there either.const frame = page.frame({ url: /\/widget/ });if (!frame) {fail('studio iframe accessible', 'no /widget frame found');@@ -104,12 +100,11 @@ await withPage('/studio preview iframe targets /widget', async (page) => {console.log(' → /tmp/widget-studio.png');});-// 3. Legacy /app#kiosk=true still works (no chrome eventually, model renders).+// 3. Legacy /app#kiosk=true still works.await withPage('/app#model=<glb>&kiosk=true (legacy path)', async (page) => {const url = `${BASE}/app#model=${encodeURIComponent(DEMO_GLB)}&kiosk=true`;await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30000 });await waitForFirstFrame(page);- // In kiosk mode, header should now be display:none.const headerHidden = await page.evaluate(() => {const h = document.querySelector('header');return !h || getComputedStyle(h).display === 'none';@@ -120,6 +115,105 @@ await withPage('/app#model=<glb>&kiosk=true (legacy path)', async (page) => {console.log(' → /tmp/widget-legacy.png');});+// 4. Reveal-on-interaction: WebGL must NOT init until the visitor clicks.+await withPage('/widget#reveal=interaction defers WebGL boot', async (page) => {+ const url = `${BASE}/widget?_=${Date.now()}#model=${encodeURIComponent(DEMO_GLB)}&kiosk=true&reveal=interaction`;+ await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30000 });+ // Wait long enough that auto mode WOULD have booted by now.+ await page.waitForTimeout(1500);++ // The gate should be visible and clickable. window.VIEWER should NOT exist yet.+ const state = await page.evaluate(() => ({+ hasGate: Boolean(document.querySelector('.widget-reveal-gate')),+ viewerLoaded: Boolean(window.VIEWER),+ booted: Boolean(window.__WIDGET_BOOTED),+ }));+ if (state.hasGate && !state.viewerLoaded && !state.booted)+ ok('reveal=interaction holds boot before click');+ else+ fail(+ 'reveal=interaction holds boot before click',+ `hasGate=${state.hasGate} viewerLoaded=${state.viewerLoaded} booted=${state.booted}`,+ );++ await page.screenshot({ path: '/tmp/widget-reveal-gate.png' });+ console.log(' → /tmp/widget-reveal-gate.png');++ // Click the play button.+ await page.click('.widget-reveal-gate');+ // Now the app must actually boot.+ await waitForFirstFrame(page);+ const after = await page.evaluate(() => ({+ viewerLoaded: Boolean(window.VIEWER),+ gateGone: !document.querySelector('.widget-reveal-gate'),+ }));+ if (after.viewerLoaded && after.gateGone) ok('click boots WebGL + dismisses gate');+ else+ fail(+ 'click boots WebGL + dismisses gate',+ `viewerLoaded=${after.viewerLoaded} gateGone=${after.gateGone}`,+ );++ await page.screenshot({ path: '/tmp/widget-reveal-after.png' });+ console.log(' → /tmp/widget-reveal-after.png');+});++// 5. JSON-RPC roundtrip: parent loads widget-client.js, calls methods, gets results.+await withPage('JSON-RPC: ping + camera.getLookAt + screenshot.capture', async (page) => {+ // Build a host page that loads the widget client + an iframe pointed at /widget.+ await page.goto(`${BASE}/`, { waitUntil: 'domcontentloaded', timeout: 30000 });+ // Inject our test scaffold on top of the home page. Cross-origin doesn't+ // apply — both iframe and host run on localhost:3000.+ const testResult = await page.evaluate(+ async ({ BASE, DEMO_GLB }) => {+ // Drop any chrome and mount the iframe + the SDK.+ document.body.innerHTML =+ '<iframe id="w" style="width:600px;height:600px;border:0" ' ++ 'src="' + BASE + '/widget#model=' + encodeURIComponent(DEMO_GLB) + '&kiosk=true"></iframe>';+ await new Promise((r) => {+ const s = document.createElement('script');+ s.src = BASE + '/widget-client.js';+ s.onload = r;+ s.onerror = r;+ document.head.appendChild(s);+ });+ if (!window.ThreeWidget) return { error: 'ThreeWidget global missing' };+ const client = window.ThreeWidget.attach(document.getElementById('w'));++ // Wait for the widget to be ready (model loaded).+ await client.ready(25000);+ // 1) ping roundtrip+ const ping = await client.call('ping', null, 5000);+ // 2) camera.getLookAt+ const cam = await client.call('camera.getLookAt');+ // 3) screenshot+ const shot = await client.call('screenshot.capture', { width: 200, height: 200 });++ return {+ ok: true,+ pingOk: ping?.pong === true,+ cam: Array.isArray(cam?.eye) && cam.eye.length === 3,+ shotOk: typeof shot?.dataUrl === 'string' && shot.dataUrl.startsWith('data:image/'),+ };+ },+ { BASE, DEMO_GLB },+ );++ if (testResult.error) {+ fail('JSON-RPC test scaffold ran', testResult.error);+ return;+ }+ if (testResult.pingOk) ok('ping → { pong: true }');+ else fail('ping → { pong: true }', JSON.stringify(testResult));+ if (testResult.cam) ok('camera.getLookAt → { eye:[3] }');+ else fail('camera.getLookAt → { eye:[3] }', JSON.stringify(testResult));+ if (testResult.shotOk) ok('screenshot.capture → data: URL');+ else fail('screenshot.capture → data: URL', JSON.stringify(testResult));++ await page.screenshot({ path: '/tmp/widget-rpc-host.png' });+ console.log(' → /tmp/widget-rpc-host.png');+});+await browser.close();const failed = results.filter((r) => !r.ok);diff --git a/vite.config.js b/vite.config.jsindex 2c935ac82..762b0c183 100644--- a/vite.config.js+++ b/vite.config.js@@ -139,6 +139,8 @@ const appConfig = {'agent-embed': resolve(__dirname, 'pages/agent-embed.html'),'agent-detail': resolve(__dirname, 'pages/agent-detail.html'),'avatar-embed': resolve(__dirname, 'pages/avatar-embed.html'),+ 'overlay-control': resolve(__dirname, 'pages/overlay-control.html'),+ 'mocap-studio': resolve(__dirname, 'pages/mocap-studio.html'),handle: resolve(__dirname, 'pages/handle.html'),'a-embed': resolve(__dirname, 'pages/a-embed.html'),'a-edit': resolve(__dirname, 'pages/a-edit.html'),