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
chore(forge): rate-limit JSON codemod across forge endpoints + registry canary
nirholasb87be9e3d709
diff --git a/api/forge-feedback.js b/api/forge-feedback.jsindex 5ec859d75..bea0e926a 100644--- a/api/forge-feedback.js+++ b/api/forge-feedback.js@@ -14,7 +14,7 @@* a clean { ok: false, stored: false } instead of failing.*/-import { cors, json, method, readJson, wrap } from './_lib/http.js';+import { cors, json, method, readJson, wrap, rateLimited } from './_lib/http.js';import { limits, clientIp } from './_lib/rate-limit.js';import { hashClient, recordFeedback, forgeStoreEnabled } from './_lib/forge-store.js';@@ -26,10 +26,7 @@ export default wrap(async (req, res) => {const rl = await limits.mcp3dStatus(clientIp(req));if (!rl.success) {- return json(res, 429, {- error: 'rate_limited',- retry_after: Math.ceil((rl.reset - Date.now()) / 1000),- });+ rateLimited(res, rl);}if (!forgeStoreEnabled()) {diff --git a/api/forge-gallery.js b/api/forge-gallery.jsindex ad051ef30..92089c9f0 100644--- a/api/forge-gallery.js+++ b/api/forge-gallery.js@@ -13,7 +13,7 @@* rather than show a broken state.*/-import { cors, json, method, wrap } from './_lib/http.js';+import { cors, json, method, wrap, rateLimited } from './_lib/http.js';import { limits, clientIp } from './_lib/rate-limit.js';import { hashClient, listCreations, forgeStoreEnabled } from './_lib/forge-store.js';@@ -23,10 +23,7 @@ export default wrap(async (req, res) => {const rl = await limits.mcp3dStatus(clientIp(req));if (!rl.success) {- return json(res, 429, {- error: 'rate_limited',- retry_after: Math.ceil((rl.reset - Date.now()) / 1000),- });+ rateLimited(res, rl);}if (!forgeStoreEnabled()) {diff --git a/api/forge-motion.js b/api/forge-motion.jsindex 0638c1faf..b94209ede 100644--- a/api/forge-motion.js+++ b/api/forge-motion.js@@ -21,7 +21,7 @@* this is the differentiating capability, reusing our rig + retarget + library.*/-import { cors, json, method, readJson, wrap } from './_lib/http.js';+import { cors, json, method, readJson, wrap, rateLimited } from './_lib/http.js';import { limits, clientIp } from './_lib/rate-limit.js';import { createRegenProvider } from './_providers/gcp.js';@@ -42,10 +42,7 @@ async function startJob(req, res) {const ip = clientIp(req);const rl = await limits.mcp3dGenerate(ip);if (!rl.success) {- return json(res, 429, {- error: 'rate_limited',- retry_after: Math.ceil((rl.reset - Date.now()) / 1000),- });+ rateLimited(res, rl);}const body = await readJson(req, 4_000).catch(() => null);@@ -90,7 +87,7 @@ async function pollJob(req, res, jobId) {const rl = await limits.mcp3dStatus(clientIp(req));if (!rl.success) {- return json(res, 429, { error: 'rate_limited', retry_after: Math.ceil((rl.reset - Date.now()) / 1000) });+ rateLimited(res, rl);}let provider;diff --git a/api/forge-rembg.js b/api/forge-rembg.jsindex 8934cf6b2..81174c7f4 100644--- a/api/forge-rembg.js+++ b/api/forge-rembg.js@@ -13,7 +13,7 @@* No auth required — rate-limited by client IP using the same mcp3d buckets.*/-import { cors, json, method, readJson, wrap } from './_lib/http.js';+import { cors, json, method, readJson, wrap, rateLimited } from './_lib/http.js';import { limits, clientIp } from './_lib/rate-limit.js';import { createRegenProvider } from './_providers/gcp.js';@@ -33,10 +33,7 @@ async function startJob(req, res) {const ip = clientIp(req);const rl = await limits.mcp3dGenerate(ip);if (!rl.success) {- return json(res, 429, {- error: 'rate_limited',- retry_after: Math.ceil((rl.reset - Date.now()) / 1000),- });+ rateLimited(res, rl);}const body = await readJson(req, 4_000).catch(() => null);@@ -74,7 +71,7 @@ async function pollJob(req, res, jobId) {const rl = await limits.mcp3dStatus(clientIp(req));if (!rl.success) {- return json(res, 429, { error: 'rate_limited', retry_after: Math.ceil((rl.reset - Date.now()) / 1000) });+ rateLimited(res, rl);}let provider;diff --git a/api/forge-remesh.js b/api/forge-remesh.jsindex 0bff2742e..347467821 100644--- a/api/forge-remesh.js+++ b/api/forge-remesh.js@@ -16,7 +16,7 @@* Routes to workers/remesh (GCP Cloud Run) when GCP_REMESH_URL is set.*/-import { cors, json, method, readJson, wrap } from './_lib/http.js';+import { cors, json, method, readJson, wrap, rateLimited } from './_lib/http.js';import { limits, clientIp } from './_lib/rate-limit.js';import { createRegenProvider } from './_providers/gcp.js';@@ -39,10 +39,7 @@ async function startJob(req, res) {const ip = clientIp(req);const rl = await limits.mcp3dGenerate(ip);if (!rl.success) {- return json(res, 429, {- error: 'rate_limited',- retry_after: Math.ceil((rl.reset - Date.now()) / 1000),- });+ rateLimited(res, rl);}const body = await readJson(req, 4_000).catch(() => null);@@ -99,7 +96,7 @@ async function pollJob(req, res, jobId) {const rl = await limits.mcp3dStatus(clientIp(req));if (!rl.success) {- return json(res, 429, { error: 'rate_limited', retry_after: Math.ceil((rl.reset - Date.now()) / 1000) });+ rateLimited(res, rl);}let provider;diff --git a/api/forge-segment.js b/api/forge-segment.jsindex ea0bd557b..4ea0fb4fb 100644--- a/api/forge-segment.js+++ b/api/forge-segment.js@@ -17,7 +17,7 @@* Routes to workers/segment (GCP Cloud Run) when GCP_SEGMENT_URL is set.*/-import { cors, json, method, readJson, wrap } from './_lib/http.js';+import { cors, json, method, readJson, wrap, rateLimited } from './_lib/http.js';import { limits, clientIp } from './_lib/rate-limit.js';import { createRegenProvider } from './_providers/gcp.js';@@ -38,10 +38,7 @@ async function startJob(req, res) {const ip = clientIp(req);const rl = await limits.mcp3dGenerate(ip);if (!rl.success) {- return json(res, 429, {- error: 'rate_limited',- retry_after: Math.ceil((rl.reset - Date.now()) / 1000),- });+ rateLimited(res, rl);}const body = await readJson(req, 4_000).catch(() => null);@@ -97,7 +94,7 @@ async function pollJob(req, res, jobId) {const rl = await limits.mcp3dStatus(clientIp(req));if (!rl.success) {- return json(res, 429, { error: 'rate_limited', retry_after: Math.ceil((rl.reset - Date.now()) / 1000) });+ rateLimited(res, rl);}let provider;diff --git a/api/forge-stylize.js b/api/forge-stylize.jsindex 98c989db8..50b8cd1a8 100644--- a/api/forge-stylize.js+++ b/api/forge-stylize.js@@ -16,7 +16,7 @@* worker's GET /styles endpoint documents each filter's density knob.*/-import { cors, json, method, readJson, wrap } from './_lib/http.js';+import { cors, json, method, readJson, wrap, rateLimited } from './_lib/http.js';import { limits, clientIp } from './_lib/rate-limit.js';import { createRegenProvider } from './_providers/gcp.js';@@ -46,10 +46,7 @@ async function startJob(req, res) {const ip = clientIp(req);const rl = await limits.mcp3dGenerate(ip);if (!rl.success) {- return json(res, 429, {- error: 'rate_limited',- retry_after: Math.ceil((rl.reset - Date.now()) / 1000),- });+ rateLimited(res, rl);}const body = await readJson(req, 4_000).catch(() => null);@@ -100,7 +97,7 @@ async function pollJob(req, res, jobId) {const rl = await limits.mcp3dStatus(clientIp(req));if (!rl.success) {- return json(res, 429, { error: 'rate_limited', retry_after: Math.ceil((rl.reset - Date.now()) / 1000) });+ rateLimited(res, rl);}let provider;diff --git a/api/forge-upload.js b/api/forge-upload.jsindex 6ea82928f..e103015b2 100644--- a/api/forge-upload.js+++ b/api/forge-upload.js@@ -16,7 +16,7 @@*/import { randomUUID } from 'node:crypto';-import { cors, json, method, readJson, wrap } from './_lib/http.js';+import { cors, json, method, readJson, wrap, rateLimited } from './_lib/http.js';import { limits, clientIp } from './_lib/rate-limit.js';import { presignUpload, publicUrl } from './_lib/r2.js';import { hashClient } from './_lib/forge-store.js';@@ -63,11 +63,7 @@ export default wrap(async (req, res) => {const ip = clientIp(req);const rl = await limits.upload(`forge:${ip}`);if (!rl.success) {- return json(res, 429, {- error: 'rate_limited',- message: 'Upload limit reached. Try again shortly.',- retry_after: Math.ceil((rl.reset - Date.now()) / 1000),- });+ rateLimited(res, rl, 'Upload limit reached. Try again shortly.');}const body = await readJson(req, 2_000).catch(() => null);diff --git a/api/forge.js b/api/forge.jsindex 6e118371f..11c819385 100644--- a/api/forge.js+++ b/api/forge.js@@ -26,7 +26,7 @@* model.*/-import { cors, json, method, readJson, wrap } from './_lib/http.js';+import { cors, json, method, readJson, wrap, rateLimited } from './_lib/http.js';import { limits, clientIp } from './_lib/rate-limit.js';import { textToImage } from './_mcp3d/text-to-image.js';import { createRegenProvider } from './_providers/replicate.js';@@ -136,11 +136,7 @@ async function startJob(req, res) {const ip = clientIp(req);const rl = await limits.mcp3dGenerate(ip);if (!rl.success) {- return json(res, 429, {- error: 'rate_limited',- message: 'Generation limit reached. Try again shortly.',- retry_after: Math.ceil((rl.reset - Date.now()) / 1000),- });+ rateLimited(res, rl, 'Generation limit reached. Try again shortly.');}const body = await readJson(req, 8_000).catch(() => null);@@ -408,11 +404,7 @@ async function startRigJob(req, res) {const ip = clientIp(req);const rl = await limits.mcp3dGenerate(ip);if (!rl.success) {- return json(res, 429, {- error: 'rate_limited',- message: 'Rigging limit reached. Try again shortly.',- retry_after: Math.ceil((rl.reset - Date.now()) / 1000),- });+ rateLimited(res, rl, 'Rigging limit reached. Try again shortly.');}const body = await readJson(req, 8_000).catch(() => null);@@ -489,10 +481,7 @@ async function pollJob(req, res, jobId) {const rl = await limits.mcp3dStatus(clientIp(req));if (!rl.success) {- return json(res, 429, {- error: 'rate_limited',- retry_after: Math.ceil((rl.reset - Date.now()) / 1000),- });+ rateLimited(res, rl);}const provider = token?.provider || 'replicate';diff --git a/api/x402-pay.js b/api/x402-pay.jsindex f78fcc5a7..a757538bc 100644--- a/api/x402-pay.js+++ b/api/x402-pay.js@@ -32,7 +32,7 @@ import {import bs58 from 'bs58';import { Redis } from '@upstash/redis';-import { cors, json, readJson, wrap } from './_lib/http.js';+import { cors, json, readJson, wrap, rateLimited } from './_lib/http.js';import { limits, clientIp } from './_lib/rate-limit.js';import {paymentRequirements,@@ -571,10 +571,7 @@ export default wrap(async (req, res) => {const ip = clientIp(req);const ipRl = await limits.x402PayIp(ip);if (!ipRl.success) {- return json(res, 429, {- error: 'rate_limited',- retry_after: Math.ceil((ipRl.reset - Date.now()) / 1000),- });+ rateLimited(res, ipRl);}const globalRl = await limits.x402PayGlobal();if (!globalRl.success) {diff --git a/pages/home.html b/pages/home.htmlindex 0bc74dec7..b997b73cf 100644--- a/pages/home.html+++ b/pages/home.html@@ -371,32 +371,6 @@background: linear-gradient(to left, var(--surface-0) 30%, transparent);}- /* ── LOGO STRIP ──────────────────────────────────────────── */- .logo-strip {- padding: 28px 0;- border-bottom: 1px solid var(--hairline);- }- .logo-strip-cap {- font-family: var(--font-mono); font-size: 10.5px;- letter-spacing: 0.2em; text-transform: uppercase;- color: var(--text-4); text-align: center; margin-bottom: 20px;- }- .logo-row {- display: flex; flex-wrap: wrap; justify-content: center;- gap: 10px 12px; align-items: center; max-width: 760px; margin: 0 auto;- }- .logo-row .logo {- font-family: var(--font-mono); font-size: 12.5px; font-weight: 500;- letter-spacing: -0.01em; color: var(--text-3); opacity: 0.8;- padding: 6px 14px; border: 1px solid var(--hairline);- border-radius: 999px;- transition: opacity 0.15s, color 0.15s, border-color 0.15s, transform 0.15s;- }- .logo-row .logo:hover {- opacity: 1; color: var(--text); border-color: var(--hairline-strong);- transform: translateY(-1px);- }-/* ── PARTNER / PRESS STRIP ───────────────────────────────── */.press-strip { padding: 38px 0 42px; }.press-strip-cap {@@ -2873,23 +2847,6 @@<div class="cap-fade cap-fade--r"></div></div>-<!-- ── LOGO STRIP ────────────────────────────────────────────────── -->-<div class="logo-strip">- <div class="wrap-1280">- <div class="logo-strip-cap">Embedded across the web</div>- <div class="logo-row">- <span class="logo">claude.ai</span>- <span class="logo">lobehub</span>- <span class="logo">agenc.tech</span>- <span class="logo">pump.fun</span>- <span class="logo">solana</span>- <span class="logo">metaplex</span>- <span class="logo">erc-8004</span>- <span class="logo">pay-per-call</span>- </div>- </div>-</div>-<div class="press-strip"><div class="wrap-1280"><div class="press-strip-cap">Partnered with & featured in</div>diff --git a/scripts/codemod-rate-limit-json.mjs b/scripts/codemod-rate-limit-json.mjsnew file mode 100644index 000000000..b4caa3bde--- /dev/null+++ b/scripts/codemod-rate-limit-json.mjs@@ -0,0 +1,67 @@+// Second-pass codemod: migrate the json(res, 429, {...rate_limited...}) family+// (mostly the forge endpoints) to the rateLimited() helper so they emit the+// same Retry-After + RateLimit-* headers as the error()-based sites. Idempotent.+//+// node scripts/codemod-rate-limit-json.mjs [--dry]+//+// Only transforms LOCAL-limiter sites — those whose body is exactly+// { error: 'rate_limited', [message: '…',] retry_after: Math.ceil((VAR.reset - Date.now())/1000) }+// guarded by `if (!VAR.success)`. Upstream-passthrough 429s (no VAR.reset, a+// distinct error code, or extra fields) are left untouched and reported.++import { readFileSync, writeFileSync } from 'node:fs';+import { execSync } from 'node:child_process';++const DRY = process.argv.includes('--dry');++const files = execSync(`grep -rln "json(res, 429" api --include="*.js"`, { encoding: 'utf8' })+ .trim()+ .split('\n')+ .filter(Boolean);++// Block form (multi-line) and one-line form. `message` is optional; both must+// reference the same VAR in the retry_after expression so we know it's a local+// limiter result.+const BLOCK_RE =+ /return json\(\s*res\s*,\s*429\s*,\s*\{\s*error:\s*'rate_limited'\s*,\s*(?:message:\s*('[^']*'|"[^"]*")\s*,\s*)?retry_after:\s*Math\.ceil\(\(\s*(\w+)\.reset\s*-\s*Date\.now\(\)\s*\)\s*\/\s*1000\)\s*,?\s*\}\s*\)/g;++let changedFiles = 0;+let changedSites = 0;+const skipped = [];++for (const file of files) {+ let src = readFileSync(file, 'utf8');+ let touched = false;++ src = src.replace(BLOCK_RE, (_m, msg, varName) => {+ touched = true;+ changedSites++;+ const args = ['res', varName];+ if (msg) args.push(msg);+ return `rateLimited(${args.join(', ')})`;+ });++ if (!touched) {+ skipped.push(`${file} (only non-local-limiter 429s)`);+ continue;+ }++ if (!/\brateLimited\b/.test(src.match(/import[\s\S]*?from\s*'[^']*_lib\/http\.js'/)?.[0] || '')) {+ const importRe = /import\s*\{([\s\S]*?)\}\s*from\s*'([^']*_lib\/http\.js)'/;+ const im = src.match(importRe);+ if (im) {+ src = src.replace(importRe, `import {${im[1].replace(/\s*$/, '')}, rateLimited } from '${im[2]}'`);+ } else {+ skipped.push(`${file} (no _lib/http.js import to extend)`);+ }+ }++ if (!DRY) writeFileSync(file, src);+ changedFiles++;+}++console.log(`${DRY ? '[dry] ' : ''}rewrote ${changedSites} site(s) across ${changedFiles} file(s)`);+if (skipped.length) {+ console.log(`\nuntouched (${skipped.length}) — verify these are upstream-passthrough only:`);+ for (const s of skipped) console.log(' ' + s);+}diff --git a/scripts/test-registry-canary.mjs b/scripts/test-registry-canary.mjsnew file mode 100644index 000000000..e085d92e1--- /dev/null+++ b/scripts/test-registry-canary.mjs@@ -0,0 +1,132 @@+#!/usr/bin/env node+/**+ * Self-contained canary for the Metaplex Agent Registry flow.+ * ---------------------------------------------------------------------------+ * Proves api/_lib/agent-registry.js end-to-end on a throwaway wallet that we+ * fully control: it mints its own standalone Core assets and then registers each+ * one via `registerIdentityV1`, so the wallet is the asset's update authority and+ * the registration is valid. NO database, NO production secrets, NO real agents —+ * purely a chain-level smoke test before the real back-fill (which must be signed+ * by the production collection authority, the only key that can register the+ * already-minted agents).+ *+ * Wallet: .secrets/test-registry-wallet.json (git-ignored). Override with+ * TEST_REGISTRY_SECRET (base58) if you want a different funded wallet.+ *+ * Usage:+ * # devnet (free — airdrops if needed):+ * node scripts/test-registry-canary.mjs --network devnet --count 2+ *+ * # mainnet (fund the wallet first, ~0.01 SOL/asset):+ * node scripts/test-registry-canary.mjs --network mainnet --count 2+ */++import { readFileSync } from 'node:fs';+import { Keypair, Connection, LAMPORTS_PER_SOL } from '@solana/web3.js';+import bs58 from 'bs58';+import { createUmi } from '@metaplex-foundation/umi-bundle-defaults';+import { mplCore, create } from '@metaplex-foundation/mpl-core';+import { createSignerFromKeypair, signerIdentity, generateSigner, publicKey as umiPublicKey } from '@metaplex-foundation/umi';+import { registerAgentIdentity } from '../api/_lib/agent-registry.js';++function arg(name, fallback) {+ const i = process.argv.indexOf(name);+ return i >= 0 && process.argv[i + 1] ? process.argv[i + 1] : fallback;+}+const sleep = (ms) => new Promise((r) => setTimeout(r, ms));+const sol = (l) => (l / LAMPORTS_PER_SOL).toFixed(4);++function loadTestSecret() {+ if (process.env.TEST_REGISTRY_SECRET) return process.env.TEST_REGISTRY_SECRET;+ const j = JSON.parse(readFileSync(new URL('../.secrets/test-registry-wallet.json', import.meta.url)));+ return j.secretKeyBase58;+}++const RPC = {+ mainnet: 'https://api.mainnet-beta.solana.com',+ devnet: 'https://api.devnet.solana.com',+};+function explorer(addr, network) {+ return `https://solscan.io/account/${addr}${network === 'devnet' ? '?cluster=devnet' : ''}`;+}++async function main() {+ const network = arg('--network', 'devnet') === 'mainnet' ? 'mainnet' : 'devnet';+ const count = Math.min(5, Math.max(1, Number(arg('--count', '2'))));++ const kp = Keypair.fromSecretKey(bs58.decode(loadTestSecret()));+ const address = kp.publicKey.toString();+ console.log(`\nthree.ws — Agent Registry canary (${network})`);+ console.log(` test wallet: ${address}`);++ const conn = new Connection(RPC[network], 'confirmed');+ let bal = await conn.getBalance(kp.publicKey);+ console.log(` balance: ${sol(bal)} SOL`);++ const needed = count * 0.012 * LAMPORTS_PER_SOL; // mint (~0.004) + register (~0.003) + fees, with headroom+ if (bal < needed) {+ if (network === 'devnet') {+ console.log(` airdropping 1 SOL (devnet) …`);+ try {+ const sig = await conn.requestAirdrop(kp.publicKey, 1 * LAMPORTS_PER_SOL);+ await conn.confirmTransaction(sig, 'confirmed');+ bal = await conn.getBalance(kp.publicKey);+ console.log(` balance: ${sol(bal)} SOL`);+ } catch (e) {+ console.error(`\n✗ devnet airdrop failed (${e.message}). Fund ${address} manually and re-run.`);+ process.exit(1);+ }+ } else {+ console.error(`\n✗ Insufficient balance. Fund ${address} with ~${sol(needed)} SOL and re-run.`);+ process.exit(1);+ }+ }++ // Umi signed by the test wallet (mplCore for the mint; registry plugin is added+ // inside agent-registry.js).+ const umi = createUmi(RPC[network]).use(mplCore());+ const signer = createSignerFromKeypair(umi, umi.eddsa.createKeypairFromSecretKey(kp.secretKey));+ umi.use(signerIdentity(signer));++ let ok = 0, fail = 0;+ for (let i = 1; i <= count; i++) {+ console.log(`\n[${i}/${count}] minting test asset …`);+ try {+ const asset = generateSigner(umi);+ await create(umi, {+ asset,+ owner: signer.publicKey,+ name: `Registry Canary ${i}`,+ uri: 'https://three.ws/.well-known/agent-card.json',+ }).sendAndConfirm(umi, { confirm: { commitment: 'confirmed' } });+ const assetAddr = asset.publicKey.toString();+ console.log(` asset: ${assetAddr}`);+ console.log(` ${explorer(assetAddr, network)}`);++ console.log(` registering identity …`);+ const r = await registerAgentIdentity({+ umi,+ authoritySigner: signer,+ asset: assetAddr,+ // standalone asset — no collection; the wallet is its own update authority+ registrationUri: 'https://three.ws/.well-known/agent-card.json',+ });+ ok++;+ console.log(` ✓ identity PDA: ${r.identityPda}${r.alreadyRegistered ? ' (already)' : ''}`);+ console.log(` ${explorer(r.identityPda, network)}`);+ if (r.signature) console.log(` register tx: ${r.signature}`);+ } catch (err) {+ fail++;+ console.log(` ✗ ${err.message}`);+ }+ await sleep(400);+ }++ console.log(`\nDone — registered: ${ok}, failed: ${fail}.`);+ if (ok > 0) console.log('Open the identity PDA link above; an account owned by program 1DREG… confirms registry membership.');+}++main().catch((err) => {+ console.error('\n✗ Fatal:', err?.stack || err?.message || err);+ process.exit(1);+});