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
fix(agent-api): answer account-wide reads in two queries instead of self-429ing
nirholas376929cb16a2
diff --git a/api/agent/launcher.js b/api/agent/launcher.jsindex 63dc8af2e..9681ac481 100644--- a/api/agent/launcher.js+++ b/api/agent/launcher.js@@ -6,6 +6,11 @@* configs = agent_launcher_configs rows for the owned agent* coins = last 50 agent_launched_coins for the agent, newest first*+ * GET /api/agent/launcher?all=1+ * Account-wide view: every launcher config and launched coin across all+ * agents the caller owns, in two queries. Rows carry agent_name and+ * agent_image. Returns { configs, coins, scope: 'all' }.+ ** POST /api/agent/launcher* UPSERT a launcher config (one row per agent per network).* Returns { ok: true, config: {...} }@@ -62,7 +67,14 @@ export default wrap(async (req, res) => {const userId = await resolveUserId(req);if (!userId) return error(res, 401, 'unauthorized', 'authentication required');- const rl = await limits.authIp(clientIp(req));+ // Reads fire on every dashboard load and on each Capabilities poll tick, so+ // they use the generous authed-read bucket. Routing them through the strict+ // credential bucket (50/10m, shared with login and register) is what made a+ // single Capabilities load 429 itself; see the authedReadIp note in+ // api/_lib/rate-limit.js. Writes keep the credential bucket.+ const rl = req.method === 'GET'+ ? await limits.authedReadIp(clientIp(req))+ : await limits.authIp(clientIp(req));if (!rl.success) return rateLimited(res, rl);if (req.method === 'GET') return getConfigs(req, res, userId);@@ -75,10 +87,18 @@ export default wrap(async (req, res) => {// ── GET ──────────────────────────────────────────────────────────────────────+const truthyParam = (v) => v === '1' || v === 'true';+async function getConfigs(req, res, userId) {const { searchParams } = new URL(req.url, 'http://localhost');const agentId = searchParams.get('agentId');+ // all=1 answers for every agent the caller owns in two queries. The+ // Capabilities command center needs a whole-account view; without this it+ // had to fan out one request per agent (2N per refresh, every 30s), which+ // scaled linearly with the roster and drowned the per-IP budget.+ if (!agentId && truthyParam(searchParams.get('all'))) return getAllConfigs(res, userId);+if (!agentId) return error(res, 400, 'missing_agent_id', 'agentId is required');if (!isUuid(agentId)) return error(res, 400, 'invalid_agent_id', 'agentId must be a uuid');if (!(await assertOwnsAgent(userId, agentId))) {@@ -103,6 +123,32 @@ async function getConfigs(req, res, userId) {return json(res, 200, { configs, coins });}+// Account-wide variant of getConfigs. Rows carry the owning agent's display+// fields so a caller rendering a cross-agent table needs no second lookup.+async function getAllConfigs(res, userId) {+ const [configs, coins] = await Promise.all([+ sql`+ SELECT c.*, a.name AS agent_name,+ COALESCE(a.profile_image_url, a.avatar_url) AS agent_image+ FROM agent_launcher_configs c+ JOIN agent_identities a ON a.id = c.agent_id AND a.deleted_at IS NULL+ WHERE a.user_id = ${userId}+ ORDER BY c.created_at ASC+ LIMIT 200+ `,+ sql`+ SELECT k.*, a.name AS agent_name,+ COALESCE(a.profile_image_url, a.avatar_url) AS agent_image+ FROM agent_launched_coins k+ JOIN agent_identities a ON a.id = k.agent_id AND a.deleted_at IS NULL+ WHERE a.user_id = ${userId}+ ORDER BY k.created_at DESC+ LIMIT 200+ `,+ ]);+ return json(res, 200, { configs, coins, scope: 'all' });+}+// ── POST action=trigger — fire now ───────────────────────────────────────────async function triggerNow(req, res, userId, body) {diff --git a/api/agent/market-maker.js b/api/agent/market-maker.jsindex 53fae5539..35735c00d 100644--- a/api/agent/market-maker.js+++ b/api/agent/market-maker.js@@ -1,4 +1,7 @@// GET /api/agent/market-maker?agentId=<uuid> — list MM configs + recent trades+// GET /api/agent/market-maker?all=1 : same, across every agent the+// caller owns (rows carry+// agent_name + agent_image)// POST /api/agent/market-maker — upsert MM config// DELETE /api/agent/market-maker?id=<config_id> — disable MM config (soft-delete)//@@ -59,13 +62,25 @@ export default wrap(async (req, res) => {const auth = await resolveAuth(req);if (!auth) return error(res, 401, 'unauthorized', 'authentication required');- const rl = await limits.authIp(clientIp(req));+ // Reads fire on every dashboard load and on each Capabilities poll tick, so+ // they use the generous authed-read bucket rather than the strict credential+ // bucket (50/10m, shared with login and register); see the authedReadIp note+ // in api/_lib/rate-limit.js. Writes keep the credential bucket.+ const rl = req.method === 'GET'+ ? await limits.authedReadIp(clientIp(req))+ : await limits.authIp(clientIp(req));if (!rl.success) return rateLimited(res, rl, 'too many market-maker requests');// ── GET ───────────────────────────────────────────────────────────────────if (req.method === 'GET') {const url = new URL(req.url, 'http://x');const agentId = url.searchParams.get('agentId');+ // all=1 answers for every agent the caller owns in two queries. The+ // Capabilities command center needs a whole-account view; without it the+ // page fanned out one request per agent on every 30s poll, which scaled+ // with the roster and drowned the per-IP budget.+ const wantsAll = url.searchParams.get('all') === '1' || url.searchParams.get('all') === 'true';+ if (!agentId && wantsAll) return getAllMarkets(res, auth.userId);if (!agentId) return error(res, 400, 'validation_error', 'agentId query param required');if (!isUuid(agentId)) return error(res, 400, 'validation_error', 'agentId must be a uuid');if (!(await assertOwnsAgent(auth.userId, agentId))) {@@ -168,3 +183,29 @@ export default wrap(async (req, res) => {return json(res, 200, { ok: true, config });});++// Account-wide variant of the GET above. Rows carry the owning agent's display+// fields so a cross-agent table needs no second lookup.+async function getAllMarkets(res, userId) {+ const [configs, recent_trades] = await Promise.all([+ sql`+ SELECT c.*, a.name AS agent_name,+ COALESCE(a.profile_image_url, a.avatar_url) AS agent_image+ FROM agent_market_maker_configs c+ JOIN agent_identities a ON a.id = c.agent_id AND a.deleted_at IS NULL+ WHERE a.user_id = ${userId}+ ORDER BY c.created_at DESC+ LIMIT 200+ `,+ sql`+ SELECT t.*, a.name AS agent_name,+ COALESCE(a.profile_image_url, a.avatar_url) AS agent_image+ FROM agent_market_maker_trades t+ JOIN agent_identities a ON a.id = t.agent_id AND a.deleted_at IS NULL+ WHERE a.user_id = ${userId}+ ORDER BY t.created_at DESC+ LIMIT 200+ `,+ ]);+ return json(res, 200, { configs, recent_trades, scope: 'all' });+}diff --git a/api/sniper/strategy.js b/api/sniper/strategy.jsindex 70f6f18d7..d19e5584f 100644--- a/api/sniper/strategy.js+++ b/api/sniper/strategy.js@@ -179,7 +179,15 @@ export default wrap(async (req, res) => {const userId = await resolveUserId(req);if (!userId) return error(res, 401, 'unauthorized', 'sign in to manage the sniper');- const rl = await limits.authIp(clientIp(req));+ // GET is a session-scoped READ that fires on every dashboard page load and+ // again on each poll tick, so it belongs in the generous read bucket. Sharing+ // the strict credential bucket (50/10m, also gating login and register) is+ // what let a single Capabilities page load 429 itself and lock the user out+ // of signing in; see the authedReadIp note in api/_lib/rate-limit.js. Writes+ // stay on the credential bucket, which is what it exists to protect.+ const rl = req.method === 'POST'+ ? await limits.authIp(clientIp(req))+ : await limits.authedReadIp(clientIp(req));if (!rl.success) return rateLimited(res, rl);if (req.method === 'POST') return upsertStrategy(req, res, userId);