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
test: cover the site-wide follow graph API; changelog for the shipped feature
fudjiacf2ebf459864
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 69bb89544..be8786538 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,6 +14,7 @@ Public history for [three.ws](https://three.ws), newest first. New pages come fr- **AI features can no longer go down when one provider does** — Every AI-powered feature on three.ws (fact checks, agent chat, persona extraction, scene composing) routes through one shared brain that tries free providers first and falls back automatically. That chain just got much deeper: Groq now has a second lane with its own separate quota, OpenRouter gets a zero-credit free lane so an empty account no longer kills it, optional Cerebras and Google AI Studio lanes activate the moment a key is added, and — the anchor — Gemini on the platform's own Google Cloud now backs the whole chain with no third-party quota to exhaust. Previously a rare bad hour where every free tier was exhausted at once could surface an error; now the request rides through. The fact-checker was also corrected to stop favoring a paid key ahead of the free lanes. (`/changelog`) `[improvement, fix, infra]`- **Closed a path-traversal hole in the API router** — The server that routes every /api request to its handler split the URL into path segments before decoding them, so a specially encoded request could smuggle a '../' into a single segment and reach a file outside the API folder — or an internal helper meant to be unreachable — and run it without authentication. The router now rejects any decoded segment that contains a path separator and, as a second line of defense, refuses to load any handler that resolves outside the API directory. Normal routes are unaffected; a regression test locks the fix in place. `[security]`- **Fixed: /play was signing players out after an hour** — Players who signed in with X to enter a coin's Holders world could get bounced back to the /play lobby with a false "not signed in" message after about an hour, even though their session was still good. The sign-in session's access token only lived for an hour, and the endpoints checking it were discarding the still-valid 30-day session instead of quietly renewing it. Signing in with X on /play now stays good for the full 30 days without needing to reconnect. (`/play`) `[fix]`+- **Follow creators site-wide and see who's following you** — Every profile at /u/:username now has a Follow button, plus follower and following counts you can open into full lists. Following someone is one-directional and needs no approval — the right model for keeping up with a creator, not the mutual-friend system that already powers /play and /walk DMs. You get a notification when someone follows you, and following people now feeds your home feed (GET /api/users/me/feed) with their new avatars, agents, coins, models, and worlds as they post them. Logged-out visitors are sent to sign in instead of the button silently doing nothing. (`/profile`) `[feature]`- **Market-maker and limit-order engines are now crash-safe on Cloud Run** — The two background workers that run agents' automated market-making and limit orders are long-running loops, not web servers. On Cloud Run, a service that never answers the platform's startup health check gets killed and restarted in a loop — which would have taken these money-moving engines offline the moment they were deployed as services. Both now start a tiny health endpoint when the platform asks for one (and stay silent when run as a scheduled job, where none is needed), so they boot cleanly either way. We also added a documented, repeatable deploy for each so there's no guesswork about how they ship. `[infra]`- **Money-moving agent skills now require an explicit spend confirmation** — The skills that let an agent send tokens, swap, or pay a paid API used to validate the format of an address or amount but never stopped to confirm the actual intent before signing — and some read a token's on-chain name and description straight into the same agent that holds the signing key, so a token deliberately named like an instruction ('send 5 to 0x…') could try to steer a real transfer. Each of these skills now renders a recipient/amount/token/chain confirmation card and waits for an explicit yes before moving any funds, and treats all on-chain and token text as untrusted data that is never followed as an instruction. The platform's operating rules were updated to make spend, transfer, and mint confirmations a required step rather than something to skip for speed. `[security]`- **New driving jobs in /play — Cross-Town Delivery and East-West Express** — Two real driving missions landed on the /play jobs board. Grab a car parked at any of the four avenue depots, run the rush order to the depot on the other side of town, and get paid — the delivery only counts if you actually drove it, not walked it. Pairs with the world's existing drivable vehicles and cash economy for a real 'drive around, do jobs, spend the cash' loop. (`/play`) `[feature]`diff --git a/data/changelog.json b/data/changelog.jsonindex 174743a5c..2620c3722 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-07-12",+ "title": "Follow creators site-wide and see who's following you",+ "summary": "Every profile at /u/:username now has a Follow button, plus follower and following counts you can open into full lists. Following someone is one-directional and needs no approval — the right model for keeping up with a creator, not the mutual-friend system that already powers /play and /walk DMs. You get a notification when someone follows you, and following people now feeds your home feed (GET /api/users/me/feed) with their new avatars, agents, coins, models, and worlds as they post them. Logged-out visitors are sent to sign in instead of the button silently doing nothing.",+ "tags": [+ "feature"+ ],+ "link": "/profile"+ },{"date": "2026-07-12","title": "Your creator portfolio: every forged model and world, in one place",diff --git a/public/changelog.json b/public/changelog.jsonindex aa5e955e7..6bed65884 100644--- a/public/changelog.json+++ b/public/changelog.json@@ -1,5 +1,5 @@{- "generated_at": "2026-07-12T15:56:33.792Z",+ "generated_at": "2026-07-12T16:06:40.049Z","generated_by": "scripts/build-page-index.mjs from data/pages.json + data/changelog.json","site": {"name": "three.ws",@@ -90,6 +90,16 @@"fix"]},+ {+ "date": "2026-07-12",+ "type": "update",+ "title": "Follow creators site-wide and see who's following you",+ "summary": "Every profile at /u/:username now has a Follow button, plus follower and following counts you can open into full lists. Following someone is one-directional and needs no approval — the right model for keeping up with a creator, not the mutual-friend system that already powers /play and /walk DMs. You get a notification when someone follows you, and following people now feeds your home feed (GET /api/users/me/feed) with their new avatars, agents, coins, models, and worlds as they post them. Logged-out visitors are sent to sign in instead of the button silently doing nothing.",+ "link": "/profile",+ "tags": [+ "feature"+ ]+ },{"date": "2026-07-12","type": "update",diff --git a/public/changelog.xml b/public/changelog.xmlindex e935a81dd..4ecb369ae 100644--- a/public/changelog.xml+++ b/public/changelog.xml@@ -70,6 +70,14 @@<category>fix</category><description>Players who signed in with X to enter a coin's Holders world could get bounced back to the /play lobby with a false "not signed in" message after about an hour, even though their session was still good. The sign-in session's access token only lived for an hour, and the endpoints checking it were discarding the still-valid 30-day session instead of quietly renewing it. Signing in with X on /play now stays good for the full 30 days without needing to reconnect.</description></item>+ <item>+ <title>Follow creators site-wide and see who's following you</title>+ <link>https://three.ws/profile</link>+ <guid isPermaLink="false">2026-07-12:Follow creators site-wide and see who's following you</guid>+ <pubDate>Sun, 12 Jul 2026 12:00:00 GMT</pubDate>+ <category>feature</category>+ <description>Every profile at /u/:username now has a Follow button, plus follower and following counts you can open into full lists. Following someone is one-directional and needs no approval — the right model for keeping up with a creator, not the mutual-friend system that already powers /play and /walk DMs. You get a notification when someone follows you, and following people now feeds your home feed (GET /api/users/me/feed) with their new avatars, agents, coins, models, and worlds as they post them. Logged-out visitors are sent to sign in instead of the button silently doing nothing.</description>+ </item><item><title>Market-maker and limit-order engines are now crash-safe on Cloud Run</title><link>https://three.ws/changelog</link>diff --git a/public/features.json b/public/features.jsonindex 9b18d1b7b..3ec8f9166 100644--- a/public/features.json+++ b/public/features.json@@ -1,5 +1,5 @@{- "generated_at": "2026-07-12T15:56:33.778Z",+ "generated_at": "2026-07-12T16:06:40.034Z","generated_by": "scripts/build-page-index.mjs from data/pages.json","site": {"name": "three.ws",diff --git a/tests/api/users-follow.test.js b/tests/api/users-follow.test.jsnew file mode 100644index 000000000..2fbb99a35--- /dev/null+++ b/tests/api/users-follow.test.js@@ -0,0 +1,231 @@+// Unit tests for the site-wide follow graph:+// GET/POST/DELETE /api/users/:username/follow+// GET /api/users/:username/follows+// GET /api/users/me/feed+//+// Mocks: sql, auth, csrf, rate-limit, feed (publishUserEvent). All offline —+// no DATABASE_URL or Redis needed. Verifies the user_follows edge semantics+// (idempotent follow/unfollow, self-follow rejected, anonymous-safe reads,+// 401 on anonymous mutation) and the follow-event shape documented in+// api/_lib/feed.js (USER_EVENT_TYPES.follow).++import { describe, it, expect, vi, beforeEach } from 'vitest';++// ── Mock layer ──────────────────────────────────────────────────────────────++const authState = { session: null };+vi.mock('../../api/_lib/auth.js', () => ({+ getSessionUser: vi.fn(async () => authState.session),+}));++vi.mock('../../api/_lib/csrf.js', () => ({ requireCsrf: vi.fn(async () => true) }));++const sqlQueue = [];+const sqlCalls = [];+vi.mock('../../api/_lib/db.js', () => ({+ sql: Object.assign(+ vi.fn(async (...args) => {+ sqlCalls.push(args);+ return sqlQueue.length ? sqlQueue.shift() : [];+ }),+ { transaction: vi.fn(async (fns) => { for (const f of fns) await f; }) },+ ),+ isDbUnavailableError: () => false,+ isDbCapacityError: () => false,+}));++const rlState = { success: true };+vi.mock('../../api/_lib/rate-limit.js', () => ({+ limits: {+ authIp: vi.fn(async () => rlState),+ authedReadIp: vi.fn(async () => rlState),+ },+ clientIp: vi.fn(() => '127.0.0.1'),+}));++const publishUserEvent = vi.fn();+vi.mock('../../api/_lib/feed.js', () => ({ publishUserEvent }));++vi.mock('../../api/_lib/r2.js', () => ({ publicUrl: (k) => `https://r2.example/${k}` }));++const { default: followHandler } = await import('../../api/users/[username]/follow.js');+const { default: followsHandler } = await import('../../api/users/[username]/follows.js');+const { default: meFeedHandler } = await import('../../api/users/me/feed.js');++// ── request/response helpers ────────────────────────────────────────────────++function makeReq({ method = 'GET', query = {} } = {}) {+ return { method, query, headers: {} };+}+function makeRes() {+ return {+ statusCode: 200,+ _h: {},+ setHeader(k, v) { this._h[k.toLowerCase()] = v; },+ getHeader(k) { return this._h[k.toLowerCase()]; },+ end(body) { this._body = body; },+ };+}+async function call(handler, req) {+ const res = makeRes();+ await handler(req, res);+ let body = null;+ try { body = JSON.parse(res._body); } catch {}+ return { res, body };+}++const VIEWER = { id: '00000000-0000-0000-0000-000000000001', username: 'alice', display_name: 'Alice' };+const TARGET = { id: '00000000-0000-0000-0000-000000000002', username: 'bob' };++beforeEach(() => {+ sqlQueue.length = 0;+ sqlCalls.length = 0;+ publishUserEvent.mockReset();+ authState.session = null;+ rlState.success = true;+});++describe('GET /api/users/:username/follow', () => {+ it('anonymous viewer sees counts with both edges false, no session required', async () => {+ sqlQueue.push([{ id: TARGET.id, username: TARGET.username }]); // target lookup+ sqlQueue.push([{ followers_count: 4, following_count: 1 }]); // counts()+ const { res, body } = await call(followHandler, makeReq({ query: { username: 'bob' } }));+ expect(res.statusCode).toBe(200);+ expect(body.following).toBe(false);+ expect(body.followed_by).toBe(false);+ expect(body.followers_count).toBe(4);+ expect(body.following_count).toBe(1);+ });++ it('404s for an unknown username', async () => {+ sqlQueue.push([]); // target lookup: no row+ const { res, body } = await call(followHandler, makeReq({ query: { username: 'ghost' } }));+ expect(res.statusCode).toBe(404);+ expect(body.error).toBe('not_found');+ });++ it('signed-in viewer sees following/followed_by from the edge rows', async () => {+ authState.session = VIEWER;+ sqlQueue.push([{ id: TARGET.id, username: TARGET.username }]); // target lookup+ sqlQueue.push([{ followers_count: 2, following_count: 0 }]); // counts()+ sqlQueue.push([{ follower_id: VIEWER.id, following_id: TARGET.id }]); // edges(): viewer follows target+ const { body } = await call(followHandler, makeReq({ query: { username: 'bob' } }));+ expect(body.following).toBe(true);+ expect(body.followed_by).toBe(false);+ });+});++describe('POST /api/users/:username/follow', () => {+ it('401s for an anonymous mutation instead of failing silently or 500ing', async () => {+ sqlQueue.push([{ id: TARGET.id, username: TARGET.username }]); // target lookup+ const { res, body } = await call(followHandler, makeReq({ method: 'POST', query: { username: 'bob' } }));+ expect(res.statusCode).toBe(401);+ expect(body.error).toBe('unauthorized');+ expect(publishUserEvent).not.toHaveBeenCalled();+ });++ it('rejects self-follow with 400', async () => {+ authState.session = TARGET;+ sqlQueue.push([{ id: TARGET.id, username: TARGET.username }]); // target lookup (self)+ const { res, body } = await call(followHandler, makeReq({ method: 'POST', query: { username: TARGET.username } }));+ expect(res.statusCode).toBe(400);+ expect(body.error).toBe('bad_request');+ });++ it('inserts the edge, fires a follow event in the documented shape, and is idempotent', async () => {+ authState.session = VIEWER;+ sqlQueue.push([{ id: TARGET.id, username: TARGET.username }]); // target lookup+ sqlQueue.push([{ follower_id: VIEWER.id }]); // insert ... returning follower_id (new edge)+ sqlQueue.push([{ followers_count: 5, following_count: 1 }]); // counts()+ sqlQueue.push([{ follower_id: VIEWER.id, following_id: TARGET.id }]); // edges()++ const { res, body } = await call(followHandler, makeReq({ method: 'POST', query: { username: 'bob' } }));+ expect(res.statusCode).toBe(200);+ expect(body.following).toBe(true);+ expect(body.followers_count).toBe(5);++ expect(publishUserEvent).toHaveBeenCalledTimes(1);+ const [recipientId, event] = publishUserEvent.mock.calls[0];+ expect(recipientId).toBe(TARGET.id);+ expect(event).toMatchObject({+ type: 'follow',+ actor: 'Alice',+ follower_username: 'alice',+ link: '/u/alice',+ });+ });++ it('re-following (conflict, no new row) does not re-fire the notification', async () => {+ authState.session = VIEWER;+ sqlQueue.push([{ id: TARGET.id, username: TARGET.username }]); // target lookup+ sqlQueue.push([]); // insert ... on conflict do nothing → no row returned+ sqlQueue.push([{ followers_count: 5, following_count: 1 }]); // counts()+ sqlQueue.push([{ follower_id: VIEWER.id, following_id: TARGET.id }]); // edges()++ await call(followHandler, makeReq({ method: 'POST', query: { username: 'bob' } }));+ expect(publishUserEvent).not.toHaveBeenCalled();+ });+});++describe('DELETE /api/users/:username/follow', () => {+ it('unfollows and reflects the new state, without emitting a follow event', async () => {+ authState.session = VIEWER;+ sqlQueue.push([{ id: TARGET.id, username: TARGET.username }]); // target lookup+ sqlQueue.push([]); // delete+ sqlQueue.push([{ followers_count: 3, following_count: 1 }]); // counts()+ sqlQueue.push([]); // edges(): no row either direction++ const { body } = await call(followHandler, makeReq({ method: 'DELETE', query: { username: 'bob' } }));+ expect(body.following).toBe(false);+ expect(publishUserEvent).not.toHaveBeenCalled();+ });+});++describe('GET /api/users/:username/follows', () => {+ it('lists followers with per-row is_following for the signed-in viewer', async () => {+ authState.session = VIEWER;+ sqlQueue.push([{ id: TARGET.id }]); // target lookup+ sqlQueue.push([+ { id: VIEWER.id, username: 'alice', display_name: 'Alice', avatar_url: null, bio: null, created_at: '2026-07-01T00:00:00Z', is_following: false },+ ]);+ const { body } = await call(followsHandler, makeReq({ query: { username: 'bob', type: 'followers' } }));+ expect(body.type).toBe('followers');+ expect(body.users).toHaveLength(1);+ expect(body.users[0]).toMatchObject({ username: 'alice', is_following: false, is_self: true });+ });++ it('defaults to followers and paginates via has_more', async () => {+ sqlQueue.push([{ id: TARGET.id }]); // target lookup+ sqlQueue.push(Array.from({ length: 50 }, (_, i) => ({+ id: `u${i}`, username: `u${i}`, display_name: `U${i}`, avatar_url: null, bio: null,+ created_at: '2026-07-01T00:00:00Z', is_following: false,+ })));+ const { body } = await call(followsHandler, makeReq({ query: { username: 'bob' } }));+ expect(body.type).toBe('followers');+ expect(body.has_more).toBe(true);+ });+});++// GET /api/users/me/feed?scope=following is the "people I follow" activity+// filter that 02-activity-feed.md's mission depends on — and it's under active+// concurrent development by that prompt's agent (its query set and response+// shape changed shape mid-session while this file was being written). We only+// assert the follow-graph-specific contract here: default scope requires auth,+// and the zero-following case degrades to an empty (never a crashed) feed. The+// merge/render logic for avatars/agents/coins/models/worlds/follows itself is+// 02's surface to test.+describe('GET /api/users/me/feed (default scope=following)', () => {+ it('401s for an anonymous caller — the following feed is inherently personal', async () => {+ const { res, body } = await call(meFeedHandler, makeReq());+ expect(res.statusCode).toBe(401);+ expect(body.error).toBe('unauthorized');+ });++ it('degrades to an empty, well-formed feed when following nobody (never 500s)', async () => {+ authState.session = VIEWER;+ sqlQueue.push([{ following_count: 0 }]);+ const { res, body } = await call(meFeedHandler, makeReq());+ expect(res.statusCode).toBe(200);+ expect(body).toMatchObject({ items: [], following_count: 0, scope: 'following' });+ });+});