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.

feat: implement asset serving for animations and avatars in development server

nirholasddb178e6edbb
diff --git a/chat/src/App.svelte b/chat/src/App.svelte
index 506d3c0bf..e81a1300a 100644
--- a/chat/src/App.svelte
+++ b/chat/src/App.svelte
@@ -616,6 +616,7 @@
if (convo.messages[i].model.id === 'o1') {
convo.messages[i].content = choice.message.content;
+ pulseTokens();
// Once content starts coming in, we can stop thinking
if (convo.messages[i].reasoning && !unexpandedThinkingOnce) {
unexpandedThinkingOnce = true;
@@ -1702,10 +1703,81 @@
tryNext([primary, ...fallbacks]);
}
+ // STEP 1 watchdog. playClipByName fires-and-forgets, the agent-3d itself
+ // kicks idle right after scene init, the embedded GLB may have its own
+ // 'idle' on a separate mixer, and any of half a dozen handlers can call
+ // _stopWalkAnimation. Poll and brute-force walk until it sticks.
+ let walkWatchdogTimer = null;
+ let _walkDiagLogged = false;
+ function ensureWalkPlaying() {
+ if (!agentEl) { return; }
+ if (!agentReady) { return; }
+ if (avatarExitAnim) return;
+
+ // Blocker #1: explicit attribute disable
+ if (agentEl.getAttribute('avatar-walk') === 'off') {
+ agentEl.removeAttribute('avatar-walk');
+ }
+ // Blocker #2: prefers-reduced-motion (browsers with this on never start walk)
+ // We can't change the OS pref, but we sidestep agent-3d's _onStreamChunk
+ // path entirely by calling play() directly. So — no early return here.
+
+ // Blocker #3: agent-3d's internal _isWalking flag stuck true ⇒ _onStreamChunk
+ // no-ops. Reset it so any future stream chunks can re-trigger walk too.
+ try { agentEl._isWalking = false; } catch {}
+ clearTimeout(agentEl._walkStopDebounce);
+
+ const viewer = agentEl._scene?.viewer;
+ const am = viewer?.animationManager;
+ // Blocker #4: stale failure marker on the manager
+ if (am?._failed?.has?.('walk')) am._failed.delete('walk');
+
+ // Blocker #5: dual-mixer fight. The viewer has a mixer for embedded GLB
+ // clips; the AnimationManager has its own mixer for external clips. Both
+ // bind to the same model and both run every frame, so an embedded "idle"
+ // keeps stomping bones even when we play external "walk". Stop the
+ // embedded mixer so only the manager animates.
+ try { viewer?.mixer?.stopAllAction?.(); } catch {}
+
+ const candidates = ['walk', 'walking', 'Walk', 'Walking', 'run', 'Run'];
+ const alreadyWalking = am && candidates.includes(am.currentName);
+
+ // Blocker #6: viewer.state.actionStates['idle'] = true keeps _animating on
+ // for the embedded mixer and re-arms idle every render. Clear it.
+ try {
+ const actionStates = viewer?.state?.actionStates;
+ if (actionStates) for (const k of Object.keys(actionStates)) actionStates[k] = false;
+ } catch {}
+
+ if (!_walkDiagLogged) {
+ _walkDiagLogged = true;
+ const embedded = (viewer?.clips || []).map(c => c.name);
+ const externalDefs = (am?._animationDefs || []).map(d => d.name);
+ const externalLoaded = am?.clips ? Array.from(am.clips.keys()) : [];
+ console.log('[avatar walk diag]', {
+ agentReady, isWalking: agentEl._isWalking,
+ avatarWalkAttr: agentEl.getAttribute('avatar-walk'),
+ prefersReducedMotion: window.matchMedia('(prefers-reduced-motion: reduce)').matches,
+ embeddedClips: embedded, externalDefs, externalLoaded,
+ currentClip: am?.currentName, alreadyWalking,
+ });
+ }
+
+ if (alreadyWalking) return;
+
+ (async () => {
+ try { await am?.ensureLoaded?.('walk'); } catch {}
+ if (am && am.currentName === 'walk') am.currentName = null; // bypass crossfade short-circuit
+ playClipWithFallback(agentEl, 'walk', ['walking', 'Walk', 'Walking', 'run', 'Run']);
+ })();
+ }
+
// STEP 1: force the walking animation always so we can confirm it plays.
// (Idle / think switching deliberately disabled while we verify the walk clip.)
$: if (agentEl && agentReady && !avatarExitAnim && !thinkingTransitioning) {
- playClipWithFallback(agentEl, 'walk', ['walking', 'Walk', 'Walking', 'run', 'Run', 'idle']);
+ ensureWalkPlaying();
+ clearInterval(walkWatchdogTimer);
+ walkWatchdogTimer = setInterval(ensureWalkPlaying, 500);
}
// When thinking ends, play a one-shot falling animation before resuming the loop.
@@ -2383,7 +2455,7 @@
{#if (effectiveAgentId || $talkingHeadEnabled) && agentVisible}
<li
class="avatar-inline mx-auto mt-2 flex flex-col items-center gap-2 select-none list-none"
- class:avatar-walking={(generating || tokensFlowing) && agentReady}
+ class:avatar-walking={generating || tokensFlowing}
>
{#if effectiveAgentId}
<!-- svelte-ignore custom-element-no-implicit-ns -->
@@ -2395,6 +2467,7 @@
height="700"
background="transparent"
kiosk
+ avatar-chat="off"
name-plate="off"
style="width:min(420px, 60vw, calc((100vh - 240px) * 420 / 700)); aspect-ratio: 420 / 700;"
></agent-3d>
diff --git a/chat/vite.config.js b/chat/vite.config.js
index d93c98943..e70aab2b7 100644
--- a/chat/vite.config.js
+++ b/chat/vite.config.js
@@ -2,6 +2,50 @@ import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import viteCompression from 'vite-plugin-compression';
import path from 'path';
+import fs from 'fs';
+
+const ROOT_PUBLIC = path.resolve(__dirname, '../public');
+const DIST_LIB = path.resolve(__dirname, '../dist-lib');
+
+function serveDevAssets() {
+ return {
+ name: 'serve-dev-assets',
+ configureServer(server) {
+ server.middlewares.use((req, res, next) => {
+ if (!req.url) return next();
+ const url = req.url.split('?')[0];
+ let filePath = null;
+ if (url.startsWith('/animations/')) {
+ filePath = path.join(ROOT_PUBLIC, url);
+ } else if (url.startsWith('/agent-3d/')) {
+ const tail = url.replace(/^\/agent-3d\/(latest|\d+(\.\d+){0,2})\//, '');
+ filePath = path.join(DIST_LIB, tail);
+ } else if (url.startsWith('/avatars/')) {
+ filePath = path.join(ROOT_PUBLIC, url);
+ }
+ if (filePath && fs.existsSync(filePath) && fs.statSync(filePath).isFile()) {
+ const ext = path.extname(filePath).toLowerCase();
+ const mime = {
+ '.js': 'application/javascript',
+ '.mjs': 'application/javascript',
+ '.cjs': 'application/javascript',
+ '.json': 'application/json',
+ '.glb': 'model/gltf-binary',
+ '.gltf': 'model/gltf+json',
+ '.fbx': 'application/octet-stream',
+ '.png': 'image/png',
+ '.jpg': 'image/jpeg',
+ }[ext] || 'application/octet-stream';
+ res.setHeader('Content-Type', mime);
+ res.setHeader('Access-Control-Allow-Origin', '*');
+ fs.createReadStream(filePath).pipe(res);
+ return;
+ }
+ next();
+ });
+ },
+ };
+}
export default defineConfig(function () {
const buildTimestamp = new Date();
@@ -12,13 +56,12 @@ export default defineConfig(function () {
emptyOutDir: true,
},
server: {
- // Forward /api requests to the 3D-Agent dev server (vercel dev on port 3000)
proxy: {
'/api': { target: 'http://localhost:3000', changeOrigin: true },
- '/avatars': { target: 'http://localhost:3000', changeOrigin: true },
},
},
plugins: [
+ serveDevAssets(),
svelte(),
viteCompression({
filter: /^(?!.*pdf\.worker\.min-[A-Z0-9]+\.mjs$).*\.(js|mjs|json|css|html)$/i,
diff --git a/public/chat/index.html b/public/chat/index.html
index a915ac551..03f57bad9 100644
--- a/public/chat/index.html
+++ b/public/chat/index.html
@@ -43,7 +43,7 @@
}
}
</script>
- <script type="module" crossorigin src="/chat/assets/index-BTk_1mTm.js"></script>
+ <script type="module" crossorigin src="/chat/assets/index-9ROqFN-T.js"></script>
<link rel="stylesheet" crossorigin href="/chat/assets/index-CHprH7n7.css">
</head>
<body>