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.

fix(play): land the population endpoint and multiplayer server work from this worktree

nirholasad4d3b71323b
diff --git a/api/play/population.js b/api/play/population.js
index 6c3af2885..8b6d5fcaa 100644
--- a/api/play/population.js
+++ b/api/play/population.js
@@ -4,6 +4,12 @@
// ?coin=<mint> narrow to one community's worlds (the /event landing page
// passes the $THREE mint so its LIVE panel counts the people
// actually at the event, not the whole platform)
+// ?by=coin also return `byCoin`, a mint → player-count map covering every
+// live world (the /play lobby paints a live "N inside" count on
+// every community card from one poll instead of one request per
+// card). Omitted from the response when the multiplayer server
+// is older than this parameter, so a caller either gets real
+// per-coin numbers or none, never invented ones.
//
// The multiplayer server is the only thing that knows: /play presence lives in
// Colyseus rooms, not in Postgres or Redis, so there is nothing here to query.
@@ -40,9 +46,26 @@ function safeCoin(raw) {
return '';
}
-async function readUpstream(base, coin) {
+// Sanitize the upstream breakdown before it is re-published. The keys are mints
+// the upstream read off live room listings, so they are shaped by whatever a
+// client passed as its `coin` join option: re-validate them here with the same
+// rule as the `?coin=` filter, and drop anything that fails or counts nobody.
+function safeByCoin(raw) {
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;
+ const out = {};
+ for (const [mint, count] of Object.entries(raw)) {
+ const key = safeCoin(mint);
+ if (!key) continue;
+ const players = Math.max(0, Math.floor(Number(count) || 0));
+ if (players > 0) out[key] = players;
+ }
+ return out;
+}
+
+async function readUpstream(base, coin, byCoin) {
const url = new URL('/population', base);
if (coin) url.searchParams.set('coin', coin);
+ if (byCoin) url.searchParams.set('by', 'coin');
const ac = new AbortController();
const timer = setTimeout(() => ac.abort(), UPSTREAM_TIMEOUT_MS);
try {
@@ -53,6 +76,7 @@ async function readUpstream(base, coin) {
return {
players: Math.max(0, Math.floor(Number(body.players) || 0)),
rooms: Math.max(0, Math.floor(Number(body.rooms) || 0)),
+ byCoin: byCoin ? safeByCoin(body.byCoin) : null,
};
} catch {
return null;
@@ -68,14 +92,16 @@ export default wrap(async (req, res) => {
const rl = await limits.publicIp(clientIp(req));
if (!rl.success) return rateLimited(res, rl);
- const coin = safeCoin(new URL(req.url, 'http://localhost').searchParams.get('coin'));
+ const params = new URL(req.url, 'http://localhost').searchParams;
+ const coin = safeCoin(params.get('coin'));
+ const wantByCoin = params.get('by') === 'coin';
const base = env.MULTIPLAYER_INTERNAL_URL;
if (!base) {
return json(res, 200, { ok: false, reason: 'unavailable', coin: coin || null });
}
- const upstream = await readUpstream(base, coin);
+ const upstream = await readUpstream(base, coin, wantByCoin);
if (!upstream) {
return json(res, 200, { ok: false, reason: 'unavailable', coin: coin || null });
}
@@ -88,5 +114,6 @@ export default wrap(async (req, res) => {
coin: coin || null,
players: upstream.players,
rooms: upstream.rooms,
+ ...(upstream.byCoin ? { byCoin: upstream.byCoin } : {}),
});
});
diff --git a/multiplayer/src/index.js b/multiplayer/src/index.js
index ffa497215..522bb4709 100644
--- a/multiplayer/src/index.js
+++ b/multiplayer/src/index.js
@@ -181,23 +181,39 @@ app.post('/internal/announce', express.json({ limit: '16kb' }), (req, res) => {
// narrows to one community's worlds, which is what the /event landing page asks
// for; without it the total spans every live world.
//
+// `?by=coin` additionally returns the per-coin breakdown as `byCoin`, a plain
+// mint → player-count map. The /play lobby renders a live "N inside" count on
+// every community card, and asking for it one coin at a time would be one HTTP
+// round trip per card on every poll; the listing is already in hand here, so the
+// breakdown costs nothing beyond the grouping. Still counts only, still no
+// identities: a mint is public information and the value is a headcount.
+//
// The three.ws API proxies this server-side (api/play/population.js), so no CORS
// header is emitted: a browser never calls it directly.
app.get('/population', async (req, res) => {
const coin = typeof req.query.coin === 'string' ? req.query.coin.trim().slice(0, 128) : '';
+ const wantByCoin = req.query.by === 'coin';
try {
const listings = await matchMaker.query({ name: 'walk_world' });
let rooms = 0;
let players = 0;
+ const byCoin = wantByCoin ? Object.create(null) : null;
for (const room of listings || []) {
if (coin && room?.coin !== coin) continue;
rooms += 1;
- players += Number(room?.clients) || 0;
+ const here = Number(room?.clients) || 0;
+ players += here;
+ // A coin's General and Holders worlds are separate room instances of the
+ // same mint (filterBy(['coin','tier'])), so both fold into one count: the
+ // card asks "how many people are in this community", not "in which tier".
+ if (byCoin && typeof room?.coin === 'string' && room.coin) {
+ byCoin[room.coin] = (byCoin[room.coin] || 0) + here;
+ }
}
// 5s of edge/CDN caching: the number moves on a human timescale and this
// runs on the same process that serves gameplay traffic.
res.set('cache-control', 'public, max-age=5');
- res.json({ ok: true, coin: coin || null, rooms, players });
+ res.json({ ok: true, coin: coin || null, rooms, players, ...(byCoin ? { byCoin } : {}) });
} catch (err) {
console.warn('[multiplayer] /population failed:', err?.message || err);
res.status(503).json({ ok: false, error: 'unavailable' });
diff --git a/pages/coin-intel.html b/pages/coin-intel.html
index d3b30f57a..61f55832d 100644
--- a/pages/coin-intel.html
+++ b/pages/coin-intel.html
@@ -1084,7 +1084,7 @@
const STAT_LABELS = ['Observed', 'Classified', 'Labeled', 'Graduated'];
const renderStats = (values) => {
$('#ci-stats').innerHTML = STAT_LABELS
- .map((l, i) => `<div class="ci-stat"><div class="v">${values[i] ?? ','}</div><div class="l">${l}</div></div>`).join('');
+ .map((l, i) => `<div class="ci-stat"><div class="v">${values[i] ?? '&mdash;'}</div><div class="l">${l}</div></div>`).join('');
};
async function loadStats() {
try {
diff --git a/src/agent-detail.css b/src/agent-detail.css
index 2865b3484..f14406fa9 100644
--- a/src/agent-detail.css
+++ b/src/agent-detail.css
@@ -1446,6 +1446,27 @@ div.ad-hero-avatar canvas {
.ad-skill-row:last-child {
border-bottom: 0;
}
+/* Arrived here from a deep link naming one skill (e.g. the Buy CTA on
+ /conversions). Marking the row is what makes the landing legible on an agent
+ selling a dozen skills; the tint fades once it has done its job. */
+.ad-skill-row--focused {
+ background: color-mix(in srgb, var(--ad-cyan) 12%, transparent);
+ box-shadow: inset 2px 0 0 var(--ad-cyan);
+ border-radius: 6px;
+ padding-left: 10px;
+ animation: ad-skill-focus-fade 2.4s ease-out 1.6s forwards;
+}
+@keyframes ad-skill-focus-fade {
+ to {
+ background: transparent;
+ box-shadow: inset 2px 0 0 transparent;
+ }
+}
+@media (prefers-reduced-motion: reduce) {
+ .ad-skill-row--focused {
+ animation: none;
+ }
+}
.ad-skill-name {
font-size: 14px;
color: var(--ad-text);