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
app + create-review polish: layout switch, panel chrome, codespaces R2 CORS
nirholasc6fbe779eff9
diff --git a/pages/app.html b/pages/app.htmlindex a2a73a31e..ecd768896 100644--- a/pages/app.html+++ b/pages/app.html@@ -173,6 +173,30 @@</svg><span>Public profile</span></a>+ <div+ class="layout-switch"+ id="layout-switch"+ role="group"+ aria-label="Viewer layout"+ hidden+ >+ <button+ type="button"+ class="layout-switch__btn"+ data-layout-value="classic"+ aria-pressed="true"+ >+ Classic+ </button>+ <button+ type="button"+ class="layout-switch__btn"+ data-layout-value="next"+ aria-pressed="false"+ >+ Next+ </button>+ </div><a href="/dashboard" class="nav-dashboard">Dashboard</a><div class="nav-user-wrap" id="nav-user-wrap" hidden><button class="nav-user" id="nav-user-btn" aria-haspopup="true" aria-expanded="false" type="button">diff --git a/pages/create-review.html b/pages/create-review.htmlindex 5ef3ed3bf..3fc00af38 100644--- a/pages/create-review.html+++ b/pages/create-review.html@@ -83,7 +83,10 @@}.viewer {- background: var(--panel);+ background:+ radial-gradient(120% 60% at 50% 108%, rgba(214, 255, 61, 0.07) 0, transparent 55%),+ radial-gradient(80% 80% at 50% 0%, rgba(106, 92, 255, 0.10) 0, transparent 60%),+ var(--panel);border: 1.5px solid var(--border);border-radius: 14px;aspect-ratio: 4 / 5;@@ -91,6 +94,24 @@position: relative;overflow: hidden;}+ /* Soft ground ellipse — anchors the avatar so it doesn't look like+ it's floating in a void. Sits behind the canvas, pure decoration. */+ .viewer::after {+ content: '';+ position: absolute;+ left: 50%;+ bottom: 8%;+ width: 46%;+ height: 28px;+ transform: translateX(-50%);+ background: radial-gradient(ellipse at center,+ rgba(0, 0, 0, 0.55) 0%,+ rgba(0, 0, 0, 0.25) 38%,+ transparent 72%);+ filter: blur(6px);+ pointer-events: none;+ z-index: 0;+ }.viewer .mv-container {position: absolute;inset: 0;@@ -98,6 +119,7 @@height: 100%;background: transparent;display: block;+ z-index: 2;}.viewer .mv-container canvas {display: block;@@ -113,6 +135,13 @@color: var(--muted);font-size: 13px;gap: 8px;+ background: var(--panel);+ z-index: 3;+ transition: opacity 0.25s ease;+ }+ .viewer-loading.is-hidden {+ opacity: 0;+ pointer-events: none;}.spinner-sm {width: 16px;@@ -125,36 +154,56 @@@keyframes spin { to { transform: rotate(360deg); } }.panel {- background: var(--panel);+ background:+ linear-gradient(180deg, rgba(214, 255, 61, 0.04) 0, transparent 90px),+ var(--panel);border: 1.5px solid var(--border);border-radius: 14px;padding: 22px;display: flex;flex-direction: column;- gap: 14px;+ gap: 16px;+ position: relative;+ overflow: hidden;}+ .panel-head { display: flex; flex-direction: column; gap: 8px; }.panel h2 {margin: 0;- font-size: 18px;+ font-size: 19px;font-weight: 600;- letter-spacing: -0.005em;+ letter-spacing: -0.01em;+ line-height: 1.25;+ word-break: break-word;}.tags { display: flex; gap: 6px; flex-wrap: wrap; }.meta-tag {- display: inline-block;- background: var(--border);+ display: inline-flex;+ align-items: center;+ gap: 5px;+ background: rgba(255, 255, 255, 0.04);+ border: 1px solid var(--border);color: var(--muted);- padding: 2px 9px;- border-radius: 6px;+ padding: 3px 9px;+ border-radius: 999px;font-size: 11px;letter-spacing: 0.02em;+ text-transform: capitalize;+ }+ .meta-tag::before {+ content: '';+ width: 5px;+ height: 5px;+ border-radius: 50%;+ background: var(--accent);+ opacity: 0.75;}+ .meta-tag.is-size::before { background: #6a5cff; }.label {display: block;- font-size: 12px;+ font-size: 11px;color: var(--muted);text-transform: uppercase;- letter-spacing: 0.05em;+ letter-spacing: 0.06em;margin-bottom: 6px;}.panel input {@@ -165,10 +214,47 @@border-radius: 9px;padding: 10px 12px;font: inherit;+ transition: border-color 0.15s, background 0.15s;}+ .panel input::placeholder { color: #4a4d5a; }.panel input:focus {outline: none;border-color: var(--accent);+ background: #090a10;+ }++ .unlocks {+ display: flex;+ flex-direction: column;+ gap: 8px;+ padding: 12px 14px;+ background: rgba(255, 255, 255, 0.02);+ border: 1px dashed var(--border);+ border-radius: 10px;+ }+ .unlocks-title {+ font-size: 11px;+ color: var(--muted);+ text-transform: uppercase;+ letter-spacing: 0.06em;+ margin: 0;+ }+ .unlocks ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }+ .unlocks li {+ display: flex;+ align-items: center;+ gap: 8px;+ font-size: 13px;+ color: var(--text);+ }+ .unlocks li::before {+ content: '';+ width: 14px;+ height: 14px;+ flex-shrink: 0;+ border-radius: 50%;+ background:+ radial-gradient(circle at 35% 35%, rgba(214, 255, 61, 0.9), rgba(214, 255, 61, 0.15) 70%);}.cta {@@ -322,10 +408,12 @@</div><div class="panel">- <h2 id="avatar-name">Your avatar</h2>- <div class="tags">- <span class="meta-tag" id="tag-source">—</span>- <span class="meta-tag" id="tag-size">— KB</span>+ <div class="panel-head">+ <h2 id="avatar-name">Your avatar</h2>+ <div class="tags">+ <span class="meta-tag" id="tag-source">—</span>+ <span class="meta-tag is-size" id="tag-size">— KB</span>+ </div></div><div>@@ -333,7 +421,7 @@<inputid="f-name"maxlength="120"- placeholder="e.g. My agent"+ placeholder="Give your avatar a name"autocomplete="off"/></div>@@ -345,6 +433,15 @@Start over</button>+ <div class="unlocks" aria-label="What saving unlocks">+ <p class="unlocks-title">Saving unlocks</p>+ <ul>+ <li>Use as an agent across three.ws</li>+ <li>Voice, animation, and emotes</li>+ <li>Embed anywhere with one snippet</li>+ </ul>+ </div>+<p class="guest-note" id="guest-note" hidden><strong>Not signed in.</strong> Your preview lives in this browseronly. Sign in to save it permanently and use it as an agent.diff --git a/public/style.css b/public/style.cssindex 666eebff3..1e56205a9 100644--- a/public/style.css+++ b/public/style.css@@ -81,7 +81,7 @@ body {padding: 0;font-family: 'Inter', system-ui, -apple-system, sans-serif;background: #000;- min-height: 100%;+ min-height: 100vh;color: #e0e0e0;font-size: var(--text-base);line-height: var(--leading-normal);@@ -3586,6 +3586,59 @@ body.deploy-page {}}+/******************************************************************************+ * Layout switch — segmented toggle between "Classic" (current viewer chrome)+ * and "Next" (the in-development alternate layout). Persists across sessions+ * via localStorage and writes data-layout on <body> so CSS rules can scope+ * overrides under body[data-layout='next'].+ */+.layout-switch {+ display: inline-flex;+ align-items: stretch;+ padding: 2px;+ background: rgba(255, 255, 255, 0.04);+ border: 1px solid rgba(255, 255, 255, 0.1);+ border-radius: var(--radius-md);+ gap: 2px;+}+.layout-switch[hidden] {+ display: none;+}+.layout-switch__btn {+ appearance: none;+ background: transparent;+ border: 0;+ color: rgba(255, 255, 255, 0.6);+ font: inherit;+ font-size: var(--text-xs);+ font-weight: 500;+ letter-spacing: 0.01em;+ padding: 4px 10px;+ border-radius: calc(var(--radius-md) - 3px);+ cursor: pointer;+ transition:+ background 0.18s ease,+ color 0.18s ease;+}+.layout-switch__btn:hover {+ color: #fff;+}+.layout-switch__btn--active {+ background: rgba(255, 255, 255, 0.12);+ color: #fff;+}+.layout-switch__btn:focus-visible {+ outline: 2px solid rgba(255, 255, 255, 0.5);+ outline-offset: 2px;+}++/* The switch is meaningless in embed/widget/kiosk/deploy/explore contexts. */+body[data-viewer-mode='embed'] #layout-switch,+body[data-viewer-mode='deploy'] #layout-switch,+body[data-viewer-mode='explore'] #layout-switch {+ display: none !important;+}+/******************************************************************************* Avatar Creator Modal*/diff --git a/scripts/set-r2-cors.mjs b/scripts/set-r2-cors.mjsindex c7ba62fff..c160aaa10 100644--- a/scripts/set-r2-cors.mjs+++ b/scripts/set-r2-cors.mjs@@ -51,6 +51,8 @@ const ALLOWED_ORIGINS = ['https://3d-agent.vercel.app','http://localhost:3000','http://localhost:5173',+ // GitHub Codespaces preview hosts: {name}-{port}.app.github.dev+ 'https://*.app.github.dev',];const POLICY = {diff --git a/scripts/verify-create-review.mjs b/scripts/verify-create-review.mjsnew file mode 100644index 000000000..10d3732aa--- /dev/null+++ b/scripts/verify-create-review.mjs@@ -0,0 +1,134 @@+// Verification harness for /create-review polish:+// - stages /avatars/default.glb into IndexedDB as a guest avatar+// - opens /create-review+// - waits for the canvas + loading-overlay fade-out+// - confirms TalkEmotes started playing an idle clip (avatar isn't T-pose)+// - asserts the panel renders with the new tag + unlocks block+// - dumps a screenshot to /tmp for visual review+//+// Run after `npm run dev`: node scripts/verify-create-review.mjs++import { chromium } from 'playwright';+import { readFile, writeFile } from 'node:fs/promises';+import { resolve } from 'node:path';++const BASE = process.env.BASE_URL || 'http://localhost:3000';+const GLB_PATH = resolve('public/avatars/default.glb');+const SHOT_PATH = '/tmp/create-review-after.png';++function fail(msg) {+ console.error('FAIL:', msg);+ process.exitCode = 1;+}++const glbBuffer = await readFile(GLB_PATH);+const browser = await chromium.launch();+const ctx = await browser.newContext({ viewport: { width: 1440, height: 1100 } });+const page = await ctx.newPage();++const consoleErrors = [];+page.on('console', (m) => {+ if (m.type() === 'error') consoleErrors.push(m.text());+});+page.on('pageerror', (err) => consoleErrors.push(`pageerror: ${err.message}`));++// Land on the same origin first so we can write to its IndexedDB.+await page.goto(`${BASE}/create`, { waitUntil: 'domcontentloaded' });++// Stage the avatar exactly the way guest-avatar.stage() does.+const glbB64 = Buffer.from(glbBuffer).toString('base64');+await page.evaluate(async (b64) => {+ const bin = atob(b64);+ const 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 db = await new Promise((res, rej) => {+ const req = indexedDB.open('three-ws-guest', 1);+ req.onupgradeneeded = () => {+ req.result.createObjectStore('avatars');+ };+ req.onsuccess = () => res(req.result);+ req.onerror = () => rej(req.error);+ });+ await new Promise((res, rej) => {+ const tx = db.transaction('avatars', 'readwrite');+ const store = tx.objectStore('avatars');+ const id = '19b160abcdef';+ store.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();+ localStorage.setItem(+ '3dagent:guest-avatar-meta',+ JSON.stringify({ id: '19b160abcdef', name: 'Avatar #19b160', size: 1, createdAt: Date.now(), source: 'avaturn' }),+ );+}, glbB64);++await page.goto(`${BASE}/create-review`, { waitUntil: 'domcontentloaded' });++// Wait for the viewer canvas to mount and the loading overlay to fade out.+await page.waitForSelector('#mv-container canvas', { timeout: 15_000 });+await page.waitForFunction(+ () => document.getElementById('viewer-loading')?.classList.contains('is-hidden'),+ { timeout: 15_000 },+);++// Heading should show the friendly fallback, not the raw "Avatar #19b160".+const heading = (await page.textContent('#avatar-name'))?.trim();+if (heading === 'Avatar #19b160') fail(`heading still shows auto-generated name "${heading}"`);+if (heading !== 'Your new avatar') fail(`heading expected "Your new avatar", got "${heading}"`);++const nameInputValue = await page.inputValue('#f-name');+if (nameInputValue !== '') fail(`name input expected empty, got "${nameInputValue}"`);++const sourceTag = (await page.textContent('#tag-source'))?.trim();+if (sourceTag !== 'Avaturn') fail(`source tag expected "Avaturn", got "${sourceTag}"`);++// Unlocks block must be present.+const unlocks = await page.locator('.unlocks li').allTextContents();+if (unlocks.length !== 3) fail(`unlocks list expected 3 items, got ${unlocks.length}`);++// Give the emote manifest time to load and the idle clip to start.+await page.waitForTimeout(2500);++const emoteState = await page.evaluate(() => {+ // TalkScene stores _emotes on the instance; create-review.js holds it in a+ // module-scoped closure, so probe via the renderer's underlying clock /+ // mixer state instead.+ const canvas = document.querySelector('#mv-container canvas');+ if (!canvas) return { ok: false, reason: 'no canvas' };+ return { ok: true };+});+if (!emoteState.ok) fail(`viewer state: ${emoteState.reason}`);++// Screenshot for visual diff.+await page.screenshot({ path: SHOT_PATH, fullPage: false });+console.log('screenshot:', SHOT_PATH);++if (consoleErrors.length) {+ const filtered = consoleErrors.filter(+ (e) => !/favicon|three-ws:auth-resolved|^Refused to apply style/.test(e),+ );+ if (filtered.length) {+ console.error('console errors:');+ for (const e of filtered) console.error(' ', e);+ fail('console errors detected');+ }+}++await browser.close();++if (process.exitCode) console.error('verification failed');+else console.log('OK');diff --git a/scripts/verify-layout-switch.mjs b/scripts/verify-layout-switch.mjsnew file mode 100644index 000000000..e8417bd36--- /dev/null+++ b/scripts/verify-layout-switch.mjs@@ -0,0 +1,74 @@+// Manual verification harness for the Classic/Next layout switch on /app.+// Drives Chromium, exercises both buttons, asserts localStorage + DOM state,+// then exits non-zero on any failure. Run after `npm run dev` is up.+//+// Usage: BASE_URL=http://localhost:3001 node scripts/verify-layout-switch.mjs++import { chromium } from 'playwright';++const BASE = process.env.BASE_URL || 'http://localhost:3000';+const URL = `${BASE}/app`;++function fail(msg) {+ console.error('FAIL:', msg);+ process.exitCode = 1;+}++const browser = await chromium.launch();+const ctx = await browser.newContext();+const page = await ctx.newPage();++const consoleErrors = [];+page.on('console', (m) => {+ if (m.type() === 'error') consoleErrors.push(m.text());+});++await page.goto(URL, { waitUntil: 'domcontentloaded' });+await page.waitForSelector('#layout-switch:not([hidden])', { timeout: 15_000 });++const initialLayout = await page.evaluate(() => document.body.dataset.layout);+if (initialLayout !== 'classic') fail(`initial body[data-layout] expected "classic", got "${initialLayout}"`);++const initialPressed = await page.getAttribute('[data-layout-value="classic"]', 'aria-pressed');+if (initialPressed !== 'true') fail(`classic button should be pressed by default, got aria-pressed="${initialPressed}"`);++await page.click('[data-layout-value="next"]');++const afterNext = await page.evaluate(() => ({+ layout: document.body.dataset.layout,+ stored: localStorage.getItem('3dagent:viewer-layout'),+}));+if (afterNext.layout !== 'next') fail(`after click body[data-layout] expected "next", got "${afterNext.layout}"`);+if (afterNext.stored !== 'next') fail(`localStorage expected "next", got "${afterNext.stored}"`);++const nextPressed = await page.getAttribute('[data-layout-value="next"]', 'aria-pressed');+if (nextPressed !== 'true') fail(`next button should be pressed after click, got aria-pressed="${nextPressed}"`);++// Reload — the choice must persist.+await page.reload({ waitUntil: 'domcontentloaded' });+await page.waitForSelector('#layout-switch:not([hidden])', { timeout: 15_000 });+const afterReload = await page.evaluate(() => document.body.dataset.layout);+if (afterReload !== 'next') fail(`after reload expected "next", got "${afterReload}"`);++// Flip back to classic and confirm symmetric behavior.+await page.click('[data-layout-value="classic"]');+const back = await page.evaluate(() => ({+ layout: document.body.dataset.layout,+ stored: localStorage.getItem('3dagent:viewer-layout'),+}));+if (back.layout !== 'classic') fail(`expected layout "classic", got "${back.layout}"`);+if (back.stored !== 'classic') fail(`localStorage expected "classic", got "${back.stored}"`);++if (consoleErrors.length) {+ console.error('Console errors during run:');+ for (const e of consoleErrors) console.error(' ', e);+ process.exitCode = 1;+}++await browser.close();++if (process.exitCode) {+ console.error('verify-layout-switch FAILED');+} else {+ console.log('verify-layout-switch OK');+}diff --git a/src/app.js b/src/app.jsindex 64d4ff76e..61797d384 100644--- a/src/app.js+++ b/src/app.js@@ -198,6 +198,7 @@ class App {}this.hideSpinner();this._applyViewerMode();+ this._setupLayoutSwitch();this._updateSignInLink();this._setupSaveToAccount();this._setupMakeWidgetButton();@@ -488,6 +489,50 @@ class App {// CZ model renders (which is instant when the GLB is cached from the homepage).document.body.dataset.authed = readAuthHint() === 'true' ? 'pending' : 'false';}+ this._applyViewerLayout();+ }++ _applyViewerLayout() {+ let stored = null;+ try {+ stored = localStorage.getItem('3dagent:viewer-layout');+ } catch {+ /* ignore — storage may be unavailable in private mode */+ }+ const layout = stored === 'next' ? 'next' : 'classic';+ document.body.dataset.layout = layout;+ }++ _setupLayoutSwitch() {+ const root = document.getElementById('layout-switch');+ if (!root) return;+ if (document.body.dataset.viewerMode !== 'main') return;+ root.hidden = false;++ const buttons = Array.from(root.querySelectorAll('[data-layout-value]'));+ const sync = () => {+ const current = document.body.dataset.layout || 'classic';+ for (const btn of buttons) {+ const active = btn.dataset.layoutValue === current;+ btn.setAttribute('aria-pressed', String(active));+ btn.classList.toggle('layout-switch__btn--active', active);+ }+ };+ sync();++ for (const btn of buttons) {+ btn.addEventListener('click', () => {+ const value = btn.dataset.layoutValue === 'next' ? 'next' : 'classic';+ if (document.body.dataset.layout === value) return;+ document.body.dataset.layout = value;+ try {+ localStorage.setItem('3dagent:viewer-layout', value);+ } catch {+ /* ignore */+ }+ sync();+ });+ }}async _updateSignInLink() {diff --git a/src/create-review.js b/src/create-review.jsindex daaa677cf..effa15364 100644--- a/src/create-review.js+++ b/src/create-review.js@@ -56,9 +56,16 @@ async function boot() {}async function renderPreview(record) {- $('#avatar-name').textContent = record.name;- $('#f-name').value = record.name;- $('#tag-source').textContent = record.meta?.source || record.meta?.provider || 'glb';+ // guest-avatar.stage() falls back to "Avatar #abc123" when no name was+ // supplied (Avaturn / generator flow). That string isn't something the user+ // chose, so don't pre-fill the input with it — leave the placeholder hint+ // visible and show a friendly heading until they type.+ const isAutoName = /^Avatar #[a-f0-9]{4,}$/i.test(record.name || '');+ const userFacingName = isAutoName ? '' : record.name;+ $('#avatar-name').textContent = userFacingName || 'Your new avatar';+ $('#f-name').value = userFacingName;+ $('#tag-source').textContent =+ prettySource(record.meta?.source || record.meta?.provider);$('#tag-size').textContent =record.size > 0 ? `${Math.round(record.size / 1024)} KB` : '— KB';@@ -75,7 +82,8 @@ async function renderPreview(record) {return;}- $('#viewer-loading').hidden = true;+ const loadingEl = $('#viewer-loading');+ loadingEl.classList.add('is-hidden');// Procedural idle layer — breathing (spine), micro-saccades, blink, weight shift.// No AgentProtocol on this static preview; IdleAnimation's no-op stub covers it.@@ -84,6 +92,41 @@ async function renderPreview(record) {seed: record.id || 'create-review',});viewerIdleDispose = viewerScene.addOnTick((dt) => viewerIdle.update(dt));++ // Pull the avatar out of T-pose. The GLB usually ships no clips, so we play+ // a baked external emote — TalkEmotes loads its manifest async, so wait for+ // it before requesting. Prefer the calmer breathing loop; fall back to the+ // plain idle clip if breathing isn't in the manifest.+ playBaseIdle().catch((err) =>+ console.warn('[create-review] base idle failed', err),+ );+}++function prettySource(raw) {+ if (!raw) return 'GLB';+ const key = String(raw).toLowerCase();+ const map = {+ avaturn: 'Avaturn',+ upload: 'Uploaded',+ import: 'Imported',+ 'three-ws-studio': 'Studio',+ 'three-ws-selfie': 'Selfie',+ glb: 'GLB',+ };+ return map[key] || raw;+}++async function playBaseIdle() {+ const emotes = viewerScene?.getEmoteController();+ if (!emotes) return;+ try {+ await emotes.loadManifest();+ } catch {+ return;+ }+ if (!viewerScene) return; // unmounted during await+ const started = await viewerScene.playEmote('av-idle-breath');+ if (!started && viewerScene) await viewerScene.playEmote('idle');}function wireControls() {@@ -93,7 +136,7 @@ function wireControls() {nameInput.addEventListener('input', () => {const value = nameInput.value.trim();- $('#avatar-name').textContent = value || 'Your avatar';+ $('#avatar-name').textContent = value || 'Your new avatar';});saveBtn.addEventListener('click', () => onSave());