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
feat(agent-edit): avatar drop, export improvements, create-agent UX polish
nirholas9423837deaa1
diff --git a/api/avatars/_actions.js b/api/avatars/_actions.jsindex deaa5eb51..146d2dbe3 100644--- a/api/avatars/_actions.js+++ b/api/avatars/_actions.js@@ -225,6 +225,7 @@ function fetchError(status, code, message) {async function assertPublicHost(hostname) {const host = hostname.replace(/^\[|\]$/g, '').toLowerCase();if (host === 'localhost' || host.endsWith('.localhost') || host.endsWith('.internal') || host.endsWith('.local')) {+ console.warn('[avatar-upload] ssrf blocked: reserved hostname', host);throw fetchError(400, 'blocked_host', 'source_url host is not allowed');}const { lookup } = await import('dns/promises');@@ -236,6 +237,7 @@ async function assertPublicHost(hostname) {}for (const { address } of records) {if (isPrivateAddress(address)) {+ console.warn('[avatar-upload] ssrf blocked: private address', host, '->', address);throw fetchError(400, 'blocked_host', 'source_url resolves to a non-public address');}}diff --git a/pages/agent-edit.html b/pages/agent-edit.htmlindex 741415337..533dc7bb5 100644--- a/pages/agent-edit.html+++ b/pages/agent-edit.html@@ -420,10 +420,15 @@color: rgba(255, 255, 255, 0.7);}- .outfit-status {+ .outfit-status-bar {position: fixed;bottom: 1rem;right: 1.5rem;+ display: flex;+ align-items: center;+ gap: 0.5rem;+ }+ .outfit-status {font-size: 0.618rem;color: rgba(255, 255, 255, 0.25);pointer-events: none;@@ -437,6 +442,20 @@.outfit-status.err {color: #fca5a5;}+ .outfit-cancel-btn {+ font-size: 0.618rem;+ padding: 0.15rem 0.5rem;+ border: 1px solid rgba(255, 255, 255, 0.2);+ border-radius: 4px;+ background: transparent;+ color: rgba(255, 255, 255, 0.5);+ cursor: pointer;+ transition: color 0.15s, border-color 0.15s;+ }+ .outfit-cancel-btn:hover {+ color: #fca5a5;+ border-color: #fca5a5;+ }.loading-msg,.error-msg {@@ -1706,7 +1725,10 @@</main></div>- <div class="outfit-status" id="outfit-status" role="status" aria-live="polite"></div>+ <div class="outfit-status-bar">+ <div class="outfit-status" id="outfit-status" role="status" aria-live="polite"></div>+ <button type="button" id="outfit-cancel" class="outfit-cancel-btn" hidden aria-label="Cancel upload">Cancel</button>+ </div><script type="module" src="/src/agent-edit.js"></script>diff --git a/src/agent-edit.js b/src/agent-edit.jsindex 8e06954bb..d052bc776 100644--- a/src/agent-edit.js+++ b/src/agent-edit.js@@ -489,9 +489,27 @@ function triggerHiddenGlbInput() {input.click();}+let _uploadController = null;+async function saveNewAvatarAndSelect(blob, meta = {}) {+ // Cancel any in-flight upload before starting a new one.+ if (_uploadController) _uploadController.abort();+ _uploadController = new AbortController();+ const { signal } = _uploadController;+const status = $('outfit-status');- if (status) { status.textContent = 'Saving avatar…'; status.className = 'outfit-status saving'; }+ const cancelBtn = $('outfit-cancel');++ const setStatus = (text, cls = 'outfit-status saving') => {+ if (status) { status.textContent = text; status.className = cls; }+ };+ const onProgress = (pct) => {+ if (status && !signal.aborted) status.textContent = `Uploading… ${pct}%`;+ };++ setStatus('Saving avatar…');+ if (cancelBtn) cancelBtn.hidden = false;+try {const provider = meta.provider || 'upload';const source = provider === 'avaturn' ? 'avaturn' : provider === 'upload' ? 'upload' : 'import';@@ -500,17 +518,23 @@ async function saveNewAvatarAndSelect(blob, meta = {}) {source,source_meta,name: meta.name,- });- if (status) { status.textContent = 'Attaching to agent…'; }+ }, { signal, onProgress });+ setStatus('Attaching to agent…');await selectAvatar(avatar.id);- // Refresh the picker so the new avatar shows up; selectAvatar already- // re-renders, but availableAvatars may be stale if the request raced.if (!availableAvatars.some((a) => a.id === avatar.id)) {availableAvatars = [avatar, ...availableAvatars];await renderAvatarList();}+ setStatus('', 'outfit-status');} catch (err) {- if (status) { status.textContent = `Error: ${err.message || 'Failed to save avatar.'}`; status.className = 'outfit-status err'; }+ if (err?.name === 'AbortError' || signal.aborted) {+ setStatus('Upload cancelled.', 'outfit-status');+ } else {+ setStatus(`Error: ${err.message || 'Failed to save avatar.'}`, 'outfit-status err');+ }+ } finally {+ if (cancelBtn) cancelBtn.hidden = true;+ _uploadController = null;}}@@ -2441,6 +2465,13 @@ document.querySelectorAll('.edit-tab').forEach((tab) => {});// Open a specific tab via ?tab=… (used by OAuth callback redirects).+const _cancelBtn = $('outfit-cancel');+if (_cancelBtn) {+ _cancelBtn.addEventListener('click', () => {+ if (_uploadController) _uploadController.abort();+ });+}+async function init() {await loadAgent();if (!agentData) return;diff --git a/src/avatar-drop.js b/src/avatar-drop.jsindex dad47a8f9..e5560cc7e 100644--- a/src/avatar-drop.js+++ b/src/avatar-drop.js@@ -355,8 +355,15 @@ export function initAvatarDrop(sectionEl) {}const AVATAR_ID = 'bacff13e-b64b-4ac0-860d-44f0168ad23b';+ const BOOT_TIMEOUT_MS = 12_000;- fetch(`${location.origin}/api/avatars/${AVATAR_ID}`)+ const timedFetch = (url, ms = BOOT_TIMEOUT_MS) => {+ const ac = new AbortController();+ const t = setTimeout(() => ac.abort(), ms);+ return fetch(url, { signal: ac.signal }).finally(() => clearTimeout(t));+ };++ timedFetch(`${location.origin}/api/avatars/${AVATAR_ID}`).then(r => r.json()).then(d => {const glb = resolveGlb(d.avatar?.model_url || d.avatar?.url);@@ -372,7 +379,7 @@ export function initAvatarDrop(sectionEl) {scene.add(avatar);mixer = new AnimationMixer(avatar);- const fetchClip = f => fetch(f).then(r => {+ const fetchClip = f => timedFetch(f, 8_000).then(r => {if (!r.ok) throw new Error(`${f} → HTTP ${r.status}`);return r.json();});diff --git a/src/avatar-export.js b/src/avatar-export.jsindex 0e25e48f9..35799c8fc 100644--- a/src/avatar-export.js+++ b/src/avatar-export.js@@ -148,6 +148,21 @@ async function glbBlobToVrmBlob(glbBlob, meta) {const jsonText = TEXT_DECODER.decode(glb.json);const json = JSON.parse(jsonText);+ // Sanity-check the re-exported glTF version before touching the JSON.+ const assetVersion = json.asset?.version;+ if (assetVersion && String(assetVersion) !== '2.0') {+ throw new Error(`vrm: glTF asset version is ${assetVersion}, expected 2.0`);+ }++ // Guard against absurdly large skeletons — anything over 500 joints is almost+ // certainly a corrupted or non-humanoid mesh and would produce a useless VRM.+ const totalJoints = (json.skins || []).reduce(+ (acc, s) => acc + (Array.isArray(s.joints) ? s.joints.length : 0), 0,+ );+ if (totalJoints > 500) {+ throw new Error(`vrm: skeleton has ${totalJoints} joints — max 500. Is this a humanoid avatar?`);+ }+// 3. Build the VRMC_vrm payload from the in-memory scene. We index back// into json.nodes by name — GLTFExporter preserves node names so this// is stable.diff --git a/src/create-agent.js b/src/create-agent.jsindex ea78dff3b..2ffe094ed 100644--- a/src/create-agent.js+++ b/src/create-agent.js@@ -438,26 +438,36 @@ function selectStarter(id) {let libraryState = 'idle'; // idle | loading | loaded | errorlet libraryAvatars = [];+let libraryOffset = 0;+let libraryHasMore = false;+const LIBRARY_PAGE = 50;// The avatars API exposes the GLB as model_url (public/unlisted) or// base_model_url; private avatars have neither. Resolve a renderable URL or ''.const avatarModelUrl = (av) => av?.model_url || av?.base_model_url || '';-async function loadLibraryAvatars() {- if (libraryState === 'loaded' || libraryState === 'loading') {+async function loadLibraryAvatars({ append = false } = {}) {+ if (libraryState === 'loading') return;+ if (!append && (libraryState === 'loaded' || libraryState === 'error')) {renderLibrary();return;}libraryState = 'loading';- renderLibrary();+ if (!append) renderLibrary();try {- const res = await apiFetch('/api/avatars?limit=50', { credentials: 'include' });+ const url = `/api/avatars?limit=${LIBRARY_PAGE + 1}&offset=${libraryOffset}`;+ const res = await apiFetch(url, { credentials: 'include' });if (!res.ok) throw new Error(`HTTP ${res.status}`);const data = await res.json();- // Selection only needs an id — the agent links by avatar_id. A renderable- // URL (model_url for public/unlisted, base_model_url, or thumbnail_url) is- // used for the tile when present; private avatars without one still list.- libraryAvatars = (data.avatars || []).filter((a) => a && a.id);+ const page = (data.avatars || []).filter((a) => a && a.id);+ libraryHasMore = page.length > LIBRARY_PAGE;+ const fresh = page.slice(0, LIBRARY_PAGE);+ if (append) {+ libraryAvatars = [...libraryAvatars, ...fresh];+ } else {+ libraryAvatars = fresh;+ }+ libraryOffset = libraryAvatars.length;libraryState = 'loaded';} catch (err) {log.warn('[create-agent] avatar library load failed', err?.message);@@ -511,6 +521,16 @@ function renderLibrary() {grid.appendChild(card);});+ if (libraryHasMore) {+ const more = document.createElement('button');+ more.type = 'button';+ more.className = 'lib-load-more';+ more.style = 'grid-column:1/-1;margin-top:6px;padding:6px 12px;font-size:0.75rem;opacity:0.6;cursor:pointer;background:transparent;border:1px solid rgba(255,255,255,0.2);border-radius:6px;color:inherit;transition:opacity 0.15s';+ more.textContent = 'Load more';+ more.addEventListener('click', () => loadLibraryAvatars({ append: true }));+ grid.appendChild(more);+ }+// Re-apply the highlight when re-rendering with an active selection.if (state.model.mode === 'library' && state.model.avatarId) {grid.querySelectorAll('.starter').forEach((c) =>@@ -906,11 +926,13 @@ async function submit() {});avatarId = av?.id || null;} else if (state.model.mode === 'upload' && state.model.file) {- setMsg('Uploading your 3D model…', '');+ setMsg('Uploading your 3D model… 0%', '');const av = await saveRemoteGlbToAccount(state.model.file, {source: 'upload',name: state.model.fileName || state.name.trim(),visibility: 'public',+ }, {+ onProgress: (pct) => setMsg(`Uploading your 3D model… ${pct}%`, ''),});avatarId = av?.id || null;} else if (state.model.mode === 'library' && state.model.avatarId) {