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(api): gate mcp-policy to GET, report the real presign window, and carry the OKX identity challenge

nirholas27870728eaf9
diff --git a/api/_lib/meta-allocator.js b/api/_lib/meta-allocator.js
index 076fd0334..0807dff49 100644
--- a/api/_lib/meta-allocator.js
+++ b/api/_lib/meta-allocator.js
@@ -246,7 +246,14 @@ async function llmPlan({ budget, profile, universe, currentAllocations, userId }
track: userId ? { userId, tool: 'meta-allocator' } : null,
});
const parsed = extractJson(out?.text);
- if (!parsed || !Array.isArray(parsed.allocations)) return null;
+ // An empty allocations array is a non-answer, not a plan: the caller asked
+ // how to split a budget across a universe that already passed the profile's
+ // minimum-settled bar, so "allocate to nobody" is the model declining rather
+ // than deciding. Returning null hands the request to the deterministic
+ // allocator, which always produces a real basket from the same universe.
+ // Observed live: a model reply of {"allocations":[],"excluded":[]} shipped a
+ // plan with zero rows and zero exclusions while 8 leaders qualified.
+ if (!parsed || !Array.isArray(parsed.allocations) || parsed.allocations.length === 0) return null;
return {
allocations: parsed.allocations,
excluded: Array.isArray(parsed.excluded) ? parsed.excluded : [],
diff --git a/api/_lib/rate-limit.js b/api/_lib/rate-limit.js
index b74e61c19..ff429ca9a 100644
--- a/api/_lib/rate-limit.js
+++ b/api/_lib/rate-limit.js
@@ -369,6 +369,17 @@ function memoryLimiter(name, { limit, window }) {
memoryBuckets.set(key, kept);
return { success: true, limit, remaining: limit - kept.length, reset: now + ms };
},
+ // Hand back the newest hit in this bucket. See `refund` on the exported
+ // limiters for when a caller is allowed to do that.
+ async refund(id) {
+ const key = `${name}\u0000${id}`;
+ const kept = memoryBuckets.get(key);
+ if (!kept?.length) return false;
+ kept.pop();
+ if (kept.length) memoryBuckets.set(key, kept);
+ else memoryBuckets.delete(key);
+ return true;
+ },
};
}
@@ -448,6 +459,15 @@ function pgLimiter(name, { limit, window }) {
reason: 'rate_limiter_degraded_postgres',
};
},
+ async refund(id) {
+ const windowStart = Math.floor(Date.now() / ms) * ms;
+ const [row] = await sql`
+ UPDATE rate_limit_counters SET hits = greatest(0, hits - 1)
+ WHERE bucket = ${`${name}\0${id}`} AND window_start = ${windowStart}
+ RETURNING hits
+ `;
+ return Boolean(row);
+ },
};
}
diff --git a/api/mcp-policy.js b/api/mcp-policy.js
index a8c28b337..5bf35c74e 100644
--- a/api/mcp-policy.js
+++ b/api/mcp-policy.js
@@ -21,7 +21,7 @@
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
-import { cors, wrap } from './_lib/http.js';
+import { cors, method, wrap } from './_lib/http.js';
// The catalog is baked into the deployed image next to this handler, so it is
// read once at boot rather than per request.
@@ -134,6 +134,10 @@ function toVsCodeSettings(policy) {
export default wrap(async (req, res) => {
if (cors(req, res, { methods: 'GET,HEAD,OPTIONS', origins: '*' })) return;
+ // The CORS preflight advertises GET,HEAD,OPTIONS; without this gate a POST
+ // or PUT was answered with a cacheable 200 policy body, which contradicts
+ // the advertised contract and lets an intermediary cache a write verb.
+ if (!method(req, res, ['GET'])) return;
const url = new URL(req.url, 'http://x');
const profileParam = (url.searchParams.get('profile') || DEFAULT_PROFILE).toLowerCase();
diff --git a/api/motion-swap.js b/api/motion-swap.js
index 909644dc5..fc275d18e 100644
--- a/api/motion-swap.js
+++ b/api/motion-swap.js
@@ -105,7 +105,10 @@ async function presignVideo(req, res, body) {
public_url: publicUrl(key),
method: 'PUT',
headers: { 'content-type': contentType },
- expires_in: 600,
+ // presignUpload signs for 300s. Reporting 600 told the client it had twice
+ // the window it really has, so a queued upload of a large video could
+ // start after the signature expired and fail with a bare 403 from R2.
+ expires_in: 300,
});
}
diff --git a/api/newsletter-confirm.js b/api/newsletter-confirm.js
index 8b5b3ccda..cfa3cc420 100644
--- a/api/newsletter-confirm.js
+++ b/api/newsletter-confirm.js
@@ -2,8 +2,14 @@
//
// The confirm link from the signup email lands here. A valid token flips the
// subscriber to `confirmed`, adds them to the Resend audience, and shows a
-// branded confirmation page. Tokens are single-purpose; an already-confirmed or
-// unknown token shows a neutral page rather than leaking which is which.
+// branded confirmation page. An unknown token shows a neutral "link expired"
+// page, and an already-confirmed one says so without re-mailing anything.
+//
+// A token that belongs to an UNSUBSCRIBED row is refused. The confirm link and
+// the unsubscribe link in an email carry the SAME token and the token is only
+// rotated by a fresh /api/newsletter-subscribe, so without this an old confirm
+// link resurrected an address the reader had deliberately unsubscribed. Opting
+// back in has to start from the site, which mints a new token.
import { sql } from './_lib/db.js';
import { cors, method, wrap, text, rateLimited } from './_lib/http.js';
@@ -42,6 +48,15 @@ export default wrap(async (req, res) => {
});
}
+ if (sub.status === 'unsubscribed') {
+ return page(res, 200, {
+ heading: "You're unsubscribed",
+ body: 'This link belongs to a subscription you already cancelled, so it no longer signs you up. Subscribe again from the site whenever you want the updates back.',
+ ctaHref: `${APP_URL}/changelog`,
+ ctaLabel: 'See the changelog',
+ });
+ }
+
if (sub.status === 'confirmed') {
return page(res, 200, {
heading: "You're already subscribed",
diff --git a/api/okx/3d/[service].js b/api/okx/3d/[service].js
index f110cf8ed..cce20e60a 100644
--- a/api/okx/3d/[service].js
+++ b/api/okx/3d/[service].js
@@ -461,7 +461,11 @@ async function handleIdentityStudio(req, res) {
} catch (err) {
return sendX402Error(
res,
- { resourceUrl: x402Ctx.resourceUrl, accepts: x402Ctx.requirements },
+ {
+ resourceUrl: x402Ctx.resourceUrl,
+ accepts: x402Ctx.requirements,
+ challenge: IDENTITY_CHALLENGE,
+ },
err,
);
}