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: marketplace polish, auth/mandate hardening, agent memory/actions + dca/subscriptions updates
nirholas0d51492625fa
diff --git a/api/_lib/a2a/mandate.js b/api/_lib/a2a/mandate.jsindex 32ddc7e61..a1fd11ce2 100644--- a/api/_lib/a2a/mandate.js+++ b/api/_lib/a2a/mandate.js@@ -141,6 +141,11 @@ export async function issueIntentMandate({}const nowSec = Math.floor(Date.now() / 1000);+ // Generate the jti up-front so the returned mandate carries the SAME id the+ // signed token (and thus verifyIntentMandate / the spend ledger) will use.+ // setJti() stamps the JWT but does not mutate `claims`, so we must thread the+ // value through explicitly rather than read it back off `claims`.+ const mandateId = jti();const claims = {typ: MANDATE_TYPE,ver: MANDATE_VERSION,@@ -162,10 +167,13 @@ export async function issueIntentMandate({.setIssuer(env.APP_ORIGIN).setIssuedAt(nowSec).setExpirationTime(nowSec + ttl)- .setJti(jti())+ .setJti(mandateId).sign(secretKey());- return { jws, mandate: decodeFromClaims(claims, { sub: subjectAgentId, exp: nowSec + ttl, iat: nowSec, jti: claims.jti }) };+ return {+ jws,+ mandate: decodeFromClaims(claims, { sub: subjectAgentId, exp: nowSec + ttl, iat: nowSec, jti: mandateId }),+ };}function jti() {diff --git a/api/agent-actions.js b/api/agent-actions.jsindex 979e22d8c..aeec4db99 100644--- a/api/agent-actions.js+++ b/api/agent-actions.js@@ -11,7 +11,9 @@import { getSessionUser, authenticateBearer, extractBearer } from './_lib/auth.js';import { sql } from './_lib/db.js';-import { cors, json, method, readJson, wrap, error } from './_lib/http.js';+import { cors, json, method, readJson, wrap, error, rateLimited } from './_lib/http.js';+import { requireCsrf } from './_lib/csrf.js';+import { limits } from './_lib/rate-limit.js';export default wrap(async (req, res) => {if (cors(req, res, { methods: 'GET,POST,OPTIONS', credentials: true })) return;@@ -68,8 +70,13 @@ async function handleList(req, res) {async function handleAppend(req, res) {const auth = await resolveAuth(req);if (!auth) return error(res, 401, 'unauthorized', 'sign in required');+ // Cookie sessions need a CSRF token; bearer callers are exempt inside requireCsrf.+ if (!(await requireCsrf(req, res, auth.userId))) return;- const body = await readJson(req);+ const rl = await limits.agentActionAppend(auth.userId);+ if (!rl.success) return rateLimited(res, rl, 'too many actions, slow down');++ const body = await readJson(req, 32_000);if (!body.agent_id) return error(res, 400, 'validation_error', 'agent_id required');if (!body.type) return error(res, 400, 'validation_error', 'type required');diff --git a/api/agent-memory.js b/api/agent-memory.jsindex 1294c6216..b664abb8d 100644--- a/api/agent-memory.js+++ b/api/agent-memory.js@@ -12,6 +12,7 @@import { getSessionUser, authenticateBearer, extractBearer } from './_lib/auth.js';import { sql } from './_lib/db.js';import { cors, json, method, readJson, wrap, error } from './_lib/http.js';+import { requireCsrf } from './_lib/csrf.js';export default wrap(async (req, res) => {if (cors(req, res, { methods: 'GET,POST,DELETE,OPTIONS', credentials: true })) return;@@ -80,6 +81,7 @@ async function handleList(req, res) {async function handleUpsert(req, res) {const auth = await resolveAuth(req);if (!auth) return error(res, 401, 'unauthorized', 'sign in required');+ if (!(await requireCsrf(req, res, auth.userId))) return;const body = await readJson(req);const agentId = body.agentId || body.agent_id;@@ -158,6 +160,7 @@ async function handleUpsert(req, res) {async function handleDelete(req, res, memoryId) {const auth = await resolveAuth(req);if (!auth) return error(res, 401, 'unauthorized', 'sign in required');+ if (!(await requireCsrf(req, res, auth.userId))) return;const [row] = await sql`SELECT m.id, a.user_iddiff --git a/api/auth/[action].js b/api/auth/[action].jsindex 5258990e7..2ea3f796b 100644--- a/api/auth/[action].js+++ b/api/auth/[action].js@@ -11,6 +11,7 @@ import {} from '../_lib/auth.js';import { randomToken, randomDigits, sha256 } from '../_lib/crypto.js';import { cors, json, method, readJson, wrap, error, rateLimited } from '../_lib/http.js';+import { requireCsrf } from '../_lib/csrf.js';import { limits, clientIp } from '../_lib/rate-limit.js';import { parse, loginBody, registerBody, usernameRegisterBody, username as usernameValidator, displayName, email, password } from '../_lib/validate.js';import { sendPasswordResetEmail, sendVerificationEmail } from '../_lib/email.js';@@ -75,6 +76,7 @@ async function handleLogoutEverywhere(req, res) {if (!method(req, res, ['POST'])) return;const user = await getSessionUser(req);if (!user) return error(res, 401, 'unauthenticated', 'not signed in');+ if (!(await requireCsrf(req, res, user.id))) return;const rl = await limits.authIp(clientIp(req));if (!rl.success) return rateLimited(res, rl);const sessionResult = await sql`update sessions set revoked_at = now() where user_id = ${user.id} and revoked_at is null`;@@ -192,6 +194,7 @@ async function handleProfile(req, res) {if (!method(req, res, ['PATCH'])) return;const user = await getSessionUser(req);if (!user) return error(res, 401, 'unauthenticated', 'not signed in');+ if (!(await requireCsrf(req, res, user.id))) return;const rl = await limits.authIp(clientIp(req));if (!rl.success) return rateLimited(res, rl);const body = parse(profileSchema, await readJson(req));diff --git a/api/auth/wallets/[action].js b/api/auth/wallets/[action].jsindex e208d1196..2c339dc8f 100644--- a/api/auth/wallets/[action].js+++ b/api/auth/wallets/[action].js@@ -18,6 +18,7 @@ import { sql } from '../../_lib/db.js';import { getSessionUser } from '../../_lib/auth.js';import { logAudit } from '../../_lib/audit.js';import { cors, json, method, readJson, wrap, error } from '../../_lib/http.js';+import { requireCsrf } from '../../_lib/csrf.js';import { parse } from '../../_lib/validate.js';import { parseSiweMessage } from '../../_lib/siwe.js';import { parseSiwsMessage, verifySiwsSignature } from '../../_lib/siws.js';@@ -496,6 +497,7 @@ async function handleSetPrimary(req, res) {const session = await getSessionUser(req);if (!session) return error(res, 401, 'unauthorized', 'sign in required');+ if (!(await requireCsrf(req, res, session.id))) return;const body = await readJson(req).catch(() => null);const rawAddress = body?.address;diff --git a/api/dca-strategies.js b/api/dca-strategies.jsindex db8cc9322..1bb1d3412 100644--- a/api/dca-strategies.js+++ b/api/dca-strategies.js@@ -5,6 +5,7 @@ import { z } from 'zod';import { sql } from './_lib/db.js';import { getSessionUser } from './_lib/auth.js';import { cors, json, error, wrap, readJson, method, rateLimited } from './_lib/http.js';+import { requireCsrf } from './_lib/csrf.js';import { parse } from './_lib/validate.js';import { limits, clientIp } from './_lib/rate-limit.js';@@ -42,6 +43,11 @@ export default wrap(async (req, res) => {const session = await getSessionUser(req);if (!session) return error(res, 401, 'unauthorized', 'sign in required');+ // State-changing methods on a cookie session require a CSRF token. These+ // strategies move real funds on a schedule, so a forged create/cancel is+ // high-impact — gate every non-GET method.+ if (req.method !== 'GET' && !(await requireCsrf(req, res, session.id))) return;+const url = new URL(req.url, 'http://x');// ── DELETE /api/dca-strategies/:id ─────────────────────────────────────────diff --git a/api/subscriptions.js b/api/subscriptions.jsindex 648c7b360..c9753165b 100644--- a/api/subscriptions.js+++ b/api/subscriptions.js@@ -9,6 +9,7 @@import { sql } from './_lib/db.js';import { getSessionUser, authenticateBearer, extractBearer } from './_lib/auth.js';import { cors, json, method, wrap, error, readJson, rateLimited } from './_lib/http.js';+import { requireCsrf } from './_lib/csrf.js';import { limits, clientIp } from './_lib/rate-limit.js';import { z } from 'zod';import { parse } from './_lib/validate.js';@@ -34,6 +35,11 @@ export default wrap(async (req, res) => {const rl = await limits.authIp(clientIp(req));if (!rl.success) return rateLimited(res, rl);+ // State-changing methods on a cookie session require a CSRF token (bearer+ // callers are exempt inside requireCsrf). Without this, a cross-origin script+ // could cancel a victim's subscriptions on their behalf.+ if (req.method !== 'GET' && !(await requireCsrf(req, res, userId))) return;+// ── POST: create subscription ─────────────────────────────────────────────if (req.method === 'POST') {diff --git a/package.json b/package.jsonindex 977e2f326..3e52e47bf 100644--- a/package.json+++ b/package.json@@ -69,6 +69,7 @@"build": "NODE_OPTIONS='--no-deprecation --max-old-space-size=6144' vite build && node scripts/strip-sw-from-embeds.mjs","build:wasm": "PATH=\"$HOME/.cargo/bin:$PATH\" RUSTFLAGS='-C target-feature=+simd128' wasm-pack build crates/vanity-grinder --target web --release --out-dir ../../src/solana/vanity/wasm && printf '%s\\n' '# wasm-pack writes a default `*` gitignore that excludes everything.' '# Override it: the generated files in this directory ARE checked in so the' '# app builds without requiring a Rust toolchain at install time. Run' '# `npm run build:wasm` after editing /crates/vanity-grinder/src/lib.rs to' '# refresh these artifacts.' '!*' > src/solana/vanity/wasm/.gitignore","build:animations": "node scripts/build-animations.mjs",+ "bake:mannequin": "node scripts/bake-mannequin-glb.mjs","build:club-props": "node scripts/build-club-props.mjs","build:club-venue": "node scripts/build-club-venue.mjs","build:club-hdri": "node scripts/build-club-hdri.mjs",diff --git a/public/marketplace.css b/public/marketplace.cssindex f73464c45..5923766e8 100644--- a/public/marketplace.css+++ b/public/marketplace.css@@ -444,6 +444,38 @@ body.market-page > header {text-transform: capitalize;}+.market-card-agent .footer-right {+ display: inline-flex;+ align-items: center;+ gap: var(--space-sm);+}++.market-card-agent .card-see3d {+ display: inline-flex;+ align-items: center;+ gap: 5px;+ padding: var(--space-3xs) var(--space-sm);+ font-size: 11px;+ font-weight: 600;+ color: var(--accent, #00d9ff);+ background: color-mix(in srgb, var(--accent, #00d9ff) 10%, transparent);+ border: 1px solid color-mix(in srgb, var(--accent, #00d9ff) 32%, transparent);+ border-radius: var(--radius-pill);+ text-decoration: none;+ transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;+}++.market-card-agent .card-see3d:hover {+ background: color-mix(in srgb, var(--accent, #00d9ff) 18%, transparent);+ border-color: color-mix(in srgb, var(--accent, #00d9ff) 60%, transparent);+ transform: translateY(-1px);+}++.market-card-agent .card-see3d:focus-visible {+ outline: 2px solid var(--accent, #00d9ff);+ outline-offset: 2px;+}+.market-loadmore {text-align: center;padding: var(--space-md);diff --git a/scripts/seed-public-avatars.mjs b/scripts/seed-public-avatars.mjsindex d652ad1df..fd35b0f47 100644--- a/scripts/seed-public-avatars.mjs+++ b/scripts/seed-public-avatars.mjs@@ -76,6 +76,12 @@ const THREE_GLTF = (file) =>const CATALOG = [// ── local repo GLBs ─────────────────────────────────────────────────────+ {+ source: 'local', name: 'Mannequin', slug: 'mannequin',+ description: 'The three.ws base avatar — a clean articulated mannequin every agent wears until it gets a custom look. Baked straight from the /pose rig.',+ tags: ['humanoid', 'base', 'mannequin'],+ file: 'public/avatars/mannequin.glb', license: 'internal',+ },{source: 'local', name: 'CZ', slug: 'cz',description: 'Stylized humanoid avatar (CZ).',diff --git a/src/marketplace.js b/src/marketplace.jsindex f31a4b2dc..b4f1b83dd 100644--- a/src/marketplace.js+++ b/src/marketplace.js@@ -17,6 +17,7 @@ import {bindDetailExtras,} from './marketplace-detail.js';import { onchainBadgeHTML } from './shared/onchain-badge.js';+import { seeInWorldHref, hasCustomAvatar } from './shared/agent-3d.js';import { coinChipHTML } from './shared/agent-coin.js';import { skeletonHTML, ensureStateKitStyles } from './shared/state-kit.js';import { log } from './shared/log.js';@@ -3915,7 +3916,13 @@ function renderCard(a) {</div><div class="footer"><span>${date}</span>- <span class="cat-pill">${CATEGORY_LABELS[a.category] || a.category || ''}</span>+ <span class="footer-right">+ <a class="card-see3d" href="${escapeHtml(seeInWorldHref(a))}" aria-label="${hasCustomAvatar(a) ? 'See' : 'View'} ${escapeHtml(a.name || 'agent')} in 3D in the three.ws world">+ <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/><polyline points="3.27 6.96 12 12.01 20.73 6.96"/><line x1="12" y1="22.08" x2="12" y2="12"/></svg>+ <span>${hasCustomAvatar(a) ? 'See in 3D' : 'View in 3D'}</span>+ </a>+ <span class="cat-pill">${CATEGORY_LABELS[a.category] || a.category || ''}</span>+ </span></div></div>`;}diff --git a/src/shared/agent-3d.js b/src/shared/agent-3d.jsindex 4808a5f63..5a029076f 100644--- a/src/shared/agent-3d.js+++ b/src/shared/agent-3d.js@@ -51,12 +51,12 @@ export function hasCustomAvatar(agent) {// Build the /play deep link that drops the agent's avatar into the $three world.// The avatar rides in `?avatar=` and is shown for the session only — it never// overwrites the visitor's saved avatar (see play-handoff.getRequestedAvatar).+// Only `coin` (the $three mint) is passed; the world backfills the community's+// real name/symbol/art from the mint, so we never mislabel it with agent data.export function seeInWorldHref(agent) {const q = new URLSearchParams({avatar: agentAvatarGlb(agent),coin: THREE_MINT,- name: (agent?.name || 'three.ws').toString().slice(0, 40),- symbol: 'three',});return `/play?${q.toString()}`;}