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 full animations library API and update related components

fudjiae417174faaf9
diff --git a/.gitignore b/.gitignore
index cd4a7bff7..48eacfa0a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -329,4 +329,7 @@ docs/content/social/x-article-backlog-leak.md
# Bulk Mixamo library (multi-GB, fetched via npm run mixamo:download) —
# mx-*.fbx are build-time retarget sources, never committed or deployed.
animation-sources/mx-*.fbx
+animation-sources/.library-clips/
scripts/mixamo-progress.json
+scripts/mixamo-library.config.json
+scripts/mixamo-upload-state.json
diff --git a/docs/api-reference.md b/docs/api-reference.md
index cead38ac0..81001a74d 100644
--- a/docs/api-reference.md
+++ b/docs/api-reference.md
@@ -1064,6 +1064,40 @@ feeds directly (`source: "rss"`).
---
+## Animations Library API
+
+```
+GET /api/animations/library
+```
+
+Returns the full three.ws motion library manifest — the complete Mixamo-sourced catalog of retargeted animation clips (~2,400), hosted on the R2 CDN. No auth required. CORS open. Edge-cached for 5 minutes.
+
+Each entry's `url` is an absolute CDN URL to the baked clip JSON (`THREE.AnimationClip.toJSON()` format, canonical skeleton) — fetch it directly and load with `THREE.AnimationClip.parse()`, or pass the `name` to the embed viewer (`/embed/avatar?anim=<name>`) and pose studio (`/pose?anim=<name>`).
+
+**Response**
+
+```json
+{
+ "clips": [
+ {
+ "name": "mx-hip-hop-dancing",
+ "label": "Hip Hop Dancing",
+ "icon": "💃",
+ "loop": true,
+ "duration": 4.4,
+ "bytes": 1174283,
+ "url": "https://cdn.three.ws/animations/library/clips/mx-hip-hop-dancing.json"
+ }
+ ],
+ "total": 2400,
+ "generated_at": "2026-07-04T00:00:00.000Z"
+}
+```
+
+Returns `{ "clips": [], "total": 0 }` until the library has been published, so clients can feature-detect by emptiness. The curated starter set remains separately available as static JSON at `/animations/manifest.json`.
+
+---
+
## Config API
```
diff --git a/package.json b/package.json
index 818676f38..68b473078 100644
--- a/package.json
+++ b/package.json
@@ -185,6 +185,7 @@
"mixamo:catalog": "node scripts/mixamo-all.mjs --catalog",
"mixamo:download": "node scripts/mixamo-all.mjs --download",
"mixamo:all": "node scripts/mixamo-all.mjs",
+ "mixamo:upload": "node scripts/mixamo-all.mjs --upload",
"test": "vitest run && playwright test",
"test:core": "vitest run --maxWorkers=1",
"test:gate": "node scripts/test-gate.mjs",
diff --git a/scripts/mixamo-all.mjs b/scripts/mixamo-all.mjs
index 7e9b3d082..6532d050d 100644
--- a/scripts/mixamo-all.mjs
+++ b/scripts/mixamo-all.mjs
@@ -520,6 +520,9 @@ async function build() {
'--config=scripts/mixamo-library.config.json',
'--out=animation-sources/.library-clips',
'--manifest=animation-sources/.library-clips/manifest.json',
+ // Staged urls are library-root-relative; the upload phase writes the
+ // final absolute CDN urls into the published manifest.
+ '--url-prefix=clips/',
], { cwd: ROOT, stdio: 'inherit' });
if (result.status !== 0) {
diff --git a/src/animation-library.js b/src/animation-library.js
index aa139a0e4..2275d2e7a 100644
--- a/src/animation-library.js
+++ b/src/animation-library.js
@@ -139,11 +139,31 @@ export class AnimationLibrary {
*/
async openByName(name) {
await this._ready;
- const def = this._defs.find((d) => d.name === name);
+ let def = this._defs.find((d) => d.name === name);
+ if (!def) def = await this._lookupFullLibrary(name);
if (!def) throw new Error(`No built-in animation named “${name}”`);
return this.preview(def);
}
+ /**
+ * Resolve a full-library clip def by name. The /animations gallery
+ * deep-links R2-hosted clips (mx-* names) that aren't in the curated
+ * manifest; their defs carry an absolute CDN url that preview()/_loadClip()
+ * fetch like any other. Returns null when the library doesn't know the
+ * name either (including before the library has been uploaded).
+ * @param {string} name
+ */
+ async _lookupFullLibrary(name) {
+ try {
+ const res = await fetch('/api/animations/library');
+ if (!res.ok) return null;
+ const data = await res.json();
+ return (data.clips || []).find((d) => d.name === name) || null;
+ } catch {
+ return null;
+ }
+ }
+
/** Called by the host when the active rig changes (avatar load / mannequin). */
onRigChanged() {
this._genToken++; // a generation in flight was for the previous rig
diff --git a/src/animations-gallery.js b/src/animations-gallery.js
index 74f4b288d..77e700ee8 100644
--- a/src/animations-gallery.js
+++ b/src/animations-gallery.js
@@ -1,14 +1,18 @@
// /animations — public animation gallery.
//
-// Surfaces two sources in one searchable, filterable grid:
-// • The built-in three.ws motion library (/animations/manifest.json) — the
-// same curated clips the /pose studio ships with. Always present.
+// Surfaces three sources in one searchable, filterable grid:
// • Community clips published by three.ws users (GET /api/animations/clips
// ?include_public=true&visibility=public). Appear first, newest-first.
+// • The built-in three.ws motion library (/animations/manifest.json) — the
+// same curated clips the /pose studio ships with. Always present.
+// • The full motion library (GET /api/animations/library) — the complete
+// Mixamo-sourced catalog (~2,400 clips) hosted on the R2 CDN. Appears
+// only once populated; the endpoint returns an empty list until the
+// library pipeline (scripts/mixamo-all.mjs) has uploaded it.
//
-// Both are normalized to one card shape, then filtered (search + loop/once) and
-// paginated entirely client-side — the library is small and bounded, so there's
-// no need to round-trip the server on every keystroke.
+// All are normalized to one card shape, then filtered (search + loop/once) and
+// paginated entirely client-side — even the full catalog is just a few hundred
+// KB of metadata, so there's no need to round-trip the server on every keystroke.
//
// Card actions:
// • Preview (hover/click) — inline <iframe> of the embed viewer playing the
@@ -19,6 +23,7 @@
const PREVIEW_MODEL = '/avatars/cz.glb';
const API_BASE = '/api/animations/clips';
const MANIFEST_URL = '/animations/manifest.json';
+const LIBRARY_API = '/api/animations/library';
const PAGE_SIZE = 24;
// Cap community pagination so a large catalog can't stall first paint.
const COMMUNITY_MAX = 300;
@@ -113,6 +118,29 @@ function normalizeLibraryClip(clip) {
};
}
+// The full R2-hosted catalog. Empty (and therefore absent from the grid)
+// until the library pipeline has uploaded it.
+async function fetchFullLibrary() {
+ const res = await fetch(LIBRARY_API);
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
+ const data = await res.json();
+ return (Array.isArray(data.clips) ? data.clips : []).map(normalizeFullLibraryClip);
+}
+
+function normalizeFullLibraryClip(clip) {
+ return {
+ id: clip.name,
+ source: 'mixamo',
+ name: clip.label || clip.name,
+ loop: clip.loop !== false,
+ icon: clip.icon || '🎬',
+ tags: clip.category ? [clip.category] : [],
+ duration_ms: clip.duration ? Math.round(clip.duration * 1000) : null,
+ thumbnail_url: null,
+ price: null,
+ };
+}
+
function normalizeCommunityClip(clip) {
return {
id: clip.id,
@@ -129,17 +157,24 @@ function normalizeCommunityClip(clip) {
async function loadAll() {
showState('loading');
- const [libRes, comRes] = await Promise.allSettled([fetchLibrary(), fetchCommunity()]);
+ const [libRes, comRes, fullRes] = await Promise.allSettled([
+ fetchLibrary(),
+ fetchCommunity(),
+ fetchFullLibrary(),
+ ]);
- if (libRes.status === 'rejected' && comRes.status === 'rejected') {
+ if (libRes.status === 'rejected' && comRes.status === 'rejected' && fullRes.status === 'rejected') {
showState('error');
return;
}
const library = libRes.status === 'fulfilled' ? libRes.value : [];
const community = comRes.status === 'fulfilled' ? comRes.value : [];
- // Community clips lead (fresh, human-authored); the curated library follows.
- state.all = [...community, ...library];
+ const full = fullRes.status === 'fulfilled' ? fullRes.value : [];
+ // Community clips lead (fresh, human-authored); the curated library follows;
+ // the full catalog trails, minus anything the curated set already surfaces.
+ const curatedNames = new Set(library.map((c) => c.id));
+ state.all = [...community, ...library, ...full.filter((c) => !curatedNames.has(c.id))];
state.loaded = true;
applyFilters();
}
@@ -212,7 +247,8 @@ function buildCard(clip) {
const studioUrl = `/pose?anim=${encodeURIComponent(clip.id)}`;
const loopBadge = clip.loop;
const hasThumb = !!clip.thumbnail_url;
- const sourceLabel = clip.source === 'community' ? 'Community' : 'Built-in';
+ const sourceLabel =
+ clip.source === 'community' ? 'Community' : clip.source === 'mixamo' ? 'Library' : 'Built-in';
card.innerHTML = `
<div class="ag-card-preview" role="button" tabindex="0"
diff --git a/src/avatar-embed.js b/src/avatar-embed.js
index 0014cb5ad..3e351dfda 100644
--- a/src/avatar-embed.js
+++ b/src/avatar-embed.js
@@ -168,15 +168,32 @@ async function main() {
log.warn('[avatar-embed] animation manifest load failed', err?.message);
}
- // ?animation= / ?anim= — supports both manifest clip names and API clip ids/slugs.
+ // ?animation= / ?anim= — supports manifest clip names, full-library (R2)
+ // clip names, and API clip ids/slugs.
const startAnim = params.get('animation') || params.get('anim') || params.get('pose');
if (startAnim) {
const isApiId = /^[0-9a-f-]{36}$/i.test(startAnim) || startAnim.startsWith('user:');
if (isApiId) {
viewer.playAnimationById(startAnim.startsWith('user:') ? startAnim.slice(5) : startAnim)
.catch(() => animMgr.crossfadeTo('idle', 0.3).catch(() => {}));
- } else {
+ } else if (animDefs.some((d) => d.name === startAnim)) {
animMgr.crossfadeTo(startAnim, 0.3).catch(() => {});
+ } else {
+ // Not in the curated manifest — resolve from the full motion library
+ // and register just the requested def (its url points at the R2 CDN).
+ (async () => {
+ try {
+ const res = await fetch('/api/animations/library');
+ if (res.ok) {
+ const data = await res.json();
+ const def = (data.clips || []).find((d) => d.name === startAnim);
+ if (def) animMgr.appendAnimationDefs([def]);
+ }
+ } catch (err) {
+ log.warn('[avatar-embed] library lookup failed', err?.message);
+ }
+ animMgr.crossfadeTo(startAnim, 0.3).catch(() => {});
+ })();
}
}
diff --git a/tests/animations-library-endpoint.test.js b/tests/animations-library-endpoint.test.js
new file mode 100644
index 000000000..a2c9d028d
--- /dev/null
+++ b/tests/animations-library-endpoint.test.js
@@ -0,0 +1,97 @@
+/**
+ * GET /api/animations/library — full motion library manifest proxy.
+ *
+ * The endpoint proxies the R2-hosted library manifest (published by
+ * scripts/mixamo-all.mjs --upload). Contract under test:
+ * - pre-launch (manifest object missing) → 200 { clips: [], total: 0 },
+ * never an error, so the gallery/embed/studio feature-detect by emptiness;
+ * - published manifest ({ clips: [...] } shape) → clips passed through with
+ * total derived server-side;
+ * - bare-array manifest (legacy shape) → also accepted;
+ * - non-GET → 405.
+ */
+
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+
+const getObjectBuffer = vi.fn();
+vi.mock('../api/_lib/r2.js', () => ({ getObjectBuffer: (...a) => getObjectBuffer(...a) }));
+
+const { default: handler } = await import('../api/animations/library.js');
+
+function fakeReq(method = 'GET') {
+ return { method, url: '/api/animations/library', headers: {} };
+}
+
+function fakeRes() {
+ const headers = {};
+ return {
+ statusCode: 0,
+ body: undefined,
+ ended: false,
+ setHeader(k, v) { headers[String(k).toLowerCase()] = v; },
+ getHeader(k) { return headers[String(k).toLowerCase()]; },
+ end(b) { this.body = b; this.ended = true; },
+ _headers: headers,
+ };
+}
+
+const CLIP = {
+ name: 'mx-hip-hop-dancing',
+ label: 'Hip Hop Dancing',
+ icon: '💃',
+ loop: true,
+ duration: 4.4,
+ bytes: 1174283,
+ url: 'https://cdn.example/animations/library/clips/mx-hip-hop-dancing.json',
+};
+
+beforeEach(() => getObjectBuffer.mockReset());
+
+describe('GET /api/animations/library', () => {
+ it('returns an empty library when the manifest has not been uploaded yet', async () => {
+ const missing = Object.assign(new Error('no such key'), { name: 'NoSuchKey' });
+ getObjectBuffer.mockRejectedValue(missing);
+ const res = fakeRes();
+ await handler(fakeReq(), res);
+ expect(res.statusCode).toBe(200);
+ expect(JSON.parse(res.body)).toEqual({ clips: [], total: 0, generated_at: null });
+ });
+
+ it('degrades to an empty library on storage errors instead of failing', async () => {
+ getObjectBuffer.mockRejectedValue(new Error('socket hang up'));
+ const res = fakeRes();
+ await handler(fakeReq(), res);
+ expect(res.statusCode).toBe(200);
+ expect(JSON.parse(res.body).clips).toEqual([]);
+ });
+
+ it('passes through a published { clips } manifest and derives total', async () => {
+ getObjectBuffer.mockResolvedValue(Buffer.from(JSON.stringify({
+ generated_at: '2026-07-04T00:00:00.000Z',
+ total: 1,
+ clips: [CLIP],
+ })));
+ const res = fakeRes();
+ await handler(fakeReq(), res);
+ expect(res.statusCode).toBe(200);
+ const body = JSON.parse(res.body);
+ expect(body.clips).toEqual([CLIP]);
+ expect(body.total).toBe(1);
+ expect(body.generated_at).toBe('2026-07-04T00:00:00.000Z');
+ expect(res.getHeader('cache-control')).toContain('s-maxage=300');
+ });
+
+ it('accepts a bare-array manifest shape', async () => {
+ getObjectBuffer.mockResolvedValue(Buffer.from(JSON.stringify([CLIP])));
+ const res = fakeRes();
+ await handler(fakeReq(), res);
+ expect(JSON.parse(res.body).clips).toEqual([CLIP]);
+ });
+
+ it('rejects non-GET methods', async () => {
+ getObjectBuffer.mockResolvedValue(Buffer.from('[]'));
+ const res = fakeRes();
+ await handler(fakeReq('POST'), res);
+ expect(res.statusCode).toBe(405);
+ });
+});