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(oracle): validate the stats, calibration and follow inputs at the boundary
nirholasd999de1f8505
diff --git a/api/oracle/agent-stats.js b/api/oracle/agent-stats.jsindex 8b78c4d99..6c1c1ffec 100644--- a/api/oracle/agent-stats.js+++ b/api/oracle/agent-stats.js@@ -35,7 +35,13 @@ export default async function handleAgentStats(req, res) {const params = new URL(req.url, 'http://x').searchParams;const agentId = params.get('agent_id') || '';const network = NETWORKS.has(params.get('network')) ? params.get('network') : 'mainnet';- const limit = Math.min(50, Math.max(1, parseInt(params.get('limit') || '20', 10)));+ // parseInt('abc') is NaN, and Math.max/min propagate it — an unparseable limit+ // used to reach the SQL `limit NaN`, which the store's read catches into an+ // empty array. The caller then got a 200 whose summary said 17 actions next to+ // an empty recent_actions and an empty by_tier. Fall back to the documented+ // default instead of shipping that contradiction.+ const limitRaw = parseInt(params.get('limit') || '20', 10);+ const limit = Number.isFinite(limitRaw) ? Math.min(50, Math.max(1, limitRaw)) : 20;if (!isUuid(agentId)) {return json(res, 400, { error: 'invalid_agent_id', message: 'agent_id must be a UUID' });@@ -66,8 +72,8 @@ export default async function handleAgentStats(req, res) {else if (a.outcome === 'loss') byTier[a.tier].losses++;}for (const t of Object.values(byTier)) {- const res = t.wins + t.losses;- t.win_rate = res > 0 ? Math.round((t.wins / res) * 100) : null;+ const resolved = t.wins + t.losses;+ t.win_rate = resolved > 0 ? Math.round((t.wins / resolved) * 100) : null;}return json(res, 200, {diff --git a/api/oracle/calibration.js b/api/oracle/calibration.jsindex d305c695e..c106e12a8 100644--- a/api/oracle/calibration.js+++ b/api/oracle/calibration.js@@ -20,7 +20,10 @@ import { sql } from '../_lib/db.js';const NETWORKS = new Set(['mainnet', 'devnet']);export default wrap(async (req, res) => {- if (cors(req, res, { methods: 'GET,OPTIONS' })) return;+ // `origins: '*'` like every other public oracle read: these win rates trace to+ // on-chain trades anyone can verify, so there is nothing here the default+ // allowlist is protecting.+ if (cors(req, res, { methods: 'GET,OPTIONS', origins: '*' })) return;if (!method(req, res, ['GET'])) return;const rl = await limits.mcpIp(clientIp(req));diff --git a/api/oracle/follow.js b/api/oracle/follow.jsindex 405a4c8b7..dc46c34cd 100644--- a/api/oracle/follow.js+++ b/api/oracle/follow.js@@ -31,6 +31,15 @@ function validateChatId(v) {return typeof v === 'string' && CHAT_ID_RE.test(v.trim());}+// JSON bodies are caller-controlled, so a field can arrive as any type. `(v ||+// '').trim()` blows up on a number or a boolean (`(123).trim is not a function`),+// which wrap() turns into a 500 for what is plainly a 400 — posting+// {"agent_id": 12345} answered internal_error. Reduce every field to a string+// here and let the validators below reject it with the right status.+function asTrimmedString(v) {+ return typeof v === 'string' ? v.trim() : '';+}+export default wrap(async (req, res) => {if (cors(req, res, { methods: 'GET,POST,DELETE,OPTIONS', origins: '*' })) return;const ip = clientIp(req);@@ -72,8 +81,8 @@ export default wrap(async (req, res) => {const body = await readJson(req).catch(() => null);if (!body) return error(res, 400, 'invalid_json', 'request body must be valid JSON');- const agentId = (body.agent_id || '').trim();- const chatId = (body.chat_id || '').trim();+ const agentId = asTrimmedString(body.agent_id);+ const chatId = asTrimmedString(body.chat_id);const network = NETWORKS.has(body.network) ? body.network : 'mainnet';const minScore = Math.min(100, Math.max(0, Number(body.min_score ?? 54) || 54));@@ -117,8 +126,8 @@ export default wrap(async (req, res) => {const body = await readJson(req).catch(() => null);if (!body) return error(res, 400, 'invalid_json', 'request body must be valid JSON');- const agentId = (body.agent_id || '').trim();- const chatId = (body.chat_id || '').trim();+ const agentId = asTrimmedString(body.agent_id);+ const chatId = asTrimmedString(body.chat_id);const network = NETWORKS.has(body.network) ? body.network : 'mainnet';if (!isUuid(agentId)) return error(res, 400, 'validation_error', 'agent_id must be a UUID');