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
fix(selfie/regen): correct routing, remove dead states, improve regen panel
nirholasea3d4ba72fc6
diff --git a/pages/scan.html b/pages/scan.htmlindex f5eae8064..d2dcc289b 100644--- a/pages/scan.html+++ b/pages/scan.html@@ -19,7 +19,7 @@<meta property="og:type" content="website" /><meta property="og:site_name" content="three.ws" />- <meta property="og:url" content="https://three.ws/scan" />+ <meta property="og:url" content="https://three.ws/create/selfie" /><meta property="og:title" content="3D Scanner · Scan yourself into 3D" /><metaproperty="og:description"@@ -1335,7 +1335,7 @@crossorigin="anonymous"></script>- <link rel="canonical" href="https://three.ws/scan">+ <link rel="canonical" href="https://three.ws/create/selfie"><meta name="twitter:title" content="3D Scanner — Scan Yourself into 3D · three.ws"><meta name="twitter:description" content="Point your camera at your face, hold still, and walk away with a rigged 3D avatar — reconstruction runs in about a minute, free, in your browser."><meta name="twitter:image" content="https://three.ws/og-image.png">@@ -1794,41 +1794,6 @@</section></main>- <!-- Step "unavailable" — shown when the reconstruction backend isn't wired. -->- <section- class="step"- data-step="unavailable"- hidden- style="text-align: center; max-width: 520px; margin: 0 auto; padding: 48px 24px"- >- <h1 style="margin: 0 0 12px">The scanner is warming up</h1>- <p class="sub" style="margin: 0 0 24px; color: #9aa3b2">- The photo-to-3D engine is being provisioned for this environment. In the meantime,- you can describe your avatar in words and generate it — or build one in the studio.- Same outputs, fully ready today.- </p>- <div class="done-actions" style="justify-content: center">- <a- href="/create/prompt"- class="btn-save"- style="text-decoration: none; display: inline-block"- >Describe it to 3D →</a- >- <a- href="/create"- class="btn-ghost"- style="text-decoration: none; display: inline-block"- >Open the avatar studio</a- >- <a- href="/app"- class="btn-ghost"- style="text-decoration: none; display: inline-block"- >Back to my workspace</a- >- </div>- </section>-<!-- Camera overlay (driven by selfie-capture.js) --><div id="cam-overlay" role="dialog" aria-modal="true" aria-label="Camera capture"><div id="cam-stage">@@ -1867,36 +1832,21 @@</div><script type="module">+ // /scan is superseded by /create/selfie which has BYOK key entry and a+ // more complete UX. Preserve any ?next or ?from query params so downstream+ // flows still work (e.g. post-login redirects).+ const dest = '/create/selfie' + window.location.search;+ window.location.replace(dest);+function showStep(name) {document.querySelectorAll('.step[data-step]').forEach((s) => {s.classList.toggle('active', s.dataset.step === name);- if (name === 'unavailable') s.hidden = s.dataset.step !== 'unavailable';});window.scrollTo({ top: 0, behavior: 'auto' });}- // Capability probe — reconstruct returns 501 unless an ML backend is wired.- const reconstructReady = await fetch('/api/config', { credentials: 'omit' })- .then((r) => (r.ok ? r.json() : null))- .then((j) => j?.features?.avatarReconstruct !== false)- .catch(() => true);-- if (!reconstructReady) {- document.querySelectorAll('.step[data-step]').forEach((s) => {- s.classList.remove('active');- s.hidden = s.dataset.step !== 'unavailable';- });- const u = document.querySelector('.step[data-step="unavailable"]');- if (u) {- u.hidden = false;- u.classList.add('active');- }- const sb = document.getElementById('submit-bar');- if (sb) sb.hidden = true;- } else {- await import('/src/selfie-capture.js');- await import('/src/selfie-pipeline.js');- }+ await import('/src/selfie-capture.js');+ await import('/src/selfie-pipeline.js');let _avatarId = null;let _modelUrl = null;diff --git a/src/create-prompt.js b/src/create-prompt.jsindex 545783ebe..4ee2de440 100644--- a/src/create-prompt.js+++ b/src/create-prompt.js@@ -175,7 +175,7 @@ function mapSubmitError(status, data) {return 'The image engine is busy right now — wait a moment and try again.';}if (code === 'regen_unconfigured' || code === 'txt2img_unconfigured') {- return 'The avatar generator isn\'t configured on this deployment yet. Try the <a href="/scan">selfie scanner</a> instead.';+ return 'The avatar generator isn\'t configured on this deployment yet. Try the <a href="/create/selfie">selfie scanner</a> instead.';}if (code === 'txt2img_billing') return 'The image engine is temporarily unavailable (provider billing). Try again later.';if (code === 'txt2img_unreachable') return 'Couldn\'t reach the image engine. Check your connection and try again.';diff --git a/src/create.js b/src/create.jsindex a00f46178..f40d16d0e 100644--- a/src/create.js+++ b/src/create.js@@ -36,23 +36,19 @@ function requireAuthForSelfie() {return true;}-// Probe whether the server has an avatar-reconstruction backend wired. When-// false, the Selfie card on /create stays visible but is marked "coming soon"-// so the user can't dead-end on it; the click handler short-circuits and shows-// an explanatory toast instead of navigating to a page that would 501.-let _reconstructReady = true;+// Probe runtime feature flags. Selfie reconstruction is always available+// (BYOK providers are always an option); only video avatar is gated on an+// optional Cloud Run worker.let _videoAvatarReady = false;-async function probeReconstruct() {+async function probeFeatures() {try {const r = await fetch('/api/config', { credentials: 'omit' });if (!r.ok) return;const j = await r.json();- _reconstructReady = j?.features?.avatarReconstruct !== false;_videoAvatarReady = j?.features?.videoAvatar === true;} catch {- // network blip — keep defaults and let page-level gates do the final check.+ // network blip — keep defaults.}- if (!_reconstructReady) markSelfieUnavailable();if (!_videoAvatarReady) markVideoAvatarUnavailable();}@@ -66,18 +62,6 @@ function markVideoAvatarUnavailable() {if (title) title.textContent = 'Talking avatar video · coming soon';}-function markSelfieUnavailable() {- const card = document.getElementById('card-selfie');- if (!card) return;- card.setAttribute('aria-disabled', 'true');- card.style.opacity = '0.55';- card.style.cursor = 'not-allowed';- const title = card.querySelector('.card-title');- if (title && !/coming soon/i.test(title.textContent)) {- title.textContent = `${title.textContent} · coming soon`;- }-}-async function handleFork(avatarId) {showSaveOverlay('Loading avatar…');try {@@ -115,7 +99,7 @@ async function boot() {return;}- probeReconstruct();+ probeFeatures();const creator = new AvatarCreator(document.body, (blob, meta = {}) => {const provider = meta.provider || 'avaturn';// Forward-compatible source mapping:@@ -145,16 +129,9 @@ async function boot() {window.location.href = '/create/studio';});wireCard('card-selfie', async () => {- if (!_reconstructReady) {- showStatus(- 'Selfie avatars are still warming up — try the studio for now (it ships every feature).',- 'info',- );- return;- }if (!requireAuthForSelfie()) return;if (await isAtAvatarLimit()) return;- window.location.href = '/scan';+ window.location.href = '/create/selfie';});wireCard('card-prompt', async () => {if (window.__authed === false) {diff --git a/src/editor/regenerate-panel.js b/src/editor/regenerate-panel.jsindex c725f7243..f5ac240e6 100644--- a/src/editor/regenerate-panel.js+++ b/src/editor/regenerate-panel.js@@ -3,24 +3,160 @@** Usage:* import { mountRegeneratePanel } from './regenerate-panel.js';- * const container = document.getElementById('regen-container');- * mountRegeneratePanel(container, {- * avatarId: 'uuid-...',- * onResult: (newAvatarId) => { ... }+ * mountRegeneratePanel(document.getElementById('regen-container'), {+ * avatarId: 'uuid-…',+ * onResult: (newAvatarId) => { … },* });** Do NOT auto-mount. Caller controls where and when the panel appears.*/-/**- * Mount the regenerate panel into a DOM container.- * @param {HTMLElement} container - Target container element- * @param {Object} options- * @param {string} options.avatarId - Avatar UUID to regenerate- * @param {(resultId: string) => void} options.onResult - Callback on successful regen- * @returns {Object} Control object with methods like .unmount()- */+const MODES = [+ { value: 'remesh', label: 'Re-mesh', desc: 'Regenerate mesh topology' },+ { value: 'retex', label: 'Re-texture', desc: 'Rebuild materials and textures' },+ { value: 'rerig', label: 'Re-rig', desc: 'Rebind the skeleton' },+ { value: 'restyle', label: 'Re-style', desc: 'Change appearance from description' },+];++const STATUS_LABELS = {+ queued: 'Queued — waiting for a worker…',+ running: 'Running…',+ done: 'Complete',+ failed: 'Failed',+};++const CSS = `+.rp-root {+ padding: 20px;+ border-top: 1px solid var(--border, #1a1a1a);+}+.rp-title {+ font-size: 13px;+ font-weight: 600;+ color: var(--text, #e8e8e8);+ margin: 0 0 16px;+ letter-spacing: -0.01em;+}+.rp-field {+ margin-bottom: 14px;+}+.rp-label {+ display: block;+ font-size: 11px;+ font-weight: 500;+ color: var(--muted, #888);+ text-transform: uppercase;+ letter-spacing: 0.04em;+ margin-bottom: 6px;+}+.rp-select, .rp-textarea {+ width: 100%;+ box-sizing: border-box;+ background: var(--panel-elev, #111);+ border: 1px solid var(--border, #1a1a1a);+ border-radius: 6px;+ color: var(--text, #e8e8e8);+ font-size: 13px;+ padding: 8px 10px;+ outline: none;+ transition: border-color 0.15s;+ appearance: none;+}+.rp-select:focus, .rp-textarea:focus {+ border-color: var(--border-strong, #2a2a2a);+}+.rp-textarea {+ height: 80px;+ resize: vertical;+ font-family: 'SF Mono', 'Fira Mono', ui-monospace, monospace;+ font-size: 12px;+ line-height: 1.5;+}+.rp-submit {+ width: 100%;+ padding: 9px 16px;+ background: var(--accent, #fff);+ color: var(--accent-ink, #000);+ border: none;+ border-radius: 6px;+ font-size: 13px;+ font-weight: 600;+ cursor: pointer;+ transition: opacity 0.15s;+}+.rp-submit:disabled {+ opacity: 0.4;+ cursor: not-allowed;+}+.rp-status {+ margin-top: 12px;+ padding: 10px 12px;+ background: var(--panel-elev, #111);+ border: 1px solid var(--border, #1a1a1a);+ border-radius: 6px;+ font-size: 12px;+ color: var(--muted, #888);+ display: flex;+ align-items: center;+ gap: 8px;+}+.rp-status-dot {+ width: 7px;+ height: 7px;+ border-radius: 50%;+ flex-shrink: 0;+ background: #555;+}+.rp-status-dot.queued { background: #6b7280; }+.rp-status-dot.running { background: #facc15; animation: rp-pulse 1.2s ease-in-out infinite; }+.rp-status-dot.done { background: #4ade80; }+.rp-status-dot.failed { background: var(--danger, #f87171); }+@keyframes rp-pulse {+ 0%, 100% { opacity: 1; }+ 50% { opacity: 0.4; }+}+.rp-error {+ margin-top: 10px;+ padding: 9px 12px;+ background: var(--danger-dim, #4a1a1a);+ border: 1px solid rgba(248,113,113,.2);+ border-radius: 6px;+ font-size: 12px;+ color: var(--danger, #f87171);+}+.rp-notice {+ padding: 14px;+ background: var(--panel-elev, #111);+ border: 1px solid var(--border, #1a1a1a);+ border-radius: 8px;+ font-size: 13px;+ color: var(--muted, #888);+ line-height: 1.5;+}+.rp-notice strong {+ display: block;+ color: var(--text, #e8e8e8);+ margin-bottom: 6px;+ font-size: 13px;+}+.rp-notice a {+ color: var(--text, #e8e8e8);+ text-decoration: underline;+ text-underline-offset: 2px;+}+`;++let _cssInjected = false;+function ensureCSS() {+ if (_cssInjected) return;+ const el = document.createElement('style');+ el.textContent = CSS;+ document.head.appendChild(el);+ _cssInjected = true;+}+export function mountRegeneratePanel(container, { avatarId, onResult }) {+ ensureCSS();const panel = new RegeneratePanel(container, { avatarId, onResult });panel.render();return panel;@@ -45,145 +181,126 @@ class RegeneratePanel {render() {this.container.innerHTML = '';- this.container.style.padding = '16px';- this.container.style.borderTop = '1px solid #ccc';- this.container.style.marginTop = '16px';-- const wrapper = document.createElement('div');- wrapper.innerHTML = `- <h3 style="margin: 0 0 12px 0; font-size: 14px; font-weight: 600;">- Regenerate Avatar- </h3>- `;- this.container.appendChild(wrapper);- // Render unconfigured banner if needed+ const root = document.createElement('div');+ root.className = 'rp-root';++ const title = document.createElement('p');+ title.className = 'rp-title';+ title.textContent = 'Regenerate avatar';+ root.appendChild(title);+if (this.state.unconfigured) {- this._renderUnconfiguredBanner();+ root.appendChild(this._buildNoticeBanner());+ this.container.appendChild(root);return;}- // Mode select- const modeLabel = document.createElement('label');- modeLabel.style.display = 'block';- modeLabel.style.marginBottom = '8px';- modeLabel.style.fontSize = '12px';- modeLabel.style.fontWeight = '500';- modeLabel.textContent = 'Mode';- this.container.appendChild(modeLabel);-- const modeSelect = document.createElement('select');- modeSelect.value = this.state.mode;- modeSelect.style.width = '100%';- modeSelect.style.padding = '6px';- modeSelect.style.marginBottom = '12px';- modeSelect.style.borderRadius = '4px';- modeSelect.style.border = '1px solid #ccc';- modeSelect.innerHTML = `- <option value="remesh">Re-mesh (regenerate topology)</option>- <option value="retex">Re-texture (materials + textures)</option>- <option value="rerig">Re-rig (skeleton binding)</option>- <option value="restyle">Re-style (appearance from description)</option>- `;- modeSelect.addEventListener('change', (e) => {- this.state.mode = e.target.value;- });- this.container.appendChild(modeSelect);-- // Params textarea- const paramsLabel = document.createElement('label');- paramsLabel.style.display = 'block';- paramsLabel.style.marginBottom = '8px';- paramsLabel.style.fontSize = '12px';- paramsLabel.style.fontWeight = '500';- paramsLabel.textContent = 'Parameters (JSON)';- this.container.appendChild(paramsLabel);-- const paramsTextarea = document.createElement('textarea');- paramsTextarea.value = this.state.params;- paramsTextarea.style.width = '100%';- paramsTextarea.style.height = '100px';- paramsTextarea.style.padding = '6px';- paramsTextarea.style.marginBottom = '12px';- paramsTextarea.style.borderRadius = '4px';- paramsTextarea.style.border = '1px solid #ccc';- paramsTextarea.style.fontFamily = 'monospace';- paramsTextarea.style.fontSize = '11px';- paramsTextarea.addEventListener('change', (e) => {- this.state.params = e.target.value;+ root.appendChild(this._buildModeField());+ root.appendChild(this._buildParamsField());+ root.appendChild(this._buildSubmitBtn());++ if (this.state.error) root.appendChild(this._buildError());+ if (this.state.jobId) root.appendChild(this._buildStatusRow());++ this.container.appendChild(root);+ }++ _buildModeField() {+ const field = document.createElement('div');+ field.className = 'rp-field';++ const label = document.createElement('label');+ label.className = 'rp-label';+ label.textContent = 'Mode';+ field.appendChild(label);++ const sel = document.createElement('select');+ sel.className = 'rp-select';+ MODES.forEach(({ value, label: lbl, desc }) => {+ const opt = document.createElement('option');+ opt.value = value;+ opt.textContent = `${lbl} — ${desc}`;+ if (value === this.state.mode) opt.selected = true;+ sel.appendChild(opt);});- this.container.appendChild(paramsTextarea);-- // Submit button- const submitBtn = document.createElement('button');- submitBtn.textContent = 'Start Regeneration';- submitBtn.style.padding = '8px 16px';- submitBtn.style.borderRadius = '4px';- submitBtn.style.border = 'none';- submitBtn.style.background = '#0066ff';- submitBtn.style.color = 'white';- submitBtn.style.cursor = this.state.inFlight ? 'not-allowed' : 'pointer';- submitBtn.style.opacity = this.state.inFlight ? '0.6' : '1';- submitBtn.disabled = this.state.inFlight;- submitBtn.addEventListener('click', () => this._submit());- this.container.appendChild(submitBtn);-- // Status / error display- if (this.state.error) {- const errorDiv = document.createElement('div');- errorDiv.style.marginTop = '12px';- errorDiv.style.padding = '8px';- errorDiv.style.backgroundColor = '#fee';- errorDiv.style.color = '#c00';- errorDiv.style.borderRadius = '4px';- errorDiv.style.fontSize = '12px';- errorDiv.textContent = this.state.error;- this.container.appendChild(errorDiv);- }+ sel.addEventListener('change', (e) => { this.state.mode = e.target.value; });+ field.appendChild(sel);+ return field;+ }- if (this.state.jobId) {- const statusDiv = document.createElement('div');- statusDiv.style.marginTop = '12px';- statusDiv.style.padding = '8px';- statusDiv.style.backgroundColor = '#eef';- statusDiv.style.color = '#006';- statusDiv.style.borderRadius = '4px';- statusDiv.style.fontSize = '12px';- statusDiv.innerHTML = `- <strong>Job:</strong> ${this.state.jobId}<br/>- <strong>Status:</strong> ${this.state.status || 'pending'}- `;- this.container.appendChild(statusDiv);- }+ _buildParamsField() {+ const field = document.createElement('div');+ field.className = 'rp-field';++ const label = document.createElement('label');+ label.className = 'rp-label';+ label.textContent = 'Parameters (JSON)';+ field.appendChild(label);++ const ta = document.createElement('textarea');+ ta.className = 'rp-textarea';+ ta.value = this.state.params;+ ta.spellcheck = false;+ ta.autocomplete = 'off';+ ta.addEventListener('change', (e) => { this.state.params = e.target.value; });+ field.appendChild(ta);+ return field;+ }++ _buildSubmitBtn() {+ const btn = document.createElement('button');+ btn.className = 'rp-submit';+ btn.type = 'button';+ btn.disabled = this.state.inFlight;+ btn.textContent = this.state.inFlight ? 'Working…' : 'Start regeneration';+ btn.addEventListener('click', () => this._submit());+ return btn;+ }++ _buildError() {+ const el = document.createElement('div');+ el.className = 'rp-error';+ el.textContent = this.state.error;+ return el;+ }++ _buildStatusRow() {+ const row = document.createElement('div');+ row.className = 'rp-status';++ const dot = document.createElement('span');+ dot.className = `rp-status-dot ${this.state.status || 'queued'}`;+ row.appendChild(dot);++ const text = document.createElement('span');+ text.textContent = STATUS_LABELS[this.state.status] || 'Queued…';+ row.appendChild(text);++ return row;}- _renderUnconfiguredBanner() {- const banner = document.createElement('div');- banner.style.padding = '12px';- banner.style.backgroundColor = '#fef3cd';- banner.style.border = '1px solid #ffeaa7';- banner.style.borderRadius = '4px';- banner.style.fontSize = '13px';- banner.style.color = '#856404';- banner.innerHTML = `- <strong>Avatar regeneration is not yet live.</strong>- Join the waitlist: <a href="mailto:[email protected]" style="color: #0066ff;">[email protected]</a><br/>- <small style="display: block; margin-top: 6px;">- ML backend integration is in progress. We'll notify you when it's ready.- </small>+ _buildNoticeBanner() {+ const el = document.createElement('div');+ el.className = 'rp-notice';+ el.innerHTML = `+ <strong>Mesh regeneration needs a backend</strong>+ Re-mesh, re-texture, and re-rig require a platform ML backend (Replicate, GCP, or HuggingFace).+ Set <code>AVATAR_REGEN_PROVIDER</code> and the matching API token in your environment to enable it.+ <br><br>+ <a href="/docs/avatar-creation" target="_blank" rel="noopener">Read the setup guide →</a>`;- this.container.appendChild(banner);+ return el;}async _submit() {if (this.state.inFlight) return;- // Validate JSONlet params;try {params = JSON.parse(this.state.params);} catch (e) {- this.state.error = `Invalid JSON in params: ${e.message}`;+ this.state.error = `Invalid JSON: ${e.message}`;this.render();return;}@@ -204,27 +321,22 @@ class RegeneratePanel {}),});- if (!resp.ok) {- const body = await resp.json();+ const body = await resp.json().catch(() => ({}));- // Handle 501 unconfigured case+ if (!resp.ok) {if (resp.status === 501 && body.error === 'regen_unconfigured') {this.state.unconfigured = true;this.state.inFlight = false;this.render();return;}-- throw new Error(body.error_description || `HTTP ${resp.status}`);+ throw new Error(body.error_description || body.message || `HTTP ${resp.status}`);}- const body = await resp.json();this.state.jobId = body.jobId;this.state.status = body.status;this.state.inFlight = false;this.render();-- // Start polling for completionthis._startPolling();} catch (err) {this.state.error = err.message;@@ -237,30 +349,18 @@ class RegeneratePanel {this.pollTimer = setInterval(async () => {try {const resp = await fetch(- `/api/avatars/regenerate-status?jobId=${this.state.jobId}`,- {- credentials: 'include',- },+ `/api/avatars/regenerate-status?jobId=${encodeURIComponent(this.state.jobId)}`,+ { credentials: 'include' },);-- if (!resp.ok) {- throw new Error(`HTTP ${resp.status}`);- }-+ if (!resp.ok) throw new Error(`HTTP ${resp.status}`);const body = await resp.json();this.state.status = body.status;-- if (body.error) {- this.state.error = body.error;- }-+ if (body.error) this.state.error = body.error;this.render();- // Terminal state — stop pollingif (body.status === 'done' || body.status === 'failed') {clearInterval(this.pollTimer);this.pollTimer = null;-if (body.status === 'done' && body.resultAvatarId && this.onResult) {this.onResult(body.resultAvatarId);}diff --git a/src/selfie-pipeline.js b/src/selfie-pipeline.jsindex 4c137f78b..20d5f955b 100644--- a/src/selfie-pipeline.js+++ b/src/selfie-pipeline.js@@ -462,8 +462,7 @@ function fit(w, h, max) {function mapApiError(status, payload) {const code = payload.error;if (status === 401) {- // Return to whichever surface initiated the flow (/create/selfie or /scan)- // so the post-login round-trip resumes on the right page.+ // Return to /create/selfie so the post-login round-trip resumes on the right page.const here = typeof location !== 'undefined' ? location.pathname : '/create/selfie';const next = encodeURIComponent(here);const e = withMessage(