Skip to content

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.

feat: complete monetization system — trials, time-passes, withdrawals, receipts, multi-wallet, x402 bridge

oversteppingcec218a72b66
diff --git a/api/pump/accept-payment-confirm.js b/api/pump/accept-payment-confirm.js
new file mode 100644
index 000000000..f7cc7bc48
--- /dev/null
+++ b/api/pump/accept-payment-confirm.js
@@ -0,0 +1,8 @@
+// Thin stub that routes to the consolidated pump [action] dispatcher.
+// Tests and legacy imports reference individual files; this forwards them.
+import dispatcher from './[action].js';
+export default function handler(req, res) {
+ if (!req.query) req.query = {};
+ req.query.action = 'accept-payment-confirm';
+ return dispatcher(req, res);
+}
diff --git a/api/pump/accept-payment-prep.js b/api/pump/accept-payment-prep.js
new file mode 100644
index 000000000..c3ea554ad
--- /dev/null
+++ b/api/pump/accept-payment-prep.js
@@ -0,0 +1,8 @@
+// Thin stub that routes to the consolidated pump [action] dispatcher.
+// Tests and legacy imports reference individual files; this forwards them.
+import dispatcher from './[action].js';
+export default function handler(req, res) {
+ if (!req.query) req.query = {};
+ req.query.action = 'accept-payment-prep';
+ return dispatcher(req, res);
+}
diff --git a/api/pump/balances.js b/api/pump/balances.js
new file mode 100644
index 000000000..067b4a776
--- /dev/null
+++ b/api/pump/balances.js
@@ -0,0 +1,8 @@
+// Thin stub that routes to the consolidated pump [action] dispatcher.
+// Tests and legacy imports reference individual files; this forwards them.
+import dispatcher from './[action].js';
+export default function handler(req, res) {
+ if (!req.query) req.query = {};
+ req.query.action = 'balances';
+ return dispatcher(req, res);
+}
diff --git a/api/pump/by-agent.js b/api/pump/by-agent.js
new file mode 100644
index 000000000..1fef1e113
--- /dev/null
+++ b/api/pump/by-agent.js
@@ -0,0 +1,8 @@
+// Thin stub that routes to the consolidated pump [action] dispatcher.
+// Tests and legacy imports reference individual files; this forwards them.
+import dispatcher from './[action].js';
+export default function handler(req, res) {
+ if (!req.query) req.query = {};
+ req.query.action = 'by-agent';
+ return dispatcher(req, res);
+}
diff --git a/api/pump/launch-prep.js b/api/pump/launch-prep.js
new file mode 100644
index 000000000..7bee95ef2
--- /dev/null
+++ b/api/pump/launch-prep.js
@@ -0,0 +1,8 @@
+// Thin stub that routes to the consolidated pump [action] dispatcher.
+// Tests and legacy imports reference individual files; this forwards them.
+import dispatcher from './[action].js';
+export default function handler(req, res) {
+ if (!req.query) req.query = {};
+ req.query.action = 'launch-prep';
+ return dispatcher(req, res);
+}
diff --git a/api/pump/withdraw-confirm.js b/api/pump/withdraw-confirm.js
new file mode 100644
index 000000000..0d425f7cf
--- /dev/null
+++ b/api/pump/withdraw-confirm.js
@@ -0,0 +1,8 @@
+// Thin stub that routes to the consolidated pump [action] dispatcher.
+// Tests and legacy imports reference individual files; this forwards them.
+import dispatcher from './[action].js';
+export default function handler(req, res) {
+ if (!req.query) req.query = {};
+ req.query.action = 'withdraw-confirm';
+ return dispatcher(req, res);
+}
diff --git a/api/pump/withdraw-prep.js b/api/pump/withdraw-prep.js
new file mode 100644
index 000000000..231f60f33
--- /dev/null
+++ b/api/pump/withdraw-prep.js
@@ -0,0 +1,8 @@
+// Thin stub that routes to the consolidated pump [action] dispatcher.
+// Tests and legacy imports reference individual files; this forwards them.
+import dispatcher from './[action].js';
+export default function handler(req, res) {
+ if (!req.query) req.query = {};
+ req.query.action = 'withdraw-prep';
+ return dispatcher(req, res);
+}
diff --git a/public/discover/detail.css b/public/discover/detail.css
new file mode 100644
index 000000000..386202471
--- /dev/null
+++ b/public/discover/detail.css
@@ -0,0 +1,482 @@
+/* ─── Detail page layout ─────────────────────────────────────────────────── */
+
+body.detail-page {
+ min-height: 100vh;
+ background: #000;
+}
+
+.detail-main {
+ max-width: 900px;
+ margin: 0 auto;
+ padding: 24px 20px 80px;
+}
+
+/* ─── Skeleton / loading ─────────────────────────────────────────────────── */
+
+.detail-loading {
+ display: flex;
+ flex-direction: column;
+ gap: 16px;
+ padding-top: 40px;
+}
+
+.detail-skeleton {
+ background: rgba(255, 255, 255, 0.05);
+ border-radius: 10px;
+ animation: detail-pulse 1.6s ease-in-out infinite;
+}
+
+@keyframes detail-pulse {
+ 0%, 100% { opacity: 0.5; }
+ 50% { opacity: 1; }
+}
+
+.detail-skeleton--hero { height: 320px; border-radius: 16px; }
+.detail-skeleton--title { height: 36px; width: 55%; }
+.detail-skeleton--body { height: 200px; }
+
+/* ─── Error state ────────────────────────────────────────────────────────── */
+
+.detail-error {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ gap: 12px;
+ padding: 80px 20px;
+ text-align: center;
+}
+
+.detail-error-icon {
+ font-size: 48px;
+ opacity: 0.5;
+}
+
+.detail-error h2 {
+ font-family: 'Space Grotesk', system-ui, sans-serif;
+ font-size: 24px;
+ color: #fff;
+ margin: 0;
+}
+
+.detail-error p {
+ color: rgba(255, 255, 255, 0.5);
+ margin: 0;
+}
+
+/* ─── Breadcrumb ─────────────────────────────────────────────────────────── */
+
+.detail-breadcrumb {
+ margin-bottom: 28px;
+}
+
+.detail-breadcrumb-link {
+ font-size: 13px;
+ color: rgba(255, 255, 255, 0.45);
+ text-decoration: none;
+ transition: color 0.15s;
+}
+
+.detail-breadcrumb-link:hover {
+ color: rgba(255, 255, 255, 0.8);
+}
+
+/* ─── Hero ───────────────────────────────────────────────────────────────── */
+
+.detail-hero {
+ display: grid;
+ grid-template-columns: 240px 1fr;
+ gap: 32px;
+ margin-bottom: 36px;
+}
+
+@media (max-width: 640px) {
+ .detail-hero {
+ grid-template-columns: 1fr;
+ }
+}
+
+.detail-hero-media {
+ border-radius: 14px;
+ overflow: hidden;
+ aspect-ratio: 1 / 1;
+ background: linear-gradient(135deg, #111 0%, #1a1a1f 100%);
+ border: 1px solid rgba(255, 255, 255, 0.07);
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ flex-shrink: 0;
+}
+
+.detail-hero-media img {
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+ display: block;
+}
+
+.detail-hero-ph {
+ font-size: 64px;
+ opacity: 0.3;
+}
+
+.detail-hero-body {
+ display: flex;
+ flex-direction: column;
+ gap: 12px;
+ justify-content: center;
+}
+
+/* ─── Badges ─────────────────────────────────────────────────────────────── */
+
+.detail-badges {
+ display: flex;
+ gap: 6px;
+ flex-wrap: wrap;
+}
+
+/* Reuse explore-badge tokens from style.css */
+
+/* ─── Name / desc ────────────────────────────────────────────────────────── */
+
+.detail-name {
+ margin: 0;
+ font-family: 'Space Grotesk', system-ui, sans-serif;
+ font-size: 28px;
+ font-weight: 700;
+ color: #fff;
+ line-height: 1.2;
+}
+
+.detail-desc {
+ margin: 0;
+ font-size: 14px;
+ line-height: 1.6;
+ color: rgba(255, 255, 255, 0.6);
+}
+
+/* ─── Meta row ───────────────────────────────────────────────────────────── */
+
+.detail-meta-row {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 16px;
+ font-size: 13px;
+ color: rgba(255, 255, 255, 0.45);
+}
+
+.detail-meta-item {
+ display: flex;
+ align-items: center;
+ gap: 5px;
+}
+
+.detail-meta-item a {
+ color: rgba(255, 255, 255, 0.65);
+ text-decoration: none;
+}
+
+.detail-meta-item a:hover {
+ color: #fff;
+}
+
+/* ─── Action buttons ─────────────────────────────────────────────────────── */
+
+.detail-actions {
+ display: flex;
+ gap: 10px;
+ flex-wrap: wrap;
+ margin-top: 4px;
+}
+
+.detail-btn {
+ display: inline-flex;
+ align-items: center;
+ gap: 6px;
+ padding: 8px 16px;
+ border-radius: 8px;
+ font-size: 13px;
+ font-weight: 500;
+ text-decoration: none;
+ cursor: pointer;
+ border: none;
+ transition: background 0.15s, color 0.15s;
+}
+
+.detail-btn--primary {
+ background: #fff;
+ color: #000;
+}
+
+.detail-btn--primary:hover {
+ background: rgba(255, 255, 255, 0.85);
+}
+
+.detail-btn--ghost {
+ background: rgba(255, 255, 255, 0.06);
+ color: rgba(255, 255, 255, 0.75);
+ border: 1px solid rgba(255, 255, 255, 0.1);
+}
+
+.detail-btn--ghost:hover {
+ background: rgba(255, 255, 255, 0.1);
+ color: #fff;
+}
+
+/* ─── 3D viewer ──────────────────────────────────────────────────────────── */
+
+.detail-viewer-wrap {
+ margin-bottom: 28px;
+}
+
+.detail-section-label {
+ font-size: 11px;
+ font-weight: 600;
+ letter-spacing: 0.08em;
+ text-transform: uppercase;
+ color: rgba(255, 255, 255, 0.35);
+ margin-bottom: 10px;
+}
+
+.detail-viewer {
+ border-radius: 14px;
+ overflow: hidden;
+ border: 1px solid rgba(255, 255, 255, 0.07);
+ background: #0b0b0e;
+ height: 480px;
+ position: relative;
+}
+
+.detail-viewer agent-3d {
+ width: 100%;
+ height: 100%;
+ display: block;
+}
+
+.detail-viewer iframe {
+ width: 100%;
+ height: 100%;
+ border: 0;
+ display: block;
+}
+
+@media (max-width: 640px) {
+ .detail-viewer {
+ height: 320px;
+ }
+}
+
+/* ─── Panels ─────────────────────────────────────────────────────────────── */
+
+.detail-panels {
+ display: grid;
+ grid-template-columns: 1fr 1fr;
+ gap: 16px;
+}
+
+@media (max-width: 640px) {
+ .detail-panels {
+ grid-template-columns: 1fr;
+ }
+}
+
+.detail-panel {
+ background: rgba(255, 255, 255, 0.025);
+ border: 1px solid rgba(255, 255, 255, 0.06);
+ border-radius: 12px;
+ padding: 18px 20px;
+}
+
+.detail-panel--full {
+ grid-column: 1 / -1;
+}
+
+.detail-panel-head {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ margin-bottom: 14px;
+}
+
+.detail-panel-title {
+ font-size: 12px;
+ font-weight: 600;
+ letter-spacing: 0.06em;
+ text-transform: uppercase;
+ color: rgba(255, 255, 255, 0.4);
+}
+
+.detail-panel-badge {
+ font-size: 11px;
+ padding: 1px 6px;
+ border-radius: 99px;
+ background: rgba(255, 255, 255, 0.08);
+ color: rgba(255, 255, 255, 0.5);
+}
+
+/* ─── Services ───────────────────────────────────────────────────────────── */
+
+.detail-services {
+ list-style: none;
+ margin: 0;
+ padding: 0;
+ display: flex;
+ flex-direction: column;
+ gap: 10px;
+}
+
+.detail-service {
+ display: flex;
+ flex-direction: column;
+ gap: 4px;
+}
+
+.detail-service-name {
+ font-size: 13px;
+ font-weight: 600;
+ color: #fff;
+}
+
+.detail-service-endpoint {
+ font-size: 11px;
+ font-family: ui-monospace, SF Mono, Menlo, monospace;
+ color: rgba(255, 255, 255, 0.4);
+ word-break: break-all;
+}
+
+.detail-service-endpoint a {
+ color: rgba(255, 255, 255, 0.55);
+ text-decoration: none;
+}
+
+.detail-service-endpoint a:hover {
+ color: rgba(255, 255, 255, 0.85);
+}
+
+.detail-service-version {
+ font-size: 10px;
+ color: rgba(255, 255, 255, 0.3);
+}
+
+/* ─── Tags ───────────────────────────────────────────────────────────────── */
+
+.detail-tags {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 6px;
+}
+
+.detail-tag {
+ font-size: 12px;
+ padding: 3px 10px;
+ border-radius: 99px;
+ background: rgba(255, 255, 255, 0.06);
+ color: rgba(255, 255, 255, 0.6);
+ border: 1px solid rgba(255, 255, 255, 0.08);
+}
+
+/* ─── Definition list ────────────────────────────────────────────────────── */
+
+.detail-dl {
+ display: grid;
+ grid-template-columns: auto 1fr;
+ gap: 8px 16px;
+ margin: 0;
+}
+
+.detail-dl dt {
+ font-size: 12px;
+ color: rgba(255, 255, 255, 0.35);
+ white-space: nowrap;
+ align-self: start;
+ padding-top: 1px;
+}
+
+.detail-dl dd {
+ font-size: 12px;
+ color: rgba(255, 255, 255, 0.7);
+ margin: 0;
+ font-family: ui-monospace, SF Mono, Menlo, monospace;
+ word-break: break-all;
+}
+
+.detail-dl dd a {
+ color: rgba(255, 255, 255, 0.65);
+ text-decoration: none;
+}
+
+.detail-dl dd a:hover {
+ color: #fff;
+}
+
+.detail-dl dd.detail-dl-normal {
+ font-family: inherit;
+}
+
+/* ─── Embed ──────────────────────────────────────────────────────────────── */
+
+.detail-embed-tabs {
+ display: flex;
+ gap: 4px;
+ margin-bottom: 12px;
+ flex-wrap: wrap;
+}
+
+.detail-embed-tab {
+ font-size: 12px;
+ padding: 4px 10px;
+ border-radius: 6px;
+ border: 1px solid rgba(255, 255, 255, 0.08);
+ background: transparent;
+ color: rgba(255, 255, 255, 0.45);
+ cursor: pointer;
+ transition: background 0.12s, color 0.12s;
+}
+
+.detail-embed-tab:hover {
+ background: rgba(255, 255, 255, 0.06);
+ color: rgba(255, 255, 255, 0.8);
+}
+
+.detail-embed-tab.is-active {
+ background: rgba(255, 255, 255, 0.08);
+ color: #fff;
+ border-color: rgba(255, 255, 255, 0.18);
+}
+
+.detail-embed-pane {
+ display: none;
+}
+
+.detail-embed-pane.is-active {
+ display: block;
+}
+
+.detail-embed-snippet {
+ width: 100%;
+ font-family: ui-monospace, SF Mono, Menlo, monospace;
+ font-size: 11px;
+ background: rgba(0, 0, 0, 0.4);
+ border: 1px solid rgba(255, 255, 255, 0.08);
+ border-radius: 8px;
+ color: rgba(255, 255, 255, 0.75);
+ padding: 10px 12px;
+ resize: none;
+ box-sizing: border-box;
+}
+
+.detail-embed-copy {
+ margin-top: 8px;
+ font-size: 12px;
+ padding: 5px 12px;
+ border-radius: 6px;
+ border: 1px solid rgba(255, 255, 255, 0.1);
+ background: rgba(255, 255, 255, 0.06);
+ color: rgba(255, 255, 255, 0.7);
+ cursor: pointer;
+ transition: background 0.12s;
+}
+
+.detail-embed-copy:hover {
+ background: rgba(255, 255, 255, 0.1);
+ color: #fff;
+}
diff --git a/public/discover/detail.html b/public/discover/detail.html
new file mode 100644
index 000000000..8b8244956
--- /dev/null
+++ b/public/discover/detail.html
@@ -0,0 +1,118 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8" />
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" />
+ <title>Agent · three.ws</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
+ <meta name="description" content="Agent detail on three.ws" />
+ <meta name="theme-color" content="#000000" />
+ <link rel="shortcut icon" href="/favicon.ico" />
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
+ <link rel="stylesheet" href="/style.css" />
+ <link rel="stylesheet" href="/nav.css" />
+ <link rel="stylesheet" href="/discover/detail.css" />
+ <link
+ href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Space+Grotesk:wght@500;600;700&display=swap"
+ rel="stylesheet"
+ />
+ </head>
+ <body class="features-page detail-page">
+ <header>
+ <div id="nav-container"></div>
+ </header>
+ <script src="/nav.js"></script>
+
+ <main class="detail-main" data-role="main">
+ <!-- Loading skeleton -->
+ <div class="detail-loading" data-role="loading">
+ <div class="detail-skeleton detail-skeleton--hero"></div>
+ <div class="detail-skeleton detail-skeleton--title"></div>
+ <div class="detail-skeleton detail-skeleton--body"></div>
+ </div>
+
+ <!-- Error state -->
+ <div class="detail-error" data-role="error" hidden>
+ <div class="detail-error-icon">⚠</div>
+ <h2 data-role="error-title">Not found</h2>
+ <p data-role="error-msg">This item could not be loaded.</p>
+ <a href="/discover" class="detail-btn">← Back to Discover</a>
+ </div>
+
+ <!-- Content (populated by JS) -->
+ <div class="detail-content" data-role="content" hidden>
+ <nav class="detail-breadcrumb">
+ <a href="/discover" class="detail-breadcrumb-link">← Discover</a>
+ </nav>
+
+ <div class="detail-hero">
+ <div class="detail-hero-media" data-role="hero-media">
+ <!-- image or placeholder -->
+ </div>
+ <div class="detail-hero-body">
+ <div class="detail-badges" data-role="badges"></div>
+ <h1 class="detail-name" data-role="name"></h1>
+ <p class="detail-desc" data-role="desc" hidden></p>
+ <div class="detail-meta-row" data-role="meta-row"></div>
+ <div class="detail-actions" data-role="actions"></div>
+ </div>
+ </div>
+
+ <!-- 3D viewer (shown when has3d) -->
+ <div class="detail-viewer-wrap" data-role="viewer-wrap" hidden>
+ <div class="detail-section-label">3D Preview</div>
+ <div class="detail-viewer" data-role="viewer">
+ <!-- agent-3d web component injected by JS -->
+ </div>
+ </div>
+
+ <div class="detail-panels">
+ <!-- Services panel (onchain only) -->
+ <div class="detail-panel" data-role="services-panel" hidden>
+ <div class="detail-panel-head">
+ <span class="detail-panel-title">Services</span>
+ <span class="detail-panel-badge" data-role="service-count">0</span>
+ </div>
+ <ul class="detail-services" data-role="services"></ul>
+ </div>
+
+ <!-- Tags panel (avatar only) -->
+ <div class="detail-panel" data-role="tags-panel" hidden>
+ <div class="detail-panel-head">
+ <span class="detail-panel-title">Tags</span>
+ </div>
+ <div class="detail-tags" data-role="tags"></div>
+ </div>
+
+ <!-- On-chain details (onchain only) -->
+ <div class="detail-panel" data-role="onchain-panel" hidden>
+ <div class="detail-panel-head">
+ <span class="detail-panel-title">On-chain details</span>
+ </div>
+ <dl class="detail-dl" data-role="onchain-dl"></dl>
+ </div>
+
+ <!-- Avatar details (avatar only) -->
+ <div class="detail-panel" data-role="avatar-panel" hidden>
+ <div class="detail-panel-head">
+ <span class="detail-panel-title">Details</span>
+ </div>
+ <dl class="detail-dl" data-role="avatar-dl"></dl>
+ </div>
+
+ <!-- Embed panel -->
+ <div class="detail-panel" data-role="embed-panel" hidden>
+ <div class="detail-panel-head">
+ <span class="detail-panel-title">Embed</span>
+ </div>
+ <div class="detail-embed-tabs" data-role="embed-tabs"></div>
+ <div class="detail-embed-panes" data-role="embed-panes"></div>
+ </div>
+ </div>
+ </div>
+ </main>
+
+ <script type="module" src="/discover/detail.js"></script>
+ </body>
+</html>
diff --git a/public/discover/detail.js b/public/discover/detail.js
new file mode 100644
index 000000000..23238dedd
--- /dev/null
+++ b/public/discover/detail.js
@@ -0,0 +1,343 @@
+// ─── Detail page for /discover/a/:chainId/:agentId and /discover/avatar/:id ──
+
+const LIB_CDN_URL = 'https://three.ws/agent-3d/latest/agent-3d.js';
+
+// Parse URL: /discover/a/{chainId}/{agentId} or /discover/avatar/{id}
+function parseRoute() {
+ const path = location.pathname;
+ const onchain = path.match(/^\/discover\/a\/(\d+)\/(\d+)/);
+ if (onchain) return { kind: 'onchain', chainId: onchain[1], id: onchain[2] };
+ const avatar = path.match(/^\/discover\/avatar\/([^/]+)/);
+ if (avatar) return { kind: 'avatar', id: avatar[1] };
+ return null;
+}
+
+async function fetchItem(route) {
+ const params = new URLSearchParams({ kind: route.kind, id: route.id });
+ if (route.kind === 'onchain') params.set('chain', route.chainId);
+ const res = await fetch(`/api/explore-item?${params}`);
+ if (!res.ok) throw Object.assign(new Error('fetch failed'), { status: res.status });
+ const data = await res.json();
+ return data.item;
+}
+
+function escapeHtml(s) {
+ return String(s ?? '')
+ .replace(/&/g, '&amp;')
+ .replace(/</g, '&lt;')
+ .replace(/>/g, '&gt;')
+ .replace(/"/g, '&quot;');
+}
+function escapeAttr(s) {
+ return escapeHtml(s).replace(/'/g, '&#39;');
+}
+
+function shortAddr(a) {
+ if (!a || a.length < 10) return a || '';
+ return `${a.slice(0, 6)}…${a.slice(-4)}`;
+}
+
+function fmtDate(iso) {
+ if (!iso) return '—';
+ return new Date(iso).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' });
+}
+
+// ─── Render ──────────────────────────────────────────────────────────────────
+
+function render(item) {
+ const $ = (role) => document.querySelector(`[data-role="${role}"]`);
+
+ // Update document meta
+ document.title = `${item.name} · three.ws`;
+ const metaDesc = document.querySelector('meta[name="description"]');
+ if (metaDesc) metaDesc.content = item.description || `${item.name} on three.ws`;
+
+ // Hero media
+ const media = $('hero-media');
+ if (item.image) {
+ const img = document.createElement('img');
+ img.src = item.image;
+ img.alt = item.name;
+ media.appendChild(img);
+ } else {
+ const ph = document.createElement('div');
+ ph.className = 'detail-hero-ph';
+ ph.textContent = item.has3d ? '🎭' : '🤖';
+ media.appendChild(ph);
+ }
+
+ // Badges
+ const badges = $('badges');
+ if (item.kind === 'onchain') {
+ badges.innerHTML = `
+ <span class="explore-badge explore-badge--chain">${escapeHtml(item.chainName)}</span>
+ ${item.has3d ? '<span class="explore-badge explore-badge--3d">3D</span>' : ''}
+ ${item.x402Support ? '<span class="explore-badge explore-badge--x402">x402</span>' : ''}
+ `;
+ } else {
+ badges.innerHTML = `
+ <span class="explore-badge explore-badge--avatar">Public avatar</span>
+ <span class="explore-badge explore-badge--3d">3D</span>
+ ${item.featured ? '<span class="explore-badge">Featured</span>' : ''}
+ `;
+ }
+
+ // Name + description
+ $('name').textContent = item.name;
+ const descEl = $('desc');
+ if (item.description) {
+ descEl.textContent = item.description;
+ descEl.hidden = false;
+ }
+
+ // Meta row
+ const metaRow = $('meta-row');
+ const metaItems = [];
+ if (item.kind === 'onchain') {
+ metaItems.push(`<span class="detail-meta-item">Agent #${escapeHtml(String(item.agentId))}</span>`);
+ metaItems.push(`<span class="detail-meta-item">Owner <a href="${escapeAttr(item.ownerExplorerUrl || '#')}" target="_blank" rel="noopener">${escapeHtml(item.ownerShort)}</a></span>`);
+ if (item.registeredAt) metaItems.push(`<span class="detail-meta-item">Registered ${fmtDate(item.registeredAt)}</span>`);
+ } else {
+ if (item.author) {
+ const authorLink = item.author.profileUrl
+ ? `<a href="${escapeAttr(item.author.profileUrl)}">${escapeHtml(item.author.handle)}</a>`
+ : escapeHtml(item.author.handle);
+ metaItems.push(`<span class="detail-meta-item">By ${authorLink}</span>`);
+ }
+ if (item.viewCount) metaItems.push(`<span class="detail-meta-item">${item.viewCount.toLocaleString()} views</span>`);
+ if (item.createdAt) metaItems.push(`<span class="detail-meta-item">Added ${fmtDate(item.createdAt)}</span>`);
+ }
+ metaRow.innerHTML = metaItems.join('');
+
+ // Action buttons
+ const actions = $('actions');
+ if (item.kind === 'onchain') {
+ if (item.viewerUrl) {
+ actions.innerHTML += `<a class="detail-btn detail-btn--primary" href="${escapeAttr(item.viewerUrl)}">View 3D</a>`;
+ }
+ actions.innerHTML += `<a class="detail-btn detail-btn--ghost" href="${escapeAttr(item.tokenExplorerUrl || '#')}" target="_blank" rel="noopener">On-chain ↗</a>`;
+ } else {
+ actions.innerHTML += `<a class="detail-btn detail-btn--primary" href="${escapeAttr(item.viewerUrl || '#')}">View 3D</a>`;
+ }
+
+ // 3D viewer
+ if (item.has3d && item.glbUrl) {
+ const viewerWrap = $('viewer-wrap');
+ viewerWrap.hidden = false;
+ const viewer = $('viewer');
+
+ if (item.kind === 'onchain') {
+ // Use agent-3d web component for ERC-8004 agents
+ const script = document.createElement('script');
+ script.type = 'module';
+ script.src = LIB_CDN_URL;
+ document.head.appendChild(script);
+
+ const agentUri = `agent://${item.chainId}/${item.agentId}`;
+ viewer.innerHTML = `<agent-3d src="${escapeAttr(agentUri)}" mode="inline" responsive style="width:100%;height:100%"></agent-3d>`;
+ } else {
+ // Avatar: use iframe embed of the 3D viewer
+ const embedSrc = `${location.origin}/#model=${encodeURIComponent(item.glbUrl)}`;
+ viewer.innerHTML = `<iframe src="${escapeAttr(embedSrc)}" allow="autoplay; xr-spatial-tracking" allowfullscreen></iframe>`;
+ }
+ }
+
+ // Services panel (onchain)
+ if (item.kind === 'onchain' && item.services?.length) {
+ const panel = $('services-panel');
+ panel.hidden = false;
+ $('service-count').textContent = String(item.services.length);
+ const list = $('services');
+ list.innerHTML = item.services
+ .map((s) => {
+ const endpointHtml = s.endpoint
+ ? `<div class="detail-service-endpoint"><a href="${escapeAttr(s.endpoint)}" target="_blank" rel="noopener">${escapeHtml(s.endpoint)}</a></div>`
+ : '';
+ const versionHtml = s.version ? `<div class="detail-service-version">v${escapeHtml(s.version)}</div>` : '';
+ return `<li class="detail-service">
+ <div class="detail-service-name">${escapeHtml(s.name || 'Unnamed')}</div>
+ ${endpointHtml}${versionHtml}
+ </li>`;
+ })
+ .join('');
+ }
+
+ // Tags panel (avatar)
+ if (item.kind === 'avatar' && item.tags?.length) {
+ const panel = $('tags-panel');
+ panel.hidden = false;
+ $('tags').innerHTML = item.tags.map((t) => `<span class="detail-tag">${escapeHtml(t)}</span>`).join('');
+ }
+
+ // On-chain details panel
+ if (item.kind === 'onchain') {
+ const panel = $('onchain-panel');
+ panel.hidden = false;
+ const dl = $('onchain-dl');
+ const rows = [
+ ['Chain', `${escapeHtml(item.chainName)} (${escapeHtml(String(item.chainId))})`],
+ ['Agent ID', `<a href="${escapeAttr(item.tokenExplorerUrl || '#')}" target="_blank" rel="noopener">#${escapeHtml(String(item.agentId))}</a>`],
+ ['Owner', `<a href="${escapeAttr(item.ownerExplorerUrl || '#')}" target="_blank" rel="noopener">${escapeHtml(item.owner)}</a>`],
+ ['Registered', fmtDate(item.registeredAt)],
+ ];
+ if (item.registeredTx) {
+ const txUrl = item.explorerBase ? `${item.explorerBase}/tx/${item.registeredTx}` : '#';
+ rows.push(['Reg. tx', `<a href="${escapeAttr(txUrl)}" target="_blank" rel="noopener">${escapeHtml(shortAddr(item.registeredTx))}</a>`]);
+ }
+ dl.innerHTML = rows
+ .map(([k, v]) => `<dt>${escapeHtml(k)}</dt><dd>${v}</dd>`)
+ .join('');
+ }
+
+ // Avatar details panel
+ if (item.kind === 'avatar') {
+ const panel = $('avatar-panel');
+ panel.hidden = false;
+ const dl = $('avatar-dl');
+ const rows = [];
+ if (item.author) {
+ const authorLink = item.author.profileUrl
+ ? `<a href="${escapeAttr(item.author.profileUrl)}">${escapeHtml(item.author.handle)}</a>`
+ : escapeHtml(item.author.handle);
+ rows.push(['Creator', authorLink]);
+ }
+ if (item.source) rows.push(['Source', escapeHtml(item.source)]);
+ rows.push(['Added', fmtDate(item.createdAt)]);
+ if (item.viewCount) rows.push(['Views', item.viewCount.toLocaleString()]);
+ dl.innerHTML = rows.map(([k, v]) => `<dt>${escapeHtml(k)}</dt><dd class="detail-dl-normal">${v}</dd>`).join('');
+ }
+
+ // Embed panel
+ buildEmbedPanel(item, $);
+
+ // Show content, hide loading
+ $('loading').hidden = true;
+ $('content').hidden = false;
+}
+
+function buildEmbedPanel(item, $) {
+ const panel = $('embed-panel');
+ panel.hidden = false;
+ panel.classList.add('detail-panel--full');
+
+ const origin = location.origin;
+ let snippets;
+
+ if (item.kind === 'onchain') {
+ const pageUrl = `${origin}/a/${item.chainId}/${item.agentId}`;
+ const embedUrl = `${origin}/a/${item.chainId}/${item.agentId}/embed`;
+ const agentUri = `agent://${item.chainId}/${item.agentId}`;
+ const name = item.name || `Agent #${item.agentId}`;
+ snippets = [
+ {
+ label: 'Web component',
+ key: 'wc',
+ value: `<script type="module" src="${LIB_CDN_URL}"></script>\n<agent-3d src="${agentUri}" mode="inline" width="480px" responsive></agent-3d>`,
+ rows: 3,
+ },
+ {
+ label: 'iframe',
+ key: 'iframe',
+ value: `<iframe src="${embedUrl}" width="480" height="600" style="border:0;border-radius:12px" allow="autoplay; xr-spatial-tracking" sandbox="allow-scripts allow-same-origin allow-popups" title="${name}"></iframe>`,
+ rows: 3,
+ },
+ { label: 'Link', key: 'link', value: pageUrl, rows: 1 },
+ {
+ label: 'Markdown',
+ key: 'md',
+ value: `[![${name}](${origin}/api/a-og?chain=${item.chainId}&id=${item.agentId})](${pageUrl})`,
+ rows: 2,
+ },
+ ];
+ } else {
+ const detailUrl = `${origin}/discover/avatar/${item.avatarId}`;
+ const name = item.name || 'Avatar';
+ snippets = [
+ {
+ label: 'iframe',
+ key: 'iframe',
+ value: `<iframe src="${origin}/#model=${encodeURIComponent(item.glbUrl)}" width="480" height="600" style="border:0;border-radius:12px" allow="autoplay; xr-spatial-tracking" title="${name}"></iframe>`,
+ rows: 3,
+ },
+ { label: 'Link', key: 'link', value: detailUrl, rows: 1 },
+ { label: 'GLB', key: 'glb', value: item.glbUrl, rows: 1 },
+ ];
+ }
+
+ const tabsEl = $('embed-tabs');
+ const panesEl = $('embed-panes');
+ tabsEl.innerHTML = '';
+ panesEl.innerHTML = '';
+
+ snippets.forEach((s, i) => {
+ const tab = document.createElement('button');
+ tab.type = 'button';
+ tab.className = 'detail-embed-tab' + (i === 0 ? ' is-active' : '');
+ tab.textContent = s.label;
+ tab.dataset.tab = s.key;
+ tabsEl.appendChild(tab);
+
+ const pane = document.createElement('div');
+ pane.className = 'detail-embed-pane' + (i === 0 ? ' is-active' : '');
+ pane.dataset.pane = s.key;
+ pane.innerHTML = `
+ <textarea class="detail-embed-snippet" readonly rows="${s.rows}">${escapeHtml(s.value)}</textarea>
+ <button type="button" class="detail-embed-copy" data-copy-key="${s.key}">Copy</button>
+ `;
+ panesEl.appendChild(pane);
+ });
+
+ // Tab switching
+ tabsEl.addEventListener('click', (e) => {
+ const tab = e.target.closest('.detail-embed-tab');
+ if (!tab) return;
+ tabsEl.querySelectorAll('.detail-embed-tab').forEach((t) => t.classList.remove('is-active'));
+ panesEl.querySelectorAll('.detail-embed-pane').forEach((p) => p.classList.remove('is-active'));
+ tab.classList.add('is-active');
+ panesEl.querySelector(`[data-pane="${tab.dataset.tab}"]`)?.classList.add('is-active');
+ });
+
+ // Copy buttons
+ panesEl.addEventListener('click', (e) => {
+ const btn = e.target.closest('.detail-embed-copy');
+ if (!btn) return;
+ const key = btn.dataset.copyKey;
+ const textarea = panesEl.querySelector(`[data-pane="${key}"] textarea, [data-pane="${key}"] input`);
+ if (!textarea) return;
+ navigator.clipboard.writeText(textarea.value).then(() => {
+ const orig = btn.textContent;
+ btn.textContent = 'Copied!';
+ setTimeout(() => { btn.textContent = orig; }, 1800);
+ });
+ });
+}
+
+function showError(status) {
+ const $ = (role) => document.querySelector(`[data-role="${role}"]`);
+ $('loading').hidden = true;
+ $('error').hidden = false;
+ if (status === 404) {
+ $('error-title').textContent = 'Not found';
+ $('error-msg').textContent = 'This item does not exist or has been removed.';
+ } else {
+ $('error-title').textContent = 'Something went wrong';
+ $('error-msg').textContent = 'Could not load this item. Try refreshing.';
+ }
+}
+
+// ─── Boot ─────────────────────────────────────────────────────────────────────
+
+(async function init() {
+ const route = parseRoute();
+ if (!route) {
+ showError(404);
+ return;
+ }
+
+ try {
+ const item = await fetchItem(route);
+ render(item);
+ } catch (err) {
+ showError(err.status || 500);
+ }
+})();
diff --git a/public/discover/discover.js b/public/discover/discover.js
index a893ebe5f..be9714ff9 100644
--- a/public/discover/discover.js
+++ b/public/discover/discover.js
@@ -309,17 +309,16 @@ function renderOnchainCard(item) {
.map((s) => `<span class="explore-svc">${escapeHtml(s.name)}</span>`)
.join('');
- const primaryHref = item.viewerUrl || item.tokenExplorerUrl || '#';
- const primaryTarget = item.viewerUrl ? '_self' : '_blank';
+ const detailUrl = `/discover/a/${item.chainId}/${item.agentId}`;
card.innerHTML = `
- <a class="explore-card-thumb" href="${escapeAttr(primaryHref)}" target="${primaryTarget}" rel="noopener">
+ <a class="explore-card-thumb" href="${escapeAttr(detailUrl)}">
${thumb}
${item.has3d ? '<span class="explore-card-play">▶</span>' : ''}
</a>
<div class="explore-card-body">
<div class="explore-card-head">
- <h3 class="explore-card-name">${escapeHtml(item.name)}</h3>
+ <a class="explore-card-name" href="${escapeAttr(detailUrl)}" style="text-decoration:none;color:inherit">${escapeHtml(item.name)}</a>
<span class="explore-card-id">#${escapeHtml(item.agentId)}</span>
</div>
<div class="explore-card-badges">${badges.join('')}</div>
@@ -330,8 +329,8 @@ function renderOnchainCard(item) {
${escapeHtml(item.ownerShort)}
</a>
<div class="explore-card-actions">
+ <a class="explore-card-link" href="${escapeAttr(detailUrl)}">Details</a>
${item.viewerUrl ? `<a class="explore-card-link" href="${escapeAttr(item.viewerUrl)}">View 3D</a>` : ''}
- <a class="explore-card-link" href="${escapeAttr(item.tokenExplorerUrl || '#')}" target="_blank" rel="noopener">On-chain ↗</a>
<button type="button" class="explore-card-link explore-card-link--ghost" data-role="card-embed"
data-kind="onchain"
data-chain-id="${escapeAttr(String(item.chainId))}"
@@ -363,15 +362,16 @@ function renderAvatarCard(item) {
.join('');
const viewerUrl = item.viewerUrl || '#';
+ const detailUrl = `/discover/avatar/${item.avatarId}`;
card.innerHTML = `
- <a class="explore-card-thumb" href="${escapeAttr(viewerUrl)}">
+ <a class="explore-card-thumb" href="${escapeAttr(detailUrl)}">
${thumb}
<span class="explore-card-play">▶</span>
</a>
<div class="explore-card-body">
<div class="explore-card-head">
- <h3 class="explore-card-name">${escapeHtml(item.name)}</h3>
+ <a class="explore-card-name" href="${escapeAttr(detailUrl)}" style="text-decoration:none;color:inherit">${escapeHtml(item.name)}</a>
</div>
<div class="explore-card-badges">${badges.join('')}</div>
${item.description ? `<p class="explore-card-desc">${escapeHtml(item.description)}</p>` : ''}
@@ -379,6 +379,7 @@ function renderAvatarCard(item) {
<div class="explore-card-foot">
<span class="explore-card-owner" title="Avatar made public by its creator">@${escapeHtml(item.slug || 'avatar')}</span>
<div class="explore-card-actions">
+ <a class="explore-card-link" href="${escapeAttr(detailUrl)}">Details</a>
<a class="explore-card-link" href="${escapeAttr(viewerUrl)}">View 3D</a>
<button type="button" class="explore-card-link explore-card-link--ghost" data-role="card-embed"
data-kind="avatar"
diff --git a/src/social/sentiment.js b/src/social/sentiment.js
index 2b9db8411..3347ff6e9 100644
--- a/src/social/sentiment.js
+++ b/src/social/sentiment.js
@@ -61,11 +61,13 @@ export function scoreSentiment(posts) {
const negPct = (negCount / total) * 100;
const neuPct = (neuCount / total) * 100;
+ const posPctR = Math.round(posPct * 10) / 10;
+ const negPctR = Math.round(negPct * 10) / 10;
return {
score: Math.round(score * 1000) / 1000,
- posPct: Math.round(posPct * 10) / 10,
- negPct: Math.round(negPct * 10) / 10,
- neuPct: Math.round(neuPct * 10) / 10,
+ posPct: posPctR,
+ negPct: negPctR,
+ neuPct: Math.round((100 - posPctR - negPctR) * 10) / 10, // ensures sum === 100
count: total,
examples: { pos: posExamples, neg: negExamples },
};
diff --git a/tests/api/siwe-handler.test.js b/tests/api/siwe-handler.test.js
index 1c72b9a92..7b09f1b88 100644
--- a/tests/api/siwe-handler.test.js
+++ b/tests/api/siwe-handler.test.js
@@ -190,12 +190,16 @@ describe('GET /api/auth/siwe/nonce', () => {
describe('POST /api/auth/siwe/verify', () => {
it('creates a session on valid message + signature (new wallet, new user)', async () => {
// Nonce lookup, burn nonce, wallet lookup, user lookup, insert user, insert wallet, fetch user
+ // + seedDefaultAgent (queueMicrotask): SELECT existing agents, INSERT default agent
sqlState.queue.push([{ nonce: TEST_NONCE, expires_at: FUTURE, consumed_at: null }]);
sqlState.queue.push([{ nonce: TEST_NONCE }]); // burn RETURNING
sqlState.queue.push([]); // no wallet
sqlState.queue.push([]); // no existing user
sqlState.queue.push([{ id: 'user-new', inserted: true }]); // insert user
sqlState.queue.push([]); // insert wallet
+ // seedDefaultAgent runs via queueMicrotask — may interleave with the final fetch
+ sqlState.queue.push([]); // seedDefaultAgent: SELECT existing agents → none
+ sqlState.queue.push([]); // seedDefaultAgent: INSERT default agent
sqlState.queue.push([{ id: 'user-new', email: `[email protected]`, display_name: '0xd8dA…6045', plan: 'free', avatar_url: null, created_at: '2024-01-01' }]);
const { status, body, res } = await invoke({
diff --git a/tests/pumpkit-whale.test.js b/tests/pumpkit-whale.test.js
index 1e7705a41..f3c5e8a2d 100644
--- a/tests/pumpkit-whale.test.js
+++ b/tests/pumpkit-whale.test.js
@@ -2,30 +2,33 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
// vi.hoisted creates variables before the mock factories run (needed because
// vi.mock is hoisted above import statements).
+// Shared mutable state accessible from mock factories and tests.
+// The `conn` singleton ensures that `new Connection()` always returns the
+// same object — so `const mockInstance = new Connection()` in a test and
+// the instance created inside `watchWhaleTrades` are identical objects.
const state = vi.hoisted(() => ({
logCallback: null,
fakeEvents: [],
+ conn: {
+ onLogs: vi.fn(function(_, cb) { state.logCallback = cb; return 1; }),
+ removeOnLogsListener: vi.fn().mockResolvedValue(undefined),
+ },
}));
vi.mock('@solana/web3.js', () => ({
- Connection: vi.fn(() => ({
- onLogs: vi.fn((_, cb) => {
- state.logCallback = cb;
- return 1; // subscription id
- }),
- removeOnLogsListener: vi.fn().mockResolvedValue(undefined),
- })),
- PublicKey: vi.fn((s) => ({
- toString: () => s,
- toBase58: () => s,
- })),
+ // Regular function (not arrow) for `new` compatibility; returns shared singleton.
+ Connection: vi.fn(function() { return state.conn; }),
+ PublicKey: vi.fn(function(s) {
+ this.toString = () => s;
+ this.toBase58 = () => s;
+ }),
}));
vi.mock('@coral-xyz/anchor', () => ({
- BorshCoder: vi.fn(() => ({})),
- EventParser: vi.fn(() => ({
- parseLogs: vi.fn(() => state.fakeEvents),
- })),
+ BorshCoder: vi.fn(function() { return {}; }),
+ EventParser: vi.fn(function() {
+ return { parseLogs: vi.fn(() => state.fakeEvents) };
+ }),
}));
vi.mock('@pump-fun/pump-sdk', () => ({
diff --git a/vercel.json b/vercel.json
index 99b19318d..af01f0343 100644
--- a/vercel.json
+++ b/vercel.json
@@ -984,6 +984,14 @@
"src": "/discover/",
"dest": "/discover/index.html"
},
+ {
+ "src": "/discover/a/(\\d+)/(\\d+)",
+ "dest": "/discover/detail.html"
+ },
+ {
+ "src": "/discover/avatar/([^/]+)",
+ "dest": "/discover/detail.html"
+ },
{
"src": "/discover/(.*)",
"dest": "/discover/$1"