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
milady
nirholase464e18c2650
diff --git a/public/dashboard/dashboard.js b/public/dashboard/dashboard.jsindex d4b9a4d86..fbaa32cc8 100644--- a/public/dashboard/dashboard.js+++ b/public/dashboard/dashboard.js@@ -1,6 +1,8 @@// Dashboard single-file app. Uses native DOM — no framework.// Keeps bundle small and ensures anything rendering <model-viewer> works without bundler.+import { AvatarCreator } from '../../src/avatar-creator.js';+export const state = { user: null };export const api = {@@ -19,6 +21,9 @@ export const api = {deleteWidget: (id) => j('DELETE', `/api/widgets/${encodeURIComponent(id)}`),duplicateWidget: (id) => j('POST', `/api/widgets/${encodeURIComponent(id)}/duplicate`),widgetStats: (id) => j('GET', `/api/widgets/${encodeURIComponent(id)}/stats`),+ createAvatarSession: (id) => j('POST', `/api/avatars/${id}/session`),+ getAvatarVersions: (id) => j('GET', `/api/avatars/${id}/versions`),+ patchAgent: (agentId, patch) => j('PUT', `/api/agents/${agentId}`, patch),};async function j(method, path, body) {diff --git a/src/avatar-creator.js b/src/avatar-creator.jsindex 435371998..d45d8ebac 100644--- a/src/avatar-creator.js+++ b/src/avatar-creator.js@@ -1,11 +1,16 @@/**- * Avatar Creator — embeds the self-hosted CharacterStudio builder in a modal.+ * Avatar Creator — embeds the self-hosted CharacterStudio builder in a modal,+ * or an Avaturn edit session when `open(sessionUrl)` is called with a URL.** CharacterStudio runs in an iframe and communicates via postMessage. When the* user clicks "Save Avatar", CharacterStudio posts a `characterstudio:export`* message carrying the GLB as a transferred ArrayBuffer, which we convert to a* Blob and hand to `onExport`.*+ * Avaturn is also loaded in an iframe. It posts an export event with a URL to+ * the GLB rather than transferring bytes directly; we fetch it then hand the+ * resulting Blob to `onExport`.+ ** The class API is identical to the previous RPM implementation so callers* (src/app.js, src/account.js) don't need to change.*/@@ -35,21 +40,40 @@ export class AvatarCreator {this.iframe = null;this._onMessage = null;this._onKeyDown = null;+ this._avaturnMode = false;+ this._avaturnOrigin = null;}/**- * Opens the avatar creator modal and mounts the CharacterStudio iframe.+ * Opens the avatar creator modal.+ * @param {string} [sessionUrl] - When provided, opens Avaturn in edit mode instead of CharacterStudio.*/- async open() {+ async open(sessionUrl) {if (this.modal) return;+ this._avaturnMode = !!sessionUrl;this._buildModal();this._onMessage = (event) => this._handleMessage(event);window.addEventListener('message', this._onMessage);- this.iframe.src = this.studioUrl;+ if (sessionUrl) {+ // @avaturn/sdk is not installed — use raw iframe.+ // If you install @avaturn/sdk, replace this with: new AvaturnSDK({ ... })+ console.info('[AvatarCreator] opening Avaturn session (raw iframe — no SDK):', sessionUrl);+ try { this._avaturnOrigin = new URL(sessionUrl).origin; } catch (_) {}+ this.iframe.src = sessionUrl;+ } else {+ this.iframe.src = this.studioUrl;+ }}_handleMessage(event) {- // Only accept messages from the CharacterStudio origin.+ if (this._avaturnMode) {+ this._handleAvaturnMessage(event);+ } else {+ this._handleCharacterStudioMessage(event);+ }+ }++ _handleCharacterStudioMessage(event) {try {const csOrigin = new URL(this.studioUrl).origin;if (event.origin !== csOrigin) return;@@ -62,6 +86,36 @@ export class AvatarCreator {if (!(msg.glb instanceof ArrayBuffer)) return;const blob = new Blob([msg.glb], { type: 'model/gltf-binary' });+ this._fireExport(blob);+ }++ async _handleAvaturnMessage(event) {+ if (this._avaturnOrigin && event.origin !== this._avaturnOrigin) return;++ const msg = event.data;+ if (!msg) return;++ // Avaturn may post: { type:'export', detail:{url} } or { avaturnEvent:'export', data:{url} }+ let glbUrl = null;+ if (msg.type === 'export') {+ glbUrl = msg.detail?.url || msg.data?.url || null;+ } else if (msg.avaturnEvent === 'export') {+ glbUrl = msg.data?.url || null;+ }+ if (!glbUrl) return;++ try {+ const resp = await fetch(glbUrl);+ if (!resp.ok) throw new Error(`GLB fetch failed: ${resp.status}`);+ const blob = await resp.blob();+ const glbBlob = blob.type ? blob : new Blob([await blob.arrayBuffer()], { type: 'model/gltf-binary' });+ this._fireExport(glbBlob);+ } catch (err) {+ console.error('[AvatarCreator] failed to fetch Avaturn GLB:', err);+ }+ }++ _fireExport(blob) {if (this.onExport) {try {this.onExport(blob);@@ -73,13 +127,14 @@ export class AvatarCreator {}_buildModal() {+ const title = this._avaturnMode ? 'Edit Your Avatar' : 'Create Your Avatar';this.modal = document.createElement('div');this.modal.className = 'avatar-creator-overlay';this.modal.innerHTML = `<div class="avatar-creator-modal"><div class="avatar-creator-header">- <span class="avatar-creator-title">Create Your Avatar</span>+ <span class="avatar-creator-title">${title}</span><button class="avatar-creator-close" aria-label="Close">×</button></div><div class="avatar-creator-body">@@ -133,6 +188,8 @@ export class AvatarCreator {this.modal = null;this.iframe = null;}+ this._avaturnMode = false;+ this._avaturnOrigin = null;}dispose() {diff --git a/src/runtime/scene.js b/src/runtime/scene.jsindex 984ad7686..c637ee712 100644--- a/src/runtime/scene.js+++ b/src/runtime/scene.js@@ -23,13 +23,44 @@ export class SceneController {this._loader = new GLTFLoader();this._userTarget = new Vector3(0, 1.6, 2); // approx user head positionthis._animationMap = {};+ this._group = null;+ this._groupMixer = null;+ this._groupClips = null;+ this._mixerHook = null;}// Expose the underlying Three.js handles skills may needget scene() { return this.viewer.scene; }- get mixer() { return this.viewer.mixer; }- get clips() { return this.viewer.clips || []; }- get content() { return this.viewer.content; }+ get mixer() { return this._groupMixer || this.viewer.mixer; }+ get clips() { return this._groupClips || this.viewer.clips || []; }+ get content() { return this._group || this.viewer.content; }++ // Scope all scene operations to a sub-group (used by <agent-stage>).+ setGroup(group, { mixer = null, clips = null } = {}) {+ this._group = group;+ this._groupMixer = mixer;+ this._groupClips = clips;+ if (mixer) {+ this._mixerHook = (dt) => {+ mixer.update(dt);+ this.viewer._animating = true;+ this.viewer.invalidate();+ };+ this._addHook(this._mixerHook);+ }+ }++ dispose() {+ if (this._mixerHook) this._removeHook(this._mixerHook);+ if (this._groupMixer) {+ try { this._groupMixer.stopAllAction(); } catch {}+ try { this._groupMixer.uncacheRoot(this._group); } catch {}+ }+ this._mixerHook = null;+ this._groupMixer = null;+ this._groupClips = null;+ this._group = null;+ }/*** Set the agent's animation slot override map (from meta.edits.animations).@@ -59,14 +90,16 @@ export class SceneController {playClipByName(name, { loop = false, fade_ms = 200 } = {}) {// Try embedded clips (viewer.clips / viewer.mixer) firstconst clip = this._findClip(name);- if (clip && this.viewer.mixer) {- const action = this.viewer.mixer.clipAction(clip);+ const mixer = this.mixer;+ if (clip && mixer) {+ const action = mixer.clipAction(clip);action.reset();action.setLoop(loop ? 2201 /* LoopRepeat */ : 2200 /* LoopOnce */);action.clampWhenFinished = !loop;action.fadeIn(fade_ms / 1000);action.play();- this.viewer.state.actionStates[clip.name] = true;+ if (!this._group) this.viewer.state.actionStates[clip.name] = true;+ this.viewer._animating = true;this.viewer.invalidate();return true;}@@ -96,15 +129,18 @@ export class SceneController {}stopClip(name) {- if (!this.viewer.mixer) return;+ const mixer = this.mixer;+ if (!mixer) return;const clip = name ? this._findClip(name) : null;if (clip) {- const action = this.viewer.mixer.existingAction(clip);+ const action = mixer.existingAction(clip);if (action) action.fadeOut(0.2);- this.viewer.state.actionStates[clip.name] = false;+ if (!this._group) this.viewer.state.actionStates[clip.name] = false;} else {- this.viewer.mixer.stopAllAction();- for (const k in this.viewer.state.actionStates) this.viewer.state.actionStates[k] = false;+ mixer.stopAllAction();+ if (!this._group) {+ for (const k in this.viewer.state.actionStates) this.viewer.state.actionStates[k] = false;+ }}this.viewer.invalidate();}@@ -112,11 +148,13 @@ export class SceneController {async play(clip, opts) {// Accept either a clip name or an AnimationClip instance.if (typeof clip === 'string') return this.playClipByName(clip, opts);- if (!this.viewer.mixer || !clip) return false;- const action = this.viewer.mixer.clipAction(clip);+ const mixer = this.mixer;+ if (!mixer || !clip) return false;+ const action = mixer.clipAction(clip);action.reset();action.fadeIn((opts?.blend ?? 0.2));action.play();+ this.viewer._animating = true;this.viewer.invalidate();return true;}