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
perf(play): fetch coin art and world thumbnails at the size they are shown
nirholascdaad67eb513
diff --git a/src/game/coincommunities-ui.js b/src/game/coincommunities-ui.jsindex 28a1db38a..cebbc9a66 100644--- a/src/game/coincommunities-ui.js+++ b/src/game/coincommunities-ui.js@@ -962,7 +962,7 @@ export class CommunityUI {}, [a.thumbnail_url? el('img', {- src: proxiedImageURL(a.thumbnail_url, a.id || ''), alt: a.name || 'Avatar', loading: 'lazy',+ src: proxiedImageURL(a.thumbnail_url, a.id || '', { width: 192 }), alt: a.name || 'Avatar', loading: 'lazy',// A stale thumbnail (e.g. a legacy OG key that 404s before the// avatar self-heals) shouldn't leave a broken-image icon: drop it// and let _renderChipPreview's live model render stand in. Removing@@ -1005,7 +1005,7 @@ export class CommunityUI {// stays clean. Same reason every other art surface on the platform proxies.const fallback = p.thumb? el('img', {- src: proxiedImageURL(p.thumb, p.url || ''), alt: p.label, loading: 'lazy',+ src: proxiedImageURL(p.thumb, p.url || '', { width: 192 }), alt: p.label, loading: 'lazy',// Broken thumb: drop it and render the real model instead, so the// chip is never left empty (on mobile a live thumbnail is what lets// us skip that render in the first place).@@ -2474,7 +2474,7 @@ export class CommunityUI {// show a real thumbnail (falling back to the glyph when a model has no render yet)._propButton(p) {const ico = p.thumbnail- ? el('img', { class: 'cc-prop-thumb', src: proxiedImageURL(p.thumbnail, p.id || ''), alt: '', loading: 'lazy', decoding: 'async' })+ ? el('img', { class: 'cc-prop-thumb', src: proxiedImageURL(p.thumbnail, p.id || '', { width: 192 }), alt: '', loading: 'lazy', decoding: 'async' }): el('span', { class: 'cc-prop-ico', 'aria-hidden': 'true', text: p.icon || '◆' });const btn = el('button', {class: 'cc-prop', type: 'button',@@ -2797,7 +2797,7 @@ export class CommunityUI {.filter(Boolean).join(' · ');return el('a', { class: 'cc-fb-item', href, title: 'Enter this world' }, [el('div', { class: 'cc-fb-thumb' }, [- b.thumb ? el('img', { src: proxiedImageURL(b.thumb, b.id || b.coinMint || ''), alt: b.title || 'Featured build', loading: 'lazy' })+ b.thumb ? el('img', { src: proxiedImageURL(b.thumb, b.id || b.coinMint || '', { width: 320 }), alt: b.title || 'Featured build', loading: 'lazy' }): el('div', { class: 'cc-fb-thumb-empty', 'aria-hidden': 'true', text: '🧱' }),]),el('div', { class: 'cc-fb-meta' }, [diff --git a/src/game/coincommunities.js b/src/game/coincommunities.jsindex 046a698b7..312e02625 100644--- a/src/game/coincommunities.js+++ b/src/game/coincommunities.js@@ -212,13 +212,19 @@ const COIN_URL = '/api/pump/coin';// Normalize a raw pump.fun coin (trending feed or search results, both share// the same upstream shape) into the compact record the lobby/world consume.+// Delivered width for coin art fetched through the image proxy.+const COIN_ART_WIDTH = 512;+function mapCoins(raw) {const list = Array.isArray(raw) ? raw : raw.data || raw.coins || raw.items || [];return list.map((c) => ({mint: c.mint || c.address,name: (c.name || '').trim() || 'Unnamed coin',symbol: (c.symbol || '').trim(),- image: proxiedImageURL(c.image_uri || c.image || c.imageUri || c.logo || '', c.mint || c.address || ''),+ // Coin art becomes a WebGL texture a few hundred pixels tall. 512 is+ // generous for that and keeps a creator's full-size upload out of both+ // the download and GPU memory.+ image: proxiedImageURL(c.image_uri || c.image || c.imageUri || c.logo || '', c.mint || c.address || '', { width: COIN_ART_WIDTH }),marketCap: c.usd_market_cap || c.market_cap_usd || c.marketCap || 0,})).filter((c) => c.mint);}@@ -902,7 +908,7 @@ export class CoinCommunities {// upstream text, and the room server truncates it for every peer.name: clampParam(c.name, 48),symbol: clampParam(c.symbol, 16),- image: proxiedImageURL(c.image_uri || c.image || c.imageUri || c.logo || '', mint),+ image: proxiedImageURL(c.image_uri || c.image || c.imageUri || c.logo || '', mint, { width: COIN_ART_WIDTH }),marketCap: c.usd_market_cap || c.market_cap_usd || c.marketCap || 0,};} catch (err) {diff --git a/src/ipfs.js b/src/ipfs.jsindex 4adc20b86..9fbb2aedc 100644--- a/src/ipfs.js+++ b/src/ipfs.js@@ -147,11 +147,19 @@ export function isSafeImageURL(url) {* file:, an over-long URL) resolves to '' so callers fall through to their own* "no art" branch instead of pushing a hostile value into an image sink.*+ * `width` asks the proxy for a copy no wider than that many pixels, re-encoded+ * as WebP (it snaps up to a fixed ladder, so a caller cannot mint unbounded+ * edge variants). Token art is stored at whatever size its creator uploaded:+ * four coins in the /play world pulled 2.7 MB of full-size PNGs for textures+ * that are a few hundred pixels on screen. Pass the size the art is actually+ * used at; leave it off to get the original bytes.+ ** @param {string} url Image URL (https://, ipfs:// or ar:// accepted).* @param {string} [seed] Stable placeholder seed (e.g. the token mint).+ * @param {{ width?: number }} [opts] Max delivered width in pixels.* @returns {string}*/-export function proxiedImageURL(url, seed = '') {+export function proxiedImageURL(url, seed = '', { width = 0 } = {}) {if (typeof url !== 'string' || !url) return '';// Protocol-relative art still deserves the proxy's CORS and gateway retry,// so give it the scheme the page is already on before anything else looks@@ -163,6 +171,7 @@ export function proxiedImageURL(url, seed = '') {if (raw.length > MAX_SOURCE_URL) return '';const q = new URLSearchParams({ url: resolveURI(raw) });if (seed) q.set('seed', seed);+ if (width > 0) q.set('w', String(Math.round(width)));return `/api/img?${q.toString()}`;}diff --git a/tests/ipfs-image-url-safety.test.js b/tests/ipfs-image-url-safety.test.jsindex d7f7dd0e9..665c8547f 100644--- a/tests/ipfs-image-url-safety.test.js+++ b/tests/ipfs-image-url-safety.test.js@@ -103,6 +103,22 @@ describe('isSafeImageURL', () => {});describe('proxiedImageURL', () => {+ it('adds ?w= only when a width is asked for, and rounds it', () => {+ const plain = new URL(proxiedImageURL('https://cdn.example/art.png', MINT), 'http://l');+ expect(plain.searchParams.has('w')).toBe(false);+ const sized = new URL(proxiedImageURL('https://cdn.example/art.png', MINT, { width: 512 }), 'http://l');+ expect(sized.searchParams.get('w')).toBe('512');+ expect(sized.searchParams.get('url')).toBe('https://cdn.example/art.png');+ expect(sized.searchParams.get('seed')).toBe(MINT);+ const rounded = new URL(proxiedImageURL('https://cdn.example/art.png', '', { width: 191.6 }), 'http://l');+ expect(rounded.searchParams.get('w')).toBe('192');+ });++ it('ignores a width on a source that never reaches the proxy', () => {+ expect(proxiedImageURL('data:image/png;base64,AAAA', '', { width: 512 })).toBe('data:image/png;base64,AAAA');+ expect(proxiedImageURL('javascript:alert(1)', '', { width: 512 })).toBe('');+ });+it('routes cross-origin art through the same-origin proxy, carrying the seed', () => {const out = proxiedImageURL('https://ipfs.io/ipfs/bafyexample', MINT);expect(out.startsWith('/api/img?')).toBe(true);