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.

feat: ensure CSRF token is returned in both top-level and data structure for compatibility

zprv50a34063917a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f6e881feb..d2b0c39ac 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@ Public history for [three.ws](https://three.ws), newest first. New pages come fr
- **Club Social Activity — the platform tracks its own nightlife economy on-chain** — The autonomous loop now pays /api/x402/analytics every 30 minutes with { report: "clubs", period: "24h" } for a live snapshot of the Pole Club's social economy. The report reads straight from the real ledgers — settled tips (club_tips), the stage roster (club_dancer_wallets) and settled door cover charges (x402_audit_log) — and returns how many stages are active, how many distinct patrons showed up, the tip count and USDC volume, the cover charges collected at the door, and a fastest-growing-stage leaderboard. Every snapshot is appended to a club_social_analytics time series so a dashboard can chart whether the nightlife is heating up or cooling down and spot which stages are on the rise. `[feature, infra]`
- **Create an agent by describing it — the wizard now builds itself** — Spinning up an agent no longer means filling out five steps of fields. At the top of the Create flow there's now a single box: describe your agent in a sentence — "a witty crypto market analyst that explains charts in plain English" — and we generate the whole thing for you: name, description, tags, the right skills, a fitting 3D body, a marketplace category, a greeting, and its personality. No idea where to start? Tap an example or hit "Surprise me" and get a complete agent with zero typing. Everything lands on the Review step pre-filled, so you read it over, tweak anything you like, and ship. The by-hand form is still right there for anyone who wants it. (`/create-agent`) `[feature]`
- **Five pages that were returning 404 are reachable again** — The Gaussian-splat viewer (/splat), the capture tool (/capture), the integrations directory (/integrations), partners (/partners), and the live-agents board (/agents-live) were all returning a 404 in production even though the pages existed and were linked from the nav. Our routing pins every clean URL explicitly, and these five were missing their entry, so the request fell through to the not-found page. We added the missing routes and tightened the route audit so a new page can no longer ship without one. (`/splat`) `[fix]`
+- **Fixed: "Generate API key" in the Agent Screen worker setup** — The Launch your browser agent wizard (/agent-screen) has a Generate button that mints the API key the worker uses to authenticate. The button was failing with a permission error because it wasn't attaching the security token the server requires, so you couldn't get past step 2. It now reads and sends that token correctly, so generating the key — and starting a live agent screen stream — works again. The same token-handling fix was applied to one-click agent wallet provisioning. (`/agent-screen`) `[fix]`
- **Forge Content Health — the platform canaries its own generation engine every 10 minutes** — Every 3D generation the Forge produces begins by running a prompt through the platform's generative AI lane, so if that lane slows down or goes dark, creations stall before a mesh is ever built. The platform now watches for this automatically. Every ten minutes an autonomous agent makes a real on-chain payment to a new lightweight health_check mode on /api/x402/forge, which runs one fast text completion over the same free-first model chain Forge depends on — no expensive 3D reconstruction — and reports back whether content was generated, how long it took, and the token count. A completion slower than five seconds, or an outright generator outage, raises a Forge performance alert that an on-call dashboard reads in a single lookup and that clears itself once generation is healthy again. The new health_check mode is also available to any x402 agent on the bazaar for a fraction of a cent, far cheaper than a full generation, for callers that just want to confirm the engine is live. `[infra, feature]`
- **Forge Image Generation Canary — the platform validates its own image pipeline every 5 minutes** — Every Forge job that reconstructs a 3D mesh starts with a text-to-image call. If the image provider chain is down or hung, every paid Forge generation silently fails — before users even hit the paywall. The platform now detects this automatically. Every five minutes an autonomous agent makes a real on-chain $0.001 USDC payment to /api/x402/forge with body { mode: "health_check", type: "image", prompt: "A simple blue circle." }. The endpoint runs one real text-to-image call through the free-first provider chain (NIM FLUX → Vertex Imagen → Replicate backstop) and uploads the result to R2 CDN — proving the full image generation and CDN upload path end-to-end. The extracted signal { generated, url, latency_ms } lands in x402_autonomous_log.signal_data. When generation fails or latency exceeds 30 seconds, a Redis alert (x402:forge-image-health:alert) is raised so ops can investigate before users see broken generations. The image alert key is separate from the existing text LLM canary alert so both lanes can degrade independently. `[infra, feature]`
- **Forge no longer dead-ends on "Generator not configured" when a free lane is live** — When the free NVIDIA text→3D lane was briefly down, Forge could return "Generator not configured" even on deployments where the free Hugging Face lane was fully set up — because the degrade step looked for a paid Replicate key that wasn't required. Forge now falls through to whichever free engine is configured (Hugging Face Spaces) instead of stopping, so a single free key keeps text and photo generation working through upstream blips. (`/forge`) `[fix]`
diff --git a/api/csrf-token.js b/api/csrf-token.js
index 482d17229..1069996bd 100644
--- a/api/csrf-token.js
+++ b/api/csrf-token.js
@@ -13,5 +13,9 @@ export default wrap(async (req, res) => {
if (!userId) return error(res, 401, 'unauthorized', 'sign in required');
const { token, expiresIn } = await issueCsrf(userId);
- return json(res, 200, { data: { token, expires_in: expiresIn } });
+ // Return the token both at the top level AND under `data` so every client
+ // accessor works regardless of the shape it expects (j.token, j.data.token,
+ // or `const { token } = ...`). Mis-reading the envelope previously sent an
+ // empty x-csrf-token header → 403 csrf_missing on otherwise-valid mutations.
+ return json(res, 200, { token, expires_in: expiresIn, data: { token, expires_in: expiresIn } });
});
diff --git a/data/changelog.json b/data/changelog.json
index c0e31d8c9..0a6e93d86 100644
--- a/data/changelog.json
+++ b/data/changelog.json
@@ -1,6 +1,15 @@
{
"$comment": "Curated changelog entries for three.ws — the editorial layer of the public changelog. New PAGE launches are tracked automatically via the `added` field in data/pages.json; this file is for everything else holders care about: improvements, fixes, SDK releases, trading/payments capabilities, security work. scripts/build-page-index.mjs merges both sources into CHANGELOG.md, public/changelog.json, and public/changelog.xml. Newest first. Allowed tags: feature, improvement, fix, sdk, infra, docs, security. `link` is optional and must be a live three.ws path.",
"entries": [
+ {
+ "date": "2026-06-28",
+ "title": "Fixed: \"Generate API key\" in the Agent Screen worker setup",
+ "summary": "The Launch your browser agent wizard (/agent-screen) has a Generate button that mints the API key the worker uses to authenticate. The button was failing with a permission error because it wasn't attaching the security token the server requires, so you couldn't get past step 2. It now reads and sends that token correctly, so generating the key — and starting a live agent screen stream — works again. The same token-handling fix was applied to one-click agent wallet provisioning.",
+ "tags": [
+ "fix"
+ ],
+ "link": "/agent-screen"
+ },
{
"date": "2026-06-28",
"title": "Forged avatars get auto-rigged whenever a rigging lane is available",
diff --git a/public/changelog.json b/public/changelog.json
index a59c20a13..27e3f6e6e 100644
--- a/public/changelog.json
+++ b/public/changelog.json
@@ -1,5 +1,5 @@
{
- "generated_at": "2026-06-28T07:03:01.292Z",
+ "generated_at": "2026-06-28T09:40:54.055Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json + data/changelog.json",
"site": {
"name": "three.ws",
@@ -152,6 +152,16 @@
"fix"
]
},
+ {
+ "date": "2026-06-28",
+ "type": "update",
+ "title": "Fixed: \"Generate API key\" in the Agent Screen worker setup",
+ "summary": "The Launch your browser agent wizard (/agent-screen) has a Generate button that mints the API key the worker uses to authenticate. The button was failing with a permission error because it wasn't attaching the security token the server requires, so you couldn't get past step 2. It now reads and sends that token correctly, so generating the key — and starting a live agent screen stream — works again. The same token-handling fix was applied to one-click agent wallet provisioning.",
+ "link": "/agent-screen",
+ "tags": [
+ "fix"
+ ]
+ },
{
"date": "2026-06-28",
"type": "update",
diff --git a/public/changelog.xml b/public/changelog.xml
index 0374c59b2..0362eeb8c 100644
--- a/public/changelog.xml
+++ b/public/changelog.xml
@@ -118,6 +118,14 @@
<category>fix</category>
<description>The Gaussian-splat viewer (/splat), the capture tool (/capture), the integrations directory (/integrations), partners (/partners), and the live-agents board (/agents-live) were all returning a 404 in production even though the pages existed and were linked from the nav. Our routing pins every clean URL explicitly, and these five were missing their entry, so the request fell through to the not-found page. We added the missing routes and tightened the route audit so a new page can no longer ship without one.</description>
</item>
+ <item>
+ <title>Fixed: &quot;Generate API key&quot; in the Agent Screen worker setup</title>
+ <link>https://three.ws/agent-screen</link>
+ <guid isPermaLink="false">2026-06-28:Fixed: &quot;Generate API key&quot; in the Agent Screen worker setup</guid>
+ <pubDate>Sun, 28 Jun 2026 12:00:00 GMT</pubDate>
+ <category>fix</category>
+ <description>The Launch your browser agent wizard (/agent-screen) has a Generate button that mints the API key the worker uses to authenticate. The button was failing with a permission error because it wasn't attaching the security token the server requires, so you couldn't get past step 2. It now reads and sends that token correctly, so generating the key — and starting a live agent screen stream — works again. The same token-handling fix was applied to one-click agent wallet provisioning.</description>
+ </item>
<item>
<title>Forge Content Health — the platform canaries its own generation engine every 10 minutes</title>
<link>https://three.ws/changelog</link>
diff --git a/public/features.json b/public/features.json
index d65015c1a..d77fb7718 100644
--- a/public/features.json
+++ b/public/features.json
@@ -1,5 +1,5 @@
{
- "generated_at": "2026-06-28T07:03:01.273Z",
+ "generated_at": "2026-06-28T09:40:54.042Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json",
"site": {
"name": "three.ws",
diff --git a/src/a-me.js b/src/a-me.js
index 0eaa379d2..2bf27f4fc 100644
--- a/src/a-me.js
+++ b/src/a-me.js
@@ -517,7 +517,7 @@ async function handleCreateWallet(btn) {
let token = null;
try {
const cr = await fetch('/api/csrf-token', { credentials: 'include' });
- if (cr.ok) token = (await cr.json()).token || null;
+ if (cr.ok) { const j = await cr.json(); token = j.data?.token || j.token || null; }
} catch { /* token optional — endpoint still rejects without it */ }
const r = await fetch(`/api/agents/${encodeURIComponent(agentId)}/wallet/provision`, {
method: 'POST',
diff --git a/src/agent-screen.js b/src/agent-screen.js
index 74119fbca..be840a85d 100644
--- a/src/agent-screen.js
+++ b/src/agent-screen.js
@@ -278,7 +278,7 @@ async function renderSetup() {
try {
const csrf = await fetch('/api/csrf-token', { credentials: 'include' })
.then((r) => r.json())
- .then((j) => j.token || '')
+ .then((j) => j.data?.token || j.token || '')
.catch(() => '');
const r = await fetch('/api/api-keys', {
diff --git a/src/irl/world-lines-client.js b/src/irl/world-lines-client.js
index 443fb1f7d..79962caaa 100644
--- a/src/irl/world-lines-client.js
+++ b/src/irl/world-lines-client.js
@@ -90,7 +90,8 @@ async function csrfToken() {
if (_csrf) return _csrf;
try {
const r = await fetch('/api/csrf-token', { credentials: 'include' });
- const { token } = await asJson(r);
+ const j = await asJson(r);
+ const token = j?.data?.token || j?.token || null;
_csrf = token;
return token;
} catch {
diff --git a/tests/csrf-token-shape-guard.test.js b/tests/csrf-token-shape-guard.test.js
new file mode 100644
index 000000000..45cfb26ae
--- /dev/null
+++ b/tests/csrf-token-shape-guard.test.js
@@ -0,0 +1,69 @@
+import { describe, it, expect, vi } from 'vitest';
+
+// Regression guard for the 403 csrf_missing storm on /api/api-keys (and the
+// silent breakage of agent-wallet provisioning and IRL world-lines).
+//
+// GET /api/csrf-token historically returned the token ONLY under `data`:
+// { data: { token, expires_in } }
+// Several clients hand-rolled the fetch and read the token off the top level
+// (`j.token`, `const { token } = await r.json()`), got `undefined`, sent an
+// empty x-csrf-token header, and the server rejected the mutation with 403.
+//
+// The permanent fix is server-side tolerance: the endpoint now returns the
+// token at BOTH the top level and under `data`, so EVERY client accessor works
+// regardless of the shape it expects. This test locks that contract in — if
+// someone "cleans up" the redundant top-level token later, the class of bug
+// comes back, and this fails the build before it ships.
+
+vi.mock('../api/_lib/auth.js', () => ({
+ getSessionUser: async () => ({ id: 'user-test-1' }),
+ authenticateBearer: async () => null,
+ extractBearer: () => null,
+}));
+
+vi.mock('../api/_lib/csrf.js', () => ({
+ issueCsrf: async () => ({ token: 'csrf-test-token-abc123', expiresIn: 3600 }),
+}));
+
+const { default: handler } = await import('../api/csrf-token.js');
+
+function invoke() {
+ const req = { method: 'GET', headers: {} };
+ let body = null;
+ let statusCode = 0;
+ const res = {
+ statusCode: 200,
+ headersSent: false,
+ writableEnded: false,
+ setHeader() {},
+ getHeader() {},
+ end(payload) {
+ this.writableEnded = true;
+ statusCode = this.statusCode;
+ body = payload ? JSON.parse(payload) : null;
+ },
+ };
+ return Promise.resolve(handler(req, res)).then(() => ({ statusCode, body }));
+}
+
+describe('CSRF token endpoint shape contract', () => {
+ it('returns 200', async () => {
+ const { statusCode } = await invoke();
+ expect(statusCode).toBe(200);
+ });
+
+ it('exposes the token at the TOP LEVEL (j.token) so flat accessors work', async () => {
+ const { body } = await invoke();
+ expect(body.token).toBe('csrf-test-token-abc123');
+ });
+
+ it('also exposes the token under `data` (j.data.token) for envelope accessors', async () => {
+ const { body } = await invoke();
+ expect(body.data?.token).toBe('csrf-test-token-abc123');
+ });
+
+ it('top-level and nested token are identical (single issued token)', async () => {
+ const { body } = await invoke();
+ expect(body.token).toBe(body.data?.token);
+ });
+});