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
fix(orb): normalize three more raw-r2.dev read paths the shared ORB fix missed
nirholas83ca1cc21a5c
diff --git a/api/_lib/forge-store.js b/api/_lib/forge-store.jsindex ca40872e9..09b2e4d61 100644--- a/api/_lib/forge-store.js+++ b/api/_lib/forge-store.js@@ -1103,13 +1103,13 @@ export async function getPublicCreation({ id, voterKey = null }) {id: r.id,prompt: r.prompt,aspect: r.aspect,- glb_url: r.glb_url,+ glb_url: normalizeStoredUrl(r.glb_url),// The phone-sized delivery variant, or null when one was never built.// Viewers prefer it and fall back to glb_url; downloads always use// glb_url. See buildWebVariant.- web_glb_url: r.web_glb_url ?? null,+ web_glb_url: normalizeStoredUrl(r.web_glb_url) ?? null,web_size_bytes: r.web_size_bytes ?? null,- preview_image_url: r.preview_image_url,+ preview_image_url: normalizeStoredUrl(r.preview_image_url),outcome: r.outcome,views_used: r.views_used ?? null,multiview: r.multiview ?? null,@@ -1179,8 +1179,8 @@ export async function listRelated({ id, category, limit = 6 }) {return rows.map((r) => ({id: r.id,prompt: r.prompt,- glb_url: r.glb_url,- preview_image_url: r.preview_image_url,+ glb_url: normalizeStoredUrl(r.glb_url),+ preview_image_url: normalizeStoredUrl(r.preview_image_url),model_category: r.model_category ?? 'other',backend: r.backend ?? null,vote_count: r.vote_count ?? 0,diff --git a/api/forge-share.js b/api/forge-share.jsindex 8b95f0e8f..a8dfc3710 100644--- a/api/forge-share.js+++ b/api/forge-share.js@@ -18,6 +18,7 @@ import { env } from './_lib/env.js';import { isUuid } from './_lib/validate.js';import { scriptJson } from './_lib/safe-text.js';import { creationJsonLd, renderPosterUrl, renderableGlb } from './_lib/creation-jsonld.js';+import { normalizeStoredUrl } from './_lib/r2.js';export default wrap(async (req, res) => {if (cors(req, res, { methods: 'GET,OPTIONS' })) return;@@ -63,7 +64,8 @@ export default wrap(async (req, res) => {]): null;const poster = posterGlb ? renderPosterUrl(origin, posterGlb) : null;- const ogImage = row.preview_image_url || poster || `${origin}/api/forge-og?id=${id}`;+ const previewImageUrl = normalizeStoredUrl(row.preview_image_url);+ const ogImage = previewImageUrl || poster || `${origin}/api/forge-og?id=${id}`;// X player card: interactive embed when the GLB is ready, degrading to the// summary_large_image tags below for crawlers (Discord, Slack, pre-approval// X) that never fetch twitter:player. Reuses /forge/embed (pages/forge-embed.html),@@ -81,7 +83,7 @@ export default wrap(async (req, res) => {description: desc,glbUrl: finished ? row.glb_url : null,glbSizeBytes: row.size_bytes,- thumbnailUrl: poster || row.preview_image_url || null,+ thumbnailUrl: poster || previewImageUrl || null,image: ogImage,creator: row.creator_username? { username: row.creator_username, displayName: row.creator_display_name }diff --git a/api/forged.js b/api/forged.jsindex 70c58a9a9..e0190b621 100644--- a/api/forged.js+++ b/api/forged.js@@ -30,6 +30,7 @@ import { cors, json, method, serverError, rateLimited } from './_lib/http.js';import { limits, clientIp } from './_lib/rate-limit.js';import { cacheGet, cacheSet } from './_lib/cache.js';import { explorerTxUrl } from './_lib/avatar-wallet.js';+import { normalizeStoredUrl } from './_lib/r2.js';import { CATEGORIES as PROP_CATEGORIES } from './_lib/x402/pipelines/forge-catalog.js';const FEED_TTL_S = 20;@@ -46,6 +47,7 @@ function shortAddr(a) {function toProp(row) {const priceUsdc = row.amount_atomic != null ? Number(row.amount_atomic) / 1e6 : null;+ const glbUrl = normalizeStoredUrl(row.glb_url);return {id: Number(row.id),ts: row.ts,@@ -53,7 +55,7 @@ function toProp(row) {category: row.category,tier: row.tier,status: row.status,- glb_url: row.glb_url,+ glb_url: glbUrl,novelty: row.novelty != null ? Number(row.novelty) : null,cluster_id: row.cluster_id,price_usdc: priceUsdc,@@ -62,7 +64,7 @@ function toProp(row) {payer_kind: row.payer_kind || 'agent',tx_sig: row.tx_sig,explorer_url: row.tx_sig ? explorerTxUrl(row.tx_sig) : null,- viewer_url: row.glb_url ? `/app?src=${encodeURIComponent(row.glb_url)}` : null,+ viewer_url: glbUrl ? `/app?src=${encodeURIComponent(glbUrl)}` : null,};}diff --git a/tests/api/forge-pipeline-endpoints.test.js b/tests/api/forge-pipeline-endpoints.test.jsindex 60f9fc571..bc3dadcb1 100644--- a/tests/api/forge-pipeline-endpoints.test.js+++ b/tests/api/forge-pipeline-endpoints.test.js@@ -122,6 +122,7 @@ const storageState = { configured: true, rejected: false };vi.mock('../../api/_lib/r2.js', () => ({presignUpload: (...a) => presignMock(...a),publicUrl: (key) => `https://cdn.example/${key}`,+ normalizeStoredUrl: (url) => url,objectStorageConfigured: () => storageState.configured,objectStorageUsable: async () => {if (!storageState.configured) return { ok: false, reason: 'unconfigured', message: null };diff --git a/tests/api/forge-share.test.js b/tests/api/forge-share.test.jsnew file mode 100644index 000000000..88f1a3437--- /dev/null+++ b/tests/api/forge-share.test.js@@ -0,0 +1,77 @@+// Integration test for GET /api/forge-share, the server-rendered share card a+// social crawler gets when it hits /forge/share/:id, and the poster the live+// /forge/embed viewer loads from its `og:image`/jsonLd `thumbnailUrl`.+//+// The regression this file exists for (prompt-402, "console errors" work+// order): a row written before the write-path fix that routes+// forge_creations.preview_image_url through cdnUrl() still carries the raw+// public *.r2.dev bucket domain. This handler read that column straight off+// the row and baked it into og:image / twitter:image / the embed poster+// param, so the raw r2.dev URL reached a browser via /forge/embed and tripped+// Chrome's Opaque Response Blocking. Every stored-URL column this handler+// serves to a browser must go through normalizeStoredUrl(), matching the+// convention in api/_lib/forge-store.js (see forge-store-listing-orb-safe.test.js).+import { describe, it, expect, vi, beforeEach } from 'vitest';++const sqlMock = vi.fn(async () => []);++vi.mock('../../api/_lib/db.js', () => ({+ sql: (...a) => sqlMock(...a),+ isDbUnavailableError: () => false,+}));+vi.mock('../../api/_lib/env.js', () => ({+ env: { APP_ORIGIN: 'https://three.ws', S3_PUBLIC_DOMAIN: 'https://pub-legacy.r2.dev' },+}));++const { default: handler } = await import('../../api/forge-share.js');++const CREATION_ID = 'fce196ec-aaa1-417e-bb9c-e8a5b4d9f945';+const LEGACY_PREVIEW = 'https://pub-legacy.r2.dev/forge/thumb/legacy.png';++function mkReq(qs = `id=${CREATION_ID}`, method = 'GET') {+ return { method, url: `/api/forge-share?${qs}`, headers: { host: 'three.ws' } };+}++function mkRes() {+ return {+ statusCode: 200,+ _h: {},+ _body: undefined,+ writableEnded: false,+ setHeader(k, v) { this._h[k.toLowerCase()] = v; },+ getHeader(k) { return this._h[k.toLowerCase()]; },+ end(b) { this._body = b; this.writableEnded = true; },+ };+}++beforeEach(() => {+ sqlMock.mockReset();+ sqlMock.mockResolvedValue([]);+});++describe('GET /api/forge-share', () => {+ it('normalizes a legacy raw-r2.dev preview_image_url before using it as og:image', async () => {+ sqlMock.mockResolvedValueOnce([{+ id: CREATION_ID,+ prompt: 'a cardboard robot',+ preview_image_url: LEGACY_PREVIEW,+ status: 'generating',+ glb_url: null,+ web_glb_url: null,+ web_size_bytes: null,+ size_bytes: null,+ model_category: 'other',+ created_at: new Date().toISOString(),+ creator_username: null,+ creator_display_name: null,+ }]);+ const res = mkRes();+ await handler(mkReq(), res);++ expect(res.statusCode).toBe(200);+ expect(res._body).not.toMatch(/r2\.dev/);+ expect(res._body).toContain(+ '<meta property="og:image" content="https://three.ws/cdn/forge/thumb/legacy.png">',+ );+ });+});diff --git a/tests/api/forged-feed.test.js b/tests/api/forged-feed.test.jsindex 7d76767ff..c69c2b20a 100644--- a/tests/api/forged-feed.test.js+++ b/tests/api/forged-feed.test.js@@ -10,6 +10,17 @@import { describe, it, expect, vi, beforeAll, afterAll, beforeEach } from 'vitest';import { createServer } from 'node:http';+// S3_PUBLIC_DOMAIN mocked (not api/_lib/r2.js itself) so normalizeStoredUrl's+// real keyFromPublicUrl/cdnUrl logic runs against a deterministic domain: the+// ORB regression this test guards against is that /gallery's model-viewer+// loads forge_autonomous_props.glb_url straight off the row (src/forged-gallery.js),+// so a legacy row still carrying the raw public r2.dev domain trips Chrome's+// Opaque Response Blocking on the GLB fetch, exactly like the forge_creations+// columns fixed in api/_lib/forge-store.js (see forge-store-listing-orb-safe.test.js).+vi.mock('../../api/_lib/env.js', () => ({+ env: { S3_PUBLIC_DOMAIN: 'https://pub-legacy.r2.dev', APP_ORIGIN: 'https://three.ws' },+}));+const ROWS = [{id: 141,@@ -41,6 +52,22 @@ const ROWS = [payer: null,amount_atomic: null,},+ // A row written before the write-path fix that routes glb_url through+ // cdnUrl(): still carries the raw public r2.dev bucket domain.+ {+ id: 143,+ ts: '2026-08-13T06:10:00.000Z',+ prompt: 'a cargo drone, 3D prop',+ category: 'vehicle',+ tier: 'standard',+ status: 'done',+ glb_url: 'https://pub-legacy.r2.dev/forge/cargo-drone.glb',+ novelty: '0.5',+ cluster_id: 3,+ tx_sig: 'SigTwo',+ payer: 'X4o2UuVNMxnrgkzVy97kPF5gmS6CLRCVJGB48VastML',+ amount_atomic: '200000',+ },];const STATS = [@@ -124,6 +151,18 @@ describe('/api/forged feed', () => {expect(body.stats.categories).toEqual({ vehicle: 1 });});+ it('normalizes a legacy raw-r2.dev glb_url before it reaches the model-viewer src', async () => {+ const r = await fetch(`${base}/api/forged?limit=3`);+ const body = await r.json();+ const legacy = body.props.find((p) => p.id === 143);++ expect(legacy.glb_url).toBe('https://three.ws/cdn/forge/cargo-drone.glb');+ expect(legacy.glb_url).not.toMatch(/r2\.dev/);+ expect(legacy.viewer_url).toBe(+ `/app?src=${encodeURIComponent('https://three.ws/cdn/forge/cargo-drone.glb')}`,+ );+ });+it('caches the shaped payload under a key scoped to every filter', async () => {await fetch(`${base}/api/forged?category=vehicle&status=all&limit=7`);expect(cacheWrites).toHaveLength(1);diff --git a/tests/forge-store-listing-orb-safe.test.js b/tests/forge-store-listing-orb-safe.test.jsindex df68be69a..024c67eba 100644--- a/tests/forge-store-listing-orb-safe.test.js+++ b/tests/forge-store-listing-orb-safe.test.js@@ -45,8 +45,10 @@ vi.mock('../api/_lib/r2.js', async (importOriginal) => {};});-const { listCreations, listCreationsByUser, listShowcase, listRecentCreations, listRemixable, listMostRemixed } =- await import('../api/_lib/forge-store.js');+const {+ listCreations, listCreationsByUser, listShowcase, listRecentCreations, listRemixable, listMostRemixed,+ getPublicCreation, listRelated,+} = await import('../api/_lib/forge-store.js');const { publicUrl, cdnUrl } = await import('../api/_lib/r2.js');const LEGACY_GLB = publicUrl('forge/client-1/legacy.glb');@@ -132,4 +134,34 @@ describe('forge-store listing reads normalize legacy raw-domain URLs', () => {expect(row.glb_url).toBe(cdnUrl('forge/client-1/legacy.glb'));expect(row.preview_image_url).toBe(cdnUrl('forge/thumb/legacy.png'));});++ it('getPublicCreation (model-page share/poster read): glb_url, web_glb_url, preview_image_url', async () => {+ rows = [{+ id: 'c7', prompt: 'x', aspect: null, glb_url: LEGACY_GLB, web_glb_url: LEGACY_GLB,+ web_size_bytes: null, preview_image_url: LEGACY_PREVIEW, outcome: 'generated',+ views_used: null, multiview: false, backend: 'trellis', tier: 'standard', path: 'image',+ model_category: 'other', created_at: new Date().toISOString(),+ x402_payer: null, x402_tx_sig: null, x402_price_atomic: null,+ vote_count: 0, size_bytes: 1024, remixable: false, remix_royalty_bps: null,+ parent_creation_id: null, refine_instruction: null, view_count: 0, remix_count: 0, voted: false,+ creator_username: null, creator_display_name: null, creator_avatar_url: null,+ sim_readiness: null, sim_readiness_graded_at: null,+ }];+ const row = await getPublicCreation({ id: 'c7' });+ expect(row.glb_url).toBe(cdnUrl('forge/client-1/legacy.glb'));+ expect(row.web_glb_url).toBe(cdnUrl('forge/client-1/legacy.glb'));+ expect(row.preview_image_url).toBe(cdnUrl('forge/thumb/legacy.png'));+ expect(row.glb_url).not.toMatch(/r2\.dev/);+ });++ it('listRelated (model-page sidebar poster read): glb_url, preview_image_url', async () => {+ rows = [{+ id: 'c8', prompt: 'x', glb_url: LEGACY_GLB, preview_image_url: LEGACY_PREVIEW,+ model_category: 'other', backend: 'trellis', vote_count: 0, view_count: 0,+ created_at: new Date().toISOString(), same_category: true,+ }];+ const [row] = await listRelated({ id: 'c7' });+ expect(row.glb_url).toBe(cdnUrl('forge/client-1/legacy.glb'));+ expect(row.preview_image_url).toBe(cdnUrl('forge/thumb/legacy.png'));+ });});