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(agents-live): move the batch read off the shared apiIp budget and floor its cadence
nirholas421da05313f3
diff --git a/api/agents/activity.js b/api/agents/activity.jsindex 0a8470744..160003b3e 100644--- a/api/agents/activity.js+++ b/api/agents/activity.js@@ -82,7 +82,11 @@ export default wrap(async function handleAgentsActivity(req, res) {if (cors(req, res, { methods: 'GET,POST,OPTIONS' })) return;if (!method(req, res, ['GET', 'POST'])) return;- const rl = await limits.apiIp(clientIp(req));+ // Same bucket as the sibling batch read (/api/agents/reputation-batch): this is+ // an agent-discovery read, and it must not draw down the shared `apiIp` budget+ // that the wall's own watch-intent and watch-status polls live on. One batch+ // here stands in for a page of streams, so starving it starves every card.+ const rl = await limits.agentProfileIp(clientIp(req));if (!rl.success) return rateLimited(res, rl);const raw = await readIds(req, res);diff --git a/src/agents-live.js b/src/agents-live.jsindex 3ff9f6a89..de3f7be4c 100644--- a/src/agents-live.js+++ b/src/agents-live.js@@ -976,8 +976,11 @@ function getStreamObserver() {const ACTIVITY_BATCH_MAX = 60; // matches MAX_IDS in api/agents/activity.jsconst ACTIVITY_BATCH_MS = 20_000; // refresh cadence for non-streamed cards+const ACTIVITY_MIN_GAP_MS = 2_500; // floor between batches, so fast scrolling cannot spamlet _activityTimer = null;let _activityInFlight = false;+let _activityLastAt = 0;+let _activityPending = null;// Fold a batch of DB-sourced entries into a card exactly as the SSE `log` event// would, so a batch row and a streamed row render identically.@@ -1011,6 +1014,7 @@ function applyActivityEntries(state, entries) {async function hydrateActivity(ids) {if (!ids.length || _activityInFlight) return;_activityInFlight = true;+ _activityLastAt = Date.now();try {const res = await apiFetch('/api/agents/activity', {method: 'POST',@@ -1018,7 +1022,10 @@ async function hydrateActivity(ids) {body: JSON.stringify({ ids }),allowAnonymous: true,});- if (!res.ok) return;+ // A throttled or briefly failing batch is not a dead end: the cards keep what+ // they have and the next tick asks again. Come back sooner than the normal+ // cadence so a card that has nothing yet is not left blank for 20s.+ if (!res.ok) { scheduleActivityFlush(ACTIVITY_MIN_GAP_MS * 2); return; }const { activity, casting } = await res.json();for (const [id, entries] of Object.entries(activity || {})) {const state = _cards.get(id);@@ -1034,10 +1041,20 @@ async function hydrateActivity(ids) {if (_streamed.size >= MAX_STREAMS) break;ensureStream(_cards.get(id));}- } catch { /* the cards keep whatever they last rendered */ }+ } catch { scheduleActivityFlush(ACTIVITY_MIN_GAP_MS * 2); }finally { _activityInFlight = false; }}+// Coalesce flush requests. Scrolling three pages in as many seconds fires three+// loadMore() calls, and one batch per page would burn the endpoint's rate budget+// for no benefit: the next batch covers every card the earlier ones would have.+function scheduleActivityFlush(delay) {+ const wait = Math.max(delay ?? 0, ACTIVITY_MIN_GAP_MS - (Date.now() - _activityLastAt), 0);+ if (_activityPending) return;+ if (!wait) { flushActivity(); return; }+ _activityPending = setTimeout(() => { _activityPending = null; flushActivity(); }, wait);+}+// Hydrate the cards that have no stream of their own. One batch cannot cover an// endlessly scrolled wall, so it is spent where it shows: what the viewer can// reach right now first, then anything still holding a blank terminal, then the@@ -1233,7 +1250,7 @@ async function loadMore() {agents.forEach(mountAgent);// One request gives the whole new page a real terminal straight away, before// the stream pool has reached any of it.- flushActivity();+ scheduleActivityFlush();updateStats();_arena.schedule();_showrunner?.refreshLive(); // fold the new page into the program@@ -1779,5 +1796,5 @@ if (spotlight && _cards.size) {document.addEventListener('visibilitychange', () => {if (document.hidden) { suspendStreams(); stopRotation(); }- else { resumeStreams(); flushActivity(); _showrunner?.refreshLive(); if (spotlight && _cards.size) startRotation(); }+ else { resumeStreams(); scheduleActivityFlush(); _showrunner?.refreshLive(); if (spotlight && _cards.size) startRotation(); }});