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
feat: update API lib, trust reputation, cron jobs, and marketplace action
nirholascaeb816911d9
diff --git a/api/_lib/http.js b/api/_lib/http.jsindex 081be0614..ecbdf96f9 100644--- a/api/_lib/http.js+++ b/api/_lib/http.js@@ -437,6 +437,33 @@ export function wrap(handler) {};}+// Wrap cron handlers with DB-unavailability awareness.+//+// When the database is unreachable (wrong credentials, connection refused, etc.)+// every cron invocation would otherwise bubble a NeonDbError to wrap(), which+// logs `[api] unhandled` and fires a sendOpsAlert per invocation — turning a+// single misconfigured DATABASE_URL into a sustained ops-alert storm. wrapCron+// intercepts DB-unavailable errors before they reach wrap(), logs a single warn,+// and returns 200 { ok: false, reason: 'db_unavailable' } so Vercel doesn't+// count the cron as a hard failure. Non-DB errors re-throw to wrap() so genuine+// bugs still surface through normal alerting.+export function wrapCron(handler) {+ return wrap(async (req, res, ...rest) => {+ try {+ await handler(req, res, ...rest);+ } catch (err) {+ if (isDbUnavailableError(err)) {+ console.warn('[cron] db unavailable — skipping tick:', err.message);+ if (!res.headersSent && !res.writableEnded) {+ json(res, 200, { ok: false, reason: 'db_unavailable' });+ }+ return;+ }+ throw err;+ }+ });+}+export function method(req, res, allowed) {const m = req.method || 'GET';// HEAD must be allowed wherever GET is allowed (RFC 9110 §9.3.2).diff --git a/api/_lib/trust/reputation-store.js b/api/_lib/trust/reputation-store.jsindex 056876f95..9def32401 100644--- a/api/_lib/trust/reputation-store.js+++ b/api/_lib/trust/reputation-store.js@@ -18,7 +18,7 @@// The score is ALWAYS the same pure computation (computeReputation) over real// inputs — this module only persists and schedules it, never invents a number.-import { sql } from '../db.js';+import { sql, isDbUnavailableError } from '../db.js';import { getAgentReputation, REPUTATION_VERSION } from './wallet-reputation.js';// A stored score older than this is treated as stale by the access layer's fast@@ -52,7 +52,8 @@ function ensureTable() {await sql`create index if not exists agent_reputation_scores_computed_idx on agent_reputation_scores (computed_at asc)`;return true;})().catch((err) => {- console.error('[reputation-store] ensureTable failed:', err?.message || err);+ if (isDbUnavailableError(err)) console.warn('[reputation-store] ensureTable deferred (db unavailable):', err?.message || err);+ else console.error('[reputation-store] ensureTable failed:', err?.message || err);_ensured = null;return false;});diff --git a/api/cron/avaturn-seed-cron.js b/api/cron/avaturn-seed-cron.jsindex 817eb09d8..6163067ba 100644--- a/api/cron/avaturn-seed-cron.js+++ b/api/cron/avaturn-seed-cron.js@@ -20,7 +20,7 @@// lane. Gated behind AVATURN_SEED_ENABLED so it's a no-op until an operator// opts in (cadence is set by the cron schedule in vercel.json — start at 1/min).-import { json, method, wrap } from '../_lib/http.js';+import { json, method, wrap, wrapCron } from '../_lib/http.js';import { env } from '../_lib/env.js';import { sql } from '../_lib/db.js';import { constantTimeEquals } from '../_lib/crypto.js';@@ -148,7 +148,7 @@ async function runOnce() {}}-export default wrap(async (req, res) => {+export default wrapCron(async (req, res) => {if (!method(req, res, ['GET'])) return;if (!requireCron(req, res)) return;diff --git a/api/cron/forge-seed-cron.js b/api/cron/forge-seed-cron.jsindex 0c64bbc39..470d968ad 100644--- a/api/cron/forge-seed-cron.js+++ b/api/cron/forge-seed-cron.js@@ -17,7 +17,7 @@// Free NVIDIA NIM lane (draft, ~22 s) is always used — zero vendor spend.// MAX_CONCURRENT_PENDING caps in-flight jobs so a slow lane never builds debt.-import { json, method, wrap } from '../_lib/http.js';+import { json, method, wrap, wrapCron } from '../_lib/http.js';import { env } from '../_lib/env.js';import { sql } from '../_lib/db.js';import { constantTimeEquals } from '../_lib/crypto.js';@@ -367,7 +367,7 @@ function toTitle(prompt) {// ── Handler ───────────────────────────────────────────────────────────────────-export default wrap(async (req, res) => {+export default wrapCron(async (req, res) => {if (!method(req, res, ['GET'])) return;if (!requireCron(req, res)) return;diff --git a/api/cron/pulse-tick.js b/api/cron/pulse-tick.jsindex d6714a539..898e702a5 100644--- a/api/cron/pulse-tick.js+++ b/api/cron/pulse-tick.js@@ -5,7 +5,7 @@// agent pool and has those agents transact with one another on-chain, so the live// money feed reflects real wallet activity.-import { json, method, wrap } from '../_lib/http.js';+import { json, method, wrapCron } from '../_lib/http.js';import { env } from '../_lib/env.js';import { constantTimeEquals } from '../_lib/crypto.js';import { runCirculationTick } from '../_lib/circulation.js';@@ -25,7 +25,7 @@ function requireCron(req, res) {return true;}-export default wrap(async (req, res) => {+export default wrapCron(async (req, res) => {if (!method(req, res, ['GET', 'POST'])) return;if (!requireCron(req, res)) return;diff --git a/api/marketplace/[action].js b/api/marketplace/[action].jsindex 0da8176f5..ce8663f63 100644--- a/api/marketplace/[action].js+++ b/api/marketplace/[action].js@@ -17,7 +17,7 @@* Routed via vercel.json — see top of file path patterns.*/-import { sql } from '../_lib/db.js';+import { sql, isDbUnavailableError } from '../_lib/db.js';import { authenticateBearer, extractBearer, getSessionUser } from '../_lib/auth.js';import { cors, error, json, method, readJson, wrap, rateLimited } from '../_lib/http.js';import { publicUrl } from '../_lib/r2.js';@@ -581,6 +581,9 @@ async function handleList(req, res, url) {LIMIT ${limit + 1}::int OFFSET ${offset}::int`,]);+ } else if (isDbUnavailableError(err)) {+ console.warn('[marketplace/list] db unavailable:', err?.message);+ return error(res, 503, 'service_unavailable', 'Database temporarily unavailable — retry shortly');} else {console.error('[marketplace/list]', err?.code, err?.message || err);return error(res, 500, 'db_error', 'Failed to load marketplace listing');