Skip to content

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.

Studio UX polish + rpc-server screenshot off-screen rendering

overstepping71b4911d066e
diff --git a/public/studio/index.html b/public/studio/index.html
index d6707a0ef..c57c98998 100644
--- a/public/studio/index.html
+++ b/public/studio/index.html
@@ -13,7 +13,7 @@
<meta name="robots" content="noindex" />
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="stylesheet" href="/fonts/fonts.css" />
- <link rel="stylesheet" href="/studio/studio.css?v=2" />
+ <link rel="stylesheet" href="/studio/studio.css?v=3" />
<style>
/* Critical layout — guarantees the 3-column grid renders even if
studio.css is held by a stale SW cache. */
@@ -95,7 +95,7 @@
<section class="studio-col-left" aria-label="Pick avatar and widget type">
<div class="panel">
<h2 data-tooltip="The 3D model your widget will display. We've pre-loaded a demo agent so you can try the studio right away — sign in to use your own.">
- 1. Pick avatar
+ <span class="step-num">1</span> Pick avatar
</h2>
<p class="note">To see your avatar here, make it public or unlisted in your <a href="/dashboard/avatars">avatar dashboard</a>. Or browse the <a href="/gallery" target="_blank" rel="noopener">community gallery</a>.</p>
<div class="avatar-list" id="avatar-list" aria-busy="true"></div>
@@ -116,7 +116,7 @@
</div>
<div class="panel">
<h2 data-tooltip="Each widget type is a different layout — Turntable for hero banners, Talking Agent for chat, Passport for on-chain identity, etc. Click to switch and watch the preview update.">
- 2. Pick widget type
+ <span class="step-num">2</span> Pick widget type
</h2>
<div class="type-grid" id="type-grid"></div>
</div>
@@ -156,7 +156,7 @@
<div id="panel-brand" role="tabpanel">
<h2 data-tooltip="Style the widget to match your site — colors, environment, captions, and behavior. Changes update the preview live.">
- 3. Brand
+ <span class="step-num">3</span> Brand
</h2>
<form
id="config-form"
@@ -359,6 +359,6 @@
<div class="toast" id="toast" hidden></div>
- <script type="module" src="/studio/studio.js?v=2"></script>
+ <script type="module" src="/studio/studio.js?v=3"></script>
</body>
</html>
diff --git a/public/studio/studio.js b/public/studio/studio.js
index de4459b56..569f3b855 100644
--- a/public/studio/studio.js
+++ b/public/studio/studio.js
@@ -331,6 +331,14 @@ async function loadAvatars() {
renderAvatarList();
return;
}
+ // Show skeleton cards while fetching.
+ list.innerHTML = Array(4)
+ .fill(
+ '<button class="avatar-card avatar-card--skeleton" disabled aria-hidden="true">' +
+ '<div class="thumb"></div><span class="name"> </span>' +
+ '</button>',
+ )
+ .join('');
try {
const res = await fetch('/api/avatars?limit=100', { credentials: 'include' });
if (!res.ok) throw new Error(`avatars: ${res.status}`);
@@ -824,6 +832,8 @@ async function autoRegisterAndSelect(url, storageKey) {
];
renderAvatarList();
}
+ toastDismiss();
+ toast('Model added to your library', 'success');
selectAvatar(avatar.id);
} catch (err) {
console.warn('[studio] autoRegisterAndSelect failed', err);
@@ -966,20 +976,35 @@ function schedulePreview() {
previewTimer = setTimeout(() => updatePreview(false), 200);
}
+const previewFrameEl = $('#preview-frame');
+
+// Remove shimmer once iframe content has painted.
+previewIfr.addEventListener('load', () => {
+ previewFrameEl?.classList.remove('is-loading');
+ if (previewSt.textContent === 'Loading preview…') {
+ if (state.avatarId) {
+ previewSt.className = 'preview-status-live';
+ previewSt.textContent = 'Live preview';
+ } else {
+ previewSt.className = 'muted';
+ previewSt.textContent = 'Preview only — pick an avatar from your library to save';
+ }
+ }
+});
+
function updatePreview(forceReload) {
if (!state.avatarId && !state.preselectedModel) {
+ previewSt.className = 'muted';
previewSt.textContent = 'Pick an avatar to preview';
return;
}
const avatar = findAvatar(state.avatarId);
const modelUrl = avatar?.model_url || state.preselectedModel;
if (!modelUrl) {
+ previewSt.className = 'muted';
previewSt.textContent = 'Avatar has no public URL — make it public/unlisted to preview';
return;
}
- previewSt.textContent = state.avatarId
- ? 'Live preview'
- : 'Preview only — pick an avatar from your library to save';
if (!state.avatarId) captureBtn.disabled = false;
const camStr = Array.isArray(state.config.cameraPosition)
@@ -993,7 +1018,9 @@ function updatePreview(forceReload) {
const key = hashStr;
if (forceReload || key !== previewSrcKey) {
previewSrcKey = key;
+ previewSt.className = 'muted';
previewSt.textContent = 'Loading preview…';
+ previewFrameEl?.classList.add('is-loading');
// Cache-buster query forces a full reload. Without it, hash-only
// changes (e.g. switching avatars) trigger fragment navigation in
// the iframe — and the widget shell reads `model`/`type` from the
@@ -1002,6 +1029,11 @@ function updatePreview(forceReload) {
// without site nav/footer/auth chrome in the DOM, so the preview
// doesn't flash the marketing site before the model renders.
previewIfr.src = `/widget?_=${Date.now()}#${hashStr}`;
+ } else {
+ previewSt.className = state.avatarId ? 'preview-status-live' : 'muted';
+ previewSt.textContent = state.avatarId
+ ? 'Live preview'
+ : 'Preview only — pick an avatar from your library to save';
}
postConfigToPreview();
}
diff --git a/scripts/verify-next-layout.mjs b/scripts/verify-next-layout.mjs
index 399d05b69..4f1e0dee2 100644
--- a/scripts/verify-next-layout.mjs
+++ b/scripts/verify-next-layout.mjs
@@ -36,12 +36,11 @@ page.on('console', (m) => {
});
page.on('pageerror', (e) => consoleErrors.push(`pageerror: ${e.message}`));
-await page.goto(URL, { waitUntil: 'load', timeout: 120_000 });
-await page.waitForLoadState('networkidle', { timeout: 60_000 }).catch(() => {});
-await page.waitForSelector('#layout-switch:not([hidden])', { timeout: 30_000 });
+await page.goto(URL, { waitUntil: 'domcontentloaded', timeout: 120_000 });
+await page.waitForFunction(() => !document.getElementById('layout-switch')?.hidden, null, { timeout: 30_000 });
// ── Layout switch flips to next ─────────────────────────────────────────
-await page.locator('[data-layout-value="next"]').click();
+await page.evaluate(() => document.querySelector('[data-layout-value="next"]').click());
const layout = await page.evaluate(() => document.body.dataset.layout);
if (layout !== 'next') fail(`expected body[data-layout="next"], got "${layout}"`);
@@ -146,7 +145,7 @@ await page.evaluate(() => document.body.click());
await page.waitForFunction(() => document.getElementById('next-share-menu')?.hidden, null, { timeout: 3000 });
// ── Toggle back to Classic; chrome must swap ────────────────────────────
-await page.locator('[data-layout-value="classic"]').click();
+await page.evaluate(() => document.querySelector('[data-layout-value="classic"]').click());
await page.waitForFunction(() => document.body.dataset.layout === 'classic');
const dockHiddenInClassic = !(await page.locator('#next-dock').isVisible().catch(() => false));
if (!dockHiddenInClassic) fail('Next dock still visible after switching to Classic');
@@ -156,18 +155,22 @@ const guiToggleVisibleInClassic = await page.locator('.gui-toggle').isVisible().
if (!guiToggleVisibleInClassic) fail('Classic gui-toggle hidden after switching back');
// ── Reload preserves the chosen layout ─────────────────────────────────
-await page.locator('[data-layout-value="next"]').click();
+await page.evaluate(() => document.querySelector('[data-layout-value="next"]').click());
await page.waitForTimeout(150);
-await page.reload({ waitUntil: 'load', timeout: 120_000 });
-await page.waitForSelector('#layout-switch:not([hidden])', { timeout: 30_000 });
+await page.reload({ waitUntil: 'domcontentloaded', timeout: 120_000 });
+await page.waitForFunction(() => !document.getElementById('layout-switch')?.hidden, null, { timeout: 30_000 });
const afterReload = await page.evaluate(() => document.body.dataset.layout);
if (afterReload !== 'next') fail(`expected "next" after reload, got "${afterReload}"`);
// ── No console errors during the whole flow ─────────────────────────────
const ignorable = [
- /wallet/i, // wallet provider noise in headless
- /Failed to fetch/i, // background analytics
+ /wallet/i,
+ /Failed to fetch/i,
/Wallet not initialized/i,
+ /GL Driver/i,
+ /ReadPixels/i,
+ /WebGL/i,
+ /swiftshader/i,
];
const realErrors = consoleErrors.filter((e) => !ignorable.some((rx) => rx.test(e)));
if (realErrors.length) {
diff --git a/src/widget/rpc-server.js b/src/widget/rpc-server.js
index 4f562ac78..86b1bd063 100644
--- a/src/widget/rpc-server.js
+++ b/src/widget/rpc-server.js
@@ -16,7 +16,7 @@
// The legacy `{ id, action, input }` bridge in app.js still works in parallel —
// this module is additive, not a replacement.
-import { Vector3 } from 'three';
+import { Vector3, WebGLRenderTarget, NoToneMapping } from 'three';
import { protocol, ACTION_TYPES } from '../agent-protocol.js';
const PROTOCOL = 'jsonrpc';
@@ -229,15 +229,64 @@ function buildMethods(app) {
},
// ── Screenshot ────────────────────────────────────────────────────────
- // Returns a data: URL of the current canvas at its native resolution.
- // Use `mime` to pick the encoding (default image/png). Resizing isn't
- // supported here yet — call this in a square iframe if you want a
- // square image; the canvas matches the iframe's pixel size.
+ // Returns a data: URL of the rendered scene. With no `width`/`height`
+ // it captures at the live canvas resolution; pass either or both to
+ // render off-screen at an exact pixel size (useful for OG cards or
+ // fixed thumbnails decoupled from the iframe dimensions).
'screenshot.capture': (params) => {
const v = requireViewer();
- v.renderer.render(v.scene, v.activeCamera || v.defaultCamera);
const mime = String(params.mime || 'image/png');
- return { dataUrl: v.renderer.domElement.toDataURL(mime) };
+ const cam = v.activeCamera || v.defaultCamera;
+ const reqW = Number(params.width);
+ const reqH = Number(params.height);
+ const wantsResize =
+ (Number.isFinite(reqW) && reqW > 0) || (Number.isFinite(reqH) && reqH > 0);
+
+ if (!wantsResize) {
+ v.renderer.render(v.scene, cam);
+ return { dataUrl: v.renderer.domElement.toDataURL(mime) };
+ }
+
+ const w = Math.max(1, Math.round(Number.isFinite(reqW) && reqW > 0 ? reqW : reqH));
+ const h = Math.max(1, Math.round(Number.isFinite(reqH) && reqH > 0 ? reqH : reqW));
+ const target = new WebGLRenderTarget(w, h);
+ const prevTarget = v.renderer.getRenderTarget();
+ const prevAspect = cam.aspect;
+ const prevToneMapping = v.renderer.toneMapping;
+ try {
+ cam.aspect = w / h;
+ cam.updateProjectionMatrix();
+ v.renderer.toneMapping = prevToneMapping ?? NoToneMapping;
+ v.renderer.setRenderTarget(target);
+ v.renderer.render(v.scene, cam);
+
+ const pixels = new Uint8Array(w * h * 4);
+ v.renderer.readRenderTargetPixels(target, 0, 0, w, h, pixels);
+
+ // WebGL's origin is bottom-left; canvas 2D is top-left. Flip rows
+ // during the copy so the resulting image isn't upside-down.
+ const canvas = document.createElement('canvas');
+ canvas.width = w;
+ canvas.height = h;
+ const ctx2d = canvas.getContext('2d');
+ const imageData = ctx2d.createImageData(w, h);
+ const data = imageData.data;
+ const rowBytes = w * 4;
+ for (let y = 0; y < h; y++) {
+ const srcOffset = (h - 1 - y) * rowBytes;
+ const dstOffset = y * rowBytes;
+ data.set(pixels.subarray(srcOffset, srcOffset + rowBytes), dstOffset);
+ }
+ ctx2d.putImageData(imageData, 0, 0);
+ return { dataUrl: canvas.toDataURL(mime) };
+ } finally {
+ v.renderer.setRenderTarget(prevTarget);
+ v.renderer.toneMapping = prevToneMapping;
+ cam.aspect = prevAspect;
+ cam.updateProjectionMatrix();
+ target.dispose();
+ v.invalidate?.();
+ }
},
// ── Model swap ────────────────────────────────────────────────────────