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
test(agent-wallet): export the accept predicates and cover self-pay selection over a USDC preference
nirholas348a219d0fcd
diff --git a/api/agent-wallet-bridge.js b/api/agent-wallet-bridge.jsindex 3c65b3faf..e80c01017 100644--- a/api/agent-wallet-bridge.js+++ b/api/agent-wallet-bridge.js@@ -69,14 +69,14 @@ function endpointAllowed(endpoint) {// 502 the moment three.ws's own paid endpoints started advertising self-pay// accepts (x402-paid-endpoint.js drops the fee payer whenever the sponsor// wallet cannot co-sign), which took /play/agent-wallet down end to end.-function isSolanaExactAccept(a) {+export function isSolanaExactAccept(a) {return Boolean(a && a.scheme === 'exact' && String(a.network || '').startsWith('solana:'));}// Pick the accept this bridge pays: USDC first, so a challenge that also// advertises a $THREE Solana entry can never settle in the platform token off a// USDC-denominated cap.-function pickSolanaAccept(accepts) {+export function pickSolanaAccept(accepts) {const solana = accepts.filter(isSolanaExactAccept);return solana.find((a) => a.asset === USDC_MINT_SOLANA) || solana[0] || null;}diff --git a/pages/play/agent-wallet.html b/pages/play/agent-wallet.htmlindex 87e245cba..10c6e12d1 100644--- a/pages/play/agent-wallet.html+++ b/pages/play/agent-wallet.html@@ -50,15 +50,24 @@:focus-visible { outline:2px solid var(--acc-lt); outline-offset:3px; }a { color:var(--usdc-lt); }- #app { display:grid; grid-template-rows:52px 1fr; height:100%; }+ #app { display:grid; grid-template-rows:auto 1fr; height:100%; min-width:0; }/* ── Top bar ─────────────────────────────────────────── */+ /* The bar WRAPS rather than clipping. The body never scrolls, so a+ fixed-height row whose contents do not fit does not produce a+ scrollbar: it stretches the grid track wider than the viewport and+ silently cuts everything to its right off the screen. At 320px that+ swallowed the three destination links AND the right-hand edge of the+ side panel below them (the wallet address, the mode pill, the balance).+ Wrapping keeps every control reachable at every width. */.topbar {- display:flex; align-items:center; justify-content:space-between; gap:12px;- padding:0 20px; border-bottom:1px solid var(--border);+ display:flex; align-items:center; justify-content:space-between;+ gap:10px 12px; flex-wrap:wrap; min-height:52px; min-width:0;+ padding:8px 20px; border-bottom:1px solid var(--border);background:rgba(7,8,15,0.95); backdrop-filter:blur(12px); z-index:20;}- .brand { display:flex; align-items:center; gap:10px; min-width:0; }+ .topbar .tb-actions { display:flex; align-items:center; gap:10px; flex-wrap:wrap; min-width:0; }+ .brand { display:flex; align-items:center; gap:8px 10px; flex-wrap:wrap; min-width:0; }.brand a { color:var(--text); text-decoration:none; font-weight:700; font-size:15px; letter-spacing:-0.01em; }.brand a.crumb { color:var(--muted); font-weight:500; }.brand a.crumb:hover { color:var(--text); }@@ -79,7 +88,8 @@.tb-btn:hover { background:rgba(255,255,255,0.09); color:var(--text); border-color:var(--border-hi); }/* ── Stage + panel layout ────────────────────────────── */- #main { display:grid; grid-template-columns:1fr 384px; min-height:0; }+ #main { display:grid; grid-template-columns:1fr 384px; min-height:0; min-width:0; }+ #main > * { min-width:0; }#stage3d { position:relative; overflow:hidden; background:var(--bg2); }#stage3d canvas { display:block; outline:none; }.scene-hint {@@ -248,7 +258,7 @@@media (max-width:860px) {#main { grid-template-columns:1fr; grid-template-rows:46vh 1fr; }#panel { border-left:0; border-top:1px solid var(--border); }- .topbar { padding:0 14px; }+ .topbar { padding:8px 14px; }.badge { display:none; }}</style>@@ -271,7 +281,7 @@<span class="sep">/</span><span class="badge" data-i18n-html="play_agent_wallet.agent_wallet_x402_on_solana"><span class="dot"></span>Agent Wallet × x402 on Solana</span></div>- <div style="display:flex;gap:10px;align-items:center;">+ <div class="tb-actions"><a class="tb-btn" href="/play/arena" title="Live agent trading arena" data-i18n="play_agent_wallet.arena" data-i18n-attr="title:play_agent_wallet.live_agent_trading_arena_title">Arena</a><a class="tb-btn" href="/agent-exchange" title="Two agents paying each other" data-i18n="play_agent_wallet.agent_exchange" data-i18n-attr="title:play_agent_wallet.two_agents_paying_each_other_title">Agent Exchange</a><a class="tb-btn" href="/pay" title="x402 pay-per-call demo" data-i18n="play_agent_wallet.x402_demo" data-i18n-attr="title:play_agent_wallet.x402_pay_per_call_demo_title">x402 demo</a>@@ -335,6 +345,13 @@<div class="ep-desc" id="epDesc"><span class="skel" data-i18n="play_agent_wallet.live_market_signal_pay_per_call_settled">Live market signal — pay per call, settled in USDC on Solana mainnet.</span></div><div class="ep-meta" id="epTags"></div>+ <div class="banner offline" id="quoteOffline" role="alert">+ <div class="b-head">Price unavailable</div>+ The endpoint did not return a payment quote, so there is no price to show+ and nothing to pay yet. This is usually brief.+ <button class="retry" id="retryQuote" type="button">Retry quote</button>+ </div>+<div class="topics" id="topics" role="group" aria-label="Intel topic"></div><button class="pay-btn" id="payBtn" type="button" disabled data-i18n-html="play_agent_wallet.send_avatar_to_pay">diff --git a/src/play-agent-wallet.js b/src/play-agent-wallet.jsindex 289e351f8..d8f2b0f9b 100644--- a/src/play-agent-wallet.js+++ b/src/play-agent-wallet.js@@ -288,6 +288,7 @@ const live = {wallet: null, // { address, mode }balanceUsd: null,quote: null, // parsed /quote payload+ quoteError: false, // the bridge could not read a 402 challengestage: null, // active stage id while payingstageText: '',receipt: null, // { amount, payer, payTo, tx, result }@@ -574,6 +575,13 @@ function updatePayButton() {lbl.textContent = live.bridge === 'offline' ? 'Bridge offline' : 'Connecting to bridge…';return;}+ // Same rule as the balance check below: never offer a payment we cannot+ // price. The quote banner above the button says why and offers a retry.+ if (live.quoteError) {+ payBtn.disabled = true;+ lbl.textContent = 'Endpoint price unavailable';+ return;+ }// Offering a button that can only fail is worse than saying why. The// low-balance banner above it carries the address to send USDC to.if (underfunded()) {@@ -608,7 +616,7 @@ async function refreshStatus() {$('wMode').textContent = `${data.wallet.mode} wallet`;own($('wBal')).innerHTML = `$${escapeHtml(Number(data.balance?.totalValue || 0).toFixed(2))}<small>USD</small>`;$('bridgeOffline').classList.remove('show');- $('lowBalance').classList.toggle('show', underfunded() && !live.receipt);+ $('lowBalance').classList.toggle('show', !live.quoteError && underfunded() && !live.receipt);} catch {// A dev machine that prefers the local bridge gets one silent promotion to// the hosted one rather than a dead page.@@ -638,6 +646,8 @@ async function loadQuote() {const q = await r.json();if (!q.ok) throw new Error(q.error || 'quote failed');live.quote = q;+ live.quoteError = false;+ $('quoteOffline').classList.remove('show');own($('epName')).textContent = q.resource?.serviceName || 'three.ws Crypto Intel';$('epPrice').textContent = `${fmtUsdc(q.amount)} USDC`;$('epDesc').textContent = q.resource?.description@@ -652,15 +662,20 @@ async function loadQuote() {tags.appendChild(el);}} catch {- // quote requires the bridge; the bridge-offline banner already explains+ // The price comes from a live 402 challenge, so without one there is no+ // price. Printing the usual $0.01 anyway would be a made-up number on a+ // page whose whole claim is that the money is real: say it is unavailable+ // and offer the retry instead.live.quote = null;+ live.quoteError = true;own($('epName')).textContent = 'three.ws Crypto Intel';- $('epPrice').textContent = '$0.01 USDC';+ $('epPrice').textContent = 'price unavailable';$('epDesc').textContent = 'Live market signal (bullish / bearish / neutral): pay per call, settled in USDC on Solana mainnet.';$('epTags').innerHTML = '';+ $('quoteOffline').classList.toggle('show', live.bridge === 'online');}// The banner is priced against the quote, so it can only settle once we have one.- $('lowBalance').classList.toggle('show', live.bridge === 'online' && underfunded() && !live.receipt);+ $('lowBalance').classList.toggle('show', live.bridge === 'online' && !live.quoteError && underfunded() && !live.receipt);updatePayButton();}@@ -770,6 +785,7 @@ function handleStageEvent(evt) {payBtn.addEventListener('click', pay);$('retryBridge').addEventListener('click', () => { refreshStatus().then(loadQuote); });+$('retryQuote').addEventListener('click', () => { loadQuote(); });$('copyAddr').addEventListener('click', async () => {const full = $('wAddr').title;if (!full) return;diff --git a/tests/agent-wallet-bridge-accept.test.js b/tests/agent-wallet-bridge-accept.test.jsnew file mode 100644index 000000000..a771920da--- /dev/null+++ b/tests/agent-wallet-bridge-accept.test.js@@ -0,0 +1,66 @@+import { describe, it, expect } from 'vitest';++// Regression for the outage that took /play/agent-wallet down end to end: the+// hosted bridge treated `extra.feePayer` as an admission test, so the moment+// three.ws's own paid endpoints started advertising SELF-PAY accepts (which+// x402-paid-endpoint.js does whenever the sponsor wallet cannot co-sign), the+// bridge found no payable accept, answered every ?quote=1 with a 502, and the+// page never got past its connecting state. A fee payer picks the SIGNING MODE;+// it does not decide whether an accept is payable.++const { isSolanaExactAccept, pickSolanaAccept } = await import('../api/agent-wallet-bridge.js');++const SOLANA = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp';+const USDC = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';+const THREE = 'FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump';++const sponsoredUsdc = {+ scheme: 'exact', network: SOLANA, asset: USDC, amount: '10000',+ payTo: 'wwwwwDxFWRn7grgr3Esrsg5C6NvDoDHSA4gaCffccrU',+ extra: { name: 'USDC', decimals: 6, feePayer: 'WwwuGbqHrwF5RG89KhUbmRWEvjnRH9k5kVM5p7T3WwW' },+};+const selfPayUsdc = {+ scheme: 'exact', network: SOLANA, asset: USDC, amount: '10000',+ payTo: 'wwwwwDxFWRn7grgr3Esrsg5C6NvDoDHSA4gaCffccrU',+ extra: { name: 'USDC', decimals: 6 },+};+const selfPayThree = {+ scheme: 'exact', network: SOLANA, asset: THREE, amount: '10000000',+ payTo: 'wwwwwDxFWRn7grgr3Esrsg5C6NvDoDHSA4gaCffccrU',+ extra: { name: 'THREE', decimals: 6 },+};+const base = {+ scheme: 'exact', network: 'eip155:8453', asset: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',+ amount: '10000', payTo: '0x4022de2d36c334e73c7a108805cea11c0564f402',+ extra: { name: 'USD Coin', version: '2', decimals: 6 },+};++describe('agent-wallet bridge accept selection', () => {+ it('accepts a sponsored Solana exact entry', () => {+ expect(isSolanaExactAccept(sponsoredUsdc)).toBe(true);+ });++ it('accepts a self-pay Solana exact entry (no advertised fee payer)', () => {+ expect(isSolanaExactAccept(selfPayUsdc)).toBe(true);+ });++ it('rejects non-Solana and non-exact entries', () => {+ expect(isSolanaExactAccept(base)).toBe(false);+ expect(isSolanaExactAccept({ ...selfPayUsdc, scheme: 'upto' })).toBe(false);+ expect(isSolanaExactAccept(null)).toBe(false);+ expect(isSolanaExactAccept({})).toBe(false);+ });++ it('picks USDC over the platform token even when USDC comes second', () => {+ expect(pickSolanaAccept([selfPayThree, selfPayUsdc])).toBe(selfPayUsdc);+ });++ it('picks the self-pay USDC entry out of a mixed real-world challenge', () => {+ expect(pickSolanaAccept([selfPayUsdc, selfPayThree, base])).toBe(selfPayUsdc);+ });++ it('returns null when nothing on Solana is payable', () => {+ expect(pickSolanaAccept([base])).toBeNull();+ expect(pickSolanaAccept([])).toBeNull();+ });+});