Skip to content

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.

fix: chat, livepeer inference, and bundle script updates

nirholas01cf77e4d5ec
diff --git a/api/chat.js b/api/chat.js
index 9d93d3efd..de5e35ea8 100644
--- a/api/chat.js
+++ b/api/chat.js
@@ -340,17 +340,17 @@ export default wrap(async (req, res) => {
// OpenRouter (and some OpenAI-compatible endpoints) reject tool-augmented
// requests for models whose backing provider has no function-calling
- // support, with a 404 "No endpoints found that support tool use". Retry
- // once on the same route without the action tools so the chat still
- // answers — it just can't drive 3D viewer actions for that model.
- if (upstream.status === 404 && includeTools && route.style === 'openai') {
+ // support, with a 404 "No endpoints found that support tool use".
+ // Strategy: (1) first retry same route without tools; (2) if that also
+ // 404s — or if tools weren't the issue — fall over to the next provider.
+ if (upstream.status === 404 && route.style === 'openai') {
const text = await upstream.text().catch(() => '');
- if (/tool[\s-]?use|support tools|require_parameters/i.test(text)) {
+ if (includeTools && /tool[\s-]?use|support tools|require_parameters/i.test(text)) {
console.warn(`[chat:${route.name}] ${route.model} has no tool-capable endpoint — retrying without action tools`);
includeTools = false;
continue;
}
- // Not a tool-use rejection: try the next provider, else surface it.
+ // Already tried without tools, or non-tool-use 404 — fall over to next provider.
if (routeIdx + 1 < fallbackRoutes.length) {
console.warn(`[chat:${route.name}] 404 — falling over to ${fallbackRoutes[routeIdx + 1].name}/${fallbackRoutes[routeIdx + 1].model}: ${text.slice(0, 120)}`);
routeIdx++;
diff --git a/api/inference/livepeer.js b/api/inference/livepeer.js
index bdb1b6155..ef698f973 100644
--- a/api/inference/livepeer.js
+++ b/api/inference/livepeer.js
@@ -59,7 +59,19 @@ function clampTemp(n, fallback = 0.7) {
// ── Claude leg ────────────────────────────────────────────────────────────────
async function callClaude({ prompt, max_tokens, temperature }) {
- const key = env.ANTHROPIC_API_KEY; // throws if unset — caller wraps
+ // ANTHROPIC_API_KEY is optional (env.opt) — skip the doomed request and
+ // report the missing-key state so the comparison still shows the Livepeer leg.
+ const key = env.ANTHROPIC_API_KEY;
+ if (!key) {
+ return {
+ ok: false,
+ network: 'Anthropic',
+ model: CLAUDE_MODEL,
+ latency_ms: 0,
+ error: 'missing_api_key',
+ upstream_body: 'ANTHROPIC_API_KEY is not configured',
+ };
+ }
const t0 = Date.now();
const upstream = await fetch('https://api.anthropic.com/v1/messages', {
method: 'POST',
diff --git a/scripts/bundle-api.mjs b/scripts/bundle-api.mjs
index e2f87de93..374804147 100644
--- a/scripts/bundle-api.mjs
+++ b/scripts/bundle-api.mjs
@@ -127,6 +127,14 @@ function esbuildArgs(files) {
'--platform=node',
'--target=node20',
'--format=esm',
+ // Some bundled CJS deps call `require("url")` (and other Node built-ins)
+ // internally. esbuild inlines those into the ESM output behind a
+ // `__require` shim that THROWS "Dynamic require of \"url\" is not
+ // supported" because bare ESM has no `require` in scope. Marking the
+ // offending packages external is whack-a-mole (the call sites live deep
+ // in transitive CJS deps, not just @x402). Inject a real CommonJS
+ // `require` via createRequire so the shim resolves built-ins natively.
+ `--banner:js=import { createRequire as __createRequireForBundle } from 'node:module'; const require = __createRequireForBundle(import.meta.url);`,
`--outdir=${API_DIR}`,
`--outbase=${API_DIR}`,
'--allow-overwrite',
diff --git a/scripts/fix-pump-sdk-esm.mjs b/scripts/fix-pump-sdk-esm.mjs
index 389eb26fb..3f4fb990a 100644
--- a/scripts/fix-pump-sdk-esm.mjs
+++ b/scripts/fix-pump-sdk-esm.mjs
@@ -90,8 +90,11 @@ if (existsSync(pumpSwapPkgPath)) {
writeFileSync(pumpSwapPkgPath, JSON.stringify(pkg, null, 2) + '\n');
pumpSwapPatched = true;
patched++;
- } else if (pkg.type !== 'module' && (head.includes('export ') || head.includes('import '))) {
- // Old layout: ESM main entry needs the module flag.
+ } else if (pkg.type !== 'module' && !importTargetHasMarker && /(^|\n)\s*(export|import)[\s{*]/.test(head)) {
+ // Old layout: the single ESM main entry needs the module flag. Guarded by
+ // !importTargetHasMarker so this never fires on the new layout (which keeps
+ // its ESM entry under a marked dist/esm/) — otherwise removing the root
+ // "type":"module" above and re-adding it here would flip-flop every run.
pkg.type = 'module';
writeFileSync(pumpSwapPkgPath, JSON.stringify(pkg, null, 2) + '\n');
pumpSwapPatched = true;