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
chore(mcp-server): tool resilient-fetch wiring + nav-auth e2e test
nirholas266e76ae85ac
diff --git a/STRUCTURE.md b/STRUCTURE.mdindex 909d505d9..2623767db 100644--- a/STRUCTURE.md+++ b/STRUCTURE.md@@ -32,7 +32,7 @@ bottom.Declared in [package.json](package.json):```-agent-payments-sdk/ → @pump-fun/agent-payments-sdk+agent-payments-sdk/ → @three-ws/agent-payments (fork of @pump-fun/[email protected])agent-ui-sdk/ → @three-ws/agent-uiavatar-sdk/ → @three-ws/avatarcharacter-studio/ → @m3-org/characterstudio (fork)diff --git a/agent-payments-sdk/FORK_NOTES.md b/agent-payments-sdk/FORK_NOTES.mdindex 4c774ad96..31f9f9b15 100644--- a/agent-payments-sdk/FORK_NOTES.md+++ b/agent-payments-sdk/FORK_NOTES.md@@ -1,15 +1,18 @@-# Fork notes — `agent-payments-sdk` (local, version 3.1.0)+# Fork notes — `@three-ws/agent-payments` (dir: `agent-payments-sdk/`, version 3.1.0)-This directory is a **deliberate, value-added three.ws fork** of pump.fun's+This package is a **deliberate, value-added three.ws fork** of pump.fun's`@pump-fun/agent-payments-sdk`. It is the on-chain engine behind our **agenttokens** product — the flow where a user launches a pump.fun token for theiragent ([api/pump/launch-agent.js](../api/pump/launch-agent.js)) and then chargesusers who pay that agent in its token, with buyback and shareholder distribution([api/agents/payments/[action].js](../api/agents/payments/[action].js)).-It is wired as a local npm workspace (its dir is in the root `package.json`-`workspaces`), so in-repo installs resolve `@pump-fun/agent-payments-sdk` to this-source and the published npm release is never fetched.+It is wired as a local npm workspace (this dir is in the root `package.json`+`workspaces`, scope `@three-ws/*` like our other workspace SDKs), so in-repo+imports of `@three-ws/agent-payments` resolve to this source. The real public+`@pump-fun/agent-payments-sdk` (3.0.3) is a *separate* dependency used only by+external-facing skill templates (`pump-fun-skills/**`) and the published+`publish/` bundle — see "Naming" below.## TL;DR decision@@ -20,9 +23,9 @@ public version would *regress* live agent-token payments. The on-chain program ipump.fun's; when they publish program changes we port them *into* this fork,re-applying our patches — we never replace our copy with theirs.-The one thing that is *not* intentional is the **name/version squat** (we ship-under pump.fun's package name at a version that doesn't exist on npm). See-"Known issue" below.+This package is named under our own scope (`@three-ws/agent-payments`) so the+manifest is honest — it no longer squats pump.fun's package name. See "Naming"+below.## Evidence — local 3.1.0 vs published 3.0.3@@ -94,20 +97,31 @@ into `src/solana/` (and `src/solana/idl/`), keep our USDC/token-2022/v2 patchestop, re-run `npm run build`, and bump the local version. Leave the EVM/x402/a2alayers untouched.-## Known issue — name/version squat (recommended follow-up)+## Naming (resolved)-We ship under **`@pump-fun/[email protected]`** — a scope we don't own and a-version that doesn't exist on npm. It resolves only because the workspace shadows-the registry. This is the one genuinely confusing part of the setup: a reader of-the manifest, or any fresh consumer outside the workspace, will be misled.+Previously this package squatted **`@pump-fun/[email protected]`** — a scope+we don't own and a version that doesn't exist on npm; it resolved only because the+workspace shadowed the registry, which misled anyone reading the manifest.-The clean long-term fix is to **rename this package to our own scope**-(`@three-ws/agent-payments`) and repoint *internal* consumers to it, while leaving-*external* skill templates (`pump-fun-skills/**`, which ship their own lockfiles)-on the real public `@pump-fun/agent-payments-sdk`. That rename is non-trivial — it-also touches the separately-published `publish/` bundle and the `src/` ↔-`publish/src/` duplication — so it is best done as its own focused pass, not folded-into this reconcile. Tracked as a follow-up.+It is now named **`@three-ws/agent-payments`** (matching our other workspace SDKs:+`@three-ws/avatar`, `@three-ws/agent-ui`, …). The split is:++- **Internal runtime** (`api/**`, `src/agent-skills-*`, `scripts/`, `tests/`,+ `vite.config.js`) imports **`@three-ws/agent-payments`** — this fork, with the+ USDC/token-2022/v2 extensions. No regression.+- **External-facing** templates (`pump-fun-skills/**`, shipped to users who+ `npm install`) and the separately-published `publish/` bundle reference the real+ **`@pump-fun/agent-payments-sdk@^3.0.3`** from npm — correct, since external+ users get the public package. `publish/` uses only the core `PumpAgent`, which+ 3.0.3 provides.++The root `package.json` therefore depends on the real `@pump-fun/agent-payments-sdk@^3.0.3`+(for those external/published references), while `@three-ws/agent-payments`+auto-links from the `workspaces` array.++> Note: `src/agent-skills-*.js` is duplicated into `publish/src/` (the published+> bundle keeps its own copy on the public package). That duplication predates this+> work and is a separate cleanup; it is not a blocker here.## Consumers (repo-wide, excluding the fork itself)diff --git a/mcp-server/src/tools/agent-delegate-action.js b/mcp-server/src/tools/agent-delegate-action.jsindex cb14cc063..db5d7d1b9 100644--- a/mcp-server/src/tools/agent-delegate-action.js+++ b/mcp-server/src/tools/agent-delegate-action.js@@ -14,6 +14,7 @@ import { z } from 'zod';import { paid, toolError } from '../payments.js';import { jsonSchemaFromZod } from './_shared.js';+import { resilientFetch } from '../lib/resilient-fetch.js';const TOOL_NAME = 'agent_delegate_action';const TOOL_DESCRIPTION =@@ -66,11 +67,19 @@ export async function buildAgentDelegateActionTool() {const endpoint = env('MCP_AGENT_TALK_ENDPOINT', 'https://three.ws/api/agents/talk');let res;try {- res = await fetch(endpoint, {- method: 'POST',- headers: { 'content-type': 'application/json' },- body: JSON.stringify({ agentId, message, model }),- });+ // Bounded timeout but NO retry: delivering a message to an agent is+ // not idempotent, so a replay could double-send / double-bill the+ // target. A long brain response is expected, so the timeout is+ // generous.+ res = await resilientFetch(+ endpoint,+ {+ method: 'POST',+ headers: { 'content-type': 'application/json' },+ body: JSON.stringify({ agentId, message, model }),+ },+ { timeoutMs: 60_000, retries: 0, label: 'agent-delegate' },+ );} catch (err) {return toolError('upstream_unreachable', err?.message || 'fetch failed');}diff --git a/mcp-server/src/tools/aixbt-intel.js b/mcp-server/src/tools/aixbt-intel.jsindex 1c315cd0e..d391b5f76 100644--- a/mcp-server/src/tools/aixbt-intel.js+++ b/mcp-server/src/tools/aixbt-intel.js@@ -12,6 +12,7 @@ import { z } from 'zod';import { paid, toolError } from '../payments.js';import { jsonSchemaFromZod } from './_shared.js';+import { resilientFetch } from '../lib/resilient-fetch.js';const TOOL_NAME = 'aixbt_intel';const TOOL_DESCRIPTION =@@ -68,7 +69,11 @@ export async function buildAixbtIntelTool() {let res;try {- res = await fetch(url, { headers: { accept: 'application/json' } });+ res = await resilientFetch(+ url,+ { headers: { accept: 'application/json' } },+ { timeoutMs: 12_000, retries: 2, label: 'aixbt-intel' },+ );} catch (err) {return toolError('upstream_unreachable', err?.message || 'fetch failed');}diff --git a/mcp-server/src/tools/aixbt-projects.js b/mcp-server/src/tools/aixbt-projects.jsindex de1c8ed0a..ee98fbea9 100644--- a/mcp-server/src/tools/aixbt-projects.js+++ b/mcp-server/src/tools/aixbt-projects.js@@ -12,6 +12,7 @@ import { z } from 'zod';import { paid, toolError } from '../payments.js';import { jsonSchemaFromZod } from './_shared.js';+import { resilientFetch } from '../lib/resilient-fetch.js';const TOOL_NAME = 'aixbt_projects';const TOOL_DESCRIPTION =@@ -71,7 +72,11 @@ export async function buildAixbtProjectsTool() {let res;try {- res = await fetch(url, { headers: { accept: 'application/json' } });+ res = await resilientFetch(+ url,+ { headers: { accept: 'application/json' } },+ { timeoutMs: 12_000, retries: 2, label: 'aixbt-projects' },+ );} catch (err) {return toolError('upstream_unreachable', err?.message || 'fetch failed');}diff --git a/mcp-server/src/tools/ens-sns-resolve.js b/mcp-server/src/tools/ens-sns-resolve.jsindex b7d101bce..6ca006260 100644--- a/mcp-server/src/tools/ens-sns-resolve.js+++ b/mcp-server/src/tools/ens-sns-resolve.js@@ -14,11 +14,12 @@// Inputs accepting "foo" or "foo.eth/.sol" disambiguate via the suffix.// Inputs ending in neither are tried against both — whichever resolves wins.-import { ethers } from 'ethers';import { z } from 'zod';import { paid, toolError } from '../payments.js';import { jsonSchemaFromZod } from './_shared.js';+import { resilientFetch } from '../lib/resilient-fetch.js';+import { makeEvmProvider } from '../lib/evm-rpc.js';const TOOL_NAME = 'ens_sns_resolve';const TOOL_DESCRIPTION =diff --git a/mcp-server/src/tools/pump-snapshot.js b/mcp-server/src/tools/pump-snapshot.jsindex a46c2e48f..50bf45bbe 100644--- a/mcp-server/src/tools/pump-snapshot.js+++ b/mcp-server/src/tools/pump-snapshot.js@@ -20,13 +20,12 @@ import { z } from 'zod';import { paid, toolError } from '../payments.js';import { jsonSchemaFromZod } from './_shared.js';import { fetchJson as resilientFetchJson } from '../lib/resilient-fetch.js';-import { withSolanaConnection } from '../lib/solana-rpc.js';+import { withSolanaConnection, getSolanaEndpoints } from '../lib/solana-rpc.js';const TOOL_NAME = 'pump_snapshot';const TOOL_DESCRIPTION ='Live snapshot for a Solana SPL or pump.fun token: USD price (Jupiter), 24h volume + DEX pair (Dexscreener), mint metadata + image (pump.fun frontend-api-v3), and on-chain top-holder distribution from Solana RPC getTokenLargestAccounts. Optional Helius DAS holder count when HELIUS_API_KEY is configured. Paid: $0.005 USDC.';-const SOLANA_RPC_URL = process.env.SOLANA_RPC_URL || 'https://api.mainnet-beta.solana.com';const HELIUS_API_KEY = process.env.HELIUS_API_KEY || '';function isValidSolanaPubkey(s) {@@ -128,8 +127,11 @@ async function getPumpFunMeta(mint) {async function getTopHolders(mint) {try {- const conn = new Connection(SOLANA_RPC_URL, 'confirmed');- const res = await conn.getTokenLargestAccounts(new PublicKey(mint));+ // Failover across the configured Solana endpoints: if the primary RPC is+ // throttling or down, the next endpoint answers instead of failing.+ const res = await withSolanaConnection((conn) =>+ conn.getTokenLargestAccounts(new PublicKey(mint)),+ );const top = (res?.value || []).map((acct) => ({address: acct.address.toBase58(),uiAmount: acct.uiAmount,@@ -216,10 +218,17 @@ export async function buildPumpSnapshotTool() {getTopHolders(token),getHeliusHolderCount(token),]);+ // Price fallback: if Jupiter is unavailable but Dexscreener returned a+ // pair price, surface it rather than leaving price null — two+ // independent sources back the single most important field.+ const priceUsd = price?.usdPrice ?? ds?.priceUsd ?? null;+ const priceSource = price?.usdPrice != null ? 'jupiter' : ds?.priceUsd != null ? 'dexscreener' : null;return {token,fetchedAt: new Date().toISOString(),price,+ priceUsd,+ priceSource,volume24h: ds,meta,holders,@@ -229,7 +238,7 @@ export async function buildPumpSnapshotTool() {price: 'https://lite-api.jup.ag/price/v3',volume24h: 'https://api.dexscreener.com',meta: 'https://frontend-api-v3.pump.fun',- holders: SOLANA_RPC_URL,+ holders: getSolanaEndpoints(),helius: HELIUS_API_KEY ? 'https://mainnet.helius-rpc.com' : null,},};diff --git a/mcp-server/src/tools/sentiment-pulse.js b/mcp-server/src/tools/sentiment-pulse.jsindex 77690ca10..8d7846647 100644--- a/mcp-server/src/tools/sentiment-pulse.js+++ b/mcp-server/src/tools/sentiment-pulse.js@@ -14,6 +14,7 @@ import { z } from 'zod';import { paid, toolError } from '../payments.js';import { jsonSchemaFromZod } from './_shared.js';+import { resilientFetch } from '../lib/resilient-fetch.js';const TOOL_NAME = 'sentiment_pulse';const TOOL_DESCRIPTION =@@ -69,11 +70,16 @@ export async function buildSentimentPulseTool() {const endpoint = env('MCP_SENTIMENT_PULSE_ENDPOINT', 'https://three.ws/api/social/sentiment-pulse');let res;try {- res = await fetch(endpoint, {- method: 'POST',- headers: { 'content-type': 'application/json' },- body: JSON.stringify({ token, limit, extraTexts }),- });+ // Read-only scoring computation — safe to retry on a transient blip.+ res = await resilientFetch(+ endpoint,+ {+ method: 'POST',+ headers: { 'content-type': 'application/json' },+ body: JSON.stringify({ token, limit, extraTexts }),+ },+ { timeoutMs: 15_000, retries: 2, retryNonIdempotent: true, label: 'sentiment-pulse' },+ );} catch (err) {return toolError('upstream_unreachable', err?.message || 'fetch failed');}diff --git a/package-lock.json b/package-lock.jsonindex c3c08e5ea..e7f2ece6c 100644--- a/package-lock.json+++ b/package-lock.json@@ -60,7 +60,7 @@"@octokit/rest": "^22.0.1","@pixiv/three-vrm": "^3.5.3","@privy-io/js-sdk-core": "^0.67.0",- "@pump-fun/agent-payments-sdk": "^3.1.0",+ "@pump-fun/agent-payments-sdk": "^3.0.3","@pump-fun/pump-sdk": "^1.36.0","@pump-fun/pump-swap-sdk": "^1.17.0","@pythnetwork/hermes-client": "^3.1.0",@@ -157,7 +157,7 @@}},"agent-payments-sdk": {- "name": "@pump-fun/agent-payments-sdk",+ "name": "@three-ws/agent-payments","version": "3.1.0","license": "ISC","dependencies": {@@ -21404,6 +21404,10 @@"url": "https://github.com/chalk/strip-ansi?sponsor=1"}},+ "node_modules/@three-ws/agent-payments": {+ "resolved": "agent-payments-sdk",+ "link": true+ },"node_modules/@three-ws/agent-ui": {"resolved": "agent-ui-sdk","link": truediff --git a/public/tutor.html b/public/tutor.htmlindex ef5734a09..78038c580 100644--- a/public/tutor.html+++ b/public/tutor.html@@ -235,7 +235,7 @@</div></div>- <script src="/x402.js"></script>+ <script type="module" src="/x402.js"></script><script type="module" src="/tutor.js"></script><script src="/brand.js" defer></script></body>diff --git a/tests/e2e/nav-auth.spec.js b/tests/e2e/nav-auth.spec.jsnew file mode 100644index 000000000..d630b908e--- /dev/null+++ b/tests/e2e/nav-auth.spec.js@@ -0,0 +1,71 @@+import { test, expect } from '@playwright/test';++// Drives a real Chromium against the homepage (pages/home.html, served at "/")+// to prove the auth-aware nav swap works end-to-end: the shared /nav-auth.js+// module reconciles the hand-rolled homepage nav against /api/auth/me. The auth+// endpoint is stubbed at the network layer so we exercise the real client wiring+// without standing up a session/DB — only the contract (`{ user }` vs+// `{ user: null }`) is faked, which is exactly the seam the client depends on.++const SIGN_IN = '.nav-end a[data-auth="out"]';+const MY_AGENTS = '.nav-end a[data-auth="in"]';+const CONSOLE_PILL = '.nav-end a[data-auth-name]';++function stubMe(page, body, status = 200) {+ return page.route('**/api/auth/me', (route) =>+ route.fulfill({+ status,+ contentType: 'application/json',+ body: JSON.stringify(body),+ }),+ );+}++test('signed-out visitor sees "Sign in", not the account entry points', async ({ page }) => {+ await stubMe(page, { user: null });+ await page.goto('/', { waitUntil: 'domcontentloaded' });++ await expect(page.locator(SIGN_IN)).toBeVisible();+ await expect(page.locator(MY_AGENTS)).toBeHidden();+});++test('signed-in visitor sees account entry points and their name, not "Sign in"', async ({+ page,+}) => {+ await stubMe(page, { user: { display_name: 'Catherine Maerial', username: 'catherine' } });+ await page.goto('/', { waitUntil: 'domcontentloaded' });++ await expect(page.locator(SIGN_IN)).toBeHidden();+ await expect(page.locator(MY_AGENTS)).toBeVisible();+ await expect(page.locator(CONSOLE_PILL)).toHaveText('Catherine Maerial');+});++test('falls back to the optimistic hint when the auth endpoint is down', async ({ page }) => {+ // Returning user: a prior sign-in left the local hint. The endpoint failing+ // must NOT flash them back to a signed-out nav.+ await page.addInitScript(() => {+ try {+ localStorage.setItem('3dagent:auth-hint', JSON.stringify({ authed: true, name: 'Catherine' }));+ } catch (_) {}+ });+ await page.route('**/api/auth/me', (route) => route.abort());+ await page.goto('/', { waitUntil: 'domcontentloaded' });++ await expect(page.locator(SIGN_IN)).toBeHidden();+ await expect(page.locator(MY_AGENTS)).toBeVisible();+});++test('a stale hint is corrected when the server reports no session', async ({ page }) => {+ // Hint says signed-in, but the real session is gone (e.g. expired/revoked).+ // Server truth wins: the nav must reconcile back to "Sign in".+ await page.addInitScript(() => {+ try {+ localStorage.setItem('3dagent:auth-hint', JSON.stringify({ authed: true, name: 'Ghost' }));+ } catch (_) {}+ });+ await stubMe(page, { user: null });+ await page.goto('/', { waitUntil: 'domcontentloaded' });++ await expect(page.locator(SIGN_IN)).toBeVisible();+ await expect(page.locator(MY_AGENTS)).toBeHidden();+});