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(pages): agents directory via server index, anonymous 401 gating, constellation error code
nirholasf8e2a69d176d
diff --git a/api/_lib/env.js b/api/_lib/env.jsindex 8fd9dc21b..c9e447df4 100644--- a/api/_lib/env.js+++ b/api/_lib/env.js@@ -275,11 +275,10 @@ export const env = {// api/_lib/siwx-server.js) to validate EIP-1271 / EIP-6492 smart-contract// wallet signatures via viem's publicClient.verifyMessage. Without this,// SIWX falls back to EOA-only verification (still works for MetaMask /- // Phantom EOAs; rejects Coinbase Smart Wallet, Safe, etc.). Falls back to- // the club-payouts cron RPC, then the per-chain RPC_URL_8453 the delegation- // + indexing crons use, so one provisioned Base RPC serves all of them.+ // Phantom EOAs; rejects Coinbase Smart Wallet, Safe, etc.). Defaults to+ // the same RPC the club-payouts cron uses so a single env var works.get BASE_RPC_URL() {- return opt('BASE_RPC_URL', opt('CLUB_BASE_RPC_URL', opt('RPC_URL_8453')));+ return opt('BASE_RPC_URL', opt('CLUB_BASE_RPC_URL'));},// ── ERC-7710 Delegation Relayer ──────────────────────────────────────────diff --git a/src/agents-directory.js b/src/agents-directory.jsindex 1e35ba3a9..718ea0e7e 100644--- a/src/agents-directory.js+++ b/src/agents-directory.js@@ -66,7 +66,7 @@ function extractTrust(metadata) {}function isActiveAgent(agent) {- return Boolean(agent.registeredBlock);+ return Boolean(agent.active ?? agent.registeredBlock);}export class AgentsDirectory {@@ -103,7 +103,12 @@ export class AgentsDirectory {}if (this.agents.length === 0) {- await this._fetchAllAgents();+ try {+ await this._fetchAllAgents();+ } catch (err) {+ log.warn('Index API unavailable, enriching from chain RPCs:', err);+ await this._fetchAllAgentsOnchain();+ }}let filtered = this._applyFilters();@@ -162,7 +167,57 @@ export class AgentsDirectory {// ─────────────────────────────────────────────────────────────────────────+ // Primary source: the server-crawled ERC-8004 index (/api/explore, fed by+ // the erc8004-crawl cron). Agent metadata lives behind arbitrary third-party+ // URLs — many plain-http, CORS-less, or dead — so resolving it in the+ // browser floods the console with mixed-content/CORS errors and burns a+ // network request per registration. The crawler already resolved all of it+ // server-side; here we just page through the index.async _fetchAllAgents() {+ const chainId = this._parseChainFilter(this.filters.chain);+ const collected = [];+ let cursor = null;+ // 10 pages × 60 = 600 agents, matching the legacy 500-per-chain ceiling.+ for (let i = 0; i < 10; i++) {+ const params = new URLSearchParams({ source: 'onchain', limit: '60' });+ if (chainId !== 'all') params.set('chain', String(chainId));+ if (cursor) params.set('cursor', cursor);+ const res = await fetch(`/api/explore?${params}`);+ if (!res.ok) throw new Error(`explore ${res.status}`);+ const body = await res.json();+ const items = (body.items || []).filter((it) => it.kind === 'onchain');+ for (const it of items) {+ const glb = it.glbUrl || null;+ // Card thumbnails live on arbitrary third-party hosts — route them+ // through the same-origin /api/img proxy (multi-gateway IPFS retry ++ // guaranteed placeholder) so a dead host never logs a console error.+ const rawImage = it.image && !/\.(glb|gltf)/i.test(it.image) ? it.image : null;+ collected.push({+ id: String(it.agentId),+ chainId: it.chainId,+ name: it.name || `Agent #${it.agentId}`,+ description: it.description || '',+ avatar: glb,+ image: rawImage ? `/api/img?url=${encodeURIComponent(rawImage)}` : null,+ owner: it.owner || '',+ protocols: extractProtocols({ services: it.services }),+ trust: [],+ createdAt: it.registeredAt ? new Date(it.registeredAt) : new Date(0),+ active: true, // the index only serves active registrations+ metadata: { services: it.services || [] },+ });+ }+ if (!body.nextCursor || items.length === 0) break;+ cursor = body.nextCursor;+ }+ this.agents = collected;+ }++ // Fallback: enrich straight from chain RPCs + agentURI metadata. Only used+ // when the index API is unreachable — it works, but third-party metadata+ // hosts make it slow and console-noisy, which is why it is no longer the+ // primary path.+ async _fetchAllAgentsOnchain() {const chainId = this._parseChainFilter(this.filters.chain);const chains = chainId === 'all' ? Object.keys(CHAIN_META).map(Number) : [chainId];diff --git a/src/create.js b/src/create.jsindex 8d7aa90bb..b3402d155 100644--- a/src/create.js+++ b/src/create.js@@ -200,10 +200,17 @@ async function loadYourAvatars() {const row = document.getElementById('your-avatars-row');if (!section || !row) return;+ // The auth hint (set/cleared by the login flows) tells us up front the+ // visitor is anonymous — skip the request instead of collecting a 401.+ try {+ const hint = localStorage.getItem('3dagent:auth-hint');+ if (!hint || JSON.parse(hint)?.authed !== true) return;+ } catch { return; }+let avatars = [];try {- // allowAnonymous: anonymous visitors 401 here by design — apiFetch would- // otherwise redirect them to /login, breaking the anonymous create flow.+ // allowAnonymous: a stale hint still 401s here by design — apiFetch would+ // otherwise redirect to /login, breaking the anonymous create flow.const res = await apiFetch('/api/avatars', { allowAnonymous: true });if (!res.ok) return;avatars = (await res.json()) ?? [];diff --git a/src/dashboard-next/components/topbar.js b/src/dashboard-next/components/topbar.jsindex fa484a85a..2e006d498 100644--- a/src/dashboard-next/components/topbar.js+++ b/src/dashboard-next/components/topbar.js@@ -111,21 +111,22 @@ export function mountTopbarBehavior(shellEl) {wallet: me.wallet_address || me.solana_address || '',plan: me.plan || 'free',});- }).catch(() => { /* network blip — chip stays "Loading…" */ });- // Load unread notification count in background.- fetch('/api/notifications?limit=1', { credentials: 'include' })- .then((r) => r.ok ? r.json() : null)- .then((data) => {- const unread = data?.unread ?? 0;- const badge = shellEl.querySelector('[data-slot="notif-badge"]');- if (!badge) return;- if (unread > 0) {- badge.style.display = 'block';- badge.textContent = unread > 9 ? '9+' : String(unread);- }- })- .catch(() => { /* notifications unavailable */ });+ // Load unread notification count in background — only once we know the+ // visitor is signed in, so anonymous sessions don't collect 401s.+ fetch('/api/notifications?limit=1', { credentials: 'include' })+ .then((r) => r.ok ? r.json() : null)+ .then((data) => {+ const unread = data?.unread ?? 0;+ const badge = shellEl.querySelector('[data-slot="notif-badge"]');+ if (!badge) return;+ if (unread > 0) {+ badge.style.display = 'block';+ badge.textContent = unread > 9 ? '9+' : String(unread);+ }+ })+ .catch(() => { /* notifications unavailable */ });+ }).catch(() => { /* network blip — chip stays "Loading…" */ });}function setDrawerOpen(shellEl, open) {diff --git a/src/friends.js b/src/friends.jsindex c37b632a9..8f0a2e5da 100644--- a/src/friends.js+++ b/src/friends.js@@ -15,6 +15,18 @@import { apiFetch } from './api.js';import { log } from './shared/log.js';+// Same auth-hint gate notifications.js uses: skip authenticated endpoints+// entirely while the visitor is anonymous instead of collecting 401s on every+// poll. The hint is set/cleared by the login flows (privy-login, email-auth);+// a stale-true hint still falls through to the 401 handling below.+const AUTH_HINT_KEY = '3dagent:auth-hint';+function isAuthedHint() {+ try {+ const raw = localStorage.getItem(AUTH_HINT_KEY);+ return raw ? JSON.parse(raw)?.authed === true : false;+ } catch { return false; }+}+// ── presence ticket ─────────────────────────────────────────────────────────// Short-lived, account-scoped token the realm room verifies before publishing// presence. Cached and refreshed lazily; the net layer calls getPresenceTicket()@@ -23,6 +35,7 @@ let _ticket = null;let _ticketExpEpoch = 0;export async function getPresenceTicket() {+ if (!isAuthedHint()) return null; // anonymous players have no presence to publishconst now = Date.now() / 1000;if (_ticket && _ticketExpEpoch - now > 60) return _ticket;try {@@ -113,6 +126,13 @@ export class FriendsClient {// ── graph ─────────────────────────────────────────────────────────────────async refresh() {+ if (!isAuthedHint()) {+ // Same outcome as a 401, minus the network round-trip on every poll.+ this.loadError = 'signin';+ this.loaded = true;+ this._emit();+ return;+ }try {const res = await apiFetch('/api/friends', { allowAnonymous: true });if (res.status === 401) {