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.

regenerate docs + screenshot script

nirholasa3a505287f50
diff --git a/api/avatars/REGENERATE.md b/api/avatars/REGENERATE.md
index a30c8bdba..fd8faeba7 100644
--- a/api/avatars/REGENERATE.md
+++ b/api/avatars/REGENERATE.md
@@ -157,14 +157,55 @@ Picking a provider is a separate decision and out of scope for this contract. Wh
## Environment
-Add to `.env.local` or Vercel settings:
+Add to `.env.local` or Vercel settings. The provider is **auto-detected from
+present credentials** (priority: paid → free). Set `AVATAR_REGEN_PROVIDER`
+explicitly to override.
```
-# Avatar regeneration provider. Set to "stub" for testing, or a provider name.
-# Unset → returns 501 regen_unconfigured.
-AVATAR_REGEN_PROVIDER=stub
+# Explicit override (optional). Auto-detected order is replicate → gcp → huggingface.
+AVATAR_REGEN_PROVIDER=replicate
+
+# --- Replicate (paid, $0.035/run TRELLIS default) ---
+REPLICATE_API_TOKEN=r8_...
+# Optional — defaults to firtoz/trellis (MIT TRELLIS). Pin a version with owner/name:hash
+REPLICATE_RECONSTRUCT_MODEL=firtoz/trellis
+# Optional — if APP_ORIGIN is set this is derived. Replicate POSTs done predictions here.
+REPLICATE_WEBHOOK_URL=https://three.ws/api/webhooks/replicate
+# REQUIRED if you create the webhook in Replicate dashboard (gives you whsec_…)
+REPLICATE_WEBHOOK_SIGNING_KEY=whsec_…
+
+# --- GCP Cloud Run (self-hosted InstantMesh, see workers/avatar-reconstruction/) ---
+GCP_RECONSTRUCTION_URL=https://avatar-reconstruction-…run.app
+GCP_RECONSTRUCTION_KEY=…
+
+# --- HuggingFace (free, Space queue, variable wait) ---
+HF_TOKEN=hf_…
+# Comma-separated failover chain. Format: "owner/name[:api_name]". First success wins.
+# Default chain (when unset): tencent/Hunyuan3D-2.1, tencent/Hunyuan3D-2,
+# JeffreyXiang/TRELLIS, stabilityai/TripoSR.
+HF_RECONSTRUCT_SPACES=tencent/Hunyuan3D-2.1,JeffreyXiang/TRELLIS:image_to_3d
```
+## Webhooks (Replicate only — optional but recommended)
+
+When `REPLICATE_WEBHOOK_URL` is configured, every prediction submission asks
+Replicate to POST `/api/webhooks/replicate` when the prediction completes.
+That handler verifies the `webhook-signature` (Standard Webhooks spec), updates
+the `avatar_regen_jobs` row, and — for `reconstruct` jobs — materializes the
+avatar inline. The client's status poll then sees `done` + `resultAvatarId`
+on its very next hit without any Replicate API call.
+
+The poll path still works as a fallback: if a webhook is dropped/blocked,
+the next `regenerate-status` call triggers a manual provider.status() poll
+that reconciles the row.
+
+To create the webhook + grab the signing secret:
+
+1. Set `REPLICATE_WEBHOOK_URL=https://three.ws/api/webhooks/replicate` in Vercel.
+2. Replicate dashboard → Webhooks → Add → URL = same → Save.
+3. Copy the `whsec_…` secret → set as `REPLICATE_WEBHOOK_SIGNING_KEY` in Vercel.
+4. Redeploy.
+
## Database schema (future migration)
The stub provider and status endpoint assume a `avatar_regen_jobs` table:
diff --git a/scripts/_snap-modals.tmp.mjs b/scripts/_snap-modals.tmp.mjs
new file mode 100644
index 000000000..5dfb5b728
--- /dev/null
+++ b/scripts/_snap-modals.tmp.mjs
@@ -0,0 +1,59 @@
+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 b64 = Buffer.from(glb).toString('base64');
+await ctx.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();
+ })();
+}, b64);
+
+async function snapOne(feat, file, dwell = 800) {
+ const page = await ctx.newPage();
+ await page.goto('http://localhost:3000/create-review', { waitUntil: 'load' });
+ try { await page.evaluate(() => window.__seed); } catch {}
+ await page.waitForTimeout(800);
+ 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(3000);
+ await page.fill('#f-name', 'Nicholas');
+ await page.evaluate((f) => document.querySelector(`[data-feature="${f}"]`).click(), 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.close();
+}
+
+for (const [feat, file, dwell] of [
+ ['identity', '/tmp/cr-final-identity.png', 1100],
+ ['paid', '/tmp/cr-final-paid.png', 700],
+ ['embed', '/tmp/cr-final-embed.png', 1200],
+ ['reputation', '/tmp/cr-final-reputation.png', 700],
+ ['download', '/tmp/cr-final-download.png', 700],
+]) {
+ try { await snapOne(feat, file, dwell); console.log('shot', feat); } catch (e) { console.error('shot fail', feat, e.message); }
+}
+
+await browser.close();
+console.log('done');
diff --git a/scripts/screenshot-app-next.mjs b/scripts/screenshot-app-next.mjs
index 831175373..1b3eb75f6 100644
--- a/scripts/screenshot-app-next.mjs
+++ b/scripts/screenshot-app-next.mjs
@@ -25,18 +25,21 @@ await page.waitForFunction(
);
await page.evaluate(async () => {
- const mgr = window.VIEWER.viewer.animationManager;
+ const v = window.VIEWER.viewer;
+ v.state.autoRotate = false;
+ v.controls.autoRotate = false;
+ const mgr = v.animationManager;
await mgr.ensureLoaded('av-waving').catch(() => {});
mgr.play('av-waving');
});
await page.waitForTimeout(2200);
-await page.screenshot({ path: '/tmp/app-next-hero.png' });
+await page.screenshot({ timeout: 60000, animations: 'disabled', path: '/tmp/app-next-hero.png' });
console.log('→ /tmp/app-next-hero.png');
// Animation sheet
await page.evaluate(() => document.getElementById('nxt-anim-btn').click());
await page.waitForTimeout(900);
-await page.screenshot({ path: '/tmp/app-next-sheet.png' });
+await page.screenshot({ timeout: 60000, animations: 'disabled', path: '/tmp/app-next-sheet.png' });
console.log('→ /tmp/app-next-sheet.png');
await page.keyboard.press('Escape');
await page.waitForTimeout(300);
@@ -44,7 +47,7 @@ await page.waitForTimeout(300);
// Share popover
await page.evaluate(() => document.getElementById('nxt-share-btn').click());
await page.waitForTimeout(400);
-await page.screenshot({ path: '/tmp/app-next-share.png' });
+await page.screenshot({ timeout: 60000, animations: 'disabled', path: '/tmp/app-next-share.png' });
console.log('→ /tmp/app-next-share.png');
await page.keyboard.press('Escape');
await page.waitForTimeout(200);
@@ -54,7 +57,7 @@ await page.evaluate(() => document.getElementById('nxt-share-popover').setAttrib
// Camera preset — wide
await page.evaluate(() => document.querySelector('[data-preset="wide"]').click());
await page.waitForTimeout(900);
-await page.screenshot({ path: '/tmp/app-next-wide.png' });
+await page.screenshot({ timeout: 60000, animations: 'disabled', path: '/tmp/app-next-wide.png' });
console.log('→ /tmp/app-next-wide.png');
// Back to body shot, then trigger a chat
@@ -62,7 +65,7 @@ await page.evaluate(() => document.querySelector('[data-preset="body"]').click()
await page.waitForTimeout(700);
await page.evaluate(() => document.querySelector('.nxt-chat-chip')?.click());
await page.waitForTimeout(2500);
-await page.screenshot({ path: '/tmp/app-next-chat.png' });
+await page.screenshot({ timeout: 60000, animations: 'disabled', path: '/tmp/app-next-chat.png' });
console.log('→ /tmp/app-next-chat.png');
// Help overlay
@@ -70,7 +73,7 @@ await page.keyboard.down('Shift');
await page.keyboard.press('/');
await page.keyboard.up('Shift');
await page.waitForTimeout(400);
-await page.screenshot({ path: '/tmp/app-next-help.png' });
+await page.screenshot({ timeout: 60000, animations: 'disabled', path: '/tmp/app-next-help.png' });
console.log('→ /tmp/app-next-help.png');
await browser.close();
diff --git a/src/app.js b/src/app.js
index 75601f2d7..9c9a82f0c 100644
--- a/src/app.js
+++ b/src/app.js
@@ -1950,7 +1950,7 @@ class App {
el.innerHTML = `
<div class="viewer-status__card viewer-status__card--error" role="alert">
<div class="viewer-status__icon" aria-hidden="true">!</div>
- <div class="viewer-status__label">${escHtml(label)}</div>
+ <div class="viewer-status__label" data-label>${escHtml(label)}</div>
${onRetry ? '<button class="viewer-status__btn" type="button" data-retry>Retry</button>' : ''}
</div>
`;