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): stop a single throttled upstream dropping ops alerts, SOL prices and market briefings
nirholase41397970db1
diff --git a/api/_lib/aixbt.js b/api/_lib/aixbt.jsindex e402fc412..7d35969bc 100644--- a/api/_lib/aixbt.js+++ b/api/_lib/aixbt.js@@ -152,12 +152,30 @@ async function request(path, { query, method = 'GET', body } = {}) {// Read-through cache around a GET. Cache keys are content-addressed by path +// query so distinct filters never collide. Errors are never cached.+//+// A separate last-known-good copy outlives the fresh TTL by design. Without it+// an aixbt 5xx propagated straight through to /api/v1/market/intel and+// /projects as a hard failure even when a perfectly serviceable answer from two+// minutes ago was sitting right there. The LKG copy is returned marked stale,+// so the caller can caption it rather than pass it off as live, and a failure+// with nothing cached still throws honestly.+const LKG_TTL_SECONDS = 6 * 60 * 60;+async function cachedGet(cacheKey, ttl, path, query) {const cached = await cacheGet(cacheKey).catch(() => null);if (cached) return cached;- const fresh = await request(path, { query });- await cacheSet(cacheKey, fresh, ttl).catch(() => {});- return fresh;+ const lkgKey = `${cacheKey}:lkg`;+ try {+ const fresh = await request(path, { query });+ await cacheSet(cacheKey, fresh, ttl).catch(() => {});+ await cacheSet(lkgKey, { ...fresh, at: Date.now() }, LKG_TTL_SECONDS).catch(() => {});+ return fresh;+ } catch (err) {+ const lkg = await cacheGet(lkgKey).catch(() => null);+ if (!lkg) throw err;+ console.warn(`[aixbt] ${path} failed (${err?.message || err}); serving last-known-good`);+ return { ...lkg, stale: true, as_of: new Date(Number(lkg.at) || Date.now()).toISOString() };+ }}function num(v) {diff --git a/api/_lib/alerts.js b/api/_lib/alerts.jsindex 330c336dd..0590b49f3 100644--- a/api/_lib/alerts.js+++ b/api/_lib/alerts.js@@ -28,6 +28,7 @@import { createHash } from 'node:crypto';import { cacheGet, cacheSet } from './cache.js';+import { fetchUpstream } from './upstream-fetch.js';const DEDUP_TTL_S = 60 * 60;const GLOBAL_LIMIT_PER_HOUR = 20;@@ -101,22 +102,28 @@ async function persistAlert({ sig, title, detail, severity, environment }) {}}+// One dropped packet used to lose an ops alert outright: a bare fetch with+// `.catch(() => {})` has no retry and leaves no trace of what went missing.+// fetchUpstream keeps it fire-and-forget but adds the timeout, the+// Retry-After-aware second attempt and the breaker every other Telegram sender+// here already uses, and a final failure is logged rather than swallowed.function post(cfg, text) {- const controller = new AbortController();- const timer = setTimeout(() => controller.abort(), 2500);- fetch(`https://api.telegram.org/bot${cfg.token}/sendMessage`, {- method: 'POST',- headers: { 'content-type': 'application/json' },- body: JSON.stringify({- chat_id: cfg.chatId,- text: text.slice(0, 4000), // Telegram message hard limit is 4096- disable_web_page_preview: true,- }),- signal: controller.signal,- keepalive: true,- })- .catch(() => {})- .finally(() => clearTimeout(timer));+ fetchUpstream(+ `https://api.telegram.org/bot${cfg.token}/sendMessage`,+ {+ method: 'POST',+ headers: { 'content-type': 'application/json' },+ body: JSON.stringify({+ chat_id: cfg.chatId,+ text: text.slice(0, 4000), // Telegram message hard limit is 4096+ disable_web_page_preview: true,+ }),+ keepalive: true,+ },+ { name: 'telegram:ops-alert', timeoutMs: 5_000, attempts: 2 },+ ).catch((err) => {+ console.warn(`[alerts] telegram delivery failed after retries: ${err?.message || err}`);+ });}/**diff --git a/api/_lib/sniper/notify.js b/api/_lib/sniper/notify.jsindex b61535740..a3da32853 100644--- a/api/_lib/sniper/notify.js+++ b/api/_lib/sniper/notify.js@@ -10,7 +10,9 @@// TELEGRAM_SNIPER_CHAT_ID — dedicated sniper notifications channel (preferred)// TELEGRAM_ALERTS_CHAT_ID — ops fallback if the dedicated channel is absent-const TIMEOUT_MS = 3000;+import { fetchUpstream } from '../upstream-fetch.js';++const TIMEOUT_MS = 5000;function defaultChatId() {return process.env.TELEGRAM_SNIPER_CHAT_ID || process.env.TELEGRAM_ALERTS_CHAT_ID || null;@@ -20,21 +22,26 @@ function send(text, chatIdOverride) {const token = process.env.TELEGRAM_BOT_TOKEN;const id = chatIdOverride || defaultChatId();if (!token || !id) return;- const controller = new AbortController();- const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);- fetch(`https://api.telegram.org/bot${token}/sendMessage`, {- method: 'POST',- headers: { 'content-type': 'application/json' },- body: JSON.stringify({- chat_id: id,- text: text.slice(0, 4000),- disable_web_page_preview: true,- }),- signal: controller.signal,- keepalive: true,- })- .catch(() => {})- .finally(() => clearTimeout(timer));+ // Still fire-and-forget so it never delays the trade path, but a single+ // dropped packet no longer loses the notification silently: fetchUpstream+ // retries a transient failure and honours Retry-After, and a final failure+ // is logged instead of swallowed.+ fetchUpstream(+ `https://api.telegram.org/bot${token}/sendMessage`,+ {+ method: 'POST',+ headers: { 'content-type': 'application/json' },+ body: JSON.stringify({+ chat_id: id,+ text: text.slice(0, 4000),+ disable_web_page_preview: true,+ }),+ keepalive: true,+ },+ { name: 'telegram:sniper', timeoutMs: TIMEOUT_MS, attempts: 2 },+ ).catch((err) => {+ console.warn(`[sniper-notify] telegram delivery failed after retries: ${err?.message || err}`);+ });}const n2 = (v) => (v != null ? Number(v).toFixed(4) : '—');diff --git a/api/demo-economy.js b/api/demo-economy.jsindex 2db92144c..37b614b20 100644--- a/api/demo-economy.js+++ b/api/demo-economy.js@@ -14,6 +14,7 @@ import { cors, method, wrap, setRateLimitHeaders } from './_lib/http.js';import { getSessionUser, authenticateBearer, extractBearer } from './_lib/auth.js';import { limits, clientIp } from './_lib/rate-limit.js';import { Bazaar } from './_lib/x402/bazaar-client.js';+import { fetchUpstreamJson, lastGood } from './_lib/upstream-fetch.js';// ── Wallet imports (lazy, only when live mode is active) ─────────────────────async function walletDeps() {@@ -24,12 +25,20 @@ async function walletDeps() {// ── Live crypto market briefing via GeckoTerminal (no API key needed) ────────async function fetchMarketBriefing() {try {- const r = await fetch(- 'https://api.geckoterminal.com/api/v2/networks/solana/trending_pools?page=1',- { headers: { Accept: 'application/json' }, signal: AbortSignal.timeout(8000) },+ // Retried, breaker-guarded and backed by a last-known-good tier: the+ // briefing is the product the demo actually transacts, so a single+ // throttled GeckoTerminal read used to leave the whole demo with nothing+ // to sell. A few minutes of staleness is a far better answer than that,+ // and the payload says which it is.+ const { value: data, stale, ageMs } = await lastGood(+ 'demo-economy:trending-pools',+ () => fetchUpstreamJson(+ 'https://api.geckoterminal.com/api/v2/networks/solana/trending_pools?page=1',+ { headers: { Accept: 'application/json' } },+ { name: 'geckoterminal:trending-pools', timeoutMs: 8_000, attempts: 2 },+ ),+ { maxAgeMs: 30 * 60_000 },);- if (!r.ok) throw new Error(`GeckoTerminal ${r.status}`);- const data = await r.json();const pools = (data.data || []).slice(0, 5).map((p) => {const attr = p.attributes || {};const priceUsd = parseFloat(attr.base_token_price_usd || 0);@@ -55,6 +64,8 @@ async function fetchMarketBriefing() {: 'Live Solana market data',pools,fetchedAt: new Date().toISOString(),+ stale,+ as_of: stale ? new Date(Date.now() - ageMs).toISOString() : null,};} catch {// No invented market data: a GeckoTerminal failure degrades to an explicitdiff --git a/api/x402-ring.js b/api/x402-ring.jsindex acf3e5357..869d4c5b1 100644--- a/api/x402-ring.js+++ b/api/x402-ring.js@@ -23,6 +23,7 @@ import { env } from './_lib/env.js';import { PublicKey } from '@solana/web3.js';import { getAccount, getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID } from '@solana/spl-token';import { solanaConnection } from './_lib/solana/connection.js';+import { solPriceUsd } from './_lib/sol-price.js';import { loadSeedKeypair, USDC_MINT } from './_lib/x402/pay.js';import { SELF_FACILITATOR_ENABLED, SPONSOR_SOL_FLOOR_LAMPORTS } from './_lib/x402/self-facilitator.js';import { validateRingConfig, warnIfRingRoutesExternal } from './_lib/x402/ring-config.js';@@ -55,19 +56,14 @@ function sol(lamports) {// Best-effort live SOL price for a USD figure on the burn — never blocks the// report if the quote is unreachable.+//+// This used to be a single keyless GeckoTerminal read, so one throttled host+// silently dropped every USD figure off the ring report. api/_lib/sol-price.js+// already runs the same question across ten providers with a cooldown and a+// short TTL, which is both more reliable and cheaper than a per-request fetch.async function solUsd() {- try {- const r = await fetch(- 'https://api.geckoterminal.com/api/v2/simple/networks/solana/token_price/So11111111111111111111111111111111111111112',- { headers: { Accept: 'application/json' }, signal: AbortSignal.timeout(4000) },- );- if (!r.ok) return null;- const d = await r.json();- const p = d?.data?.attributes?.token_prices?.So11111111111111111111111111111111111111112;- return p ? Number(p) : null;- } catch {- return null;- }+ const price = await solPriceUsd();+ return price > 0 ? price : null;}async function usdcBalance(conn, ownerB58) {