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(feeds): give the news archive, collectibles panel, deployer check and Farcaster lane a way to survive their single host
nirholas58b59bf9d114
diff --git a/api/_lib/env.js b/api/_lib/env.jsindex a984f06c4..d7b29d069 100644--- a/api/_lib/env.js+++ b/api/_lib/env.js@@ -1613,11 +1613,20 @@ export const env = {},// Public Farcaster hub HTTP endpoint — the keyless rung of that same chain.- // Any hub that speaks the standard /v1 HTTP API works.+ // Any hub that speaks the standard /v1 HTTP API works. Kept as the FIRST+ // rung when set, so an operator's preferred hub still leads.get FARCASTER_HUB_URL() {return opt('FARCASTER_HUB_URL');},+ // Additional hubs, comma-separated, appended after FARCASTER_HUB_URL. Hubs+ // replicate the same message set, so hubGet walks them until one answers and+ // a single unreachable host no longer takes the whole Farcaster lane down.+ // Optional: a built-in list of public hubs is always appended behind these.+ get FARCASTER_HUB_URLS() {+ return opt('FARCASTER_HUB_URLS');+ },+// OpenAI API key — used by TTS proxy (/api/tts/speak) and chat endpoints.// Never sent to the browser.get OPENAI_API_KEY() {diff --git a/api/_lib/farcaster-client.js b/api/_lib/farcaster-client.jsindex c4aa860e3..382cefbf6 100644--- a/api/_lib/farcaster-client.js+++ b/api/_lib/farcaster-client.js@@ -52,33 +52,73 @@ async function neynar() {}export function hubUrl() {- return (env.FARCASTER_HUB_URL || 'https://hub.pinata.cloud').replace(/\/+$/, '');+ return hubUrls()[0];}-async function hubGet(path) {- let resp;- try {- resp = await fetch(`${hubUrl()}${path}`, {- headers: { accept: 'application/json' },- signal: AbortSignal.timeout(HUB_TIMEOUT_MS),- });- } catch (err) {- throw new FarcasterError(`Farcaster hub unreachable: ${err?.message || err}`);+// Farcaster hubs are interchangeable: every one of them serves the same+// replicated set, which is the whole point of the protocol. Pinning a single+// host therefore bought nothing and cost everything, since one unreachable hub+// took the entire Farcaster lane down with it. An operator can still pin or+// reorder the list through FARCASTER_HUB_URLS (comma-separated), and+// FARCASTER_HUB_URL stays honoured as the first rung so existing deploys keep+// their preferred host.+const DEFAULT_HUBS = [+ 'https://hub.pinata.cloud',+ 'https://hub.farcaster.standardcrypto.vc:2281',+ 'https://nemes.farcaster.xyz:2281',+];++export function hubUrls() {+ const configured = [+ ...(env.FARCASTER_HUB_URL ? [env.FARCASTER_HUB_URL] : []),+ ...String(env.FARCASTER_HUB_URLS || '').split(',').map((u) => u.trim()).filter(Boolean),+ ];+ const seen = new Set();+ const out = [];+ for (const u of [...configured, ...DEFAULT_HUBS]) {+ const clean = u.replace(/\/+$/, '');+ if (clean && !seen.has(clean)) {+ seen.add(clean);+ out.push(clean);+ }}- if (resp.status === 404) throw new FarcasterError('Farcaster user not found', { status: 404, code: 'farcaster_user_not_found' });- if (!resp.ok) {- // A hub answers "no such fname" with 400 + a NotFound detail, not 404.- // Without this the caller cannot tell a typo'd handle from an outage.- const body = await resp.text().catch(() => '');- if (resp.status === 400 && /not\s*found/i.test(body)) {- throw new FarcasterError('Farcaster user not found', {- status: 404,- code: 'farcaster_user_not_found',+ return out;+}++async function hubGet(path) {+ const hubs = hubUrls();+ let lastErr;+ for (const base of hubs) {+ let resp;+ try {+ resp = await fetch(`${base}${path}`, {+ headers: { accept: 'application/json' },+ signal: AbortSignal.timeout(HUB_TIMEOUT_MS),});+ } catch (err) {+ // Unreachable host: try the next hub rather than failing the read.+ lastErr = new FarcasterError(`Farcaster hub unreachable: ${err?.message || err}`);+ continue;+ }+ // "No such user" is the network's answer, not this hub's opinion, so it+ // ends the walk immediately. Only infrastructure failures fail over.+ if (resp.status === 404) throw new FarcasterError('Farcaster user not found', { status: 404, code: 'farcaster_user_not_found' });+ if (!resp.ok) {+ // A hub answers "no such fname" with 400 + a NotFound detail, not 404.+ // Without this the caller cannot tell a typo'd handle from an outage.+ const body = await resp.text().catch(() => '');+ if (resp.status === 400 && /not\s*found/i.test(body)) {+ throw new FarcasterError('Farcaster user not found', {+ status: 404,+ code: 'farcaster_user_not_found',+ });+ }+ lastErr = new FarcasterError(`Farcaster hub ${resp.status}`);+ continue;}- throw new FarcasterError(`Farcaster hub ${resp.status}`);+ return resp.json();}- return resp.json();+ throw lastErr || new FarcasterError('no Farcaster hub answered');}/** Page through a hub message endpoint until `limit` messages or the pages run out. */diff --git a/api/_lib/news-archive-store.js b/api/_lib/news-archive-store.jsindex 5b167a1b4..ce8285660 100644--- a/api/_lib/news-archive-store.js+++ b/api/_lib/news-archive-store.js@@ -13,6 +13,7 @@// meta/stats.json (last_article_date), which the appender keeps current.import { createCache } from './mem-cache.js';+import { fetchUpstream, fetchUpstreamJson, lastGood } from './upstream-fetch.js';const GCS_BASE = 'https://storage.googleapis.com/three-ws-news-archive';const GCS_LIST =@@ -63,18 +64,26 @@ export function compact(a) {};}-async function fetchJson(url, timeoutMs = 15_000) {- const resp = await fetch(url, {- headers: { accept: 'application/json' },- signal: AbortSignal.timeout(timeoutMs),- });- if (!resp.ok) throw new Error(`archive upstream ${resp.status}`);- return resp.json();+// One bucket, one read, no recovery: a GCS blip took the archive index, the+// month listing and the sitemap down together, and the in-process caches above+// are empty on a cold instance, which is exactly when an outage hurts. A retry+// absorbs the transient, and a last-known-good copy keyed per URL absorbs the+// rest. Archive data is immutable once written, so a remembered copy is not+// merely acceptable here, it is the same answer.+async function fetchJson(url, timeoutMs = 15_000, lastGoodKey = null) {+ const load = () => fetchUpstreamJson(+ url,+ { headers: { accept: 'application/json' } },+ { name: 'news-archive', timeoutMs, attempts: 2 },+ );+ if (!lastGoodKey) return load();+ const { value } = await lastGood(lastGoodKey, load, { maxAgeMs: 6 * 60 * 60_000 });+ return value;}export async function getStats() {if (statsCache && statsCache.expiresAt > Date.now()) return statsCache.value;- const value = await fetchJson(`${GCS_BASE}/meta/stats.json`);+ const value = await fetchJson(`${GCS_BASE}/meta/stats.json`, 15_000, 'news-archive:stats');statsCache = { value, expiresAt: Date.now() + META_TTL_MS };return value;}@@ -82,7 +91,7 @@ export async function getStats() {/** Queryable months, ascending YYYY-MM. */export async function getMonths() {if (monthsCache && monthsCache.expiresAt > Date.now()) return monthsCache.value;- const listing = await fetchJson(GCS_LIST);+ const listing = await fetchJson(GCS_LIST, 15_000, 'news-archive:months');const value = (listing.items || []).map((o) => {const m = /^articles\/(\d{4}-\d{2})\.jsonl$/.exec(o.name);@@ -113,11 +122,21 @@ export async function loadMonth(month) {monthCache.set(month, hit); // refresh LRU recencyreturn hit.records;}- const resp = await fetch(`${GCS_BASE}/articles/${month}.jsonl`, {- signal: AbortSignal.timeout(30_000),- });- if (!resp.ok) throw new Error(`month ${month} → ${resp.status}`);- const text = await resp.text();+ // A sealed month never changes, so its remembered body is byte-identical to+ // the live one; the mutable current month is worth at most a few minutes of+ // staleness against being unreadable altogether.+ const { value: text } = await lastGood(+ `news-archive:month:${month}`,+ async () => {+ const resp = await fetchUpstream(+ `${GCS_BASE}/articles/${month}.jsonl`,+ {},+ { name: 'news-archive:month', timeoutMs: 30_000, attempts: 2 },+ );+ return resp.text();+ },+ { maxAgeMs: isMutableMonth(month) ? 10 * 60_000 : 6 * 60 * 60_000 },+ );const records = [];for (const line of text.split('\n')) {if (!line.trim()) continue;diff --git a/api/_lib/x402/identity-claim-verify.js b/api/_lib/x402/identity-claim-verify.jsindex 9d3d0a733..a16bcc8de 100644--- a/api/_lib/x402/identity-claim-verify.js+++ b/api/_lib/x402/identity-claim-verify.js@@ -68,6 +68,8 @@ const CAIP2_TO_EVM_CHAINID = {};// Etherscan V2 unified multichain API — one key covers every chain via `chainid`.+import { fetchUpstreamJson, lastGood } from '../upstream-fetch.js';+const ETHERSCAN_V2 = 'https://api.etherscan.io/v2/api';function normEvm(addr) {@@ -188,9 +190,20 @@ export const realDeps = {if (!key) return { deployer: null, txHash: null, reason: 'no_explorer_key' };try {const url = `${ETHERSCAN_V2}?chainid=${chainId}&module=contract&action=getcontractcreation&contractaddresses=${address}&apikey=${key}`;- const res = await fetch(url, { signal: AbortSignal.timeout(6000), headers: { accept: 'application/json' } });- if (!res.ok) return { deployer: null, txHash: null, reason: `explorer_http_${res.status}` };- const data = await res.json();+ // A contract's deployer is immutable, so a remembered answer is not+ // merely tolerable here, it is the same answer forever. That matters+ // because this check fails CLOSED: without it an Etherscan blip rejects+ // a legitimate deployer's identity claim, which is a far worse outcome+ // than reading a fact that cannot change from a day-old cache.+ const { value: data } = await lastGood(+ `identity-claim:creation:${chainId}:${address.toLowerCase()}`,+ () => fetchUpstreamJson(+ url,+ { headers: { accept: 'application/json' } },+ { name: 'etherscan:contract-creation', timeoutMs: 6_000, attempts: 2 },+ ),+ { maxAgeMs: 24 * 60 * 60_000 },+ );const row = Array.isArray(data?.result) ? data.result[0] : null;if (!row?.contractCreator) return { deployer: null, txHash: null, reason: 'no_creation_record' };return {diff --git a/api/users/[username]/collectibles.js b/api/users/[username]/collectibles.jsindex 1b76f60ef..450a1fac2 100644--- a/api/users/[username]/collectibles.js+++ b/api/users/[username]/collectibles.js@@ -18,6 +18,7 @@// Public, no auth: the profile it backs is public.import { sql } from '../../_lib/db.js';+import { fetchUpstreamJson, lastGood } from '../../_lib/upstream-fetch.js';import { cors, json, method, wrap, error, rateLimited } from '../../_lib/http.js';import { limits, clientIp } from '../../_lib/rate-limit.js';import { env } from '../../_lib/env.js';@@ -276,9 +277,21 @@ async function fetchEvmNfts(wallet, chainId) {};const host = hosts[Number(chainId)] || 'eth-mainnet';const url = `https://${host}.g.alchemy.com/nft/v3/${apiKey}/getNFTsForOwner?owner=${encodeURIComponent(wallet)}&withMetadata=true&pageSize=${NFT_CAP}&excludeFilters[]=SPAM`;- const resp = await fetch(url, { signal: AbortSignal.timeout(PROVIDER_TIMEOUT_MS) });- if (!resp.ok) throw new Error(`Alchemy ${resp.status}`);- const data = await resp.json();+ // One indexer, and its failure used to empty a user's public collectibles+ // panel outright. NFT ownership barely changes minute to minute, so a+ // remembered response is a genuinely good answer during a blip, and the same+ // last-known-good discipline api/nft/resolve.js already applies to single+ // descriptors. The wallet and chain key it, so one user's stale panel can+ // never leak into another's.+ const { value: data } = await lastGood(+ `collectibles:${chainId}:${wallet.toLowerCase()}`,+ () => fetchUpstreamJson(+ url,+ {},+ { name: 'alchemy:nfts', timeoutMs: PROVIDER_TIMEOUT_MS, attempts: 2 },+ ),+ { maxAgeMs: 30 * 60_000 },+ );const base = explorerForEvm(chainId, '').replace(/\/address\/$/, '');return (data.ownedNfts || []).map((n) => {