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(tournaments): route the per-tournament actions that filesystem routing never matched
nirholasdcebe147d030
diff --git a/api/tournaments/[id]/[action].js b/api/tournaments/[id]/[action].jsnew file mode 100644index 000000000..dbb113c55--- /dev/null+++ b/api/tournaments/[id]/[action].js@@ -0,0 +1,18 @@+/**+ * Social Trading Arena — sub-route entry point for /api/tournaments/:id/<action>.+ *+ * GET /api/tournaments/:id/stream → SSE live rank changes+ * POST /api/tournaments/:id/join → enter an agent you own+ * POST /api/tournaments/:id/withdraw → withdraw an agent you own+ * POST /api/tournaments/:id/close → freeze + attest final standings (creator)+ * POST /api/tournaments/:id/settle → pay $THREE prizes (creator)+ *+ * Filesystem routing only matches a `[param].js` file on the LAST path segment, so+ * `api/tournaments/[id].js` answered /api/tournaments/:id and nothing beneath it:+ * every action above 404'd, which killed the Arena's Join button and left the live+ * board's EventSource reconnecting against a 404 forever. This file is the segment+ * that makes them reachable. The dispatch itself stays in [id].js, which reads the+ * action off the request path, so there is exactly one copy of the logic.+ */++export { default } from '../[id].js';diff --git a/api/tournaments/index.js b/api/tournaments/index.jsindex 54aed4b29..1a53ebeb3 100644--- a/api/tournaments/index.js+++ b/api/tournaments/index.js@@ -76,13 +76,33 @@ function atomicsToThree(atomics, decimals) {return Number(`${a / div}.${(a % div).toString().padStart(decimals, '0')}`);}-function threeToAtomics(amount, decimals) {- const n = Number(amount);- if (!Number.isFinite(n) || n < 0) return null;- // Parse via string to avoid float drift on the fractional part.- const [whole, frac = ''] = String(n).split('.');+const DECIMAL_RE = /^\d+(?:\.\d+)?$/;+// Far above $THREE's 1B supply. It exists to keep the value in plain decimal form,+// because JS renders anything past 1e21 in exponential notation.+const MAX_PRIZE_THREE = 1e15;++/**+ * Decimal $THREE to atomics, or null when the caller sent something that is not a+ * non-negative decimal amount. The conversion runs on TEXT, never on a float+ * round-trip: String(1e21) and String(0.0000001) are exponential notation, which+ * BigInt refuses, so both of those (plausible) request bodies used to escape the+ * validator and crash the handler with a 500 instead of being answered with a 400.+ * A numeric string is read as written, so precision beyond a double survives.+ */+export function threeToAtomics(amount, decimals) {+ let text;+ if (typeof amount === 'number') {+ if (!Number.isFinite(amount) || amount < 0 || amount > MAX_PRIZE_THREE) return null;+ text = amount.toFixed(decimals); // plain decimal even for exponential input+ } else if (typeof amount === 'string') {+ text = amount.trim();+ } else {+ return null;+ }+ if (!DECIMAL_RE.test(text) || Number(text) > MAX_PRIZE_THREE) return null;+ const [whole, frac = ''] = text.split('.');const fracPadded = (frac + '0'.repeat(decimals)).slice(0, decimals);- return BigInt(whole || '0') * 10n ** BigInt(decimals) + BigInt(fracPadded || '0');+ return BigInt(whole) * 10n ** BigInt(decimals) + BigInt(fracPadded || '0');}function validSplits(splits) {@@ -176,7 +196,14 @@ export default wrap(async (req, res) => {let prize_splits = [];if (bracket === 'prize' && body.prize_pool_three != null) {const atomics = threeToAtomics(body.prize_pool_three, decimals);- if (atomics == null) return error(res, 400, 'invalid_prize', 'prize_pool_three must be a non-negative number');+ if (atomics == null) {+ return error(+ res,+ 400,+ 'invalid_prize',+ `prize_pool_three must be a non-negative decimal amount of $THREE, at most ${MAX_PRIZE_THREE}`,+ );+ }prizeAtomics = atomics;if (prizeAtomics > 0n) {prize_splits = Array.isArray(body.prize_splits) && body.prize_splits.lengthdiff --git a/api/vaults/ledger.js b/api/vaults/ledger.jsindex ad0e2fce5..03b081728 100644--- a/api/vaults/ledger.js+++ b/api/vaults/ledger.js@@ -2,7 +2,7 @@//// The vault's immutable audit trail: every open, deposit, redeem, trade, fee,// drawdown halt, pause/resume and terms change, newest first, with the on-chain-// signature where one exists. Public — this is the transparency that makes backing+// signature where one exists. Public: this is the transparency that makes backing// rational.import { cors, json, method, error, wrap } from '../_lib/http.js';