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(marketplace): agent purchase flow, demo/firstparty avatar seeding + wallet auth refinements

nirholas4f2a74be194a
diff --git a/api/_lib/demo-avatars.js b/api/_lib/demo-avatars.js
index 9562cd79c..5eb6d9075 100644
--- a/api/_lib/demo-avatars.js
+++ b/api/_lib/demo-avatars.js
@@ -43,7 +43,7 @@ export const DEMO_AVATARS = [
demoItem({ id: "avatar_demo_disk_cz", slug: "demo-cz", name: "CZ", description: "CZ — stylized humanoid with idle pose, ready for chat overlays.", tags: ["humanoid","character","community"], glbUrl: "https://three.ws/avatars/cz.glb", image: null, sortDate: "2025-04-01T00:00:00.000Z", attribution: {"handle":"three.ws","displayName":"three.ws starter","url":"https://three.ws","license":"CC-BY 4.0"}, author: {"handle":"three.ws","displayName":"three.ws starter","profileUrl":"https://three.ws"} }),
demoItem({ id: "avatar_demo_disk_ansem", slug: "demo-ansem", name: "Ansem", description: "Ansem — trader persona for chart-watchers and crypto Twitter.", tags: ["humanoid","community","trader"], glbUrl: "https://three.ws/avatars/default.glb", image: null, sortDate: "2025-03-31T23:00:00.000Z", attribution: {"handle":"three.ws","displayName":"three.ws starter","url":"https://three.ws","license":"CC-BY 4.0"}, author: {"handle":"three.ws","displayName":"three.ws starter","profileUrl":"https://three.ws"} }),
demoItem({ id: "avatar_demo_disk_boss", slug: "demo-boss", name: "Boss", description: "Boss — for the one running the room. Soldier rig with locomotion.", tags: ["humanoid","rigged","animated","community"], glbUrl: "https://three.ws/animations/soldier.glb", image: null, sortDate: "2025-03-31T22:00:00.000Z", attribution: {"handle":"threejs","displayName":"three.js examples","url":"https://github.com/mrdoob/three.js","license":"MIT"}, author: {"handle":"threejs","displayName":"three.js examples","profileUrl":"https://github.com/mrdoob/three.js"} }),
- demoItem({ id: "avatar_demo_disk_vernington", slug: "demo-vernington", name: "Vernington", description: "Vernington — the senior of the Vern lineage, full-body ready-player rig.", tags: ["humanoid","rigged","avatar","community"], glbUrl: "https://three.ws/avatars/readyplayerme.glb", image: null, sortDate: "2025-03-31T21:00:00.000Z", attribution: {"handle":"threejs","displayName":"three.js examples","url":"https://github.com/mrdoob/three.js","license":"MIT"}, author: {"handle":"threejs","displayName":"three.js examples","profileUrl":"https://github.com/mrdoob/three.js"} }),
+ demoItem({ id: "avatar_demo_disk_vernington", slug: "demo-vernington", name: "Vernington", description: "Vernington — the senior of the Vern lineage, full-body humanoid rig.", tags: ["humanoid","rigged","avatar","community"], glbUrl: "https://three.ws/avatars/readyplayerme.glb", image: null, sortDate: "2025-03-31T21:00:00.000Z", attribution: {"handle":"threejs","displayName":"three.js examples","url":"https://github.com/mrdoob/three.js","license":"MIT"}, author: {"handle":"threejs","displayName":"three.js examples","profileUrl":"https://github.com/mrdoob/three.js"} }),
demoItem({ id: "avatar_demo_disk_saga", slug: "demo-saga", name: "Saga", description: "Saga — mobile-native, expressive robot rig with idle, walk, jump, dance clips.", tags: ["robot","animated","rigged","community"], glbUrl: "https://three.ws/animations/robotexpressive.glb", image: null, sortDate: "2025-03-31T20:00:00.000Z", attribution: {"handle":"threejs","displayName":"three.js examples","url":"https://github.com/mrdoob/three.js","license":"MIT"}, author: {"handle":"threejs","displayName":"three.js examples","profileUrl":"https://github.com/mrdoob/three.js"} }),
demoItem({ id: "avatar_demo_disk_claude", slug: "demo-claude", name: "Claude", description: "Claude — calm, thoughtful AI persona on a clean walking rig.", tags: ["humanoid","rigged","animated","community","ai"], glbUrl: "https://three.ws/avatars/cesium-man.glb", image: null, sortDate: "2025-03-31T19:00:00.000Z", attribution: {"handle":"khronos","displayName":"Khronos Group","url":"https://github.com/KhronosGroup/glTF-Sample-Assets","license":"CC-BY 4.0"}, author: {"handle":"khronos","displayName":"Khronos Group","profileUrl":"https://github.com/KhronosGroup/glTF-Sample-Assets"} }),
demoItem({ id: "avatar_demo_disk_3d", slug: "demo-3d", name: "3D", description: "3D — meta avatar for the platform itself, fully articulated sci-fi rig.", tags: ["robot","rigged","animated","community","meta"], glbUrl: "https://three.ws/avatars/brainstem.glb", image: null, sortDate: "2025-03-31T18:00:00.000Z", attribution: {"handle":"khronos","displayName":"Khronos Group","url":"https://github.com/KhronosGroup/glTF-Sample-Assets","license":"CC-BY 4.0"}, author: {"handle":"khronos","displayName":"Khronos Group","profileUrl":"https://github.com/KhronosGroup/glTF-Sample-Assets"} }),
diff --git a/api/auth/wallets/[action].js b/api/auth/wallets/[action].js
index 2c339dc8f..53c42488c 100644
--- a/api/auth/wallets/[action].js
+++ b/api/auth/wallets/[action].js
@@ -544,6 +544,7 @@ async function handleUnlinkWallet(req, res, address) {
const session = await getSessionUser(req);
if (!session) return error(res, 401, 'unauthorized', 'sign in required');
+ if (!(await requireCsrf(req, res, session.id))) return;
if (!address) return error(res, 400, 'missing_address', 'address required');
diff --git a/api/marketplace/purchase-as-agent.js b/api/marketplace/purchase-as-agent.js
index d66c58e1f..8c098a0b0 100644
--- a/api/marketplace/purchase-as-agent.js
+++ b/api/marketplace/purchase-as-agent.js
@@ -131,21 +131,32 @@ export default wrap(async (req, res) => {
return error(res, 400, 'unsupported_chain', `only solana auto-purchase supported, got '${price.chain}'`);
}
- // Daily spending cap check
+ // Daily spending cap — fast pre-check. This is a cheap early rejection; the
+ // authoritative, race-safe enforcement happens AFTER the pending row is
+ // inserted (see below). On its own this check is a TOCTOU: concurrent
+ // purchases all read the same pre-spend SUM and each pass, collectively
+ // blowing past the cap and spending real funds beyond the user's limit.
const limitUsdc = buyer.meta?.auto_purchase_daily_limit_usdc;
- if (typeof limitUsdc === 'number' && limitUsdc > 0) {
- const limitAtomics = BigInt(Math.round(limitUsdc * 10 ** USDC_DECIMALS));
- const todayStart = new Date();
- todayStart.setUTCHours(0, 0, 0, 0);
+ const capEnabled = typeof limitUsdc === 'number' && limitUsdc > 0;
+ const limitAtomics = capEnabled ? BigInt(Math.round(limitUsdc * 10 ** USDC_DECIMALS)) : 0n;
+ const dayStart = () => {
+ const d = new Date();
+ d.setUTCHours(0, 0, 0, 0);
+ return d.toISOString();
+ };
+ const sumSpentAtomics = async () => {
const [spent] = await sql`
SELECT COALESCE(SUM(amount), 0)::bigint AS total
FROM skill_purchases
WHERE user_id = ${auth.userId}
- AND created_at >= ${todayStart.toISOString()}
+ AND created_at >= ${dayStart()}
AND currency_mint = ${price.currency_mint}
AND status NOT IN ('failed', 'expired')
`;
- const spentAtomics = BigInt(spent?.total ?? 0);
+ return BigInt(spent?.total ?? 0);
+ };
+ if (capEnabled) {
+ const spentAtomics = await sumSpentAtomics();
if (spentAtomics + BigInt(price.amount) > limitAtomics) {
log('purchase_as_agent.spend_cap_exceeded', {
buyer_agent_id, skill, spent: spentAtomics.toString(),
@@ -204,6 +215,26 @@ export default wrap(async (req, res) => {
amount: price.amount, is_self_dealing: isSelfDealing,
});
+ // Authoritative, race-safe spend-cap enforcement. Our pending row is now
+ // persisted and counted by sumSpentAtomics(), so re-reading the SUM here
+ // includes every concurrent in-flight purchase. If the total (already
+ // including this row) exceeds the cap we void this row and abort BEFORE
+ // broadcasting any transaction — concurrent requests can no longer each pass
+ // a stale pre-check and overspend. Fails safe: under a tie, contending
+ // requests abort rather than risk exceeding the user's configured limit.
+ if (capEnabled) {
+ const spentAtomics = await sumSpentAtomics();
+ if (spentAtomics > limitAtomics) {
+ await sql`UPDATE skill_purchases SET status = 'failed' WHERE id = ${pur.id} AND status = 'pending'`;
+ log('purchase_as_agent.spend_cap_exceeded_reserved', {
+ purchase_id: pur.id, buyer_agent_id, skill,
+ spent: spentAtomics.toString(), limit_atomics: limitAtomics.toString(),
+ });
+ return error(res, 402, 'spend_cap_exceeded',
+ `daily spend cap of ${limitUsdc} USDC reached — increase meta.auto_purchase_daily_limit_usdc or wait until UTC midnight`);
+ }
+ }
+
// Build, sign, and submit the SPL transferChecked
const connection = solanaConnection({ url: SOLANA_RPC, commitment: 'confirmed' });
const mintKey = new PublicKey(price.currency_mint);
diff --git a/scripts/gen-demo-avatars.mjs b/scripts/gen-demo-avatars.mjs
index 556f761ec..f382033d8 100644
--- a/scripts/gen-demo-avatars.mjs
+++ b/scripts/gen-demo-avatars.mjs
@@ -31,7 +31,7 @@ const ON_DISK = [
{ name: 'CZ', slug: 'cz', path: '/avatars/cz.glb', tags: ['humanoid', 'character', 'community'], desc: 'CZ — stylized humanoid with idle pose, ready for chat overlays.' },
{ name: 'Ansem', slug: 'ansem', path: '/avatars/default.glb', tags: ['humanoid', 'community', 'trader'], desc: 'Ansem — trader persona for chart-watchers and crypto Twitter.' },
{ name: 'Boss', slug: 'boss', path: '/animations/soldier.glb', tags: ['humanoid', 'rigged', 'animated', 'community'], desc: 'Boss — for the one running the room. Soldier rig with locomotion.', attr: 'threejs' },
- { name: 'Vernington', slug: 'vernington', path: '/avatars/readyplayerme.glb', tags: ['humanoid', 'rigged', 'avatar', 'community'], desc: 'Vernington — the senior of the Vern lineage, full-body ready-player rig.', attr: 'threejs' },
+ { name: 'Vernington', slug: 'vernington', path: '/avatars/readyplayerme.glb', tags: ['humanoid', 'rigged', 'avatar', 'community'], desc: 'Vernington — the senior of the Vern lineage, full-body humanoid rig.', attr: 'threejs' },
{ name: 'Saga', slug: 'saga', path: '/animations/robotexpressive.glb', tags: ['robot', 'animated', 'rigged', 'community'], desc: 'Saga — mobile-native, expressive robot rig with idle, walk, jump, dance clips.', attr: 'threejs' },
{ name: 'Claude', slug: 'claude', path: '/avatars/cesium-man.glb', tags: ['humanoid', 'rigged', 'animated', 'community', 'ai'], desc: 'Claude — calm, thoughtful AI persona on a clean walking rig.', attr: 'khronos' },
{ name: '3D', slug: '3d', path: '/avatars/brainstem.glb', tags: ['robot', 'rigged', 'animated', 'community', 'meta'], desc: '3D — meta avatar for the platform itself, fully articulated sci-fi rig.', attr: 'khronos' },
diff --git a/scripts/seed-firstparty-avatars.mjs b/scripts/seed-firstparty-avatars.mjs
index df638122b..f50157cf8 100644
--- a/scripts/seed-firstparty-avatars.mjs
+++ b/scripts/seed-firstparty-avatars.mjs
@@ -63,28 +63,21 @@ const CATALOG = [
file: 'public/avatars/realistic-female.glb',
description: 'Realistic full-body feminine avatar with PBR skin, hair, and outfit. Fully rigged for animation retargeting.',
tags: ['humanoid', 'realistic', 'photorealistic', 'rigged', 'female', 'avatar'],
- license: 'infosia/readyplayerme-Tpose (MIT)',
+ license: 'MIT (community T-pose rig)',
},
{
slug: 'kai-realistic', name: 'Kai',
file: 'public/avatars/realistic-male.glb',
description: 'Realistic full-body masculine avatar in a clean T-pose with PBR materials. Fully rigged and retarget-ready.',
tags: ['humanoid', 'realistic', 'photorealistic', 'rigged', 'male', 'avatar'],
- license: 'infosia/readyplayerme-Tpose (MIT)',
+ license: 'MIT (community T-pose rig)',
},
{
slug: 'vox-presenter', name: 'Vox',
file: 'public/avatars/realistic-halfbody.glb',
description: 'Realistic half-body presenter avatar with 18 baked facial and gesture animations — built for talking-head and assistant UIs.',
tags: ['humanoid', 'realistic', 'rigged', 'animated', 'presenter', 'avatar'],
- license: 'readyplayerme/visage (MIT)',
- },
- {
- slug: 'riven-rpm', name: 'Riven',
- file: 'public/avatars/readyplayerme.glb',
- description: 'Realistic full-body ready-player avatar with PBR skin and apparel. Rigged humanoid, retarget-ready.',
- tags: ['humanoid', 'realistic', 'rigged', 'avatar'],
- license: 'three.js example (MIT)',
+ license: 'MIT (community half-body rig)',
},
{
slug: 'michelle-dancer', name: 'Michelle',
diff --git a/src/marketplace.js b/src/marketplace.js
index b4f1b83dd..c8d0872c5 100644
--- a/src/marketplace.js
+++ b/src/marketplace.js
@@ -1121,6 +1121,9 @@ function renderGrid() {
navTo(`/marketplace/agents/${card.dataset.id}`);
});
card.addEventListener('keydown', (e) => {
+ // A focused inner link (See in 3D, on-chain badge) handles its own
+ // activation — don't hijack Enter/Space to the detail page.
+ if (e.target.closest('a')) return;
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
navTo(`/marketplace/agents/${card.dataset.id}`);