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: communities, walk-net, vercel routes, vite config updates
nirholas049dde1d1107
diff --git a/pages/communities.html b/pages/communities.htmlindex 170791195..31f51cba6 100644--- a/pages/communities.html+++ b/pages/communities.html@@ -195,6 +195,52 @@.coin-card .sk { height: 10px; border-radius: 5px; background: rgba(255,255,255,0.08); animation: pulse 1.3s ease-in-out infinite; }.coin-card .sk-a { width: 60%; } .coin-card .sk-b { width: 85%; }@keyframes pulse { 0%,100% { opacity: 0.4; } 50% { opacity: 0.85; } }+ /* Coin profile */+ .coin-profile { padding-top: 8px; }+ .coin-profile-back { margin-bottom: 18px; }+ .cp-head { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }+ .cp-avatar { width: 72px; height: 72px; border-radius: 50%; overflow: hidden; flex-shrink: 0; position: relative; background: linear-gradient(135deg, rgba(124,92,255,0.45), rgba(0,0,0,0.45)); display: flex; align-items: center; justify-content: center; }+ .cp-avatar img { width: 100%; height: 100%; object-fit: cover; position: relative; z-index: 1; }+ .cp-avatar-fallback { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 22px; color: #fff; }+ .cp-head-text { flex: 1; min-width: 0; }+ .cp-symbol { font-size: 13px; font-weight: 700; color: var(--accent); letter-spacing: 0.3px; }+ .cp-name { font-size: clamp(24px, 4vw, 36px); line-height: 1.05; letter-spacing: -0.8px; font-weight: 760; margin: 2px 0 6px; word-break: break-word; }+ .cp-mint { font-family: ui-monospace, monospace; font-size: 12px; color: var(--muted); background: rgba(0,0,0,0.28); border: 1px solid var(--panel-border); border-radius: 8px; padding: 4px 10px; cursor: pointer; transition: border-color .15s, color .15s; }+ .cp-mint:hover { border-color: var(--accent); color: var(--text); }+ .cp-mint.copied { color: #34d399; border-color: rgba(52,211,153,0.4); }+ .cp-graduation { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-left: auto; }+ .cp-grad-ring { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; background: conic-gradient(var(--accent) var(--pct, 0%), rgba(255,255,255,0.08) 0); position: relative; }+ .cp-grad-ring::after { content: ''; position: absolute; inset: 5px; border-radius: 50%; background: var(--bg); }+ .cp-grad-ring span { position: relative; z-index: 1; }+ .cp-grad-label { font-size: 10px; color: var(--muted-2); text-transform: uppercase; letter-spacing: 0.5px; }+ .cp-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-top: 22px; }+ .cp-stat { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 12px; padding: 14px 16px; }+ .cp-stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }+ .cp-stat-value { font-size: 20px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }+ .cp-stat-value.up { color: #34d399; }+ .cp-desc { margin-top: 20px; color: var(--muted); font-size: 14px; line-height: 1.6; max-width: 680px; }+ .cp-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; align-items: center; }+ .cp-actions .ghost-btn { text-decoration: none; display: inline-flex; align-items: center; }+ .cp-socials { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }+ .cp-social { font-size: 12px; color: var(--muted); text-decoration: none; background: var(--panel); border: 1px solid var(--panel-border); border-radius: 999px; padding: 6px 13px; transition: border-color .15s, color .15s; }+ .cp-social:hover { border-color: var(--accent); color: var(--text); }+ .cp-section { margin-top: 34px; }+ .cp-trades { display: flex; flex-direction: column; border: 1px solid var(--panel-border); border-radius: 12px; overflow: hidden; }+ .cp-trade { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 12px; padding: 10px 14px; font-size: 13px; background: var(--panel); }+ .cp-trade + .cp-trade { border-top: 1px solid var(--panel-border); }+ .cp-trade-side { font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; padding: 2px 8px; border-radius: 6px; }+ .cp-trade-side.buy { color: #34d399; background: rgba(52,211,153,0.12); }+ .cp-trade-side.sell { color: #f87171; background: rgba(248,113,113,0.12); }+ .cp-trade-user { font-family: ui-monospace, monospace; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }+ .cp-trade-amt { font-variant-numeric: tabular-nums; font-weight: 600; }+ .cp-trade-time { color: var(--muted-2); font-size: 11px; font-variant-numeric: tabular-nums; }+ .cp-skel-head { display: flex; gap: 18px; align-items: center; }+ .cp-skel-avatar { width: 72px; height: 72px; border-radius: 50%; background: rgba(255,255,255,0.06); animation: pulse 1.3s ease-in-out infinite; }+ .cp-skel-lines { flex: 1; display: flex; flex-direction: column; gap: 10px; }+ .cp-skel-line { height: 14px; border-radius: 6px; background: rgba(255,255,255,0.06); animation: pulse 1.3s ease-in-out infinite; }+ .cp-skel-line.w50 { width: 50%; } .cp-skel-line.w30 { width: 30%; }+ .cp-skel-stats { height: 80px; border-radius: 12px; background: rgba(255,255,255,0.05); margin-top: 22px; animation: pulse 1.3s ease-in-out infinite; }+ .coin-profile-empty { padding: 60px 20px; text-align: center; color: var(--muted); }</style></head><body>@@ -259,6 +305,53 @@</section></main>+ <!-- Coin profile (deep-linkable at /communities/:mint) -->+ <main class="wrap coin-profile" id="coin-profile" hidden>+ <button type="button" class="ghost-btn coin-profile-back" id="coin-profile-back">← All communities</button>++ <div class="coin-profile-skeleton" id="coin-profile-skeleton">+ <div class="cp-skel-head"><div class="cp-skel-avatar"></div><div class="cp-skel-lines"><div class="cp-skel-line w50"></div><div class="cp-skel-line w30"></div></div></div>+ <div class="cp-skel-stats"></div>+ </div>++ <div class="coin-profile-empty" id="coin-profile-empty" hidden>+ <p>That coin couldn't be found on pump.fun.</p>+ <p class="coin-empty-sub" id="coin-profile-empty-mint"></p>+ </div>++ <div class="coin-profile-body" id="coin-profile-body" hidden>+ <header class="cp-head">+ <span class="cp-avatar" id="cp-avatar"><span class="cp-avatar-fallback" id="cp-avatar-fallback"></span></span>+ <div class="cp-head-text">+ <div class="cp-symbol" id="cp-symbol">$—</div>+ <h1 class="cp-name" id="cp-name">—</h1>+ <button type="button" class="cp-mint" id="cp-mint" title="Copy mint address"></button>+ </div>+ <div class="cp-graduation" id="cp-graduation" hidden>+ <div class="cp-grad-ring" id="cp-grad-ring"><span id="cp-grad-pct">0%</span></div>+ <span class="cp-grad-label">to graduation</span>+ </div>+ </header>++ <div class="cp-stats" id="cp-stats"></div>++ <p class="cp-desc" id="cp-desc" hidden></p>++ <div class="cp-actions">+ <button type="button" class="primary-btn" id="cp-enter">Enter 3D world →</button>+ <a class="ghost-btn" id="cp-pumpfun" href="#" target="_blank" rel="noopener">Trade on pump.fun ↗</a>+ <button type="button" class="ghost-btn" id="cp-share">Share</button>+ </div>++ <div class="cp-socials" id="cp-socials"></div>++ <section class="cp-section" id="cp-trades-wrap" hidden>+ <div class="section-head"><h2>Recent trades</h2><span class="hint" id="cp-trades-hint"></span></div>+ <div class="cp-trades" id="cp-trades"></div>+ </section>+ </div>+ </main>+<script type="module" src="/src/communities.js"></script></body></html>diff --git a/src/communities.js b/src/communities.jsindex 07a18958a..66077b286 100644--- a/src/communities.js+++ b/src/communities.js@@ -174,8 +174,9 @@ function coinCard(coin) {<span class="coin-name">${esc(name)}</span></span>${mcap ? `<span class="coin-mcap">${mcap}</span>` : ''}- <span class="coin-enter">Enter →</span>`;- card.addEventListener('click', () => enterWorld({ mint, name, symbol, image }));+ <span class="coin-enter">View →</span>`;+ // Cards open the coin's profile; the profile has the "Enter 3D world" CTA.+ card.addEventListener('click', () => navTo(`/communities/${mint}`));return card;}@@ -266,6 +267,248 @@ if (mintInput) mintInput.addEventListener('keydown', (e) => { if (e.key === 'Ent// Mainland card (shared world, no coin).$('enter-mainland')?.addEventListener('click', () => enterWorld(null));+// ── Coin profile (deep-linkable at /communities/:mint) ─────────────────────+// Card clicks land here instead of jumping straight into the world. The+// profile pulls real pump.fun data — coin meta, live price + graduation, and+// recent trades — and offers the "Enter 3D world" hand-off as the primary CTA.++const heroEl = document.querySelector('.hero');+const browseEl = document.querySelector('main.wrap:not(.coin-profile)');+const profileEl = $('coin-profile');++let _coinProfileMint = null;++function navTo(path, replace = false) {+ const url = new URL(path, location.origin);+ if (replace) history.replaceState({}, '', url);+ else history.pushState({}, '', url);+ routeView();+}++function routeView() {+ const m = location.pathname.match(/^\/communities\/([1-9A-HJ-NP-Za-km-z]{32,44})/);+ const showProfile = !!m;+ if (heroEl) heroEl.hidden = showProfile;+ if (browseEl) browseEl.hidden = showProfile;+ if (profileEl) profileEl.hidden = !showProfile;+ if (showProfile) {+ window.scrollTo(0, 0);+ loadCoinProfile(m[1]);+ } else {+ _coinProfileMint = null;+ }+}+window.addEventListener('popstate', routeView);++function fmtPrice(v) {+ const n = Number(v);+ if (!Number.isFinite(n) || n <= 0) return '';+ if (n >= 1) return `$${n.toFixed(2)}`;+ if (n >= 0.01) return `$${n.toFixed(4)}`;+ return `$${n.toExponential(2)}`;+}++function fmtAge(ts) {+ // pump.fun returns unix seconds (created_timestamp) or ISO strings (trades).+ let ms;+ if (typeof ts === 'number' || /^\d+$/.test(String(ts))) {+ const t = Number(ts);+ if (!Number.isFinite(t) || t <= 0) return '';+ ms = t < 1e12 ? t * 1000 : t;+ } else {+ ms = new Date(ts).getTime();+ if (!Number.isFinite(ms)) return '';+ }+ const sec = (Date.now() - ms) / 1000;+ if (sec < 60) return 'just now';+ if (sec < 3600) return `${Math.floor(sec / 60)}m ago`;+ if (sec < 86400) return `${Math.floor(sec / 3600)}h ago`;+ return `${Math.floor(sec / 86400)}d ago`;+}++function shortAddr(a) { return a ? `${a.slice(0, 4)}…${a.slice(-4)}` : ''; }++async function loadCoinProfile(mint) {+ if (_coinProfileMint === mint) return;+ _coinProfileMint = mint;++ $('coin-profile-skeleton').hidden = false;+ $('coin-profile-body').hidden = true;+ $('coin-profile-empty').hidden = true;++ let coin = null;+ try {+ const r = await fetch(`/api/pump/coin?mint=${encodeURIComponent(mint)}`, { headers: { accept: 'application/json' } });+ if (r.ok) coin = await r.json();+ } catch (err) {+ console.warn('[communities] coin profile', err?.message ?? err);+ }++ // User may have navigated away during the fetch.+ if (_coinProfileMint !== mint) return;++ if (!coin || !coin.mint) {+ $('coin-profile-skeleton').hidden = true;+ $('coin-profile-empty').hidden = false;+ $('coin-profile-empty-mint').textContent = mint;+ document.title = 'Coin not found · three.ws';+ return;+ }++ renderCoinProfile(coin);+ // Live market data + trades enrich the page once the core render is up.+ loadCoinMarket(mint);+ loadCoinTrades(mint);+}++function renderCoinProfile(coin) {+ const symbol = coin.symbol || '';+ const name = coin.name || symbol || `${coin.mint.slice(0, 4)}…`;+ const image = coin.image_uri || coin.image || '';++ const avatarEl = $('cp-avatar');+ const fallback = $('cp-avatar-fallback');+ avatarEl.querySelectorAll('img').forEach((el) => el.remove());+ if (image) {+ const img = document.createElement('img');+ img.src = image; img.alt = ''; img.loading = 'lazy'; img.referrerPolicy = 'no-referrer';+ img.onerror = () => img.remove();+ avatarEl.appendChild(img);+ }+ fallback.textContent = (symbol || name).slice(0, 3).toUpperCase();++ $('cp-symbol').textContent = `$${symbol || '—'}`;+ $('cp-name').textContent = name;++ const mintBtn = $('cp-mint');+ mintBtn.textContent = shortAddr(coin.mint);+ mintBtn.onclick = () => {+ navigator.clipboard?.writeText(coin.mint).then(() => {+ mintBtn.textContent = 'Copied ✓';+ mintBtn.classList.add('copied');+ setTimeout(() => { mintBtn.textContent = shortAddr(coin.mint); mintBtn.classList.remove('copied'); }, 1500);+ });+ };++ // Core stats from the coin record; price/graduation arrive via loadCoinMarket.+ const mcap = fmtMcap(coin.usd_market_cap ?? coin.market_cap);+ $('cp-stats').innerHTML = [+ mcap ? statHtml('Market cap', mcap, true) : '',+ statHtml('Price', '—', false, 'cp-stat-price'),+ statHtml('Created', fmtAge(coin.created_timestamp) || '—'),+ coin.reply_count != null ? statHtml('Replies', String(coin.reply_count)) : '',+ ].filter(Boolean).join('');++ const descEl = $('cp-desc');+ if (coin.description) { descEl.hidden = false; descEl.textContent = coin.description; }+ else descEl.hidden = true;++ // Actions.+ $('cp-enter').onclick = () => enterWorld({ mint: coin.mint, name, symbol, image });+ $('cp-pumpfun').href = `https://pump.fun/${coin.mint}`;+ const shareBtn = $('cp-share');+ shareBtn.onclick = async () => {+ const url = location.href;+ const title = `$${symbol || name} on three.ws`;+ const text = `Join the ${name} community in 3D on three.ws`;+ if (navigator.share) { try { await navigator.share({ title, text, url }); return; } catch {} }+ try {+ await navigator.clipboard.writeText(url);+ const orig = shareBtn.textContent;+ shareBtn.textContent = 'Link copied ✓';+ setTimeout(() => { shareBtn.textContent = orig; }, 1500);+ } catch {}+ };++ // Social links when pump.fun provides them.+ const socials = [];+ if (coin.twitter) socials.push(['Twitter', coin.twitter]);+ if (coin.telegram) socials.push(['Telegram', coin.telegram]);+ if (coin.website) socials.push(['Website', coin.website]);+ $('cp-socials').innerHTML = socials+ .map(([label, href]) => `<a class="cp-social" href="${escAttr(href)}" target="_blank" rel="noopener">${esc(label)} ↗</a>`)+ .join('');++ $('coin-profile-skeleton').hidden = true;+ $('coin-profile-body').hidden = false;++ document.title = `$${symbol || name} · Coin Communities · three.ws`;+}++function statHtml(label, value, up = false, id = '') {+ return `<div class="cp-stat">+ <div class="cp-stat-label">${esc(label)}</div>+ <div class="cp-stat-value${up ? ' up' : ''}"${id ? ` id="${id}"` : ''}>${esc(value)}</div>+ </div>`;+}++async function loadCoinMarket(mint) {+ try {+ const r = await fetch(`/api/pump/curve?mint=${encodeURIComponent(mint)}`, { headers: { accept: 'application/json' } });+ if (!r.ok) return;+ const data = await r.json();+ if (_coinProfileMint !== mint) return;++ const usd = data?.price?.usdPrice;+ const priceEl = $('cp-stat-price');+ if (priceEl && usd) priceEl.textContent = fmtPrice(usd) || priceEl.textContent;++ // Graduation comes as progressBps (0–10000) + isGraduated.+ const g = data?.graduation || {};+ const bps = Number(g.progressBps);+ const gradWrap = $('cp-graduation');+ if (gradWrap && Number.isFinite(bps)) {+ const pct = Math.max(0, Math.min(100, bps / 100));+ gradWrap.hidden = false;+ $('cp-grad-ring').style.setProperty('--pct', `${pct.toFixed(0)}%`);+ $('cp-grad-pct').textContent = g.isGraduated ? '✓' : `${pct.toFixed(0)}%`;+ const lbl = gradWrap.querySelector('.cp-grad-label');+ if (lbl) lbl.textContent = g.isGraduated ? 'graduated' : 'to graduation';+ }+ } catch (err) {+ console.warn('[communities] coin market', err?.message ?? err);+ }+}++async function loadCoinTrades(mint) {+ const wrap = $('cp-trades-wrap');+ const list = $('cp-trades');+ try {+ const r = await fetch(`/api/pump/coin-trades?mint=${encodeURIComponent(mint)}&limit=20`, { headers: { accept: 'application/json' } });+ if (!r.ok) return;+ const data = await r.json();+ if (_coinProfileMint !== mint) return;+ const trades = Array.isArray(data?.trades) ? data.trades : [];+ if (!trades.length) return;++ // Price fallback: graduated coins have no bonding-curve price, so use the+ // most recent trade's USD price if loadCoinMarket left the stat empty.+ const priceEl = $('cp-stat-price');+ if (priceEl && (!priceEl.textContent || priceEl.textContent === '…' || priceEl.textContent === '—')) {+ const last = trades.find((t) => Number(t.price_usd) > 0);+ if (last) priceEl.textContent = fmtPrice(last.price_usd) || '—';+ }++ list.innerHTML = trades.map((t) => {+ const buy = !!t.is_buy;+ const usd = Number(t.usd_amount);+ const amt = Number.isFinite(usd) && usd > 0 ? fmtMcap(usd) : `${Number(t.sol_amount || 0).toFixed(3)} SOL`;+ return `<div class="cp-trade">+ <span class="cp-trade-side ${buy ? 'buy' : 'sell'}">${buy ? 'Buy' : 'Sell'}</span>+ <span class="cp-trade-user">${esc(shortAddr(t.user || ''))}</span>+ <span class="cp-trade-amt">${esc(amt)}</span>+ <span class="cp-trade-time">${esc(fmtAge(t.timestamp))}</span>+ </div>`;+ }).join('');+ $('cp-trades-hint').textContent = `Last ${trades.length}`;+ wrap.hidden = false;+ } catch (err) {+ console.warn('[communities] coin trades', err?.message ?? err);+ }+}++$('coin-profile-back')?.addEventListener('click', () => navTo('/communities'));+// ── helpers ────────────────────────────────────────────────────────────────function esc(s) { return String(s).replace(/[<>&"']/g, (c) => ({ '<': '<', '>': '>', '&': '&', '"': '"', "'": ''' }[c])); }function escAttr(s) { return String(s).replace(/[<>&"]/g, (c) => ({ '<': '<', '>': '>', '&': '&', '"': '"' }[c])); }@@ -273,3 +516,4 @@ function escAttr(s) { return String(s).replace(/[<>&"]/g, (c) => ({ '<': '<',// ── boot ───────────────────────────────────────────────────────────────────initAvatars();loadTrending();+routeView();diff --git a/src/game/community-net.js b/src/game/community-net.jsindex 930ff55bd..aaa45f494 100644--- a/src/game/community-net.js+++ b/src/game/community-net.js@@ -112,8 +112,25 @@ export class CommunityNet {this._emit('status', { status, error });}+ // Detach and close the current room without triggering a reconnect. Every+ // (re)connect replaces this.room; if the previous room were left live its+ // socket would keep firing onMessage('chat') alongside the new one, so a+ // single broadcast got appended once per leftover connection — the duplicate+ // chat bug. State-based events (move/avatar/blocks) hid it by being+ // idempotent; chat appends a row on every delivery, so it showed.+ _closeRoom() {+ const room = this.room;+ if (!room) return;+ this.room = null;+ // Drop onLeave/onError/onMessage first so leaving doesn't schedule a+ // reconnect or surface a spurious error.+ try { room.removeAllListeners(); } catch {}+ try { room.leave(); } catch {}+ }+async connect() {if (this._destroyed) return;+ this._closeRoom();this._setStatus('connecting');try {this.client = new Client(this.url);@@ -276,7 +293,7 @@ export class CommunityNet {destroy() {this._destroyed = true;if (this._reconnectTimer) { clearTimeout(this._reconnectTimer); this._reconnectTimer = null; }- try { this.room?.leave(); } catch {}- this.room = null; this.client = null;+ this._closeRoom();+ this.client = null;}}diff --git a/src/walk-net.js b/src/walk-net.jsindex 73965f2d8..27f200cca 100644--- a/src/walk-net.js+++ b/src/walk-net.js@@ -107,8 +107,23 @@ export class WalkNet {this._emit('status', { status, error });}+ // Detach and close the current room without triggering a reconnect. Every+ // (re)connect replaces this.room; left live, the old socket would keep firing+ // onMessage('chat') alongside the new one, so a single broadcast got appended+ // once per leftover connection — the duplicate chat bug. State events+ // (move/avatar/blocks) hid it by being idempotent; chat appends a row per+ // delivery, so it showed.+ _closeRoom() {+ const room = this.room;+ if (!room) return;+ this.room = null;+ try { room.removeAllListeners(); } catch {}+ try { room.leave(); } catch {}+ }+async connect() {if (this._destroyed) return;+ this._closeRoom();this._setStatus('connecting');try {this.client = new Client(this.url);@@ -243,8 +258,7 @@ export class WalkNet {clearTimeout(this._reconnectTimer);this._reconnectTimer = null;}- try { this.room?.leave(); } catch {}- this.room = null;+ this._closeRoom();this.client = null;}}diff --git a/vercel.json b/vercel.jsonindex 16a010d9b..61daae43f 100644--- a/vercel.json+++ b/vercel.json@@ -337,6 +337,10 @@"src": "/communities/?","dest": "/communities.html"},+ {+ "src": "/communities/([1-9A-HJ-NP-Za-km-z]{32,44})/?",+ "dest": "/communities.html"+ },{"src": "/town/?","dest": "/communities.html"diff --git a/vite.config.js b/vite.config.jsindex 4e23f45d7..0f40ab9ba 100644--- a/vite.config.js+++ b/vite.config.js@@ -736,6 +736,9 @@ const appConfig = {// /town → communities (alias; mirrors vercel.json rewrite)else if (!filePath && /^\/town\/?$/.test(path))filePath = resolve(root, 'pages/communities.html');+ // /communities/:mint → coin profile deep link+ else if (!filePath && /^\/communities\/[1-9A-HJ-NP-Za-km-z]{32,44}\/?$/.test(path))+ filePath = resolve(root, 'pages/communities.html');// /@<handle> → public live profile pageelse if (!filePath && /^\/@[a-z0-9_-]{3,30}\/?$/i.test(path))filePath = resolve(root, 'pages/handle.html');