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
nirholasd14e53753e3d
diff --git a/api/v1/agents/[caip].js b/api/v1/agents/[caip].jsnew file mode 100644index 000000000..b5380458c--- /dev/null+++ b/api/v1/agents/[caip].js@@ -0,0 +1,121 @@+/**+ * GET /api/v1/agents/:caip+ *+ * Public, gateway-cached resolver for an ERC-8004 / 3D Agent Card v1 agent.+ * Consumers (badge web component, indexers, third-party sites) call this so+ * they don't have to do RPC + IPFS + sha256 verification themselves.+ *+ * The :caip parameter is a CAIP-style ref:+ * eip155:<chainId>:<registryAddress>/<tokenId>+ *+ * URL-encode it: `eip155%3A8453%3A0x8004A169...%2F1`.+ *+ * Response (200):+ * {+ * ref: "eip155:8453:0x...",+ * chainId, agentId, registry, owner, tokenURI,+ * card: {...}, // the resolved agent card JSON+ * verified: {+ * modelSha256: true|false|null, // null when card has no model.sha256+ * cardSchema: "registration-v1" | "3d-agent-card-v1" | "unknown"+ * },+ * fetchedAt: "2026-04-27T12:00:00Z"+ * }+ *+ * Errors: 400 invalid_caip, 404 not_found, 502 upstream, 429 rate_limited.+ */++import { wrap, cors, method, json, error } from '../../_lib/http.js';+import { limits, clientIp } from '../../_lib/rate-limit.js';+import { resolveOnChainAgent, resolveURI } from '../../_lib/onchain.js';++const CAIP_RE = /^eip155:(\d+):(0x[a-fA-F0-9]{40})\/(\d+)$/;+const CACHE_HEADERS = {+ // 5 min fresh, 1 h stale-while-revalidate at the edge.+ 'cache-control': 'public, s-maxage=300, stale-while-revalidate=3600',+};++export default wrap(async (req, res) => {+ if (cors(req, res, { methods: 'GET,OPTIONS' })) return;+ if (!method(req, res, ['GET'])) return;++ const rl = await limits.mcpIp(clientIp(req));+ if (!rl.success) return error(res, 429, 'rate_limited', 'too many requests');++ const raw = decodeURIComponent(req.query?.caip || '');+ const m = CAIP_RE.exec(raw);+ if (!m) {+ return error(res, 400, 'invalid_caip', 'expected eip155:<chainId>:<registry>/<tokenId>');+ }+ const chainId = Number(m[1]);+ const registry = m[2];+ const agentId = m[3];++ const result = await resolveOnChainAgent({ chainId, agentId, fetchManifest: true });++ if (result.error === 'unsupported_chain') {+ return error(res, 400, 'unsupported_chain', `chain ${chainId} not in registry table`);+ }+ if (result.error?.startsWith('chain_read')) {+ return error(res, 404, 'not_found', `agent ${agentId} not found on chain ${chainId}`);+ }+ if (result.registry?.toLowerCase() !== registry.toLowerCase()) {+ return error(res, 400, 'registry_mismatch', 'CAIP registry differs from canonical deployment');+ }++ const card = result.manifest || null;+ const verified = await verifyCard(card);++ return json(+ res,+ 200,+ {+ ref: `eip155:${chainId}:${result.registry}/${agentId}`,+ chainId,+ agentId,+ registry: result.registry,+ owner: result.owner,+ tokenURI: result.tokenURI,+ card,+ verified,+ fetchedAt: new Date().toISOString(),+ },+ CACHE_HEADERS,+ );+});++async function verifyCard(card) {+ const out = { modelSha256: null, cardSchema: 'unknown' };+ if (!card || typeof card !== 'object') return out;++ const types = Array.isArray(card.type) ? card.type : card.type ? [card.type] : [];+ if (types.includes('https://3dagent.vercel.app/specs/3d-agent-card-v1')) {+ out.cardSchema = '3d-agent-card-v1';+ } else if (types.includes('https://eips.ethereum.org/EIPS/eip-8004#registration-v1')) {+ out.cardSchema = 'registration-v1';+ }++ const expected = card?.model?.sha256;+ const uri = card?.model?.uri;+ if (expected && uri) {+ try {+ const httpUrl = resolveURI(uri);+ const r = await fetch(httpUrl, { signal: AbortSignal.timeout(5000) });+ if (r.ok) {+ const buf = new Uint8Array(await r.arrayBuffer());+ const hash = await sha256Hex(buf);+ out.modelSha256 = hash.toLowerCase() === String(expected).toLowerCase();+ } else {+ out.modelSha256 = false;+ }+ } catch {+ out.modelSha256 = false;+ }+ }+ return out;+}++async function sha256Hex(bytes) {+ const buf = await crypto.subtle.digest('SHA-256', bytes);+ return [...new Uint8Array(buf)].map((b) => b.toString(16).padStart(2, '0')).join('');+}diff --git a/public/discover/discover.js b/public/discover/discover.jsindex 0ec6f841d..1cc760d42 100644--- a/public/discover/discover.js+++ b/public/discover/discover.js@@ -51,10 +51,13 @@ function updateSearchClearVisibility() {els.searchClear.hidden = !els.search.value;}-// Reveal "View my agents" chip when signed in. Same probe as index.html.+// Reveal "View my agents" chip + nav link when signed in.fetch('/api/auth/me', { credentials: 'include' }).then((r) => {- if (r.ok && els.myAgentsChip) els.myAgentsChip.hidden = false;+ if (!r.ok) return;+ if (els.myAgentsChip) els.myAgentsChip.hidden = false;+ const navLink = document.getElementById('nav-my-agents');+ if (navLink) navLink.hidden = false;}).catch(() => {});diff --git a/scripts/_patch-anim.mjs b/scripts/_patch-anim.mjsnew file mode 100644index 000000000..529222ec7--- /dev/null+++ b/scripts/_patch-anim.mjs@@ -0,0 +1,241 @@+import { readFileSync, writeFileSync } from 'fs';++const path = 'public/dashboard/dashboard.js';+let code = readFileSync(path, 'utf8');++// ── 1. Replace renderClipList block ─────────────────────────────────────────++const OLD_CLIP_LIST = `\tlet listEl, presetGridEl;++\tfunction renderClipList() {+\t\tlistEl.innerHTML = '';+\t\tif (!animations.length) {+\t\t\tlistEl.innerHTML =+\t\t\t\t'<div class="muted" style="padding:12px 0">No clips attached yet.</div>';+\t\t\treturn;+\t\t}+\t\tfor (const clip of animations) {+\t\t\tconst row = document.createElement('div');+\t\t\trow.className = 'clip-row';+\t\t\trow.innerHTML = \`+\t\t\t\t<span class="clip-name">\${esc(clip.name)}</span>+\t\t\t\t<span class="clip-source">\${esc(clip.source || 'custom')}</span>+\t\t\t\t<label class="loop-toggle" title="Toggle loop">+\t\t\t\t\t<input type="checkbox" \${clip.loop !== false ? 'checked' : ''}>+\t\t\t\t\t<span>Loop</span>+\t\t\t\t</label>+\t\t\t\t<div class="clip-actions">+\t\t\t\t\t<button class="preview-btn">Preview</button>+\t\t\t\t\t<button class="danger detach-btn">Remove</button>+\t\t\t\t</div>+\t\t\t\`;+\t\t\trow.querySelector('.loop-toggle input').addEventListener('change', (e) => {+\t\t\t\tclip.loop = e.target.checked;+\t\t\t\tdebounceSync();+\t\t\t});+\t\t\trow.querySelector('.detach-btn').addEventListener('click', () => {+\t\t\t\tconst idx = animations.indexOf(clip);+\t\t\t\tif (idx === -1) return;+\t\t\t\tanimations.splice(idx, 1);+\t\t\t\trenderClipList();+\t\t\t\trenderPresetGrid();+\t\t\t\tdebounceSync();+\t\t\t\ttoastUndo(\`Removed "\${clip.name}"\`, () => {+\t\t\t\t\tanimations.splice(idx, 0, clip);+\t\t\t\t\trenderClipList();+\t\t\t\t\trenderPresetGrid();+\t\t\t\t\tdebounceSync();+\t\t\t\t});+\t\t\t});+\t\t\trow.querySelector('.preview-btn').addEventListener('click', () =>+\t\t\t\topenAnimPreview(clip, avatarUrl),+\t\t\t);+\t\t\tlistEl.appendChild(row);+\t\t}+\t}`;++const NEW_CLIP_LIST = `\tlet listEl, presetGridEl;+\tlet _dragClip = null;++\tfunction renderClipList() {+\t\tlistEl.innerHTML = '';+\t\tif (!animations.length) {+\t\t\tlistEl.innerHTML =+\t\t\t\t'<div class="muted" style="padding:12px 0">No clips attached yet.</div>';+\t\t\treturn;+\t\t}+\t\tfor (const clip of animations) {+\t\t\tconst row = document.createElement('div');+\t\t\trow.className = 'clip-row';+\t\t\trow.draggable = true;+\t\t\trow.innerHTML = \`+\t\t\t\t<span class="drag-handle" aria-hidden="true" title="Drag to reorder">⠇</span>+\t\t\t\t<span class="clip-name" tabindex="0" title="Click to rename">\${esc(clip.name)}</span>+\t\t\t\t<span class="clip-source">\${esc(clip.source || 'custom')}</span>+\t\t\t\t<label class="loop-toggle" title="Toggle loop">+\t\t\t\t\t<input type="checkbox" \${clip.loop !== false ? 'checked' : ''}>+\t\t\t\t\t<span>Loop</span>+\t\t\t\t</label>+\t\t\t\t<div class="clip-actions">+\t\t\t\t\t<button class="preview-btn">Preview</button>+\t\t\t\t\t<button class="danger detach-btn">Remove</button>+\t\t\t\t</div>+\t\t\t\`;+\t\t\tconst nameEl = row.querySelector('.clip-name');+\t\t\tnameEl.addEventListener('click', () => beginRename(clip, nameEl));+\t\t\tnameEl.addEventListener('keydown', (e) => {+\t\t\t\tif (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); beginRename(clip, nameEl); }+\t\t\t});+\t\t\trow.querySelector('.loop-toggle input').addEventListener('change', (e) => {+\t\t\t\tclip.loop = e.target.checked;+\t\t\t\tdebounceSync();+\t\t\t});+\t\t\trow.querySelector('.detach-btn').addEventListener('click', () => {+\t\t\t\tconst idx = animations.indexOf(clip);+\t\t\t\tif (idx === -1) return;+\t\t\t\tanimations.splice(idx, 1);+\t\t\t\trenderClipList();+\t\t\t\trenderPresetGrid();+\t\t\t\tdebounceSync();+\t\t\t\ttoastUndo(\`Removed "\${clip.name}"\`, () => {+\t\t\t\t\tanimations.splice(idx, 0, clip);+\t\t\t\t\trenderClipList();+\t\t\t\t\trenderPresetGrid();+\t\t\t\t\tdebounceSync();+\t\t\t\t});+\t\t\t});+\t\t\trow.querySelector('.preview-btn').addEventListener('click', () =>+\t\t\t\topenAnimPreview(clip, avatarUrl),+\t\t\t);+\t\t\t// drag-to-reorder+\t\t\trow.addEventListener('dragstart', (e) => {+\t\t\t\trow.classList.add('dragging');+\t\t\t\te.dataTransfer.effectAllowed = 'move';+\t\t\t\te.dataTransfer.setData('text/plain', clip.name);+\t\t\t\t_dragClip = clip;+\t\t\t});+\t\t\trow.addEventListener('dragend', () => {+\t\t\t\trow.classList.remove('dragging');+\t\t\t\t_dragClip = null;+\t\t\t\tlistEl.querySelectorAll('.drop-above,.drop-below').forEach((r) =>+\t\t\t\t\tr.classList.remove('drop-above', 'drop-below'),+\t\t\t\t);+\t\t\t});+\t\t\trow.addEventListener('dragover', (e) => {+\t\t\t\tif (!_dragClip || _dragClip === clip) return;+\t\t\t\te.preventDefault();+\t\t\t\te.dataTransfer.dropEffect = 'move';+\t\t\t\tconst { top, height } = row.getBoundingClientRect();+\t\t\t\tconst after = e.clientY - top > height / 2;+\t\t\t\trow.classList.toggle('drop-above', !after);+\t\t\t\trow.classList.toggle('drop-below', after);+\t\t\t});+\t\t\trow.addEventListener('dragleave', () =>+\t\t\t\trow.classList.remove('drop-above', 'drop-below'),+\t\t\t);+\t\t\trow.addEventListener('drop', (e) => {+\t\t\t\te.preventDefault();+\t\t\t\trow.classList.remove('drop-above', 'drop-below');+\t\t\t\tif (!_dragClip || _dragClip === clip) return;+\t\t\t\tconst from = animations.indexOf(_dragClip);+\t\t\t\tif (from === -1) return;+\t\t\t\tconst { top, height } = row.getBoundingClientRect();+\t\t\t\tconst after = e.clientY - top > height / 2;+\t\t\t\tconst moved = _dragClip;+\t\t\t\tanimations.splice(from, 1);+\t\t\t\tlet to = animations.indexOf(clip);+\t\t\t\tif (after) to += 1;+\t\t\t\tanimations.splice(to, 0, moved);+\t\t\t\trenderClipList();+\t\t\t\tdebounceSync();+\t\t\t});+\t\t\tlistEl.appendChild(row);+\t\t}+\t}++\tfunction beginRename(clip, nameEl) {+\t\tif (nameEl.querySelector('input')) return;+\t\tconst original = clip.name;+\t\tconst input = document.createElement('input');+\t\tinput.type = 'text';+\t\tinput.value = original;+\t\tinput.maxLength = 60;+\t\tinput.className = 'clip-name-input';+\t\tnameEl.replaceChildren(input);+\t\tinput.focus();+\t\tinput.select();+\t\tlet committed = false;+\t\tconst finish = (save) => {+\t\t\tif (committed) return;+\t\t\tcommitted = true;+\t\t\tif (save) {+\t\t\t\tconst next = input.value.trim();+\t\t\t\tif (!next) { toast('Name required', true); nameEl.textContent = original; return; }+\t\t\t\tif (next.length > 60) { toast('Name too long (max 60)', true); nameEl.textContent = original; return; }+\t\t\t\tif (next !== original && nameTaken(next, clip)) {+\t\t\t\t\ttoast(\`"\${next}" already exists\`, true);+\t\t\t\t\tnameEl.textContent = original;+\t\t\t\t\treturn;+\t\t\t\t}+\t\t\t\tif (next !== original) { clip.name = next; debounceSync(); renderPresetGrid(); }+\t\t\t\tnameEl.textContent = clip.name;+\t\t\t} else {+\t\t\t\tnameEl.textContent = original;+\t\t\t}+\t\t};+\t\tinput.addEventListener('blur', () => finish(true));+\t\tinput.addEventListener('keydown', (e) => {+\t\t\tif (e.key === 'Enter') { e.preventDefault(); finish(true); input.blur(); }+\t\t\telse if (e.key === 'Escape') { e.preventDefault(); finish(false); input.blur(); }+\t\t});+\t}`;++// ── 2. Add "Add all" bulk button to renderPresetGrid ────────────────────────++const OLD_PRESET_GRID_END = `\t\t\tpresetGridEl.appendChild(tile);+\t\t}+\t}`;++const NEW_PRESET_GRID_END = `\t\t\tpresetGridEl.appendChild(tile);+\t\t}+\t}++\tfunction addAllPresets() {+\t\tconst toAdd = presets.filter((p) => !isAttached(p.name));+\t\tif (!toAdd.length) { toast('All presets already attached'); return; }+\t\tfor (const p of toAdd) {+\t\t\tanimations.push({+\t\t\t\tname: p.name,+\t\t\t\turl: p.url,+\t\t\t\tloop: p.loop !== false,+\t\t\t\tclipName: p.clipName || undefined,+\t\t\t\tsource: 'preset',+\t\t\t\taddedAt: new Date().toISOString(),+\t\t\t});+\t\t}+\t\trenderClipList();+\t\trenderPresetGrid();+\t\tdebounceSync();+\t\ttoast(\`Added \${toAdd.length} preset\${toAdd.length === 1 ? '' : 's'}\`);+\t}`;++let replaced = 0;++if (code.includes(OLD_CLIP_LIST)) {+ code = code.replace(OLD_CLIP_LIST, NEW_CLIP_LIST);+ replaced++;+ console.log('✓ renderClipList replaced');+} else {+ console.error('✗ OLD_CLIP_LIST not found');+}++if (code.includes(OLD_PRESET_GRID_END)) {+ code = code.replace(OLD_PRESET_GRID_END, NEW_PRESET_GRID_END);+ replaced++;+ console.log('✓ addAllPresets added');+} else {+ console.error('✗ OLD_PRESET_GRID_END not found');+}++writeFileSync(path, code);+console.log(`Done (${replaced}/2 replacements applied)`);diff --git a/specs/ENS_AGENT_CLAIM.md b/specs/ENS_AGENT_CLAIM.mdnew file mode 100644index 000000000..7912a42fc--- /dev/null+++ b/specs/ENS_AGENT_CLAIM.md@@ -0,0 +1,83 @@+# ENS / DNS Agent Claim — v1++A convention for letting a domain prove it owns a 3D Agent (and vice versa). Bidirectional binding between human-readable names and on-chain agent identities.++## Why++ERC-8004 gives an agent a CAIP-10 reference. Humans don't memorize `eip155:8453:0x8004A169…/42`. Without a name binding, every "this is the official 3D Agent for example.com" claim is just an unverifiable assertion in a card.++This spec defines two records that are cheap to set, easy to verify, and require no new on-chain infrastructure.++## Forward record (name → agent)++### ENS++Set the text record `agent` on the ENS name:++```+agent = eip155:<chainId>:<registry>/<tokenId>+```++Example for `coachleo.eth`:++```+agent = eip155:8453:0x8004A169FB4a3325136EB29fA0ceB6D2e539a432/42+```++Multiple agents: comma-separated list, first entry is canonical.++### DNS (TXT)++For domains without ENS, publish a TXT record at `_agent.<domain>`:++```+_agent.example.com. IN TXT "v=agent1; ref=eip155:8453:0x8004A169.../42"+```++Resolvers MUST treat the first valid `v=agent1` record as canonical and ignore others.++## Reverse record (agent → name)++The agent card SHOULD include a `claims` array pointing at the names that claim it:++```json+"claims": [+ { "type": "ens", "name": "coachleo.eth" },+ { "type": "dns", "name": "coachleo.com" }+]+```++A claim is **verified** only when both directions match:++- forward: the name's `agent` record contains the agent's CAIP ref.+- reverse: the agent card lists the name in `claims`.++Either direction alone is **unverified**. A consumer (resolver, badge, indexer) MUST display the trust state — verified, half-claim from name, half-claim from agent — distinctly. A half-claim is a useful discovery signal but not a trust signal.++## Resolver behavior++The HTTP resolver at [`/api/v1/agents/:caip`](../api/v1/agents/[caip].js) SHOULD, when reachable, resolve the `claims` array and return:++```json+"claims": [+ { "type": "ens", "name": "coachleo.eth", "verified": true },+ { "type": "dns", "name": "coachleo.com", "verified": false, "reason": "no _agent TXT" }+]+```++Verification is best-effort and time-bounded; failures are reported, not thrown.++## Adding `claims` to the v1 schema++Treat `claims` as an optional extension block (not yet in [3d-agent-card.schema.json](../public/.well-known/3d-agent-card.schema.json) v1.0). It will be promoted to v1.1 once at least one validator runs claim verification as part of the suite.++## Security notes++- A name binding is only as strong as the name's own custody. Compromise the ENS owner key → spoofed claims. Consumers SHOULD show the chain age of the binding (block of last `setText`) so a freshly-set `agent` record is treated with more skepticism.+- DNS bindings are weaker (DNS hijack vector). Treat ENS-verified above DNS-verified above unverified.+- Never auto-trust a one-sided claim. The bidirectional requirement defeats the easy attack of "I'll just put your domain in my card."++## Out of scope (v1)++- On-chain reverse resolver contract. The card-level `claims` array is sufficient until indexers want O(1) reverse lookup.+- Wildcard / subdomain claims (e.g. `*.example.com → agent`). Easy to add later.diff --git a/src/runtime/scene.js b/src/runtime/scene.jsindex 22fb8bbe4..ee4c5d79e 100644--- a/src/runtime/scene.js+++ b/src/runtime/scene.js@@ -117,9 +117,10 @@ export class SceneController {this.viewer.invalidate();return true;}- // Fall back to animation manager (external clips from manifest)+ // Fall back to animation manager (external clips from manifest).+ // crossfadeTo/play are async (lazy-load on demand); fire-and-forget is fine.const am = this.viewer?.animationManager;- if (!am?.isLoaded(name)) return false;+ if (!am || am.isFailed(name)) return false;if (loop) am.crossfadeTo(name, fade_ms / 1000);else am.play(name);return true;