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: paywall script, home page updates, analytics dashboard JS

nirholas79fca4ae704b
diff --git a/pages/home.html b/pages/home.html
index 56138c054..2a6ca3e21 100644
--- a/pages/home.html
+++ b/pages/home.html
@@ -1482,5 +1482,50 @@
}
})();
</script>
+
+ <script>
+ // Traction stats — fetch /api/platform/stats and animate counters.
+ (function () {
+ function fmtNum(n) {
+ if (n >= 1_000_000) return (n / 1_000_000).toFixed(1).replace(/\.0$/, '') + 'M';
+ if (n >= 1_000) return (n / 1_000).toFixed(1).replace(/\.0$/, '') + 'K';
+ return String(n);
+ }
+
+ function animateCount(el, target) {
+ const duration = 900;
+ const start = performance.now();
+ const from = 0;
+ function step(now) {
+ const t = Math.min((now - start) / duration, 1);
+ const ease = 1 - Math.pow(1 - t, 3);
+ const val = Math.round(from + (target - from) * ease);
+ el.textContent = fmtNum(val);
+ if (t < 1) requestAnimationFrame(step);
+ }
+ requestAnimationFrame(step);
+ }
+
+ const vals = document.querySelectorAll('[data-traction-val]');
+ vals.forEach((el) => el.classList.add('is-loading'));
+
+ fetch('/api/platform/stats')
+ .then((r) => r.ok ? r.json() : Promise.reject(r.status))
+ .then((data) => {
+ vals.forEach((el) => {
+ const key = el.dataset.tractionVal;
+ const raw = data[key];
+ if (raw == null) return;
+ el.classList.remove('is-loading');
+ animateCount(el, Number(raw));
+ });
+ })
+ .catch(() => {
+ // On failure, just hide the section rather than show broken state.
+ const section = document.querySelector('.h-traction');
+ if (section) section.hidden = true;
+ });
+ })();
+ </script>
</body>
</html>
diff --git a/public/home.css b/public/home.css
index ec3bd07c7..30341d0d5 100644
--- a/public/home.css
+++ b/public/home.css
@@ -189,6 +189,77 @@
font-size: 1.4rem;
}
+/* ── Traction stats bar ─────────────────────────────────────────────────── */
+
+.h-traction {
+ position: relative;
+ z-index: 30;
+ background: rgba(8, 7, 11, 0.95);
+ border-top: 1px solid rgba(255, 255, 255, 0.06);
+ border-bottom: 1px solid rgba(255, 255, 255, 0.06);
+ padding: clamp(1.75rem, 4vh, 2.5rem) clamp(1.25rem, 4vw, 2rem);
+}
+
+.h-traction-inner {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ gap: 0;
+ max-width: 1100px;
+ margin: 0 auto;
+ flex-wrap: wrap;
+}
+
+.h-traction-stat {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ gap: 0.35rem;
+ padding: 0.5rem clamp(1.5rem, 3vw, 3rem);
+ flex: 1 1 120px;
+}
+
+.h-traction-val {
+ font-family: 'Space Grotesk', 'Inter', sans-serif;
+ font-size: clamp(1.6rem, 3vw, 2.2rem);
+ font-weight: 700;
+ color: #fff;
+ letter-spacing: -0.02em;
+ line-height: 1;
+ transition: opacity 0.3s;
+}
+
+.h-traction-val.is-loading {
+ opacity: 0.3;
+}
+
+.h-traction-label {
+ font-size: 0.78rem;
+ font-weight: 500;
+ color: rgba(255, 255, 255, 0.45);
+ text-transform: uppercase;
+ letter-spacing: 0.06em;
+ white-space: nowrap;
+}
+
+.h-traction-divider {
+ width: 1px;
+ height: 2.5rem;
+ background: rgba(255, 255, 255, 0.1);
+ flex-shrink: 0;
+}
+
+@media (max-width: 700px) {
+ .h-traction-inner { gap: 0; row-gap: 0.5rem; }
+ .h-traction-divider { display: none; }
+ .h-traction-stat { flex: 1 1 45%; padding: 0.75rem 1rem; }
+ .h-traction-val { font-size: 1.5rem; }
+}
+
+@media (max-width: 400px) {
+ .h-traction-stat { flex: 1 1 100%; }
+}
+
/* ── Pillars transition band (docs.pai.direct style) ───────────────────── */
.h-pillars {
diff --git a/public/paywall.js b/public/paywall.js
new file mode 100644
index 000000000..0f441e9cf
--- /dev/null
+++ b/public/paywall.js
@@ -0,0 +1,287 @@
+(function () {
+ 'use strict';
+
+ // ── URL param helpers ──────────────────────────────────────────────────
+
+ function getParams() {
+ return new URLSearchParams(location.search);
+ }
+
+ /**
+ * Decode the base64url-encoded PaymentRequirements from ?req=
+ * Handles both base64url (from Buffer.toString('base64url')) and
+ * standard base64 (from btoa).
+ *
+ * @returns {Array|null}
+ */
+ function decodeRequirements() {
+ var params = getParams();
+ var raw = params.get('req');
+ if (!raw) return null;
+ try {
+ // Normalise base64url → base64
+ var b64 = raw.replace(/-/g, '+').replace(/_/g, '/');
+ // Pad to multiple of 4
+ while (b64.length % 4 !== 0) b64 += '=';
+ var json = decodeURIComponent(escape(atob(b64)));
+ var parsed = JSON.parse(json);
+ // Accept either a single object (one requirement) or an array
+ return Array.isArray(parsed) ? parsed : [parsed];
+ } catch (e) {
+ return null;
+ }
+ }
+
+ function getReturnUrl() {
+ var params = getParams();
+ var ret = params.get('return');
+ if (!ret) return '/';
+ try { return decodeURIComponent(ret); } catch (e) { return '/'; }
+ }
+
+ // ── Price formatting ───────────────────────────────────────────────────
+
+ /**
+ * Format atomics amount to human-readable USD string.
+ * @param {string|number} amount raw atomics (USDC has 6 decimals)
+ * @param {number} [decimals=6]
+ * @returns {string} e.g. "$0.001"
+ */
+ function formatAmount(amount, decimals) {
+ decimals = decimals || 6;
+ var n = Number(amount || 0);
+ var usd = n / Math.pow(10, decimals);
+ // Show enough decimal places to make small amounts readable
+ var str;
+ if (usd === 0) {
+ str = '0.00';
+ } else if (usd < 0.000001) {
+ str = usd.toFixed(8).replace(/\.?0+$/, '');
+ } else if (usd < 0.01) {
+ str = usd.toFixed(6).replace(/\.?0+$/, '');
+ } else if (usd < 1) {
+ str = usd.toFixed(4).replace(/\.?0+$/, '');
+ } else {
+ str = usd.toFixed(2);
+ }
+ return '$' + str;
+ }
+
+ // ── Network detection ──────────────────────────────────────────────────
+
+ var SOLANA_NETWORK_PREFIX = 'solana:';
+ var BASE_NETWORK_PREFIX = 'eip155:8453';
+ var BASE_SEP_PREFIX = 'eip155:84532';
+ var TESTNET_NETWORKS = ['eip155:84532', 'eip155:11155111', 'solana:devnet'];
+
+ function isTestnet(network) {
+ return TESTNET_NETWORKS.some(function (t) { return String(network || '').startsWith(t); });
+ }
+
+ function isSolana(network) {
+ return String(network || '').startsWith(SOLANA_NETWORK_PREFIX);
+ }
+
+ function isBase(network) {
+ var n = String(network || '');
+ return n.startsWith(BASE_NETWORK_PREFIX) || n.startsWith(BASE_SEP_PREFIX) || n.startsWith('eip155:');
+ }
+
+ // ── Render ─────────────────────────────────────────────────────────────
+
+ function render(requirements) {
+ var returnUrl = getReturnUrl();
+
+ // Wire the close button
+ var closeBtn = document.getElementById('close-btn');
+ if (closeBtn) closeBtn.href = returnUrl;
+
+ if (!requirements || !requirements.length) {
+ // No requirements decoded — show generic message
+ setEl('service-name', 'Payment Required');
+ setEl('service-desc', 'This endpoint requires a micropayment.');
+ setEl('price-amount', '—');
+ setEl('raw-json', '(no payment requirements found in URL)');
+ return;
+ }
+
+ // Find the cheapest non-zero requirement for the price display
+ var cheapest = requirements.reduce(function (a, b) {
+ return Number(b.amount || 0) < Number(a.amount || 0) ? b : a;
+ }, requirements[0]);
+
+ var decimals = (cheapest.extra && cheapest.extra.decimals) || 6;
+ var price = formatAmount(cheapest.amount, decimals);
+ var assetName = (cheapest.extra && cheapest.extra.name) || 'USDC';
+
+ setEl('price-amount', price);
+ setEl('price-currency', assetName + ' on ' + networkLabel(cheapest.network));
+
+ // Service name / description from tags or resource URL
+ var serviceName = cheapest.serviceName || extractServiceName(cheapest.resource);
+ var desc = cheapest.description || 'Access this paid endpoint with a single micropayment.';
+ setEl('service-name', serviceName);
+ setEl('service-desc', desc);
+
+ // Check which networks are actually present
+ var hasBase = requirements.some(function (r) { return isBase(r.network); });
+ var hasSolana = requirements.some(function (r) { return isSolana(r.network); });
+
+ // Show/hide tabs
+ var tabBase = document.getElementById('tab-base');
+ var tabSolana = document.getElementById('tab-solana');
+ var tabRow = document.getElementById('tab-row');
+
+ if (!hasBase && hasSolana) {
+ // Solana only — hide Base tab, activate Solana
+ if (tabBase) tabBase.style.display = 'none';
+ activateTab('solana');
+ } else if (!hasSolana) {
+ // Base only — hide Solana tab
+ if (tabSolana) tabSolana.style.display = 'none';
+ }
+
+ // Testnet hint
+ var hasTestnet = requirements.some(function (r) { return isTestnet(r.network); });
+ if (hasTestnet) {
+ var hint = document.getElementById('testnet-hint-base');
+ if (hint) hint.classList.add('visible');
+ }
+
+ // Raw JSON
+ setEl('raw-json', JSON.stringify(requirements, null, 2));
+ }
+
+ function networkLabel(network) {
+ var n = String(network || '');
+ if (n.startsWith('eip155:8453')) return 'Base';
+ if (n.startsWith('eip155:84532')) return 'Base Sepolia';
+ if (n.startsWith('solana:')) return 'Solana';
+ if (n.startsWith('eip155:56')) return 'BNB Chain';
+ return network || 'Unknown';
+ }
+
+ function extractServiceName(resourceUrl) {
+ if (!resourceUrl) return 'Paid Endpoint';
+ try {
+ var u = new URL(resourceUrl);
+ var parts = u.pathname.split('/').filter(Boolean);
+ if (parts.length >= 2) {
+ return parts[parts.length - 1]
+ .replace(/-/g, ' ')
+ .replace(/\b\w/g, function (c) { return c.toUpperCase(); });
+ }
+ return u.hostname;
+ } catch (e) { return 'Paid Endpoint'; }
+ }
+
+ function setEl(id, text) {
+ var el = document.getElementById(id);
+ if (el) el.textContent = text;
+ }
+
+ // ── Tab switching ──────────────────────────────────────────────────────
+
+ function activateTab(net) {
+ var tabs = document.querySelectorAll('.tab-btn');
+ var panels = document.querySelectorAll('.net-panel');
+ tabs.forEach(function (t) {
+ t.classList.toggle('active', t.dataset.net === net);
+ });
+ panels.forEach(function (p) {
+ p.classList.toggle('active', p.id === 'net-' + net);
+ });
+ }
+
+ // ── Wallet click ───────────────────────────────────────────────────────
+
+ /**
+ * Show an "Opening wallet…" message with the raw payment requirements.
+ * Full on-chain wallet integration is browser-wallet-specific; this UI
+ * explains what would happen and surfaces the requirements for dev use.
+ */
+ function handleWalletClick(walletName, net, requirements) {
+ var statusId = 'wallet-status-' + net;
+ var statusEl = document.getElementById(statusId);
+ if (!statusEl) return;
+
+ var req = (requirements || []).find(function (r) {
+ return net === 'solana' ? isSolana(r.network) : isBase(r.network);
+ });
+
+ statusEl.classList.add('visible');
+
+ if (walletName === 'metamask' || walletName === 'coinbase' || walletName === 'walletconnect') {
+ statusEl.innerHTML =
+ '<strong>Opening ' + escHtml(walletName.charAt(0).toUpperCase() + walletName.slice(1)) + ' Wallet…</strong><br />' +
+ 'Full browser wallet integration is coming to three.ws. To pay manually as a developer, ' +
+ 'use the x402 CLI or SDK with the requirements shown in the Advanced panel below.' +
+ (req ? '<br /><br /><strong>Pay to:</strong> <code>' + escHtml(req.payTo || '') + '</code>' +
+ '<br /><strong>Amount:</strong> ' + escHtml(formatAmount(req.amount, (req.extra && req.extra.decimals) || 6)) +
+ '<br /><strong>Asset:</strong> <code>' + escHtml(req.asset || '') + '</code>' : '');
+ } else if (walletName === 'phantom' || walletName === 'solflare') {
+ statusEl.innerHTML =
+ '<strong>Opening ' + escHtml(walletName.charAt(0).toUpperCase() + walletName.slice(1)) + '…</strong><br />' +
+ 'Solana wallet signing is coming soon. Use the x402 Solana SDK to pay programmatically.' +
+ (req ? '<br /><br /><strong>Pay to:</strong> <code>' + escHtml(req.payTo || '') + '</code>' +
+ '<br /><strong>Amount:</strong> ' + escHtml(formatAmount(req.amount, 6)) : '');
+ }
+
+ // Open the accordion automatically so the developer sees the raw requirements
+ var advBody = document.getElementById('adv-body');
+ var advToggle = document.getElementById('adv-toggle');
+ if (advBody && !advBody.classList.contains('open')) {
+ advBody.classList.add('open');
+ if (advToggle) advToggle.classList.add('open');
+ }
+ }
+
+ function escHtml(str) {
+ return String(str)
+ .replace(/&/g, '&amp;')
+ .replace(/</g, '&lt;')
+ .replace(/>/g, '&gt;')
+ .replace(/"/g, '&quot;')
+ .replace(/'/g, '&#39;');
+ }
+
+ // ── Wire events ────────────────────────────────────────────────────────
+
+ document.addEventListener('DOMContentLoaded', function () {
+ var requirements = decodeRequirements();
+ render(requirements);
+
+ // Tab clicks
+ var tabRow = document.getElementById('tab-row');
+ if (tabRow) {
+ tabRow.addEventListener('click', function (e) {
+ var btn = e.target.closest('.tab-btn');
+ if (!btn) return;
+ activateTab(btn.dataset.net);
+ });
+ }
+
+ // Wallet button clicks — delegate from both panels
+ var payCard = document.getElementById('pay-card');
+ if (payCard) {
+ payCard.addEventListener('click', function (e) {
+ var btn = e.target.closest('.wallet-btn');
+ if (!btn) return;
+ // Determine which network panel is active
+ var activePanel = payCard.querySelector('.net-panel.active');
+ var net = activePanel ? activePanel.id.replace('net-', '') : 'base';
+ handleWalletClick(btn.dataset.wallet, net, requirements);
+ });
+ }
+
+ // Accordion toggle
+ var advToggle = document.getElementById('adv-toggle');
+ var advBody = document.getElementById('adv-body');
+ if (advToggle && advBody) {
+ advToggle.addEventListener('click', function () {
+ var open = advBody.classList.toggle('open');
+ advToggle.classList.toggle('open', open);
+ });
+ }
+ });
+})();
diff --git a/src/dashboard-next/pages/analytics.js b/src/dashboard-next/pages/analytics.js
index d50a66e71..cafc5e297 100644
--- a/src/dashboard-next/pages/analytics.js
+++ b/src/dashboard-next/pages/analytics.js
@@ -70,8 +70,8 @@ async function loadAndRender(root) {
)
);
- const totalViews = widgetStats.reduce((s, ws) => s + (ws?.stats?.total_views ?? 0), 0);
- const totalChats = widgetStats.reduce((s, ws) => s + (ws?.stats?.total_chats ?? 0), 0);
+ const totalViews = widgetStats.reduce((s, ws) => s + (ws?.stats?.view_count ?? ws?.stats?.total_views ?? 0), 0);
+ const totalChats = widgetStats.reduce((s, ws) => s + (ws?.stats?.chat_count ?? ws?.stats?.total_chats ?? 0), 0);
const recentViews = widgetStats.reduce((s, ws) => {
const arr = ws?.stats?.recent_views_7d ?? [];
return s + arr.reduce((a, p) => a + (p.count ?? p.value ?? 0), 0);
@@ -241,12 +241,12 @@ function renderAgentTable(agents, widgets, widgetStats) {
widgets.forEach((w, i) => {
const stats = widgetStats[i];
if (!stats) return;
- const key = w.avatar_id || w.agent_id;
+ const key = w.avatar_id;
if (key) {
const prev = widgetMap.get(key) || { views: 0, chats: 0 };
widgetMap.set(key, {
- views: prev.views + (stats.stats?.total_views ?? 0),
- chats: prev.chats + (stats.stats?.total_chats ?? 0),
+ views: prev.views + (stats.stats?.view_count ?? stats.stats?.total_views ?? 0),
+ chats: prev.chats + (stats.stats?.chat_count ?? stats.stats?.total_chats ?? 0),
});
}
});