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(agora): bound the job board and say out loud how much it is not showing

nirholas15c6a138e420
diff --git a/api/agora/[action].js b/api/agora/[action].js
index 10d9f3713..44eb3d570 100644
--- a/api/agora/[action].js
+++ b/api/agora/[action].js
@@ -11,7 +11,9 @@
// Routes (all GET):
// /api/agora/citizens?profession=&status=&kind=&limit=
// The population — world-renderable citizens (projection).
-// /api/agora/board?maxItems=&network=&maxPrice=
+// /api/agora/board?maxItems=&network=&maxPrice=&asset=
+// (maxPrice is ATOMIC units: 10000 = 0.01 USDC. asset takes a symbol or
+// the raw contract/mint address.)
// The live job board — open AgenC tasks (projected, still-open) + every
// x402 bazaar service as a claimable Fetcher job (real, populated now).
// /api/agora/pulse
@@ -29,7 +31,13 @@ import { cors, json, method, error, wrap, serverError } from '../_lib/http.js';
import { limits, clientIp } from '../_lib/rate-limit.js';
import { sql } from '../_lib/db.js';
import { isUuid } from '../_lib/validate.js';
-import { Bazaar, filterByMaxPrice, filterByNetwork } from '../_lib/x402/bazaar-client.js';
+// Mask URL-embedded credentials (Helius/RPC `?api-key=`, bearer tokens) before an
+// error message reaches a log sink: a Solana web3.js network error carries the
+// keyed RPC URL, so logging its raw `.message` on a best-effort catch would spill
+// HELIUS_API_KEY. Shared with act.js and the 5xx sink in http.js so every Agora
+// path masks identically.
+import { redactUrlSecrets as redactSecrets } from '../_lib/scrub-secrets.js';
+import { Bazaar, filterByMaxPrice, filterByNetwork, parseAtomicAmount } from '../_lib/x402/bazaar-client.js';
import { assembleTaskLive } from '../_lib/agora-task-live.js';
// Terminal-kind sets + type helpers are the labour engine's single source of
// truth (workers/agora-citizens/policy.js) — the board's open lane and the
@@ -37,18 +45,6 @@ import { assembleTaskLive } from '../_lib/agora-task-live.js';
// import the very same constants rather than re-declaring them here.
import { EXCLUSIVE_TERMINAL_KINDS, MULTI_TERMINAL_KINDS, isArenaType, isGuildType } from '../../workers/agora-citizens/policy.js';
-// Redact URL credentials (Helius/RPC `?api-key=`, bearer tokens, secrets) from an
-// error message before it reaches a log sink. A Solana web3.js network error
-// embeds the keyed RPC URL, so logging its raw `.message` on a best-effort catch
-// would spill the RPC key (HELIUS_API_KEY) into Vercel logs. Keeps the rest of the
-// message for debugging; only the credential value is masked.
-function redactSecrets(text) {
- return String(text ?? '').replace(
- /([?&](?:api[-_]?key|access[-_]?token|token|secret|key|auth)=)[^&\s"'`]+/gi,
- '$1REDACTED',
- );
-}
-
// The only coin Agora denominates in. Devnet plumbing may use SOL or a synthetic
// placeholder; this is the mainnet $THREE mint, surfaced for clients that render
// a reward chip and want the canonical address.
@@ -189,6 +185,12 @@ async function handleCitizens(req, res) {
async function handleBoard(req, res) {
const q = req.query || {};
const maxItems = clampInt(q.maxItems, 60, 1, 500);
+ // `maxPrice` is an atomic cap. Reject a malformed one here: inside the bazaar
+ // lane's own try it would be swallowed as an outage and report an empty board
+ // (`empty:true`) while 500+ real services exist, a dishonest empty state.
+ if (q.maxPrice != null && parseAtomicAmount(q.maxPrice) === null) {
+ return error(res, 400, 'validation_error', 'maxPrice must be an atomic integer amount (e.g. 10000 = 0.01 USDC)');
+ }
// Lane 1 — open AgenC tasks (projected from real on-chain postings + hires).
// The "still open" predicate is PER TYPE: an Exclusive posting closes on its
@@ -314,11 +316,25 @@ async function handleBoard(req, res) {
errors.push({ source: 'x402', error: redactSecrets(err?.message) || 'bazaar_unavailable' });
}
+ // `maxItems` bounds the BOARD, not just each facilitator's page loop. Bazaar
+ // pages per facilitator, so a union across several of them overshoots the cap
+ // (573 services for maxItems=60 before this slice) and every consumer (the
+ // 3D marker pool most of all) pays for a payload it never asked for. AgenC
+ // tasks are the scarce lane and always keep their slots; the x402 lane fills
+ // what's left, and the honest totals ship alongside so a client can say
+ // "showing 60 of 573" rather than silently pretending it has everything.
+ const serviceTotal = services.length;
+ const serviceBudget = Math.max(0, maxItems - tasks.length);
+ if (serviceTotal > serviceBudget) services = services.slice(0, serviceBudget);
+
res.setHeader('cache-control', 'public, max-age=15, stale-while-revalidate=60');
return json(res, 200, {
ok: true,
openTaskCount: tasks.length,
serviceCount: services.length,
+ serviceTotal,
+ maxItems,
+ truncated: serviceTotal > services.length,
tasks,
services,
errors,
diff --git a/src/agora/README.md b/src/agora/README.md
index b2c23ceeb..c5964a3c7 100644
--- a/src/agora/README.md
+++ b/src/agora/README.md
@@ -48,6 +48,7 @@ Deep links: `?task=<pda>`, `?arena=<pda>`, `?guild=<pda>` (plus `&cluster=`) ope
| [citizen-avatar.js](citizen-avatar.js) | `CitizenPopulation`, `professionColor`, `buildLabelSprite` | The animated crowd with name + profession labels |
| [economy-layer.js](economy-layer.js) | `mountEconomyLayer` | Single mount point wiring board + ticker + FX to one pulse poll |
| [job-board.js](job-board.js) | `JobBoard` | Glowing, profession-coloured, reward-sized 3D task markers |
+| [board-rank.js](board-rank.js) | `rankBoardItems`, `MARKER_BUDGET`, `ROSTER_BUDGET` | Which open jobs earn a marker: on-chain bounties first, then reward order, capped with an honest overflow count |
| [economy-fx.js](economy-fx.js) | `EconomyFx` | The completion moment: coin arc, reputation tick, deliverable plinth |
| [pulse-feed.js](pulse-feed.js) | `PulseFeed` | Deduped, backing-off poll of `/api/agora/board` + `/api/agora/pulse`; pauses when the tab is hidden |
| [ticker.js](ticker.js) | `Ticker` | HUD economy readout + click-to-focus narration feed |
@@ -74,7 +75,7 @@ Style modules ([agora.css](agora.css), [economy-layer.css.js](economy-layer.css.
All under [api/agora/[action].js](../../api/agora/%5Baction%5D.js) (reads) and [api/agora/act.js](../../api/agora/act.js) (writes):
- `GET /api/agora/citizens` : the world-renderable population
-- `GET /api/agora/board` : open AgenC tasks + x402 bazaar services as claimable jobs
+- `GET /api/agora/board` : open AgenC tasks + x402 bazaar services as claimable jobs. `maxItems` (default 60) bounds the whole board, not just each facilitator's page loop; the response carries `serviceTotal` and `truncated` so a client can report the real size of the open economy while rendering a bounded slice of it
- `GET /api/agora/pulse` : population breakdown, 24h flows, top earners, narration
- `GET /api/agora/passport?id=|agentPda=|agentId=` : one citizen's living passport
- `POST /api/agora/act` : `join`, `post-task`, `hire`, `claim`, `complete`, `vouch` (session auth + CSRF + spend policy + idempotency)
diff --git a/src/agora/board-rank.js b/src/agora/board-rank.js
new file mode 100644
index 000000000..dfc1f60ac
--- /dev/null
+++ b/src/agora/board-rank.js
@@ -0,0 +1,73 @@
+// Board ranking + budgets: which open jobs earn a 3D marker.
+//
+// /api/agora/board unions two lanes: scarce on-chain AgenC bounties and the x402
+// bazaar catalog, which is large and grows on its own (hundreds of live services
+// on a normal day). Rendering a glowing marker per item is what "legible at a
+// glance" must NOT mean: past a couple of dozen the board stops reading as a
+// board, the markers stack into a tower well above the kiosk, and the GPU pays
+// for geometry nobody can parse anyway.
+//
+// So the board has a budget, and this module decides who spends it:
+// • AgenC bounties outrank x402 services. They're the scarce lane, they carry
+// escrow and a claimant, and they're what the Commons is actually about.
+// • Inside a lane, the biggest reward wins the slot, the same value signal the
+// marker size already encodes, so the cap keeps the headline work visible.
+// • Ties keep the server's order, so a steady board doesn't reshuffle between
+// polls and markers stay put.
+//
+// The overflow count is returned, never swallowed: the roster states "+N more
+// open jobs" so a capped board reads as capped, not as the whole economy.
+//
+// Deliberately free of Three.js and DOM imports so the selection rule is
+// unit-testable on its own (tests/agora-board-rank.test.js).
+
+// A marker is a lit sphere + additive glow sprite + beam. Two dozen reads as a
+// busy board and lays out as four rows of six above the kiosk; more is noise.
+export const MARKER_BUDGET = 24;
+
+// The accessible roster is cheap HTML, so it carries more than the 3D board:
+// enough to scroll through real work without building a thousand buttons.
+export const ROSTER_BUDGET = 40;
+
+function isOnchainTask(item) {
+ // AgenC postings carry a task PDA; x402 services are tagged at the source.
+ if (item?.source === 'x402') return false;
+ return Boolean(item?.taskPda || item?.taskId);
+}
+
+// Rank the merged board and split it into the marker set, the roster set, and an
+// honest overflow count.
+//
+// `magnitudeOf` maps a reward object to a comparable number (job-board.js passes
+// professions.js's rewardMagnitude); it is injected so this module stays free of
+// the Three.js-importing helpers.
+export function rankBoardItems(items, opts = {}) {
+ const list = Array.isArray(items) ? items.filter(Boolean) : [];
+ const markerBudget = opts.markerBudget ?? MARKER_BUDGET;
+ const rosterBudget = opts.rosterBudget ?? ROSTER_BUDGET;
+ const magnitudeOf = opts.magnitudeOf || (() => 0);
+
+ const ranked = list
+ .map((item, index) => ({
+ item,
+ index,
+ lane: isOnchainTask(item) ? 0 : 1,
+ magnitude: Number(magnitudeOf(item.reward)) || 0,
+ }))
+ .sort((a, b) => (
+ a.lane - b.lane
+ || b.magnitude - a.magnitude
+ || a.index - b.index
+ ))
+ .map((entry) => entry.item);
+
+ const markers = ranked.slice(0, Math.max(0, markerBudget));
+ const roster = ranked.slice(0, Math.max(0, rosterBudget));
+ return {
+ markers,
+ roster,
+ total: ranked.length,
+ hiddenFromRoster: Math.max(0, ranked.length - roster.length),
+ hiddenFromBoard: Math.max(0, ranked.length - markers.length),
+ };
+}
diff --git a/src/agora/economy-layer.css.js b/src/agora/economy-layer.css.js
index 7bddc5605..882c6b4db 100644
--- a/src/agora/economy-layer.css.js
+++ b/src/agora/economy-layer.css.js
@@ -63,6 +63,12 @@ export const ECON_LAYER_CSS = `
-webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.agora-econ-board-item-meta { font-size: 11.5px; color: var(--econ-dim); }
+/* Overflow line: the board renders a bounded set of markers, so the roster says
+ out loud how much open work it isn't showing. Never a silent cap. */
+.agora-econ-board-more {
+ font-size: 11.5px; color: var(--econ-dim); text-align: center;
+ padding: 7px 10px 3px; font-variant-numeric: tabular-nums;
+}
/* Arena / Guild type badge (Task 09) — a small inline tag on a multi-worker task. */
.agora-econ-board-badge {
display: inline-flex; align-items: center; gap: 3px;
diff --git a/src/agora/job-board.js b/src/agora/job-board.js
index 359b3c3b1..4b4848cf9 100644
--- a/src/agora/job-board.js
+++ b/src/agora/job-board.js
@@ -1,6 +1,7 @@
import * as THREE from 'three';
import { professionThreeColor, professionColor, professionLabelFor, rewardMagnitude, rewardMarkerScale, rewardChip } from './professions.js';
import { isArena, isGuild, isMultiWorker, taskTypeBadge, ARENA_COLOR, GUILD_COLOR } from './task-types.js';
+import { rankBoardItems } from './board-rank.js';
// The board marker + roster tint an Arena red-hot and a Guild collaborative-green
// (Task 09), overriding the profession accent, so a multi-worker task reads as a
@@ -197,8 +198,21 @@ export class JobBoard {
...(Array.isArray(board?.services) ? board.services : []),
];
this._tasks = tasks;
- this._reconcileMarkers(tasks);
- this._renderRoster(tasks);
+
+ // The x402 lane is a live catalog of hundreds of services; a marker each
+ // would tower over the kiosk and burn frames on geometry nobody can read.
+ // Rank by lane then reward, spend the marker budget on the headline work,
+ // and carry the overflow count so the roster can say so out loud.
+ const ranked = rankBoardItems(tasks, { magnitudeOf: rewardMagnitude });
+
+ // `serviceTotal` is the count BEFORE the API's own maxItems slice, so a
+ // truncated payload still reports the true size of the open economy.
+ const serverTotal = (board?.openTaskCount ?? (board?.tasks?.length || 0))
+ + (board?.serviceTotal ?? (board?.services?.length || 0));
+ this._hiddenCount = Math.max(0, serverTotal - ranked.roster.length);
+
+ this._reconcileMarkers(ranked.markers);
+ this._renderRoster(ranked.roster);
}
_reconcileMarkers(tasks) {
@@ -289,6 +303,14 @@ export class JobBoard {
}
_disposeMarker(marker) {
+ // A hovered task can be claimed out from under the pointer between polls.
+ // Drop the hover first, or update() keeps a tooltip glued to a marker that
+ // no longer exists.
+ const key = this._meshIndex.get(marker.core.uuid);
+ if (key != null && this._hoverKey === key) {
+ this._hoverKey = null;
+ this._tip.hidden = true;
+ }
this._meshIndex.delete(marker.core.uuid);
this.group.remove(marker.group);
marker.coreGeo.dispose();
@@ -299,10 +321,11 @@ export class JobBoard {
}
_renderRoster(tasks) {
- this._count.textContent = tasks.length ? ` · ${tasks.length}` : '';
+ const total = tasks.length + (this._hiddenCount || 0);
+ this._count.textContent = total ? ` · ${total}` : '';
this._list.innerHTML = '';
- this._empty.hidden = tasks.length > 0;
- this._list.hidden = tasks.length === 0;
+ this._empty.hidden = total > 0;
+ this._list.hidden = total === 0;
for (const task of tasks) {
const key = taskKey(task);
@@ -336,6 +359,14 @@ export class JobBoard {
li.appendChild(btn);
this._list.appendChild(li);
}
+
+ // Never let a capped board read as the whole economy.
+ if (this._hiddenCount > 0) {
+ const more = document.createElement('li');
+ more.className = 'agora-econ-board-more';
+ more.textContent = `+${this._hiddenCount} more open ${this._hiddenCount === 1 ? 'job' : 'jobs'} in the bazaar`;
+ this._list.appendChild(more);
+ }
}
// ── Raycast routing (called by the economy layer's single picker) ─────────
@@ -397,7 +428,10 @@ export class JobBoard {
// Keep the tooltip glued to its marker.
if (this._hoverKey) {
const marker = this._markers.get(this._hoverKey);
- if (marker) {
+ if (!marker) {
+ this._hoverKey = null;
+ this._tip.hidden = true;
+ } else {
const s = this.ctx.worldToScreen(marker.anchor);
if (s.visible) {
this._tip.style.transform = `translate(-50%, -100%) translate(${s.x}px, ${s.y - 14}px)`;
@@ -409,6 +443,21 @@ export class JobBoard {
}
}
+ // Live prefers-reduced-motion change (the OS toggle, no reload). Settle every
+ // animated value on its calm resting state so the board stops mid-bob instead
+ // of freezing wherever the last animated frame left it.
+ setReducedMotion(on) {
+ this.reducedMotion = !!on;
+ if (!this.reducedMotion) return;
+ for (const marker of this._markers.values()) {
+ marker.core.position.y = 0;
+ marker.glow.position.y = 0;
+ marker.glowMat.opacity = 0.85;
+ marker.coreMat.emissiveIntensity = 1.4;
+ }
+ if (this._strip) this._strip.material.opacity = 0.85;
+ }
+
dispose() {
for (const marker of this._markers.values()) this._disposeMarker(marker);
this._markers.clear();
diff --git a/tests/agora-board-rank.test.js b/tests/agora-board-rank.test.js
new file mode 100644
index 000000000..26e380ad5
--- /dev/null
+++ b/tests/agora-board-rank.test.js
@@ -0,0 +1,77 @@
+import { describe, it, expect } from 'vitest';
+import { rankBoardItems, MARKER_BUDGET, ROSTER_BUDGET } from '../src/agora/board-rank.js';
+
+// The board merges a scarce on-chain lane with the x402 bazaar catalog, which is
+// large and grows on its own (573 live services against a maxItems=60 request is
+// what prompted this module). These tests pin the two properties the Commons
+// depends on: the 3D marker pool stays bounded, and the overflow is reported
+// rather than swallowed.
+
+const magnitudeOf = (reward) => Number(reward?.amountAtomic || 0);
+
+function service(name, amountAtomic) {
+ return { source: 'x402', title: name, resource: `https://x.test/${name}`, reward: { amountAtomic } };
+}
+function bounty(name, amountAtomic) {
+ return { taskPda: `pda-${name}`, title: name, profession: 'sculptor', reward: { amountAtomic } };
+}
+
+describe('rankBoardItems', () => {
+ it('bounds the marker set to the budget while keeping the roster larger', () => {
+ const items = Array.from({ length: 573 }, (_, i) => service(`svc-${i}`, 1000 + i));
+ const ranked = rankBoardItems(items, { magnitudeOf });
+
+ expect(ranked.markers).toHaveLength(MARKER_BUDGET);
+ expect(ranked.roster).toHaveLength(ROSTER_BUDGET);
+ expect(ranked.total).toBe(573);
+ expect(ranked.hiddenFromBoard).toBe(573 - MARKER_BUDGET);
+ expect(ranked.hiddenFromRoster).toBe(573 - ROSTER_BUDGET);
+ });
+
+ it('gives on-chain bounties the slots ahead of every x402 service', () => {
+ // The services are far richer on paper; the scarce lane still outranks them.
+ const items = [
+ service('rich-a', 10_000_000),
+ service('rich-b', 9_000_000),
+ bounty('small-bounty', 5),
+ ];
+ const ranked = rankBoardItems(items, { magnitudeOf, markerBudget: 2 });
+
+ expect(ranked.markers[0].title).toBe('small-bounty');
+ expect(ranked.markers[1].title).toBe('rich-a');
+ });
+
+ it('orders within a lane by reward, biggest first', () => {
+ const items = [service('a', 10), service('b', 900), service('c', 50)];
+ const ranked = rankBoardItems(items, { magnitudeOf });
+ expect(ranked.markers.map((m) => m.title)).toEqual(['b', 'c', 'a']);
+ });
+
+ it('keeps server order on ties so a steady board does not reshuffle', () => {
+ const items = [service('a', 100), service('b', 100), service('c', 100)];
+ const first = rankBoardItems(items, { magnitudeOf }).markers.map((m) => m.title);
+ const second = rankBoardItems(items, { magnitudeOf }).markers.map((m) => m.title);
+ expect(first).toEqual(['a', 'b', 'c']);
+ expect(second).toEqual(first);
+ });
+
+ it('treats a missing or unparseable reward as zero, never NaN ordering', () => {
+ const items = [service('no-reward'), service('paid', 42)];
+ items[0].reward = null;
+ const ranked = rankBoardItems(items, { magnitudeOf });
+ expect(ranked.markers.map((m) => m.title)).toEqual(['paid', 'no-reward']);
+ });
+
+ it('returns an honest empty shape for an empty board', () => {
+ const ranked = rankBoardItems([], { magnitudeOf });
+ expect(ranked.markers).toEqual([]);
+ expect(ranked.roster).toEqual([]);
+ expect(ranked.total).toBe(0);
+ expect(ranked.hiddenFromBoard).toBe(0);
+ });
+
+ it('tolerates a non-array payload and null entries', () => {
+ expect(rankBoardItems(null, { magnitudeOf }).total).toBe(0);
+ expect(rankBoardItems([null, service('a', 1), undefined], { magnitudeOf }).total).toBe(1);
+ });
+});