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(routing): serve /avatars/:id as its own page, redirect stale agent ids to it

nirholas43062e70ec92
diff --git a/scripts/mint-aixbt-key.mjs b/scripts/mint-aixbt-key.mjs
new file mode 100644
index 000000000..e21b20b03
--- /dev/null
+++ b/scripts/mint-aixbt-key.mjs
@@ -0,0 +1,62 @@
+// One-off: mint an aixbt.tech API key via x402 (USDC on Base), using the
+// official @x402 client so the payload matches Coinbase CDP's facilitator
+// schema exactly. Pays from A2A_PAYER_PRIVATE_KEY in .env.
+//
+// node scripts/mint-aixbt-key.mjs [1d|1w|4w]
+//
+// stdout: the JSON key response (apiKey shown once). stderr: progress.
+
+import { readFileSync } from 'node:fs';
+
+import { createPublicClient, http } from 'viem';
+import { privateKeyToAccount } from 'viem/accounts';
+import { base } from 'viem/chains';
+import { wrapFetchWithPayment, x402Client } from '@x402/fetch';
+import { ExactEvmScheme, toClientEvmSigner } from '@x402/evm';
+
+const period = process.argv[2] || '1d';
+const url = `https://api.aixbt.tech/x402/v2/api-keys/${period}`;
+const BASE_RPC = process.env.BASE_RPC_URL || 'https://mainnet.base.org';
+
+function loadEnv() {
+ const raw = readFileSync(new URL('../.env', import.meta.url), 'utf8');
+ for (const line of raw.split('\n')) {
+ const m = line.match(/^([A-Z0-9_]+)=(.*)$/);
+ if (m && !(m[1] in process.env)) process.env[m[1]] = m[2];
+ }
+}
+
+async function main() {
+ loadEnv();
+ const pk = process.env.A2A_PAYER_PRIVATE_KEY;
+ if (!pk) throw new Error('A2A_PAYER_PRIVATE_KEY not set in .env');
+
+ const account = privateKeyToAccount(pk.startsWith('0x') ? pk : `0x${pk}`);
+ const publicClient = createPublicClient({ chain: base, transport: http(BASE_RPC) });
+ const signer = toClientEvmSigner(account, publicClient);
+ console.error(`payer: ${account.address}`);
+
+ const client = new x402Client().register('eip155:8453', new ExactEvmScheme(signer));
+ const fetchWithPay = wrapFetchWithPayment(globalThis.fetch, client);
+
+ console.error(`minting ${period} key → ${url}`);
+ const res = await fetchWithPay(url, {
+ method: 'POST',
+ headers: { 'content-type': 'application/json' },
+ });
+ const text = await res.text();
+ if (!res.ok) throw new Error(`mint failed ${res.status}: ${text || '(empty)'}`);
+
+ let data;
+ try {
+ data = JSON.parse(text);
+ } catch {
+ data = { raw: text };
+ }
+ process.stdout.write(JSON.stringify(data, null, 2) + '\n');
+}
+
+main().catch((err) => {
+ console.error(`ERROR: ${err.message}`);
+ process.exit(1);
+});
diff --git a/src/agent-detail.js b/src/agent-detail.js
index 7310edab5..6054d46d6 100644
--- a/src/agent-detail.js
+++ b/src/agent-detail.js
@@ -1500,6 +1500,20 @@ function normalize(rec, avatar) {
};
}
+// Agents and avatars live in separate tables with separate UUIDs — an agent
+// merely references an avatar via avatar_id. So an id that 404s as an agent may
+// actually be an avatar shared (or old-linked) as /agents/:id. Probe the avatar
+// store; if it resolves, the caller redirects to the avatar page instead of
+// showing a dead "not found".
+async function resolveAsAvatar(id) {
+ try {
+ const json = await fetchJson(`/api/avatars/${encodeURIComponent(id)}`);
+ return !!(json && json.avatar);
+ } catch {
+ return false;
+ }
+}
+
async function loadAgent(id) {
if (!id) return { error: 'missing id', agent: null, notFound: true };
if (!UUID_RE.test(id))
@@ -1513,13 +1527,23 @@ async function loadAgent(id) {
// A 404 is genuinely "no such agent"; anything else (offline, 5xx) is a
// transient load failure the user should be able to retry.
const notFound = e.status === 404;
+ if (notFound && (await resolveAsAvatar(id))) {
+ location.replace(`/avatars/${encodeURIComponent(id)}`);
+ return { agent: null, error: null, redirecting: true };
+ }
return {
error: notFound ? 'No agent with id' : e,
agent: null,
notFound,
};
}
- if (!rec) return { error: 'No agent with id', agent: null, notFound: true };
+ if (!rec) {
+ if (await resolveAsAvatar(id)) {
+ location.replace(`/avatars/${encodeURIComponent(id)}`);
+ return { agent: null, error: null, redirecting: true };
+ }
+ return { error: 'No agent with id', agent: null, notFound: true };
+ }
let avatar = null;
if (rec.avatar_id) {
@@ -1577,7 +1601,8 @@ const id =
function runLoad() {
loadAgent(id)
- .then(({ agent, error, notFound }) => {
+ .then(({ agent, error, notFound, redirecting }) => {
+ if (redirecting) return;
if (agent) return render(agent);
if (notFound) return renderNotFound(id, typeof error === 'string' ? error : '');
renderLoadError(error);
diff --git a/vercel.json b/vercel.json
index 54c9acc84..98eec2f70 100644
--- a/vercel.json
+++ b/vercel.json
@@ -1816,11 +1816,8 @@
"dest": "/ar.html"
},
{
- "src": "/avatars/([^/]+)",
- "status": 301,
- "headers": {
- "Location": "/agents/$1"
- }
+ "src": "/avatars/([^/.]+)",
+ "dest": "/avatar-page.html"
},
{
"src": "/api/characters",