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: resolve all production errors from 2026-05-27 Vercel logs
overstepping1c45b751f01e
diff --git a/api/_lib/http.js b/api/_lib/http.jsindex 1c5be5e77..7defdb9f7 100644--- a/api/_lib/http.js+++ b/api/_lib/http.js@@ -144,7 +144,7 @@ export function wrap(handler) {console.error('[api] unhandled', err);captureException(err, { url: req.url, method: req.method });}- if (!res.writableEnded) {+ if (!res.headersSent && !res.writableEnded) {if (err.code === 'validation_error' && Array.isArray(err.issues)) {validationError(res, err);} else {diff --git a/api/_lib/migrations/20260527000000_schema_fixes.sql b/api/_lib/migrations/20260527000000_schema_fixes.sqlnew file mode 100644index 000000000..650338f06--- /dev/null+++ b/api/_lib/migrations/20260527000000_schema_fixes.sql@@ -0,0 +1,18 @@+-- Schema fixes for issues surfaced in production logs 2026-05-27.+-- Idempotent: all statements use IF NOT EXISTS / IF EXISTS / TRY patterns.++BEGIN;++-- 1. x_triggers: add agent_id column that was in CREATE TABLE but missing from+-- the ALTER TABLE rollforward, so deployments that already had the table+-- did not receive it.+ALTER TABLE x_triggers ADD COLUMN IF NOT EXISTS agent_id uuid REFERENCES agent_identities(id) ON DELETE SET NULL;+CREATE INDEX IF NOT EXISTS x_triggers_agent_id ON x_triggers(agent_id) WHERE enabled;++-- 2. avatar_regen_jobs: make source_avatar_id nullable.+-- The reconstruct flow (build from photos, no source avatar) inserts null+-- here legitimately. The NOT NULL constraint was only valid for regenerate+-- jobs; relax it and let application logic enforce presence when relevant.+ALTER TABLE avatar_regen_jobs ALTER COLUMN source_avatar_id DROP NOT NULL;++COMMIT;diff --git a/api/avatars/[id]/[action].js b/api/avatars/[id]/[action].jsindex 4e5cbbd28..d866f3352 100644--- a/api/avatars/[id]/[action].js+++ b/api/avatars/[id]/[action].js@@ -15,7 +15,7 @@ import {import { sql } from '../../_lib/db.js';import { cors, json, method, readJson, wrap, error } from '../../_lib/http.js';import { limits, clientIp } from '../../_lib/rate-limit.js';-import { parse } from '../../_lib/validate.js';+import { parse, isUuid } from '../../_lib/validate.js';import {readStorageMode,storageModeSchema,@@ -443,6 +443,7 @@ async function handleVersions(req, res) {const id = req.query?.id;if (!id) return error(res, 400, 'invalid_request', 'id required');+ if (!isUuid(id)) return error(res, 400, 'invalid_request', 'id must be a valid UUID');const auth = await resolveVersionsAuth(req);diff --git a/api/avatars/_actions.js b/api/avatars/_actions.jsindex 498697998..825eb580a 100644--- a/api/avatars/_actions.js+++ b/api/avatars/_actions.js@@ -766,7 +766,7 @@ const handleReconstruct = wrap(async (req, res) => {insert into avatar_regen_jobs(job_id, user_id, source_avatar_id, mode, params, status, provider, ext_job_id, created_at, updated_at)values- (${jobId}, ${userId}, ${body.sourceAvatarId ?? jobId}, ${'reconstruct'}, ${JSON.stringify(params)}, 'queued', ${provider.name}, ${submission.extJobId ?? null}, now(), now())+ (${jobId}, ${userId}, ${null}, ${'reconstruct'}, ${JSON.stringify(params)}, 'queued', ${provider.name}, ${submission.extJobId ?? null}, now(), now())`;return json(res, 202, {ok: true,diff --git a/api/chat.js b/api/chat.jsindex af00f4c05..2a2594ada 100644--- a/api/chat.js+++ b/api/chat.js@@ -430,13 +430,12 @@ function pickProvider(requested, model, userKeys = {}) {// position 0 so the happy path is one entry.//// Why per-provider sibling models: OpenRouter's `:free` tier rate-limits per-// model. Falling over from llama-3.3-70b:free → llama-3.1-8b:free → mistral--// 7b:free recovers from a single upstream burst without paying. Last resort-// is paid Anthropic so the user still gets a response.+// model. Falling over from llama-3.3-70b:free → mistral-7b:free recovers+// from a single upstream burst without paying. Last resort is paid Anthropic+// so the user still gets a response.const FALLBACK_SIBLINGS = {openrouter: ['meta-llama/llama-3.3-70b-instruct:free',- 'meta-llama/llama-3.1-8b-instruct:free','mistralai/mistral-7b-instruct:free',],groq: ['llama-3.3-70b-versatile', 'llama-3.1-8b-instant'],diff --git a/api/cron/[name].js b/api/cron/[name].jsindex f884c3971..de948a7ea 100644--- a/api/cron/[name].js+++ b/api/cron/[name].js@@ -2829,13 +2829,31 @@ async function handleRunXTriggers(req, res) {}const started = Date.now();- const rows = await sql`- select id, user_id, agent_id, kind, config, auto_publish, last_fired_at, last_state- from x_triggers- where enabled = true- order by coalesce(last_fired_at, '1970-01-01'::timestamptz) asc- limit 200- `;+ let rows;+ try {+ rows = await sql`+ select id, user_id, agent_id, kind, config, auto_publish, last_fired_at, last_state+ from x_triggers+ where enabled = true+ order by coalesce(last_fired_at, '1970-01-01'::timestamptz) asc+ limit 200+ `;+ } catch (err) {+ if (err.code === '42703') {+ rows = await sql`+ select id, user_id, null::uuid as agent_id, kind, config,+ coalesce(auto_publish, false) as auto_publish,+ last_fired_at,+ null::jsonb as last_state+ from x_triggers+ where enabled = true+ order by coalesce(last_fired_at, '1970-01-01'::timestamptz) asc+ limit 200+ `;+ } else {+ throw err;+ }+ }const report = { evaluated: 0, fired: 0, skipped: 0, errors: 0 };for (const t of rows) {diff --git a/api/llm/anthropic.js b/api/llm/anthropic.jsindex 908dcd94f..3c96fb595 100644--- a/api/llm/anthropic.js+++ b/api/llm/anthropic.js@@ -49,9 +49,8 @@ const MODELS = {'claude-haiku-4-5-20251001': { kind: 'anthropic', envKey: 'ANTHROPIC_API_KEY' },// OpenRouter free tier (no per-token cost; daily rate cap shared across host).- // All three are tool-call capable in OpenRouter's catalog.+ // All are tool-call capable in OpenRouter's catalog.'meta-llama/llama-3.3-70b-instruct:free': { kind: 'openai', provider: 'openrouter', envKey: 'OPENROUTER_API_KEY' },- 'meta-llama/llama-3.1-8b-instruct:free': { kind: 'openai', provider: 'openrouter', envKey: 'OPENROUTER_API_KEY' },'openai/gpt-oss-120b:free': { kind: 'openai', provider: 'openrouter', envKey: 'OPENROUTER_API_KEY' },'nousresearch/hermes-3-llama-3.1-405b:free': { kind: 'openai', provider: 'openrouter', envKey: 'OPENROUTER_API_KEY' },diff --git a/api/marketplace/[action].js b/api/marketplace/[action].jsindex e3bdcecce..3f2201a8a 100644--- a/api/marketplace/[action].js+++ b/api/marketplace/[action].js@@ -179,21 +179,43 @@ async function handleTheme(req, res) {const weekNum = Math.floor(Date.now() / (7 * 24 * 3600 * 1000));const cat = THEME_CATEGORIES[weekNum % THEME_CATEGORIES.length];- const rows = await sql`- SELECT a.id, a.name, a.description, a.category, a.tags, a.skills,- a.views_count, a.forks_count,- COALESCE((SELECT AVG(rating)::numeric(3,2) FROM agent_reviews r WHERE r.agent_id = a.id), 0) AS rating_avg,- COALESCE((SELECT COUNT(*) FROM agent_reviews r WHERE r.agent_id = a.id), 0) AS rating_count,- a.published_at, a.created_at,- v.storage_key AS avatar_storage_key, v.is_public AS avatar_public,- v.thumbnail_key- FROM agent_identities a- LEFT JOIN avatars v ON v.id = a.avatar_id AND v.deleted_at IS NULL- WHERE a.is_published = true AND a.deleted_at IS NULL- AND (${cat.slug === 'general'} OR a.category = ${cat.slug})- ORDER BY a.views_count DESC, rating_avg DESC- LIMIT 8- `;+ let rows;+ try {+ rows = await sql`+ SELECT a.id, a.name, a.description, a.category, a.tags, a.skills,+ a.views_count, a.forks_count,+ COALESCE((SELECT AVG(rating)::numeric(3,2) FROM agent_reviews r WHERE r.agent_id = a.id), 0) AS rating_avg,+ COALESCE((SELECT COUNT(*) FROM agent_reviews r WHERE r.agent_id = a.id), 0) AS rating_count,+ a.published_at, a.created_at,+ v.storage_key AS avatar_storage_key, v.is_public AS avatar_public,+ v.thumbnail_key+ FROM agent_identities a+ LEFT JOIN avatars v ON v.id = a.avatar_id AND v.deleted_at IS NULL+ WHERE a.is_published = true AND a.deleted_at IS NULL+ AND (${cat.slug === 'general'} OR a.category = ${cat.slug})+ ORDER BY a.views_count DESC, rating_avg DESC+ LIMIT 8+ `;+ } catch (err) {+ if (err.code === '42P01') {+ rows = await sql`+ SELECT a.id, a.name, a.description, a.category, a.tags, a.skills,+ a.views_count, a.forks_count,+ 0::numeric AS rating_avg, 0::int AS rating_count,+ a.published_at, a.created_at,+ v.storage_key AS avatar_storage_key, v.is_public AS avatar_public,+ v.thumbnail_key+ FROM agent_identities a+ LEFT JOIN avatars v ON v.id = a.avatar_id AND v.deleted_at IS NULL+ WHERE a.is_published = true AND a.deleted_at IS NULL+ AND (${cat.slug === 'general'} OR a.category = ${cat.slug})+ ORDER BY a.views_count DESC+ LIMIT 8+ `;+ } else {+ throw err;+ }+ }const agents = rows.map((row) => ({id: row.id,@@ -409,8 +431,52 @@ async function handleList(req, res, url) {`,]);} catch (err) {- console.error('[marketplace/list]', err?.message || err);- return error(res, 500, 'db_error', 'Failed to load marketplace listing');+ if (err.code === '42P01') {+ [, rows] = await sql.transaction([+ sql`SET LOCAL statement_timeout = '8000'`,+ sql`+ SELECT ai.id, ai.name, ai.description, ai.category, ai.tags, ai.avatar_id, ai.user_id,+ ai.forks_count, ai.views_count, ai.published_at, ai.created_at, ai.skills,+ av.thumbnail_key,+ u.display_name AS author_name,+ EXISTS (+ SELECT 1 FROM agent_skill_prices asp+ WHERE asp.agent_id = ai.id AND asp.is_active = true+ ) AS has_paid_skills,+ COALESCE((SELECT count(*)::int FROM skill_purchases sp+ WHERE sp.agent_id = ai.id AND sp.status = 'confirmed'), 0) AS buyers_total,+ COALESCE((SELECT count(*)::int FROM skill_purchases sp+ WHERE sp.agent_id = ai.id AND sp.status = 'confirmed'+ AND sp.created_at > now() - interval '24 hours'), 0) AS buyers_24h,+ 0::numeric AS rating_avg,+ 0::int AS rating_count,+ ap.amount AS asset_price_amount,+ ap.currency_mint AS asset_price_currency_mint,+ ap.chain AS asset_price_chain,+ ap.mint_decimals AS asset_price_mint_decimals+ FROM agent_identities ai+ LEFT JOIN avatars av ON av.id = ai.avatar_id AND av.deleted_at IS NULL+ LEFT JOIN users u ON u.id = ai.user_id+ LEFT JOIN asset_prices ap+ ON ap.item_type = 'agent' AND ap.item_id = ai.id AND ap.is_active = true+ WHERE ai.is_published = true+ AND ai.deleted_at IS NULL+ AND ai.name !~* ${AGENT_AUTONAMED_RE_SQL}+ AND (${cat}::text IS NULL OR ai.category = ${cat})+ AND (+ ${qLike}::text IS NULL+ OR ai.name ILIKE ${qLike}+ OR ai.description ILIKE ${qLike}+ OR EXISTS (SELECT 1 FROM unnest(ai.tags) t WHERE t ILIKE ${qLike})+ )+ ORDER BY ${orderBy}+ LIMIT ${limit + 1}::int OFFSET ${offset}::int+ `,+ ]);+ } else {+ console.error('[marketplace/list]', err?.message || err);+ return error(res, 500, 'db_error', 'Failed to load marketplace listing');+ }}const hasMore = rows.length > limit;