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.

wrapped(agents): route the agent recap page, its share card and OG image

nirholas98c47e3f6bad
diff --git a/api/wrapped-share.js b/api/wrapped-share.js
new file mode 100644
index 000000000..4a836af35
--- /dev/null
+++ b/api/wrapped-share.js
@@ -0,0 +1,154 @@
+/**
+ * SSR share page for a Trader Wrapped recap.
+ * -----------------------------------------
+ * GET /api/wrapped-share?agent=<uuid>[&window=7d|30d|all][&ref=CODE]
+ *
+ * Wired via vercel.json: /wrapped/<agent_id>/share -> /api/wrapped-share?agent=$1
+ *
+ * Bakes Open Graph + Twitter Card + Farcaster Frame meta into <head> so a shared
+ * recap previews with the real season card. Real browsers are redirected to the
+ * deck at /wrapped?agent=<id>, carrying the referral code the sharer's link
+ * arrived with so the loop pays whoever spread it.
+ *
+ * OG image: /api/wrapped-og?agent=<uuid>&window=<window>
+ */
+
+import { cors, wrap } from './_lib/http.js';
+import { env } from './_lib/env.js';
+import { isUuid } from './_lib/validate.js';
+import { WRAPPED_WINDOWS, getWrapped } from './_lib/wrapped.js';
+
+const REF_RE = /^[A-Z0-9]{3,20}$/;
+const WINDOW_LABEL = { '24h': 'the last 24 hours', '7d': 'the last 7 days', '30d': 'the last 30 days', all: 'all time' };
+
+export default wrap(async (req, res) => {
+ if (cors(req, res, { methods: 'GET,OPTIONS' })) return;
+
+ const url = new URL(req.url, 'http://x');
+ const agentId = (url.searchParams.get('agent') || url.searchParams.get('agent_id') || '').trim();
+ const windowParam = url.searchParams.get('window');
+ const window = WRAPPED_WINDOWS.has(windowParam) ? windowParam : '30d';
+ const ref = (url.searchParams.get('ref') || '').trim().toUpperCase();
+ const origin = env.APP_ORIGIN || 'https://three.ws';
+
+ if (!isUuid(agentId)) return redirect(res, `${origin}/wrapped`);
+
+ const deepParams = new URLSearchParams({ agent: agentId });
+ if (window !== '30d') deepParams.set('window', window);
+ if (REF_RE.test(ref)) deepParams.set('ref', ref);
+ const deepUrl = `${origin}/wrapped?${deepParams}`;
+
+ let deck = null;
+ try {
+ deck = await getWrapped({ agentId, network: 'mainnet', window });
+ } catch {
+ return redirect(res, deepUrl);
+ }
+ if (!deck) return redirect(res, `${origin}/wrapped`);
+
+ const name = deck.agent.name || 'Trader';
+ const windowLabel = WINDOW_LABEL[window] || window;
+
+ const title = deck.enough_history
+ ? `${name} wrapped: ${windowLabel} on pump.fun · three.ws`
+ : `${name} · Trader Wrapped · three.ws`;
+ const desc = deck.enough_history
+ ? `${deck.headline} Verified against closed on-chain round-trips, not screenshots.`
+ : `${name} has not settled enough round-trips in ${windowLabel} for a recap. Every three.ws Trader Wrapped is cut from closed on-chain trades or it is not cut at all.`;
+
+ const shareParams = new URLSearchParams({ agent: agentId });
+ if (window !== '30d') shareParams.set('window', window);
+ const pageUrl = `${origin}/wrapped/${encodeURIComponent(agentId)}/share${window !== '30d' ? `?window=${encodeURIComponent(window)}` : ''}`;
+ const ogImage = `${origin}/api/wrapped-og?${shareParams}`;
+
+ res.statusCode = 200;
+ res.setHeader('content-type', 'text/html; charset=utf-8');
+ res.setHeader('cache-control', 'public, max-age=60, s-maxage=600, stale-while-revalidate=3600');
+ res.end(renderHtml({ title, desc, pageUrl, deepUrl, ogImage, name, deck, origin }));
+});
+
+function redirect(res, to) {
+ res.statusCode = 302;
+ res.setHeader('location', to);
+ res.setHeader('cache-control', 'no-cache');
+ res.end();
+}
+
+function esc(s) {
+ return String(s ?? '').replace(/[&<>"']/g, (c) =>
+ ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c],
+ );
+}
+
+function renderHtml({ title, desc, pageUrl, deepUrl, ogImage, name, deck, origin }) {
+ const t = esc(title);
+ const d = esc(desc);
+ const pnl = deck.enough_history ? Number(deck.metrics?.realized_pnl_sol ?? 0) : null;
+ const pnlStr = pnl != null ? `${pnl > 0 ? '+' : ''}${pnl.toFixed(3).replace(/\.?0+$/, '') || '0'} SOL` : null;
+ const pnlColor = pnl == null ? '#94a3b8' : pnl > 0 ? '#34d399' : pnl < 0 ? '#fb7185' : '#94a3b8';
+ return `<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>${t}</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
+ <meta name="description" content="${d}">
+ <meta name="theme-color" content="#0a0a0a">
+
+ <meta property="og:type" content="article">
+ <meta property="og:site_name" content="three.ws">
+ <meta property="og:title" content="${t}">
+ <meta property="og:description" content="${d}">
+ <meta property="og:url" content="${esc(pageUrl)}">
+ <meta property="og:image" content="${esc(ogImage)}">
+ <meta property="og:image:width" content="1200">
+ <meta property="og:image:height" content="630">
+ <meta property="og:image:alt" content="${esc(name)}'s Trader Wrapped season recap on three.ws">
+
+ <meta name="twitter:card" content="summary_large_image">
+ <meta name="twitter:site" content="@trythreews">
+ <meta name="twitter:title" content="${t}">
+ <meta name="twitter:description" content="${d}">
+ <meta name="twitter:image" content="${esc(ogImage)}">
+
+ <meta property="fc:frame" content="vNext">
+ <meta property="fc:frame:image" content="${esc(ogImage)}">
+ <meta property="fc:frame:image:aspect_ratio" content="1.91:1">
+ <meta property="fc:frame:button:1" content="Open the recap">
+ <meta property="fc:frame:button:1:action" content="link">
+ <meta property="fc:frame:button:1:target" content="${esc(deepUrl)}">
+ <meta property="fc:frame:button:2" content="Verify on-chain">
+ <meta property="fc:frame:button:2:action" content="link">
+ <meta property="fc:frame:button:2:target" content="${esc(origin)}${esc(deck.agent.profile_url)}">
+
+ <link rel="canonical" href="${esc(pageUrl)}">
+ <link rel="shortcut icon" href="/favicon.ico">
+
+ <style>
+ html,body{margin:0;padding:0;background:#08080a;color:#e5e7eb;font-family:Inter,system-ui,sans-serif;height:100%}
+ .shell{display:grid;place-items:center;min-height:100vh;text-align:center;padding:2rem;gap:.75rem}
+ .name{font-size:1.15rem;font-weight:700;color:#f6f6f8}
+ .pnl{font-size:2.6rem;font-weight:800;line-height:1;color:${pnlColor}}
+ .spinner{width:24px;height:24px;border:2px solid rgba(255,255,255,.1);border-top-color:rgba(255,255,255,.5);border-radius:50%;animation:spin .9s linear infinite;margin:0 auto}
+ @keyframes spin{to{transform:rotate(360deg)}}
+ p{margin:0;color:rgba(255,255,255,.42);font-size:13px;max-width:46ch}
+ a{color:#f472b6}
+ </style>
+</head>
+<body>
+ <noscript>
+ <div class="shell">
+ <div class="name">${esc(name)}</div>
+ ${pnlStr ? `<div class="pnl">${esc(pnlStr)}</div>` : ''}
+ <p>${d}</p>
+ <p><a href="${esc(deepUrl)}">Open the recap</a></p>
+ </div>
+ </noscript>
+ <div class="shell" aria-live="polite">
+ <div class="spinner" aria-hidden="true"></div>
+ <p>Opening the recap…</p>
+ </div>
+ <script>(function(){window.location.replace(${JSON.stringify(deepUrl)});})()</script>
+</body>
+</html>`;
+}
diff --git a/data/pages.json b/data/pages.json
index 3ceada0d1..8fdc67ebf 100644
--- a/data/pages.json
+++ b/data/pages.json
@@ -1645,6 +1645,14 @@
"changefreq": "weekly",
"added": "2026-08-02"
},
+ {
+ "path": "/wrapped",
+ "title": "Trader Wrapped: your season on pump.fun",
+ "description": "The season recap for any verified pump.fun trading agent on three.ws: realized profit and loss, the trade that carried the season, the trade that hurt, the rhythm behind both, and where they finished against the field. Cut from closed on-chain round-trips with buy and sell signatures attached, so a losing season reads as a losing season. Swipeable, shareable, no account and no wallet.",
+ "priority": 0.7,
+ "changefreq": "weekly",
+ "added": "2026-09-04"
+ },
{
"path": "/meta-allocator",
"title": "Meta-Allocator: the ETF of degens",
diff --git a/vercel.json b/vercel.json
index 58efba695..39b553232 100644
--- a/vercel.json
+++ b/vercel.json
@@ -1122,6 +1122,14 @@
"src": "/meta-allocator/?",
"dest": "/meta-allocator.html"
},
+ {
+ "src": "/wrapped/([^/]+)/share/?",
+ "dest": "/api/wrapped-share?agent=$1"
+ },
+ {
+ "src": "/wrapped/?",
+ "dest": "/wrapped.html"
+ },
{
"src": "/ghost-copy/?",
"dest": "/ghost-copy.html"
@@ -1377,6 +1385,14 @@
"src": "/api/trader-og",
"dest": "/api/trader-og.js"
},
+ {
+ "src": "/api/wrapped-og",
+ "dest": "/api/wrapped-og.js"
+ },
+ {
+ "src": "/api/wrapped-share",
+ "dest": "/api/wrapped-share.js"
+ },
{
"src": "/api/trader-passport/verify",
"dest": "/api/trader-passport-verify.js"
@@ -3318,6 +3334,10 @@
"src": "/api/pump/ghost-copy",
"dest": "/api/pump/ghost-copy.js"
},
+ {
+ "src": "/api/pump/wrapped",
+ "dest": "/api/pump/wrapped.js"
+ },
{
"src": "/api/pump/smart-money",
"dest": "/api/pump/smart-money.js"
diff --git a/vite.config.js b/vite.config.js
index 0ea545683..fe46304a3 100644
--- a/vite.config.js
+++ b/vite.config.js
@@ -738,6 +738,7 @@ const appConfig = {
'claim-wallet': resolve(__dirname, 'pages/claim-wallet.html'),
'meta-allocator': resolve(__dirname, 'pages/meta-allocator.html'),
'ghost-copy': resolve(__dirname, 'pages/ghost-copy.html'),
+ wrapped: resolve(__dirname, 'pages/wrapped.html'),
'clip-director': resolve(__dirname, 'pages/clip-director.html'),
'avatar-embed': resolve(__dirname, 'pages/avatar-embed.html'),
'avatar-wallet-chat': resolve(__dirname, 'pages/avatar-wallet-chat.html'),