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(aixbt): classify upstream failures once so every door answers the same envelope
nirholas1d6211bf707d
diff --git a/api/_lib/aixbt.js b/api/_lib/aixbt.jsindex b0465549c..2c4bde97e 100644--- a/api/_lib/aixbt.js+++ b/api/_lib/aixbt.js@@ -66,6 +66,49 @@ export class AixbtNotConfiguredError extends Error {}}+export const AIXBT_SETUP_HINT =+ 'Set AIXBT_API_KEY (full aixbt.tech subscription or an x402 key pass from https://api.aixbt.tech/x402/v2/api-keys).';++/**+ * Classify an aixbt failure into the envelope every door should answer with.+ *+ * One classifier, every door: api/aixbt/* renders it through respondAixbtError,+ * and the /api/v1/market/* handlers rethrow it through the gateway's fail().+ * Keeping it here is what stops the two surfaces from drifting again — the v1+ * doors used to relay aixbt's raw 401 straight to a caller of a public,+ * credential-free endpoint (live on three.ws until this was fixed), telling+ * them to authenticate against a door they hold no key to, while /api/aixbt/*+ * had already mapped that case to a 503.+ *+ * @param {any} err error thrown by this module's request path+ * @returns {{ status: number, code: string, message: string, setup?: string } | null}+ * null for a genuine internal fault, which the caller must sanitize.+ */+export function mapAixbtFailure(err) {+ if (err?.code === 'aixbt_not_configured') {+ return { status: 503, code: err.code, message: err.message, setup: AIXBT_SETUP_HINT };+ }+ const status = Number(err?.status) || 502;+ // aixbt rejecting OUR server-side key is a deployment fault, never the+ // caller's. It is the same class of failure as a missing key, so it gets the+ // same 503 + actionable setup hint. The `aixbt_unauthorized` code is+ // preserved so existing clients keep their typed branch.+ if (status === 401 || status === 403) {+ return {+ status: 503,+ code: 'aixbt_unauthorized',+ message: 'aixbt rejected this deployment key (expired, revoked, or below the plan this read needs)',+ setup: AIXBT_SETUP_HINT,+ };+ }+ // 4xx and "upstream is the fault" (502/503/504/429) carry their descriptive+ // code + message; only genuine internal faults get sanitized.+ if (err?.code && (status < 500 || status === 502 || status === 503 || status === 504)) {+ return { status, code: err.code, message: err.message || 'aixbt request failed' };+ }+ return null;+}+function buildUrl(path, query) {const url = new URL(`${env.AIXBT_API_BASE}${path}`);for (const [k, v] of Object.entries(query || {})) {diff --git a/api/aixbt/_shared.js b/api/aixbt/_shared.jsindex 969937175..49d413ad1 100644--- a/api/aixbt/_shared.js+++ b/api/aixbt/_shared.js@@ -5,36 +5,18 @@// the UI can render an actionable empty state instead of a dead error.import { error, serverError } from '../_lib/http.js';--const SETUP_HINT =- 'Set AIXBT_API_KEY (full aixbt.tech subscription or an x402 key pass from https://api.aixbt.tech/x402/v2/api-keys).';+import { mapAixbtFailure } from '../_lib/aixbt.js';export function respondAixbtError(res, err) {- if (err?.code === 'aixbt_not_configured') {- return error(res, 503, err.code, err.message, { setup: SETUP_HINT });- }- const status = Number(err?.status) || 502;- // aixbt rejecting OUR server-side key is a deployment fault, never the- // caller's: /api/aixbt/* takes no client credential, so relaying the raw- // 401/403 would tell a client to authenticate against a door it holds no- // key to (and a bare 401 with no WWW-Authenticate is malformed besides).- // It is the same class of failure as a missing key, so it gets the same- // 503 + actionable setup hint. The `aixbt_unauthorized` code is preserved- // so existing clients keep their typed branch.- if (status === 401 || status === 403) {- return error(- res,- 503,- 'aixbt_unauthorized',- 'aixbt rejected this deployment key (expired, revoked, or below the plan this read needs)',- { setup: SETUP_HINT },- );- }- // 4xx and "upstream is the fault" (502/503/504/429) carry their descriptive- // code + message; only genuine internal faults get the sanitized 5xx- // treatment.- if (err?.code && (status < 500 || status === 502 || status === 503 || status === 504)) {- return error(res, status, err.code, err.message || 'aixbt request failed');- }- return serverError(res, 500, 'aixbt_error', err);+ // The classification itself lives in api/_lib/aixbt.js so this door and the+ // /api/v1/market/* doors answer the same failure the same way.+ const mapped = mapAixbtFailure(err);+ if (!mapped) return serverError(res, 500, 'aixbt_error', err);+ return error(+ res,+ mapped.status,+ mapped.code,+ mapped.message,+ mapped.setup ? { setup: mapped.setup } : undefined,+ );}