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(api): answer 400 on an unparseable cursor instead of a 500 or an empty page
nirholasd75b10a1b609
diff --git a/api/_lib/validate.js b/api/_lib/validate.jsindex 60f58271e..33ea6b452 100644--- a/api/_lib/validate.js+++ b/api/_lib/validate.js@@ -172,6 +172,21 @@ export function isUuid(value) {return typeof value === 'string' && UUID_RE.test(value);}+// Pagination / stream cursors arrive as caller-controlled strings and end up+// interpolated into a `::timestamptz` cast. Postgres rejects anything it cannot+// parse, so an unvalidated cursor turns a typo into either a 500 (the handler+// lets the query error bubble) or a permanently empty result (the handler+// swallows it) — both wrong answers to what is plainly a client fault. Normalize+// here: a parseable instant comes back in ISO form, ready to hand straight to+// the cast; anything else comes back null so the caller can answer 400.+export function isoTimestamp(value) {+ if (typeof value !== 'string') return null;+ const trimmed = value.trim();+ if (!trimmed) return null;+ const ms = Date.parse(trimmed);+ return Number.isNaN(ms) ? null : new Date(ms).toISOString();+}+export function isValidSolanaAddress(address) {return typeof address === 'string' && /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(address);}diff --git a/api/oracle/action-stream.js b/api/oracle/action-stream.jsindex e277be8b4..bb345ca46 100644--- a/api/oracle/action-stream.js+++ b/api/oracle/action-stream.js@@ -18,9 +18,10 @@* It passes `?since=<iso>` on reconnect so no events are missed.*/-import { cors, method, rateLimited } from '../_lib/http.js';+import { cors, method, error, rateLimited } from '../_lib/http.js';import { limits, clientIp } from '../_lib/rate-limit.js';import { sql } from '../_lib/db.js';+import { isoTimestamp } from '../_lib/validate.js';const NETWORKS = new Set(['mainnet', 'devnet']);const MODES = new Set(['live', 'simulate']);@@ -111,9 +112,18 @@ export default async function handleActionStream(req, res) {const url = new URL(req.url, `http://${req.headers.host || 'x'}`);const network = NETWORKS.has(url.searchParams.get('network')) ? url.searchParams.get('network') : 'mainnet';const mode = MODES.has(url.searchParams.get('mode')) ? url.searchParams.get('mode') : null;- // Client passes `since` on reconnect to avoid gaps.+ // Client passes `since` on reconnect to avoid gaps. Validate it BEFORE the+ // stream headers go out: an unparseable cursor makes every `::timestamptz`+ // cast below reject, both poll queries swallow that rejection, and the client+ // then holds an open stream that emits hello + ping forever and never a single+ // action. EventSource reconnects with the same bad cursor, so the stall is+ // permanent and silent. A 400 tells the caller what is actually wrong.const sinceParam = url.searchParams.get('since');- let cursor = sinceParam ? sinceParam : new Date(Date.now() - 10_000).toISOString();+ const since = sinceParam ? isoTimestamp(sinceParam) : null;+ if (sinceParam && !since) {+ return error(res, 400, 'validation_error', 'since must be an ISO 8601 timestamp');+ }+ let cursor = since || new Date(Date.now() - 10_000).toISOString();let settleCursor = cursor;res.writeHead(200, {diff --git a/api/oracle/activity.js b/api/oracle/activity.jsindex 178b2f9ca..a6440b2c6 100644--- a/api/oracle/activity.js+++ b/api/oracle/activity.js@@ -16,10 +16,10 @@* agents acting on conviction in real time.*/-import { cors, json, method, wrap, rateLimited } from '../_lib/http.js';+import { cors, json, method, wrap, error, rateLimited } 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 { isUuid, isoTimestamp } from '../_lib/validate.js';const NETWORKS = new Set(['mainnet', 'devnet']);const TIERS = new Set(['prime', 'strong', 'lean', 'watch', 'avoid']);@@ -55,7 +55,11 @@ function shapeRow(r) {}export default wrap(async (req, res) => {- if (cors(req, res, { methods: 'GET,OPTIONS' })) return;+ // `origins: '*'` like every other public oracle read (feed, batch, categories,+ // backtest): this is an unauthenticated, credential-free feed, and the default+ // allowlist would otherwise block the same third-party dashboards that can+ // already read /api/oracle/feed.+ if (cors(req, res, { methods: 'GET,OPTIONS', origins: '*' })) return;if (!method(req, res, ['GET'])) return;const rl = await limits.publicIp(clientIp(req));@@ -68,7 +72,13 @@ export default wrap(async (req, res) => {const tier = TIERS.has(params.get('tier')) ? params.get('tier') : null;const outcome = OUTCOMES.has(params.get('outcome')) ? params.get('outcome') : null;const agentId = isUuid(params.get('agent_id') || '') ? params.get('agent_id') : null;- const before = params.get('before') || null;+ // A malformed cursor is a client fault, so answer 400 rather than letting the+ // `::timestamptz` cast reject inside the query and surface as an opaque 500.+ const beforeRaw = params.get('before');+ const before = beforeRaw ? isoTimestamp(beforeRaw) : null;+ if (beforeRaw && !before) {+ return error(res, 400, 'validation_error', 'before must be an ISO 8601 timestamp');+ }const rows = await sql`selectdiff --git a/api/play/builds.js b/api/play/builds.jsindex ab9bef884..3e04c7a10 100644--- a/api/play/builds.js+++ b/api/play/builds.js@@ -21,8 +21,21 @@ const MAX_BLOCKS = 6000;// screenshot can't bloat a coin's storage.const MAX_THUMB_CHARS = 280_000; // ~210 KB decoded+// The mint is not just an identifier here: it becomes the Redis key a coin's+// featured builds live under. So its FORMAT is checked, not only its length,+// which is what api/play/population.js does with the same coin-world identifier+// and what billboard-store.js does with the same kind of per-coin Redis key.+// Base58 covers Solana worlds, 0x-hex covers the EVM ones; a length check alone+// let any 32-to-64-character string mint a key from an unauthenticated publish.+const SOLANA_MINT_RE = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;+const EVM_ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;+function isCoinWorld(v) {+ const s = String(v || '').trim();+ return SOLANA_MINT_RE.test(s) || EVM_ADDRESS_RE.test(s);+}+const publishSchema = z.object({- mint: z.string().trim().min(32).max(64),+ mint: z.string().trim().refine(isCoinWorld),title: z.string().trim().max(60).optional().default(''),author: z.string().trim().max(32).optional().default(''),blocks: z.number().int().min(0).max(MAX_BLOCKS),@@ -40,7 +53,7 @@ export default wrap(async (req, res) => {const rl = await limits.publicIp(clientIp(req));if (!rl.success) return rateLimited(res, rl);const mint = String(req.query?.mint || '').trim();- if (!mint || mint.length < 32 || mint.length > 64) {+ if (!isCoinWorld(mint)) {return error(res, 400, 'bad_mint', 'a valid coin mint is required');}try {