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(discover): on-chain agent discovery page

nirholasab9abc5205c4
diff --git a/index.html b/index.html
index dec52c25c..cc63153c0 100644
--- a/index.html
+++ b/index.html
@@ -936,5 +936,15 @@
const btn = document.getElementById('btn-wallet-signin');
if (btn) wireSigninButton(btn);
</script>
+ <!-- BEGIN:DISCOVER_LINK -->
+ <a href="/discover" id="discoverLink" class="discover-cta" hidden
+ >Find my on-chain agents →</a
+ >
+ <script type="module">
+ fetch('/api/auth/me', { credentials: 'include' })
+ .then((r) => r.ok && (document.getElementById('discoverLink').hidden = false))
+ .catch(() => {});
+ </script>
+ <!-- END:DISCOVER_LINK -->
</body>
</html>
diff --git a/prompts/final-integration/04-discover-page.md b/prompts/archive/final-integration/04-discover-page.md
similarity index 100%
rename from prompts/final-integration/04-discover-page.md
rename to prompts/archive/final-integration/04-discover-page.md
diff --git a/public/discover/discover.css b/public/discover/discover.css
new file mode 100644
index 000000000..25dd091d8
--- /dev/null
+++ b/public/discover/discover.css
@@ -0,0 +1,343 @@
+/* discover.css — On-chain agent discovery page styles */
+
+/* ── Design tokens (mirrored from dashboard) ─────────────────────────── */
+:root {
+ color-scheme: dark;
+ --d-accent: #6a5cff;
+ --d-accent2: #ff5ca8;
+ --d-border: #22222e;
+ --d-bg: #0b0b10;
+ --d-panel: #14141c;
+}
+
+/* ── Reset ───────────────────────────────────────────────────────────── */
+*,
+*::before,
+*::after {
+ box-sizing: border-box;
+}
+
+/* ── Base ────────────────────────────────────────────────────────────── */
+body {
+ font:
+ 15px/1.55 -apple-system,
+ system-ui,
+ Segoe UI,
+ Roboto,
+ sans-serif;
+ color: #eee;
+ margin: 0;
+ background: var(--d-bg);
+ min-height: 100vh;
+}
+
+a {
+ color: #9a8cff;
+ text-decoration: none;
+}
+a:hover {
+ text-decoration: underline;
+}
+
+/* ── Header ──────────────────────────────────────────────────────────── */
+.discover-header {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ padding: 16px 24px;
+ border-bottom: 1px solid var(--d-border);
+ position: sticky;
+ top: 0;
+ background: var(--d-bg);
+ z-index: 5;
+ gap: 12px;
+}
+
+.discover-header__brand {
+ font-weight: 600;
+ letter-spacing: -0.01em;
+ flex-shrink: 0;
+}
+
+.discover-header__nav {
+ display: flex;
+ align-items: center;
+ gap: 14px;
+}
+
+.discover-header__nav a {
+ color: #aaa;
+ font-size: 14px;
+}
+.discover-header__nav a:hover {
+ color: #eee;
+ text-decoration: none;
+}
+
+/* ── Main content ────────────────────────────────────────────────────── */
+.discover-main {
+ padding: 32px 24px;
+ max-width: 1100px;
+ margin: 0 auto;
+}
+
+.discover-title {
+ font-size: 22px;
+ margin: 0 0 6px;
+ letter-spacing: -0.01em;
+}
+
+.discover-subtitle {
+ color: #888;
+ margin: 0 0 28px;
+ font-size: 14px;
+}
+
+/* ── Toolbar ─────────────────────────────────────────────────────────── */
+.discover-toolbar {
+ display: flex;
+ align-items: center;
+ justify-content: flex-end;
+ margin-bottom: 18px;
+}
+
+/* ── Grid ────────────────────────────────────────────────────────────── */
+.discover-grid {
+ display: grid;
+ grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
+ gap: 14px;
+}
+
+@media (max-width: 600px) {
+ .discover-grid {
+ grid-template-columns: 1fr;
+ }
+}
+
+/* ── Agent card ──────────────────────────────────────────────────────── */
+.discover-card {
+ background: var(--d-panel);
+ border: 1px solid var(--d-border);
+ border-radius: 14px;
+ padding: 0;
+ display: flex;
+ flex-direction: column;
+ overflow: hidden;
+ transition: border-color 0.15s;
+}
+
+.discover-card:hover {
+ border-color: #2c2c40;
+}
+
+.discover-card__thumb {
+ aspect-ratio: 1 / 1;
+ background: #0f0f17;
+ display: grid;
+ place-items: center;
+ color: #444;
+ font-size: 40px;
+ overflow: hidden;
+}
+
+.discover-card__thumb img {
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+ display: block;
+}
+
+.discover-card__body {
+ padding: 14px 16px;
+ display: flex;
+ flex-direction: column;
+ gap: 6px;
+ flex: 1;
+}
+
+.discover-card__name {
+ font-size: 15px;
+ font-weight: 600;
+ margin: 0;
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
+
+.discover-card__row {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+}
+
+.discover-card__chain-pill {
+ display: inline-flex;
+ align-items: center;
+ gap: 4px;
+ font-size: 11px;
+ padding: 2px 8px;
+ border-radius: 99px;
+ background: #20202c;
+ color: #ccc;
+ white-space: nowrap;
+ flex-shrink: 0;
+}
+
+.discover-card__desc {
+ font-size: 13px;
+ color: #888;
+ margin: 0;
+ display: -webkit-box;
+ -webkit-line-clamp: 2;
+ -webkit-box-orient: vertical;
+ overflow: hidden;
+}
+
+.discover-card__footer {
+ padding: 0 16px 14px;
+ display: flex;
+ flex-direction: column;
+ gap: 6px;
+}
+
+.discover-card__inline-err {
+ font-size: 12px;
+ color: #ffb3b3;
+}
+
+/* ── Buttons ─────────────────────────────────────────────────────────── */
+.discover-btn {
+ padding: 9px 14px;
+ border-radius: 9px;
+ border: 0;
+ font-size: 13px;
+ font-weight: 600;
+ cursor: pointer;
+ background: var(--d-accent);
+ color: #fff;
+ width: 100%;
+ text-align: center;
+ transition: filter 0.12s;
+}
+
+.discover-btn:hover:not(:disabled) {
+ filter: brightness(1.08);
+}
+
+.discover-btn:disabled {
+ opacity: 0.55;
+ cursor: not-allowed;
+}
+
+.discover-btn--sec {
+ background: #222230;
+ color: #ddd;
+}
+
+.discover-btn--done {
+ background: #1a2a1a;
+ color: #6fcf6f;
+ border: 1px solid #2a4a2a;
+ cursor: default;
+}
+
+/* ── Skeleton shimmer ────────────────────────────────────────────────── */
+@keyframes discover-shimmer {
+ 0% {
+ background-position: -600px 0;
+ }
+ 100% {
+ background-position: 600px 0;
+ }
+}
+
+.discover-skeleton {
+ background: var(--d-panel);
+ border: 1px solid var(--d-border);
+ border-radius: 14px;
+ overflow: hidden;
+}
+
+.discover-skeleton__thumb {
+ aspect-ratio: 1 / 1;
+ background: linear-gradient(90deg, #1a1a24 25%, #22222e 50%, #1a1a24 75%);
+ background-size: 600px 100%;
+ animation: discover-shimmer 1.4s infinite linear;
+}
+
+.discover-skeleton__body {
+ padding: 14px 16px;
+ display: flex;
+ flex-direction: column;
+ gap: 10px;
+}
+
+.discover-skeleton__line {
+ height: 12px;
+ border-radius: 6px;
+ background: linear-gradient(90deg, #1a1a24 25%, #22222e 50%, #1a1a24 75%);
+ background-size: 600px 100%;
+ animation: discover-shimmer 1.4s infinite linear;
+}
+
+.discover-skeleton__line--short {
+ width: 55%;
+}
+
+.discover-skeleton__line--btn {
+ height: 36px;
+ margin-top: 10px;
+ border-radius: 9px;
+}
+
+/* ── State panels ────────────────────────────────────────────────────── */
+.discover-state {
+ text-align: center;
+ padding: 64px 20px;
+ border: 1px dashed var(--d-border);
+ border-radius: 14px;
+ color: #888;
+}
+
+.discover-state__icon {
+ font-size: 40px;
+ margin-bottom: 12px;
+}
+
+.discover-state__title {
+ font-size: 17px;
+ font-weight: 600;
+ color: #ddd;
+ margin: 0 0 6px;
+}
+
+.discover-state__msg {
+ font-size: 14px;
+ margin: 0 0 18px;
+}
+
+/* ── Error banner ────────────────────────────────────────────────────── */
+.discover-error-banner {
+ padding: 14px 16px;
+ background: rgba(255, 92, 92, 0.1);
+ border: 1px solid rgba(255, 92, 92, 0.3);
+ border-radius: 10px;
+ color: #ffb3b3;
+ margin-bottom: 18px;
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 12px;
+}
+
+.discover-error-banner__msg {
+ font-size: 14px;
+}
+
+/* ── Already-imported link ───────────────────────────────────────────── */
+.discover-card__agent-link {
+ font-size: 12px;
+ color: #9a8cff;
+ display: block;
+ text-align: center;
+}
diff --git a/public/discover/discover.js b/public/discover/discover.js
new file mode 100644
index 000000000..62088af5c
--- /dev/null
+++ b/public/discover/discover.js
@@ -0,0 +1,267 @@
+/**
+ * On-chain agent discovery page logic.
+ * Fetches agents owned by the signed-in user's linked wallets and renders them
+ * as importable cards.
+ */
+
+/** @type {Record<number, string>} Minimal chain name map to avoid importing chain-meta.js deps. */
+const CHAIN_NAMES = {
+ 1: 'Ethereum',
+ 10: 'Optimism',
+ 56: 'BNB Chain',
+ 97: 'BSC Testnet',
+ 100: 'Gnosis',
+ 137: 'Polygon',
+ 250: 'Fantom',
+ 324: 'zkSync Era',
+ 1284: 'Moonbeam',
+ 5000: 'Mantle',
+ 8453: 'Base',
+ 42161: 'Arbitrum',
+ 42220: 'Celo',
+ 43113: 'Avalanche Fuji',
+ 43114: 'Avalanche',
+ 59144: 'Linea',
+ 80002: 'Polygon Amoy',
+ 84532: 'Base Sepolia',
+ 421614: 'Arb Sepolia',
+ 534352: 'Scroll',
+ 11155111: 'Sepolia',
+ 11155420: 'OP Sepolia',
+};
+
+/** @param {number} id */
+function chainName(id) {
+ return CHAIN_NAMES[id] || `Chain ${id}`;
+}
+
+/** @param {string} text @returns {string} */
+function escapeHtml(text) {
+ if (text == null) return '';
+ const d = document.createElement('div');
+ d.textContent = String(text);
+ return d.innerHTML;
+}
+
+// ── Session ──────────────────────────────────────────────────────────────────
+
+/** @returns {Promise<object|null>} */
+async function getSession() {
+ try {
+ const res = await fetch('/api/auth/me', { credentials: 'include' });
+ if (!res.ok) return null;
+ const { user } = await res.json();
+ return user ?? null;
+ } catch {
+ return null;
+ }
+}
+
+// ── Rendering helpers ─────────────────────────────────────────────────────────
+
+const grid = /** @type {HTMLElement} */ (document.getElementById('discover-grid'));
+const errorBanner = /** @type {HTMLElement} */ (document.getElementById('discover-error'));
+
+/** Show N skeleton cards in the grid. */
+function showSkeletons(n = 6) {
+ grid.innerHTML = Array.from(
+ { length: n },
+ () => `
+ <div class="discover-skeleton" aria-hidden="true">
+ <div class="discover-skeleton__thumb"></div>
+ <div class="discover-skeleton__body">
+ <div class="discover-skeleton__line"></div>
+ <div class="discover-skeleton__line discover-skeleton__line--short"></div>
+ <div class="discover-skeleton__line discover-skeleton__line--btn"></div>
+ </div>
+ </div>`,
+ ).join('');
+}
+
+/**
+ * @param {string} icon
+ * @param {string} title
+ * @param {string} msg
+ * @param {{ label: string, href: string }|null} [cta]
+ */
+function showState(icon, title, msg, cta = null) {
+ grid.innerHTML = `
+ <div class="discover-state" style="grid-column: 1 / -1" role="status">
+ <div class="discover-state__icon" aria-hidden="true">${icon}</div>
+ <p class="discover-state__title">${escapeHtml(title)}</p>
+ <p class="discover-state__msg">${escapeHtml(msg)}</p>
+ ${cta ? `<a class="discover-btn" style="display:inline-block;width:auto;padding:9px 22px" href="${escapeHtml(cta.href)}">${escapeHtml(cta.label)}</a>` : ''}
+ </div>`;
+}
+
+/**
+ * @param {string} msg
+ * @param {boolean} showRetry
+ */
+function showErrorBanner(msg, showRetry = true) {
+ errorBanner.innerHTML = `
+ <span class="discover-error-banner__msg">${escapeHtml(msg)}</span>
+ ${showRetry ? `<button class="discover-btn discover-btn--sec" id="discover-retry" style="width:auto;padding:7px 14px;font-size:12px" aria-label="Retry loading agents">Retry</button>` : ''}`;
+ errorBanner.hidden = false;
+ if (showRetry) {
+ document.getElementById('discover-retry')?.addEventListener('click', () => {
+ errorBanner.hidden = true;
+ grid.innerHTML = '';
+ loadAgents();
+ });
+ }
+}
+
+/**
+ * Render one agent card.
+ * @param {{ chainId: number, agentId: string, name: string, description: string, image: string|null, glbUrl: string|null, alreadyImported: boolean }} agent
+ * @returns {HTMLElement}
+ */
+function buildCard(agent) {
+ const card = document.createElement('article');
+ card.className = 'discover-card';
+ card.setAttribute('aria-label', `Agent: ${agent.name}`);
+
+ const thumbSrc = agent.glbUrl || agent.image;
+ const thumbHtml = thumbSrc
+ ? `<img src="${escapeHtml(thumbSrc)}" alt="${escapeHtml(agent.name)} preview" loading="lazy" />`
+ : `<span aria-hidden="true">🤖</span>`;
+
+ card.innerHTML = `
+ <div class="discover-card__thumb">${thumbHtml}</div>
+ <div class="discover-card__body">
+ <h2 class="discover-card__name" title="${escapeHtml(agent.name)}">${escapeHtml(agent.name)}</h2>
+ <div class="discover-card__row">
+ <span class="discover-card__chain-pill" title="Chain ID ${escapeHtml(String(agent.chainId))}">${escapeHtml(chainName(agent.chainId))}</span>
+ </div>
+ ${agent.description ? `<p class="discover-card__desc">${escapeHtml(agent.description)}</p>` : ''}
+ </div>
+ <div class="discover-card__footer">
+ <div class="discover-card__action-wrap"></div>
+ </div>`;
+
+ const wrap = /** @type {HTMLElement} */ (card.querySelector('.discover-card__action-wrap'));
+ _renderCardAction(wrap, agent);
+ return card;
+}
+
+/**
+ * @param {HTMLElement} wrap
+ * @param {{ chainId: number, agentId: string, name: string, alreadyImported: boolean }} agent
+ * @param {string|null} [importedId]
+ */
+function _renderCardAction(wrap, agent, importedId = null) {
+ if (agent.alreadyImported || importedId) {
+ const id = importedId || '';
+ wrap.innerHTML = `
+ <button class="discover-btn discover-btn--done" disabled aria-label="Agent already in library">Already in library</button>
+ ${id ? `<a class="discover-card__agent-link" href="/agent/${escapeHtml(id)}">Open agent →</a>` : ''}`;
+ return;
+ }
+
+ const btn = document.createElement('button');
+ btn.className = 'discover-btn';
+ btn.textContent = 'Import';
+ btn.setAttribute('aria-label', `Import ${agent.name}`);
+ btn.addEventListener('click', () => _handleImport(btn, wrap, agent));
+ wrap.appendChild(btn);
+}
+
+/**
+ * @param {HTMLButtonElement} btn
+ * @param {HTMLElement} wrap
+ * @param {{ chainId: number, agentId: string, name: string }} agent
+ */
+async function _handleImport(btn, wrap, agent) {
+ btn.disabled = true;
+ btn.textContent = 'Importing…';
+
+ // Clear any previous inline error
+ const prev = wrap.querySelector('.discover-card__inline-err');
+ if (prev) prev.remove();
+
+ try {
+ const { importAgent } = await import('/src/erc8004/hydrate.js');
+ const result = await importAgent({ chainId: agent.chainId, agentId: agent.agentId });
+ _renderCardAction(wrap, { ...agent, alreadyImported: true }, result.id);
+ } catch (err) {
+ btn.disabled = false;
+ btn.textContent = 'Import';
+ const errEl = document.createElement('span');
+ errEl.className = 'discover-card__inline-err';
+ errEl.textContent = err.message || 'Import failed';
+ errEl.setAttribute('role', 'alert');
+ wrap.appendChild(errEl);
+ }
+}
+
+// ── Main load ─────────────────────────────────────────────────────────────────
+
+async function loadAgents() {
+ showSkeletons();
+
+ try {
+ const { fetchDiscoveredAgents } = await import('/src/erc8004/hydrate.js');
+ const agents = await fetchDiscoveredAgents();
+
+ grid.innerHTML = '';
+
+ if (agents.length === 0) {
+ showState(
+ '🔭',
+ 'No on-chain agents yet',
+ 'No ERC-8004 agents found in your linked wallets.',
+ );
+ return;
+ }
+
+ for (const agent of agents) {
+ grid.appendChild(buildCard(agent));
+ }
+ } catch (err) {
+ grid.innerHTML = '';
+ const msg = err.message || '';
+ if (msg.includes('429') || /too many/i.test(msg)) {
+ showErrorBanner('Too many requests. Try again in a minute.', true);
+ } else {
+ showErrorBanner(msg || 'Failed to load agents.', true);
+ }
+ }
+}
+
+// ── Bootstrap ─────────────────────────────────────────────────────────────────
+
+(async () => {
+ const user = await getSession();
+
+ if (!user) {
+ showState(
+ '🔐',
+ 'Sign in to discover your agents',
+ 'Link a wallet and sign in to see your on-chain agents.',
+ { label: 'Sign in', href: '/login.html' },
+ );
+ return;
+ }
+
+ // Check if user has linked wallets before hitting hydrate
+ try {
+ const walletsRes = await fetch('/api/auth/wallets', { credentials: 'include' });
+ if (walletsRes.ok) {
+ const { wallets } = await walletsRes.json();
+ if (!wallets || wallets.length === 0) {
+ showState(
+ '👛',
+ 'No wallets linked',
+ 'Link a wallet to discover your on-chain agents.',
+ { label: 'Link a wallet', href: '/dashboard/wallets.html' },
+ );
+ return;
+ }
+ }
+ } catch {
+ // If wallet check fails, proceed to hydrate anyway — it will handle empty gracefully
+ }
+
+ await loadAgents();
+})();
diff --git a/public/discover/index.html b/public/discover/index.html
new file mode 100644
index 000000000..bc168faa4
--- /dev/null
+++ b/public/discover/index.html
@@ -0,0 +1,47 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+ <title>On-chain Agents · 3D Agent</title>
+ <meta
+ name="description"
+ content="Discover ERC-8004 agents you own across every supported chain."
+ />
+ <link rel="icon" href="/favicon.ico" />
+ <link rel="stylesheet" href="/discover/discover.css" />
+ </head>
+ <body>
+ <header class="discover-header">
+ <div class="discover-header__brand"><a href="/">3D Agent</a></div>
+ <nav class="discover-header__nav" aria-label="Page navigation">
+ <a href="/">Home</a>
+ <a href="/dashboard">Dashboard</a>
+ </nav>
+ </header>
+
+ <main class="discover-main" id="discover-main">
+ <h1 class="discover-title">On-chain Agents</h1>
+ <p class="discover-subtitle">Agents we found in your linked wallets</p>
+
+ <div
+ id="discover-error"
+ class="discover-error-banner"
+ hidden
+ role="alert"
+ aria-live="polite"
+ ></div>
+
+ <div
+ id="discover-grid"
+ class="discover-grid"
+ role="list"
+ aria-label="Discovered agents"
+ aria-live="polite"
+ aria-busy="true"
+ ></div>
+ </main>
+
+ <script type="module" src="/discover/discover.js"></script>
+ </body>
+</html>
diff --git a/vercel.json b/vercel.json
index 01c277702..8e60218c8 100644
--- a/vercel.json
+++ b/vercel.json
@@ -104,6 +104,9 @@
{ "src": "/api/erc8004/hydrate", "dest": "/api/erc8004/hydrate.js" },
{ "src": "/api/erc8004/import", "dest": "/api/erc8004/import.js" },
+ { "src": "/discover", "dest": "/public/discover/index.html" },
+ { "src": "/discover/", "dest": "/public/discover/index.html" },
+
{ "src": "/api/(.*)", "dest": "/api/$1" },
{
diff --git a/vite.config.js b/vite.config.js
index 7fdc83415..d18e043fc 100644
--- a/vite.config.js
+++ b/vite.config.js
@@ -36,6 +36,9 @@ const appConfig = {
studio: resolve(__dirname, 'public/studio/index.html'),
reputation: resolve(__dirname, 'public/reputation/index.html'),
hydrate: resolve(__dirname, 'public/hydrate/index.html'),
+ // BEGIN:DISCOVER_ROUTE
+ discover: resolve(__dirname, 'public/discover/index.html'),
+ // END:DISCOVER_ROUTE
},
},
},
@@ -66,6 +69,10 @@ const appConfig = {
'/reputation/': resolve(root, 'public/reputation/index.html'),
'/hydrate': resolve(root, 'public/hydrate/index.html'),
'/hydrate/': resolve(root, 'public/hydrate/index.html'),
+ // BEGIN:DISCOVER_ROUTE
+ '/discover': resolve(root, 'public/discover/index.html'),
+ '/discover/': resolve(root, 'public/discover/index.html'),
+ // END:DISCOVER_ROUTE
'/agent': resolve(root, 'agent-home.html'),
};
server.middlewares.use(async (req, res, next) => {