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(agent-trade): land the solana wallet, trade panel and AGI page follow-ups

nirholas6f4a3ecc9e5a
diff --git a/api/_lib/sketchfab.js b/api/_lib/sketchfab.js
index 1255161f7..568809087 100644
--- a/api/_lib/sketchfab.js
+++ b/api/_lib/sketchfab.js
@@ -74,7 +74,8 @@ const PLACEHOLDER_PROMPT_RE = /^(image-to-3d|untitled|test)$/i;
function categoryName(modelCategory) {
const cat = String(modelCategory || '').trim();
if (!cat) return '3D Model';
- return `Forged ${cat.replace(/[-_]+/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase())}`;
+ // Underscores are a slug separator; hyphens are part of the word ("sci-fi").
+ return `Forged ${cat.replace(/_+/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase())}`;
}
// Model name from the generation prompt: first clause, title-cased, article
diff --git a/public/changelog.json b/public/changelog.json
index a9cb7fd68..01097c3f9 100644
--- a/public/changelog.json
+++ b/public/changelog.json
@@ -1,5 +1,5 @@
{
- "generated_at": "2026-08-16T17:06:38.924Z",
+ "generated_at": "2026-08-16T17:07:14.691Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json + data/changelog.json",
"site": {
"name": "three.ws",
diff --git a/public/features.json b/public/features.json
index e4b0230cb..c5eacdab9 100644
--- a/public/features.json
+++ b/public/features.json
@@ -1,5 +1,5 @@
{
- "generated_at": "2026-08-16T17:06:38.904Z",
+ "generated_at": "2026-08-16T17:07:14.630Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json",
"site": {
"name": "three.ws",
diff --git a/src/agent-solana-wallet.js b/src/agent-solana-wallet.js
index 6083bffb6..2a3959e22 100644
--- a/src/agent-solana-wallet.js
+++ b/src/agent-solana-wallet.js
@@ -21,6 +21,20 @@ import { consumeCsrfToken } from './api.js';
const ENDPOINT = (id, qs = '') =>
`/api/agents/${encodeURIComponent(id)}/solana${qs ? `?${qs}` : ''}`;
+/**
+ * GET /api/agents/:id/solana answers in two shapes: the owner read returns
+ * `{ address, sol, … }`, while the public read a visitor gets returns
+ * `{ wallet, balance, … }` for the same wallet. Callers code to the documented
+ * owner shape, so a visitor used to see a dash where a real, publicly-readable
+ * balance existed. Normalize here, once, rather than in every caller.
+ */
+function normalizeWalletRead(data) {
+ if (!data || typeof data !== 'object') return data;
+ const address = data.address ?? data.wallet ?? null;
+ const sol = data.sol ?? data.balance ?? null;
+ return { ...data, address, sol };
+}
+
/**
* Fetch current wallet state from the server.
* @returns {Promise<{ status: 'ok'|'none'|'forbidden'|'error',
@@ -36,7 +50,11 @@ export async function fetchAgentSolanaWallet(agentId, network = 'mainnet') {
const json = await resp.json().catch(() => ({}));
if (resp.status === 404) return { status: 'none' };
if (!resp.ok) return { status: 'error', error: json?.error?.message || `HTTP ${resp.status}` };
- return { status: 'ok', data: json.data };
+ const data = normalizeWalletRead(json.data);
+ // The public read answers 200 with a null wallet for an agent whose wallet is
+ // still being prepared; the owner read answers 404. Both mean "no wallet yet".
+ if (!data?.address) return { status: 'none' };
+ return { status: 'ok', data };
}
/**
diff --git a/src/agent-trade.js b/src/agent-trade.js
index 7e72c1187..ac75863b6 100644
--- a/src/agent-trade.js
+++ b/src/agent-trade.js
@@ -285,7 +285,31 @@ function buildStage() {
el.style.transform = 'translate(-50%, -100%)';
}
+ // Below this width the projected anchors clamp into the same pixels as the
+ // central card, so the overlays leave the scene and stack into the fixed
+ // strip the stylesheet lays out (the same one the no-WebGL fallback uses).
+ const FLAT_OVERLAY_W = 560;
+ let flatOverlays = null;
+
+ function syncOverlayMode() {
+ const flat = innerWidth <= FLAT_OVERLAY_W;
+ if (flat === flatOverlays) return flat;
+ flatOverlays = flat;
+ document.body.classList.toggle('flat-overlays', flat);
+ if (flat) {
+ // Drop the inline positions the projector wrote, or they would win over
+ // the stylesheet's strip layout.
+ for (const el of [els.buyerLabel, els.sellerLabel, els.buyerBubble, els.sellerBubble]) {
+ el.style.left = '';
+ el.style.top = '';
+ el.style.transform = '';
+ }
+ }
+ return flat;
+ }
+
function updateOverlays() {
+ if (syncOverlayMode()) return;
placeEl(els.buyerLabel, labelPos.buyer, 0, -8);
placeEl(els.sellerLabel, labelPos.seller, 0, -8);
diff --git a/src/agi.js b/src/agi.js
index b1e9c34dc..931dd22c7 100644
--- a/src/agi.js
+++ b/src/agi.js
@@ -30,6 +30,7 @@ const state = {
el3d: null, // the embodied <agent-3d>
embodied: false,
bodyFailover: false, // the agent's own model died; the default body is standing in
+ bodyGaveUp: false, // both bodies failed; the stage explains itself and polls stop remounting
lastScore: null, // last reputation value drawn, so the ring only re-sweeps on a real change
shell: false, // the stable layout has been built
filter: 'trade', // decision stream lens: 'trade' | 'all'
@@ -532,6 +533,7 @@ function renderError() {
state.el3d = null;
state.embodied = false;
state.bodyFailover = false;
+ state.bodyGaveUp = false;
document.getElementById('agi-retry')?.addEventListener('click', () => { renderLoading(); boot(); });
}
diff --git a/tests/api/x-connect-scope.test.js b/tests/api/x-connect-scope.test.js
new file mode 100644
index 000000000..19670e9cd
--- /dev/null
+++ b/tests/api/x-connect-scope.test.js
@@ -0,0 +1,106 @@
+// What /api/auth/x/connect actually asks X for.
+//
+// tests/api/x-scopes.test.js pins the scope sets themselves; this pins the one
+// place they reach the user: the authorize URL their browser is sent to. The
+// promise the seeding card makes ("it cannot post as you") is only true if the
+// `scope` parameter on that redirect carries no write scope, so that parameter
+// is asserted directly rather than the helper that builds it.
+
+import { describe, it, expect, beforeEach, vi } from 'vitest';
+
+vi.mock('../../api/_lib/db.js', () => ({
+ sql: vi.fn(async () => []),
+ isDbUnavailableError: () => false,
+ isDbCapacityError: () => false,
+ isStoragePressured: () => false,
+}));
+
+const authState = { session: { id: 'user-1' } };
+vi.mock('../../api/_lib/auth.js', () => ({
+ getSessionUser: vi.fn(async () => authState.session),
+ authenticateBearer: vi.fn(async () => null),
+ extractBearer: vi.fn(() => null),
+}));
+
+vi.mock('../../api/_lib/rate-limit.js', () => ({
+ limits: { authIp: vi.fn(async () => ({ success: true })) },
+ clientIp: vi.fn(() => '127.0.0.1'),
+}));
+
+vi.mock('../../api/_lib/env.js', () => ({
+ env: {
+ X_OAUTH_CLIENT_ID: 'test-client-id',
+ X_OAUTH_CLIENT_SECRET: 'test-client-secret',
+ APP_ORIGIN: 'https://three.ws',
+ JWT_SECRET: 'test-jwt-secret-value-long-enough',
+ },
+}));
+
+const { default: handler } = await import('../../api/auth/x/[action].js');
+const { X_SCOPE_SETS } = await import('../../api/_lib/x-scopes.js');
+
+function mockRes() {
+ return {
+ statusCode: 200,
+ headers: {},
+ headersSent: false,
+ writableEnded: false,
+ body: null,
+ setHeader(k, v) { this.headers[k.toLowerCase()] = v; },
+ getHeader(k) { return this.headers[k.toLowerCase()]; },
+ end(payload) { this.headersSent = true; this.writableEnded = true; this.body = payload ?? null; },
+ };
+}
+
+async function connect(query = '') {
+ const req = {
+ method: 'GET',
+ url: `/api/auth/x/connect${query}`,
+ headers: {},
+ socket: {},
+ query: { action: 'connect' },
+ };
+ const res = mockRes();
+ await handler(req, res);
+ const location = res.headers.location ? new URL(res.headers.location) : null;
+ return { res, location, scope: location?.searchParams.get('scope') ?? null };
+}
+
+beforeEach(() => {
+ authState.session = { id: 'user-1' };
+});
+
+describe('GET /api/auth/x/connect', () => {
+ it('sends a browser to X with only read scopes when the seeding card asks', async () => {
+ const { res, location, scope } = await connect('?scope=read');
+ expect(res.statusCode).toBe(302);
+ expect(location.host).toBe('twitter.com');
+ expect(scope.split(' ')).toEqual([...X_SCOPE_SETS.read]);
+ expect(scope).not.toMatch(/\.write/);
+ });
+
+ it('still asks for the full set by default, so posting surfaces are unaffected', async () => {
+ const { scope } = await connect();
+ expect(scope.split(' ')).toEqual([...X_SCOPE_SETS.full]);
+ expect(scope).toContain('tweet.write');
+ });
+
+ it('treats an unrecognised scope name as the full set rather than a narrower one', async () => {
+ const { scope } = await connect('?scope=readonly');
+ expect(scope.split(' ')).toEqual([...X_SCOPE_SETS.full]);
+ });
+
+ it('keeps PKCE and the signed state cookie on the read-only path', async () => {
+ const { res, location } = await connect('?scope=read&agent_id=agent-9');
+ expect(location.searchParams.get('code_challenge_method')).toBe('S256');
+ expect(location.searchParams.get('code_challenge')).toBeTruthy();
+ expect(location.searchParams.get('state')).toBeTruthy();
+ expect(String(res.headers['set-cookie'])).toMatch(/^__Host-xoa=/);
+ });
+
+ it('requires a session before starting any authorization', async () => {
+ authState.session = null;
+ const { res } = await connect('?scope=read');
+ expect(res.statusCode).toBe(401);
+ });
+});
diff --git a/tests/avatar-thumbs.test.js b/tests/avatar-thumbs.test.js
index eed821cff..c4ccccef1 100644
--- a/tests/avatar-thumbs.test.js
+++ b/tests/avatar-thumbs.test.js
@@ -33,7 +33,12 @@ vi.mock('../api/_lib/db.js', () => ({ sql: (...a) => sqlMock(...a) }));
const headObjectMock = vi.fn();
const putObjectMock = vi.fn();
const presignGetMock = vi.fn(async ({ key }) => `https://signed.example/${key}`);
-vi.mock('../api/_lib/r2.js', () => ({
+// Only the IO is faked. The failure classifiers come from the real modules: they
+// decide whether a failed render costs the avatar one of its three lifetime
+// attempts, and a hand-copied stand-in drifts from production silently, which is
+// exactly how "spawn EFAULT" ended up retiring four blameless avatars for good.
+vi.mock('../api/_lib/r2.js', async (importActual) => ({
+ ...(await importActual()),
headObject: (...a) => headObjectMock(...a),
putObject: (...a) => putObjectMock(...a),
presignGet: (...a) => presignGetMock(...a),
@@ -42,13 +47,9 @@ vi.mock('../api/_lib/r2.js', () => ({
}));
const renderGlbToPngMock = vi.fn();
-// Mirrors the real classifier in render-glb.js — renderBatch depends on it to tell
-// "this model is broken" apart from "chromium died".
-const INFRA_RE =
- /connection closed|target closed|browser has disconnected|browser was not found|protocol error|session closed|websocket|econnreset|socket hang up|failed to launch/i;
-vi.mock('../api/_lib/render-glb.js', () => ({
+vi.mock('../api/_lib/render-glb.js', async (importActual) => ({
+ ...(await importActual()),
renderGlbToPng: (...a) => renderGlbToPngMock(...a),
- isBrowserInfrastructureError: (err) => INFRA_RE.test(String(err?.message || err || '')),
}));
const { adoptForgePreviews, renderThumbnail, renderBatch, thumbKeyFor, isMissingThumbnail } =
diff --git a/tests/forge-store-delete.test.js b/tests/forge-store-delete.test.js
index dafb788fc..75f27c49a 100644
--- a/tests/forge-store-delete.test.js
+++ b/tests/forge-store-delete.test.js
@@ -43,6 +43,9 @@ vi.mock('../api/_lib/db.js', () => ({
const deleteObjectMock = vi.fn(async () => {});
vi.mock('../api/_lib/r2.js', () => ({
putObject: vi.fn(async () => {}),
+ // forgeStoreEnabled() reads the object-storage gate through r2.js, so this
+ // mock has to carry it or every store call throws before it runs.
+ objectStorageConfigured: () => true,
publicUrl: (key) => `https://cdn.example.com/${key}`,
deleteObject: (...args) => deleteObjectMock(...args),
keyFromPublicUrl: (url) =>