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.

demos: wire avatar-sdk by-id demo, fix deep-link clobber, add e2e tests

overstepping4de25fc24a43
diff --git a/public/demos/avatar-sdk.html b/public/demos/avatar-sdk.html
index 4d0257369..a4b41c566 100644
--- a/public/demos/avatar-sdk.html
+++ b/public/demos/avatar-sdk.html
@@ -106,6 +106,7 @@ creator.open();</pre>
<script type="module">
const $ = (id) => document.getElementById(id);
const componentLog = $('component-log');
+ const byIdLog = $('byid-log');
const creatorLog = $('creator-log');
const stamp = () => new Date().toTimeString().slice(0, 8);
const line = (el, msg, cls = '') => {
@@ -121,6 +122,7 @@ creator.open();</pre>
$('sdk-viewer-host').appendChild(el);
line(componentLog, `✓ &lt;agent-3d&gt; registered in ${Math.round(performance.now() - start)} ms`, 'ok');
line(componentLog, '✓ mounted with src=/avatars/default.glb', 'ok');
+ mountByIdDemo();
} else if (performance.now() - start < 8000) {
setTimeout(check, 100);
} else {
@@ -129,6 +131,27 @@ creator.open();</pre>
};
check();
+ // Section 2 — resolve a real public avatar by ID and mount it.
+ async function mountByIdDemo() {
+ try {
+ const res = await fetch('/api/avatars/public?limit=1');
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
+ const data = await res.json();
+ const avatar = data?.avatars?.[0];
+ if (!avatar?.id) {
+ line(byIdLog, '✗ /api/avatars/public returned no avatars', 'err');
+ return;
+ }
+ line(byIdLog, `→ resolving avatar-id=${avatar.id}`, 'info');
+ const el = document.createElement('agent-3d');
+ el.setAttribute('avatar-id', avatar.id);
+ $('byid-viewer-host').appendChild(el);
+ line(byIdLog, `✓ &lt;agent-3d avatar-id="${avatar.id}"&gt; mounted (${avatar.name || 'unnamed'})`, 'ok');
+ } catch (err) {
+ line(byIdLog, '✗ avatar-id demo failed: ' + err.message, 'err');
+ }
+ }
+
// Programmatic Creator demo. Imports from the SDK source so we don't
// rebuild the whole bundle every time creator.js changes.
$('open-creator-btn').addEventListener('click', async () => {
diff --git a/public/demos/gallery-picker.html b/public/demos/gallery-picker.html
index cf557952f..d15842046 100644
--- a/public/demos/gallery-picker.html
+++ b/public/demos/gallery-picker.html
@@ -558,7 +558,12 @@
const set = (k, v) => (v ? u.searchParams.set(k, v) : u.searchParams.delete(k));
set('q', state.query);
set('tag', state.tag);
- set('id', state.selected?.id || '');
+ if (state.selected?.id) {
+ u.searchParams.set('id', state.selected.id);
+ }
+ // Leave any existing `?id=` alone when nothing is selected so the
+ // initial resetAndLoad() before hydrateDeepLink() does not clobber
+ // the deep-link the user navigated in with.
history.replaceState(null, '', u);
}
diff --git a/tests/e2e/gallery-picker.spec.js b/tests/e2e/gallery-picker.spec.js
new file mode 100644
index 000000000..db063edf1
--- /dev/null
+++ b/tests/e2e/gallery-picker.spec.js
@@ -0,0 +1,105 @@
+/**
+ * Gallery picker smoke. Drives the page against the live /api/avatars/public
+ * feed and the dev-server-served avatar-sdk bundle. Verifies:
+ * • cards render from real API data
+ * • selecting a card builds the preview pane
+ * • each handoff mode produces the correct payload in the preview
+ * • the embed snippet uses the new avatar-id attribute
+ * • ?id= deep-links auto-select on first paint
+ * • the SDK bundle resolves avatar-id against /api/avatars/:id
+ */
+
+import { test, expect } from '@playwright/test';
+
+test.describe('demos/gallery-picker', () => {
+ test('renders public avatars and produces correct handoff payloads', async ({ page }) => {
+ test.setTimeout(90_000);
+
+ page.on('pageerror', (err) => {
+ throw new Error(`Page error: ${err.message}`);
+ });
+
+ await page.goto('/demos/gallery-picker.html');
+
+ // Wait for at least one card from the live feed. The API degrades to
+ // an empty array on DB failure, so we explicitly require >0 cards.
+ const firstCard = page.locator('.card[data-id]').first();
+ await firstCard.waitFor({ state: 'visible', timeout: 30_000 });
+
+ const cardCount = await page.locator('.card[data-id]').count();
+ expect(cardCount).toBeGreaterThan(0);
+
+ const avatarId = await firstCard.getAttribute('data-id');
+ expect(avatarId).toBeTruthy();
+
+ await firstCard.click();
+
+ // The preview pane should now show the avatar's name and enable CTA.
+ await expect(page.locator('#cta')).toBeEnabled();
+
+ // — Share-link mode (default)
+ await expect(page.locator('#preview-foot')).toContainText(
+ `https://three.ws/avatars/${avatarId}`,
+ );
+
+ // — GLB URL mode. The radio inputs are CSS-hidden (display:none) so the
+ // visible affordance is the wrapping <label>; click that to flip the
+ // input via native HTML behavior.
+ await page.locator('label:has(input[name="mode"][value="glb"])').click();
+ const glbText = await page.locator('#preview-foot').textContent();
+ expect(glbText).toMatch(/^https?:\/\//);
+ expect(glbText).toMatch(/\.glb($|\?)/i);
+
+ // — Embed-snippet mode: must use the new `avatar-id` attribute, not the
+ // broken `<agent-3d avatar-id="">` that 404'd against the old element.
+ await page.locator('label:has(input[name="mode"][value="embed"])').click();
+ const embedText = await page.locator('#preview-foot').textContent();
+ expect(embedText).toContain('/avatar-sdk/dist/index.mjs');
+ expect(embedText).toContain(`avatar-id="${avatarId}"`);
+ expect(embedText).toContain('<agent-3d');
+
+ // URL should have been synced to include the selection.
+ expect(page.url()).toContain(`id=${avatarId}`);
+ });
+
+ test('?id= deep-link auto-selects on first paint', async ({ page, request }) => {
+ test.setTimeout(60_000);
+
+ // Pull a real avatar id from the live feed so the test data matches
+ // what the deep-link path will actually resolve.
+ const res = await request.get('/api/avatars/public?limit=1');
+ expect(res.ok()).toBeTruthy();
+ const body = await res.json();
+ const avatar = body?.avatars?.[0];
+ test.skip(!avatar?.id, 'no public avatars available to deep-link to');
+
+ page.on('pageerror', (err) => {
+ throw new Error(`Page error: ${err.message}`);
+ });
+
+ await page.goto(`/demos/gallery-picker.html?id=${avatar.id}`);
+
+ // CTA enables only once an avatar is selected — wait on that as the
+ // "deep-link hydrated" signal, then assert the preview matches.
+ await expect(page.locator('#cta')).toBeEnabled({ timeout: 30_000 });
+ await expect(page.locator('#preview-foot')).toContainText(
+ `https://three.ws/avatars/${avatar.id}`,
+ );
+ });
+
+ test('SDK resolves <agent-3d avatar-id="..."> via /api/avatars/:id', async ({ page }) => {
+ test.setTimeout(90_000);
+
+ page.on('pageerror', (err) => {
+ throw new Error(`Page error: ${err.message}`);
+ });
+
+ await page.goto('/demos/avatar-sdk.html');
+
+ // Section 2 mounts a real public avatar by id once the SDK has
+ // registered. Wait for the success line in its log.
+ const byIdLog = page.locator('#byid-log');
+ await expect(byIdLog).toContainText('mounted', { timeout: 30_000 });
+ await expect(byIdLog).not.toContainText('failed');
+ });
+});