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.

IRL GPS pins + Oracle conviction OG cards + pump-live prime counter

nirholasf7e4a74edf0e
diff --git a/api/irl/pins.js b/api/irl/pins.js
new file mode 100644
index 000000000..47bbbbf30
--- /dev/null
+++ b/api/irl/pins.js
@@ -0,0 +1,147 @@
+/**
+ * IRL GPS Pins — place 3D agents at real-world GPS coordinates.
+ *
+ * GET /api/irl/pins?lat=&lng=&radius=150 nearby pins (public)
+ * POST /api/irl/pins { lat, lng, heading, avatarUrl, avatarName, caption, agentId }
+ * DELETE /api/irl/pins?id= (requires device_token cookie match or auth)
+ */
+
+import { cors, json, wrap } from '../_lib/http.js';
+import { sql } from '../_lib/db.js';
+
+// Haversine distance in meters between two GPS points
+function haversineDist(lat1, lng1, lat2, lng2) {
+ const R = 6371000;
+ const dLat = (lat2 - lat1) * Math.PI / 180;
+ const dLng = (lng2 - lng1) * Math.PI / 180;
+ const a =
+ Math.sin(dLat / 2) ** 2 +
+ Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) *
+ Math.sin(dLng / 2) ** 2;
+ return R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
+}
+
+let _tableReady = false;
+async function ensureTable() {
+ if (_tableReady) return;
+ await sql`
+ CREATE TABLE IF NOT EXISTS irl_pins (
+ id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
+ user_id UUID,
+ agent_id UUID,
+ device_token TEXT,
+ lat DOUBLE PRECISION NOT NULL,
+ lng DOUBLE PRECISION NOT NULL,
+ heading FLOAT DEFAULT 0,
+ avatar_url TEXT,
+ avatar_name TEXT,
+ caption TEXT,
+ x402_endpoint TEXT,
+ placed_at TIMESTAMPTZ DEFAULT NOW(),
+ expires_at TIMESTAMPTZ DEFAULT (NOW() + INTERVAL '7 days')
+ )
+ `;
+ await sql`CREATE INDEX IF NOT EXISTS irl_pins_lat_lng ON irl_pins (lat, lng)`;
+ await sql`CREATE INDEX IF NOT EXISTS irl_pins_expires ON irl_pins (expires_at)`;
+ _tableReady = true;
+}
+
+export default wrap(async (req, res) => {
+ cors(req, res, { methods: ['GET', 'POST', 'DELETE', 'OPTIONS'] });
+ if (req.method === 'OPTIONS') return res.end();
+
+ await ensureTable();
+
+ // ── GET — nearby pins ─────────────────────────────────────────────────────
+ if (req.method === 'GET') {
+ const lat = parseFloat(req.query.lat);
+ const lng = parseFloat(req.query.lng);
+ const radius = Math.min(500, Math.max(10, parseFloat(req.query.radius ?? '150')));
+
+ if (!isFinite(lat) || !isFinite(lng)) {
+ return json(res, 400, { error: 'lat and lng are required' });
+ }
+
+ // Bounding-box pre-filter (fast index scan), then haversine in app
+ const latDelta = radius / 110540;
+ const lngDelta = radius / (111320 * Math.cos(lat * Math.PI / 180));
+
+ const rows = await sql`
+ SELECT id, user_id, agent_id, lat, lng, heading,
+ avatar_url, avatar_name, caption, x402_endpoint, placed_at
+ FROM irl_pins
+ WHERE lat BETWEEN ${lat - latDelta} AND ${lat + latDelta}
+ AND lng BETWEEN ${lng - lngDelta} AND ${lng + lngDelta}
+ AND (expires_at IS NULL OR expires_at > NOW())
+ ORDER BY placed_at DESC
+ LIMIT 50
+ `;
+
+ const pins = rows
+ .map(r => ({
+ ...r,
+ distance_m: Math.round(haversineDist(lat, lng, r.lat, r.lng)),
+ }))
+ .filter(r => r.distance_m <= radius)
+ .sort((a, b) => a.distance_m - b.distance_m);
+
+ return json(res, 200, { pins });
+ }
+
+ // ── POST — create pin ─────────────────────────────────────────────────────
+ if (req.method === 'POST') {
+ const body = req.body ?? {};
+ const lat = parseFloat(body.lat);
+ const lng = parseFloat(body.lng);
+
+ if (!isFinite(lat) || !isFinite(lng)) {
+ return json(res, 400, { error: 'lat and lng are required' });
+ }
+ if (lat < -90 || lat > 90 || lng < -180 || lng > 180) {
+ return json(res, 400, { error: 'invalid coordinates' });
+ }
+
+ const [pin] = await sql`
+ INSERT INTO irl_pins
+ (user_id, agent_id, device_token, lat, lng, heading,
+ avatar_url, avatar_name, caption, x402_endpoint)
+ VALUES (
+ ${body.userId ?? null},
+ ${body.agentId ?? null},
+ ${body.deviceToken ?? null},
+ ${lat}, ${lng},
+ ${parseFloat(body.heading) || 0},
+ ${body.avatarUrl ?? null},
+ ${body.avatarName ?? null},
+ ${body.caption ?? null},
+ ${body.x402Endpoint ?? null}
+ )
+ RETURNING *
+ `;
+
+ return json(res, 201, { pin });
+ }
+
+ // ── DELETE — remove own pin ───────────────────────────────────────────────
+ if (req.method === 'DELETE') {
+ const id = req.query.id;
+ const deviceToken = req.query.deviceToken ?? req.body?.deviceToken;
+
+ if (!id) return json(res, 400, { error: 'id required' });
+
+ // Allow deletion by device_token (anonymous) or user_id (authenticated)
+ const result = await sql`
+ DELETE FROM irl_pins
+ WHERE id = ${id}
+ AND (device_token = ${deviceToken ?? ''} OR device_token IS NULL)
+ RETURNING id
+ `;
+
+ if (!result.length) {
+ return json(res, 404, { error: 'pin not found or not yours' });
+ }
+ return json(res, 200, { ok: true });
+ }
+
+ json(res, 405, { error: 'method not allowed' });
+});
diff --git a/api/oracle/og.js b/api/oracle/og.js
new file mode 100644
index 000000000..80238b152
--- /dev/null
+++ b/api/oracle/og.js
@@ -0,0 +1,314 @@
+/**
+ * GET /api/oracle/og?mint=<mint>
+ *
+ * Dynamic OG image for /oracle?mint=<mint> — conviction-focused social card.
+ * Shows the coin's Oracle score, tier, pillar breakdown, and smart-wallet signal
+ * so every shared conviction link previews with real data.
+ *
+ * Card anatomy (1200×630, dark):
+ * top — three.ws wordmark + "Oracle conviction"
+ * hero left — coin image (120×120 circle)
+ * hero right — name, symbol, category
+ * center — conviction score (large), tier badge
+ * pillars — four labeled bars (Who / How / What / Move)
+ * bottom-right — smart wallet count, graduated/live pill
+ * footer — "proof.not.promises"
+ */
+
+import { cors, wrap } from '../_lib/http.js';
+import { sql } from '../_lib/db.js';
+
+const MINT_RE = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
+const PUMP_FRONTEND_V3 = 'https://frontend-api-v3.pump.fun';
+const CACHE = 'public, max-age=120, s-maxage=900, stale-while-revalidate=60';
+
+function x(s) {
+ return String(s || '')
+ .replace(/&/g, '&amp;')
+ .replace(/</g, '&lt;')
+ .replace(/>/g, '&gt;')
+ .replace(/"/g, '&quot;')
+ .replace(/'/g, '&apos;');
+}
+
+function trunc(s, n) {
+ s = String(s || '');
+ return s.length <= n ? s : s.slice(0, n - 1) + '…';
+}
+
+function shortMint(m) {
+ return `${m.slice(0, 6)}…${m.slice(-4)}`;
+}
+
+function tierColor(tier) {
+ if (tier === 'prime') return '#c084fc';
+ if (tier === 'strong') return '#34d399';
+ if (tier === 'lean') return '#fbbf24';
+ if (tier === 'watch') return '#94a3b8';
+ if (tier === 'avoid') return '#f87171';
+ return '#94a3b8';
+}
+
+function tierLabel(tier) {
+ if (tier === 'prime') return 'PRIME';
+ if (tier === 'strong') return 'STRONG';
+ if (tier === 'lean') return 'LEAN';
+ if (tier === 'watch') return 'WATCH';
+ if (tier === 'avoid') return 'AVOID';
+ return tier ? tier.toUpperCase() : '';
+}
+
+async function fetchLogoBase64(imageUri) {
+ if (!imageUri) return null;
+ const url = imageUri.startsWith('ipfs://')
+ ? `https://ipfs.io/ipfs/${imageUri.slice(7)}`
+ : imageUri;
+ try {
+ const resp = await fetch(url, { signal: AbortSignal.timeout(3000) });
+ if (!resp.ok) return null;
+ const ct = resp.headers.get('content-type') || 'image/png';
+ const buf = await resp.arrayBuffer();
+ const b64 = Buffer.from(buf).toString('base64');
+ return `data:${ct};base64,${b64}`;
+ } catch {
+ return null;
+ }
+}
+
+async function buildCardData(mint) {
+ const [convRows, outcomeRows] = await Promise.all([
+ sql`
+ select c.score, c.tier, c.symbol, c.name, c.image_uri, c.category,
+ c.pedigree, c.structure, c.narrative, c.momentum,
+ c.smart_wallet_count, c.scored_at
+ from oracle_conviction c
+ where c.mint = ${mint} and c.network = 'mainnet'
+ limit 1
+ `,
+ sql`
+ select graduated, rugged, ath_multiple, last_market_cap_usd
+ from pump_coin_outcomes
+ where mint = ${mint}
+ limit 1
+ `,
+ ]);
+
+ const cv = convRows[0] || null;
+ const outcome = outcomeRows[0] || null;
+
+ // Fallback: try to get name/symbol from coin_intel if oracle has no row
+ let name = cv?.name || '';
+ let symbol = cv?.symbol || '';
+ let imageUri = cv?.image_uri || null;
+ let category = cv?.category || '';
+
+ if (!name || !symbol) {
+ try {
+ const intelRows = await sql`
+ select name, symbol, image_uri, category
+ from pump_coin_intel
+ where mint = ${mint}
+ limit 1
+ `;
+ const intel = intelRows[0];
+ if (intel) {
+ name = name || intel.name || '';
+ symbol = symbol || intel.symbol || '';
+ imageUri = imageUri || intel.image_uri || null;
+ category = category || intel.category || '';
+ }
+ } catch { /* non-fatal */ }
+ }
+
+ // Fetch live market cap if not yet resolved
+ let liveMcap = null;
+ if (!outcome?.graduated && !outcome?.rugged) {
+ try {
+ const r = await fetch(`${PUMP_FRONTEND_V3}/coins-v2/${mint}`, {
+ headers: { accept: 'application/json' },
+ signal: AbortSignal.timeout(3000),
+ });
+ if (r.ok) {
+ const d = await r.json();
+ liveMcap = d?.market_cap_in_usd ?? null;
+ }
+ } catch { /* non-fatal */ }
+ }
+
+ const logoBase64 = await fetchLogoBase64(imageUri);
+
+ return { cv, outcome, name, symbol, logoBase64, category, liveMcap };
+}
+
+function pillarBar(label, val, color, x0, y0) {
+ const v = val != null ? Math.round(Number(val)) : null;
+ const barW = 230;
+ const fill = v != null ? Math.round((v / 100) * barW) : 0;
+ const txt = v != null ? String(v) : '?';
+ return `
+ <text x="${x0}" y="${y0}" fill="rgba(229,229,229,0.35)" font-size="13" letter-spacing="2">${x(label)}</text>
+ <rect x="${x0}" y="${y0 + 8}" width="${barW}" height="8" rx="4" fill="rgba(255,255,255,0.07)"/>
+ <rect x="${x0}" y="${y0 + 8}" width="${fill}" height="8" rx="4" fill="${color}"/>
+ <text x="${x0 + barW + 12}" y="${y0 + 17}" fill="${color}" font-size="14" font-weight="700">${x(txt)}</text>`;
+}
+
+function renderCard(mint, d) {
+ const { cv, outcome, name, symbol, logoBase64, category, liveMcap } = d;
+
+ const score = cv?.score != null ? Math.round(Number(cv.score)) : null;
+ const tier = cv?.tier || '';
+ const tc = tierColor(tier);
+ const tl = tierLabel(tier);
+ const pillar = (k) => cv?.[k] != null ? Math.round(Number(cv[k])) : null;
+ const smCount = cv?.smart_wallet_count ?? null;
+
+ const displayName = trunc(name || 'Unknown coin', 34);
+ const displaySym = symbol ? `$${symbol.toUpperCase()}` : '';
+
+ // Outcome pill
+ let outcomePill = '';
+ if (outcome?.graduated) {
+ outcomePill = `
+ <rect x="930" y="536" width="190" height="52" rx="10" fill="#16a34a22"/>
+ <text x="945" y="570" fill="#22c55e" font-size="20" font-weight="600" font-family="Inter,-apple-system,system-ui,sans-serif">GRADUATED ✓</text>`;
+ } else if (outcome?.rugged) {
+ outcomePill = `
+ <rect x="930" y="536" width="190" height="52" rx="10" fill="#dc262622"/>
+ <text x="945" y="570" fill="#ef4444" font-size="20" font-weight="600" font-family="Inter,-apple-system,system-ui,sans-serif">RUGGED ✕</text>`;
+ } else {
+ outcomePill = `
+ <circle cx="942" cy="562" r="6" fill="#22c55e"/>
+ <text x="958" y="568" fill="#22c55e" font-size="18" font-weight="500" font-family="Inter,-apple-system,system-ui,sans-serif">LIVE</text>`;
+ }
+
+ // Logo block
+ const imgBlock = logoBase64
+ ? `<image href="${logoBase64}" x="80" y="148" width="112" height="112" clip-path="url(#imgCircle)"/>`
+ : `<rect x="80" y="148" width="112" height="112" rx="56" fill="#1a1d2e"/>
+ <text x="136" y="225" text-anchor="middle" fill="#4b5563" font-size="44">${x((displaySym || displayName)[0] || '?')}</text>`;
+
+ // Smart wallet count badge
+ const smBadge = smCount != null
+ ? `<rect x="80" y="468" width="${String(smCount).length * 14 + 120}" height="34" rx="8" fill="rgba(192,132,252,0.12)"/>
+ <text x="94" y="491" fill="${tc}" font-size="15" font-weight="500" font-family="Inter,-apple-system,system-ui,sans-serif">🧠 ${smCount} smart wallet${smCount !== 1 ? 's' : ''}</text>`
+ : '';
+
+ // Score block — centered anchor
+ const scoreStr = score != null ? String(score) : '—';
+ const scoreBlock = score != null ? `
+ <!-- Score circle -->
+ <circle cx="640" cy="310" r="110" fill="rgba(${tier === 'prime' ? '192,132,252' : tier === 'strong' ? '52,211,153' : tier === 'lean' ? '251,191,36' : tier === 'avoid' ? '248,113,113' : '148,163,184'},0.06)" stroke="${tc}" stroke-width="2" stroke-opacity="0.5"/>
+ <text x="640" y="360" text-anchor="middle" fill="${tc}"
+ font-family="Inter,-apple-system,system-ui,sans-serif"
+ font-size="100" font-weight="800" letter-spacing="-3">${x(scoreStr)}</text>
+ <text x="640" y="395" text-anchor="middle" fill="rgba(229,229,229,0.25)"
+ font-family="Inter,-apple-system,system-ui,sans-serif"
+ font-size="18" letter-spacing="1">/ 100</text>
+ <!-- Tier badge -->
+ ${tl ? `<rect x="${640 - tl.length * 9 - 24}" y="415" width="${tl.length * 18 + 48}" height="38" rx="8" fill="${tc}18"/>
+ <text x="640" y="441" text-anchor="middle" fill="${tc}"
+ font-family="Inter,-apple-system,system-ui,sans-serif"
+ font-size="20" font-weight="700" letter-spacing="3">${x(tl)} CONVICTION</text>` : ''}
+ ` : `
+ <text x="640" y="330" text-anchor="middle" fill="rgba(229,229,229,0.3)"
+ font-family="Inter,-apple-system,system-ui,sans-serif"
+ font-size="28" font-weight="400">Not yet scored</text>`;
+
+ return `<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
+ width="1200" height="630" viewBox="0 0 1200 630" role="img"
+ aria-label="${x(displayName)} Oracle conviction card">
+ <defs>
+ <clipPath id="imgCircle"><circle cx="136" cy="204" r="56"/></clipPath>
+ <linearGradient id="bg" x1="0" y1="0" x2="1" y2="1">
+ <stop offset="0%" stop-color="#08090d"/>
+ <stop offset="100%" stop-color="#0d1018"/>
+ </linearGradient>
+ </defs>
+
+ <!-- Background -->
+ <rect width="1200" height="630" fill="url(#bg)"/>
+ <!-- Top accent line (tier-colored) -->
+ <rect x="0" y="0" width="1200" height="3" fill="${tc}" opacity="0.8"/>
+
+ <!-- Header row -->
+ <text x="80" y="88" fill="rgba(229,229,229,0.9)"
+ font-family="Inter,-apple-system,system-ui,sans-serif"
+ font-size="24" font-weight="600" letter-spacing="1.5">three.ws</text>
+ <text x="152" y="85" fill="rgba(229,229,229,0.22)"
+ font-family="Inter,-apple-system,system-ui,sans-serif"
+ font-size="18" font-weight="400"> / Oracle</text>
+ <text x="1140" y="88" text-anchor="end" fill="rgba(229,229,229,0.22)"
+ font-family="Inter,-apple-system,system-ui,sans-serif"
+ font-size="17" font-weight="400">${x(shortMint(mint))}</text>
+
+ <!-- Horizontal rule under header -->
+ <line x1="80" y1="108" x2="1120" y2="108" stroke="rgba(255,255,255,0.06)" stroke-width="1"/>
+
+ <!-- Coin logo -->
+ ${imgBlock}
+
+ <!-- Coin identity -->
+ <text x="220" y="190" fill="#e5e5e5"
+ font-family="Inter,-apple-system,system-ui,sans-serif"
+ font-size="46" font-weight="300" letter-spacing="-0.5">${x(displayName)}</text>
+ <text x="220" y="234" fill="rgba(229,229,229,0.45)"
+ font-family="Inter,-apple-system,system-ui,sans-serif"
+ font-size="26" font-weight="400" letter-spacing="1">${x(displaySym)}</text>
+ ${category ? `<rect x="220" y="246" width="${category.length * 10 + 24}" height="28" rx="6" fill="rgba(255,255,255,0.05)"/>
+ <text x="232" y="265" fill="rgba(229,229,229,0.35)" font-size="14" font-family="Inter,-apple-system,system-ui,sans-serif">${x(category)}</text>` : ''}
+
+ <!-- Horizontal divider -->
+ <line x1="80" y1="300" x2="540" y2="300" stroke="rgba(255,255,255,0.06)" stroke-width="1"/>
+
+ <!-- Conviction score block (center) -->
+ ${scoreBlock}
+
+ <!-- Pillar bars (right column) -->
+ ${pillarBar('WHO · PEDIGREE', pillar('pedigree'), '#a78bfa', 730, 148)}
+ ${pillarBar('HOW · STRUCTURE', pillar('structure'), '#22d3ee', 730, 210)}
+ ${pillarBar('WHAT · NARRATIVE', pillar('narrative'), '#fbbf24', 730, 272)}
+ ${pillarBar('MOVE · MOMENTUM', pillar('momentum'), '#f472b6', 730, 334)}
+
+ <!-- Smart wallet count -->
+ ${smBadge}
+
+ <!-- Outcome pill -->
+ ${outcomePill}
+
+ <!-- Footer -->
+ <text x="80" y="594" fill="rgba(229,229,229,0.15)"
+ font-family="Inter,-apple-system,system-ui,sans-serif"
+ font-size="16" letter-spacing="5">PROOF.NOT.PROMISES</text>
+ <text x="1140" y="594" text-anchor="end" fill="rgba(229,229,229,0.15)"
+ font-family="Inter,-apple-system,system-ui,sans-serif"
+ font-size="16" letter-spacing="2">THREE.WS / ORACLE</text>
+</svg>`;
+}
+
+export default wrap(async (req, res) => {
+ if (cors(req, res, { methods: 'GET,OPTIONS' })) return;
+
+ const url = new URL(req.url, 'http://x');
+ const mint = (url.searchParams.get('mint') || '').trim();
+
+ if (!MINT_RE.test(mint)) {
+ res.statusCode = 400;
+ res.setHeader('content-type', 'text/plain');
+ res.end('bad mint');
+ return;
+ }
+
+ let data;
+ try {
+ data = await buildCardData(mint);
+ } catch {
+ data = { cv: null, outcome: null, name: '', symbol: '', logoBase64: null, category: '', liveMcap: null };
+ }
+
+ const svg = renderCard(mint, data);
+ res.statusCode = 200;
+ res.setHeader('content-type', 'image/svg+xml; charset=utf-8');
+ res.setHeader('cache-control', CACHE);
+ res.end(svg);
+});
diff --git a/data/changelog.json b/data/changelog.json
index c2ba8751b..ce9ed9ff4 100644
--- a/data/changelog.json
+++ b/data/changelog.json
@@ -1,6 +1,20 @@
{
"$comment": "Curated changelog entries for three.ws — the editorial layer of the public changelog. New PAGE launches are tracked automatically via the `added` field in data/pages.json; this file is for everything else holders care about: improvements, fixes, SDK releases, trading/payments capabilities, security work. scripts/build-page-index.mjs merges both sources into CHANGELOG.md, public/changelog.json, and public/changelog.xml. Newest first. Allowed tags: feature, improvement, fix, sdk, infra, docs, security. `link` is optional and must be a live three.ws path.",
"entries": [
+ {
+ "date": "2026-06-16",
+ "title": "IRL: place your agent on the map — others nearby can see it",
+ "summary": "Pin your 3D avatar to a real GPS coordinate in IRL mode and other users who walk within 150 metres see your agent appear in their AR view. Each nearby agent shows its name and distance as a floating label; tap it for a detail sheet with the option to pay via x402. Your own pin is removed automatically when you unpin the avatar or close the page. Requires location permission.",
+ "tags": ["feature"],
+ "link": "/irl"
+ },
+ {
+ "date": "2026-06-16",
+ "title": "Oracle: rich conviction card on every shared link",
+ "summary": "Sharing an Oracle link — /oracle?mint=X — now generates a dynamic social card showing the coin's name, conviction score, tier badge, four-pillar breakdown (Who/How/What/Move), and smart wallet count. The card updates when you open the coin drawer, so the URL you share previews real conviction data on X, Telegram, Discord, and iMessage.",
+ "tags": ["feature", "improvement"],
+ "link": "/oracle"
+ },
{
"date": "2026-06-16",
"title": "Launch detail: pump.fun comment sentiment in Community section",
diff --git a/pages/irl.html b/pages/irl.html
index 6c1e60a89..736a00ee6 100644
--- a/pages/irl.html
+++ b/pages/irl.html
@@ -418,6 +418,138 @@
flex-shrink: 0;
}
+ /* Nearby agents badge */
+ #irl-nearby-badge {
+ position: fixed;
+ top: 72px;
+ right: 16px;
+ z-index: 8;
+ background: rgba(0,0,0,0.72);
+ border: 1px solid rgba(255,255,255,0.13);
+ border-radius: 999px;
+ padding: 5px 12px;
+ font-size: 12px;
+ font-weight: 600;
+ color: #34d399;
+ backdrop-filter: blur(12px);
+ -webkit-backdrop-filter: blur(12px);
+ pointer-events: none;
+ transition: opacity 0.2s;
+ }
+ #irl-nearby-badge[hidden] { display: none; }
+
+ /* Agent interaction bottom sheet */
+ #irl-sheet {
+ position: fixed;
+ bottom: 0;
+ left: 0;
+ right: 0;
+ z-index: 20;
+ background: rgba(12,14,20,0.92);
+ border-top: 1px solid rgba(255,255,255,0.10);
+ border-radius: 18px 18px 0 0;
+ padding: 20px 24px 36px;
+ backdrop-filter: blur(20px);
+ -webkit-backdrop-filter: blur(20px);
+ transform: translateY(100%);
+ transition: transform 0.28s cubic-bezier(0.32,0.72,0,1);
+ pointer-events: none;
+ }
+ #irl-sheet.is-open {
+ transform: translateY(0);
+ pointer-events: all;
+ }
+ .irl-sheet-handle {
+ width: 40px;
+ height: 4px;
+ border-radius: 2px;
+ background: rgba(255,255,255,0.2);
+ margin: 0 auto 16px;
+ }
+ .irl-sheet-row {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ margin-bottom: 8px;
+ }
+ #irl-sheet-name {
+ font-size: 20px;
+ font-weight: 700;
+ color: #e5e7eb;
+ flex: 1;
+ }
+ #irl-sheet-dist {
+ font-size: 13px;
+ color: #6b7280;
+ font-variant-numeric: tabular-nums;
+ }
+ #irl-sheet-caption {
+ font-size: 14px;
+ color: #9ca3af;
+ margin-bottom: 14px;
+ line-height: 1.5;
+ }
+ .irl-sheet-actions {
+ display: flex;
+ gap: 10px;
+ }
+ .irl-sheet-btn {
+ flex: 1;
+ padding: 12px 16px;
+ border-radius: 12px;
+ border: 1px solid rgba(255,255,255,0.12);
+ background: rgba(255,255,255,0.06);
+ color: #e5e7eb;
+ font: inherit;
+ font-size: 14px;
+ font-weight: 600;
+ cursor: pointer;
+ transition: background 0.15s, border-color 0.15s;
+ }
+ .irl-sheet-btn:hover { background: rgba(255,255,255,0.12); border-color: rgba(255,255,255,0.22); }
+ .irl-sheet-btn.primary { background: rgba(52,211,153,0.18); border-color: rgba(52,211,153,0.4); color: #34d399; }
+ .irl-sheet-btn.primary:hover { background: rgba(52,211,153,0.28); }
+ #irl-sheet-close {
+ background: none;
+ border: 1px solid rgba(255,255,255,0.12);
+ border-radius: 10px;
+ padding: 8px 16px;
+ color: #6b7280;
+ font: inherit;
+ font-size: 13px;
+ cursor: pointer;
+ margin-top: 12px;
+ width: 100%;
+ transition: color 0.15s, border-color 0.15s;
+ }
+ #irl-sheet-close:hover { color: #e5e7eb; border-color: rgba(255,255,255,0.25); }
+
+ /* 3D→2D agent labels (injected by JS per nearby pin) */
+ .irl-agent-label {
+ position: fixed;
+ transform: translate(-50%, -100%);
+ pointer-events: auto;
+ cursor: pointer;
+ z-index: 7;
+ background: rgba(0,0,0,0.76);
+ border: 1px solid rgba(136,187,255,0.42);
+ border-radius: 9px;
+ padding: 4px 10px;
+ font-size: 12px;
+ font-weight: 600;
+ color: #88bbff;
+ white-space: nowrap;
+ backdrop-filter: blur(8px);
+ -webkit-backdrop-filter: blur(8px);
+ box-shadow: 0 0 10px rgba(136,187,255,0.15);
+ animation: irl-label-in 0.22s ease-out;
+ }
+ @keyframes irl-label-in {
+ from { opacity:0; transform: translate(-50%, -90%); }
+ to { opacity:1; transform: translate(-50%, -100%); }
+ }
+ .irl-agent-label-name { display: block; }
+
/* Desktop keyboard hints */
#irl-keys {
position: fixed;
@@ -554,6 +686,24 @@
</div>
</footer>
+<!-- Nearby agents count badge (top-right, shown when GPS pins are loaded) -->
+<div id="irl-nearby-badge" hidden aria-live="polite"></div>
+
+<!-- Agent interaction bottom sheet (slides up when user taps a nearby pin label) -->
+<div id="irl-sheet" role="dialog" aria-modal="false" aria-label="Nearby agent">
+ <div class="irl-sheet-handle" aria-hidden="true"></div>
+ <div class="irl-sheet-row">
+ <span id="irl-sheet-name">Agent</span>
+ <span id="irl-sheet-dist"></span>
+ </div>
+ <p id="irl-sheet-caption" hidden></p>
+ <div class="irl-sheet-actions">
+ <button id="irl-sheet-pay" class="irl-sheet-btn primary" type="button" hidden>Pay via x402</button>
+ <button id="irl-sheet-view" class="irl-sheet-btn" type="button">View agent</button>
+ </div>
+ <button id="irl-sheet-close" type="button">Dismiss</button>
+</div>
+
<script type="module" src="/src/irl.js"></script>
<script>
diff --git a/src/irl.js b/src/irl.js
index 2ec3e34cb..822f11472 100644
--- a/src/irl.js
+++ b/src/irl.js
@@ -633,35 +633,284 @@ async function setLocked(next) {
if (lockBtn) {
lockBtn.setAttribute('aria-pressed', String(next));
lockBtn.classList.toggle('is-active', next);
- lockBtn.querySelector('.irl-lock-label').textContent = next ? 'Locked' : 'Lock';
+ lockBtn.querySelector('.irl-lock-label').textContent = next ? 'Pinned' : 'Pin here';
}
if (arActive) {
if (next) {
- // Capture baseline — delta orientation from here drives the camera
+ // Capture baseline orientation — gyro deltas from here drive the camera
devOrientBaseAlpha = lastDevAlpha;
devOrientBaseBeta = lastDevBeta;
devOrientBaseCamYaw = cameraYaw;
devOrientBaseCamPitch = cameraPitch;
- // Unfreeze — gyro (or drag fallback) now moves the camera
arFrozenCamPos = null;
arFrozenCamLook = null;
document.body.classList.add('is-locked');
+
+ // GPS: anchor the avatar to real-world coordinates
+ if (gpsState.ready) {
+ // Pin is at the avatar's current virtual position translated to GPS
+ const mLat = 110540;
+ const mLng = 111320 * Math.cos(gpsState.lat * (Math.PI / 180));
+ gpsPin = {
+ lat: gpsState.lat + (-avatarRig.position.z / mLat),
+ lng: gpsState.lng + ( avatarRig.position.x / mLng),
+ };
+ gpsModeActive = true;
+ savePin(gpsPin.lat, gpsPin.lng).then(id => { if (id && gpsPin) gpsPin.id = id; });
+ }
} else {
devOrientBaseAlpha = null;
arFrozenCamPos = camera.position.clone();
arFrozenCamLook = camLookCurrent.clone();
document.body.classList.remove('is-locked');
+
+ // Remove the GPS pin
+ if (gpsPin?.id) {
+ fetch(`/api/irl/pins?id=${gpsPin.id}&deviceToken=${_deviceToken}`, { method: 'DELETE' }).catch(() => {});
+ }
+ gpsPin = null;
+ gpsModeActive = false;
}
}
+ const gpsNote = gpsState.ready ? ' · others nearby can see you' : '';
setStatus(next
- ? (arActive ? 'Pinned — move phone to look around' : 'Avatar pinned — drag to orbit')
- : 'Avatar unpinned');
+ ? (arActive ? `Pinned in real space${gpsNote} — move phone to look around` : 'Agent pinned — drag to orbit')
+ : 'Agent unpinned');
}
if (lockBtn) {
lockBtn.addEventListener('click', () => setLocked(!avatarLocked));
}
+// ── GPS world-anchor system ───────────────────────────────────────────────
+//
+// When the user pins their agent we record the GPS latitude/longitude of that
+// real-world spot. From then on the avatar's 3D position is derived from the
+// delta between the user's current GPS and the pin's GPS. As they walk away
+// the avatar appears smaller (perspective); as they turn, the existing gyro
+// system already rotates the camera so the agent stays locked to real-world
+// direction — Pokémon GO style, but for 3D AI agents.
+//
+// Coordinate system: North = −Z · East = +X · Y = up · 1 unit = 1 m.
+
+const EYE_HEIGHT = 1.6; // metres — camera height in GPS pin mode
+
+let _deviceToken = localStorage.getItem('irl_device_token');
+if (!_deviceToken) {
+ _deviceToken = crypto.randomUUID();
+ localStorage.setItem('irl_device_token', _deviceToken);
+}
+
+const gpsState = { lat: null, lng: null, ready: false, watchId: null };
+let gpsPin = null; // { lat, lng, id? } — the user's own anchored pin
+let gpsModeActive = false;
+
+function gpsToWorld(agentLat, agentLng) {
+ if (!gpsState.ready) return new Vector3(0, 0, 0);
+ const mLat = 110540;
+ const mLng = 111320 * Math.cos(gpsState.lat * (Math.PI / 180));
+ return new Vector3(
+ (agentLng - gpsState.lng) * mLng, // east = +X
+ 0,
+ -(agentLat - gpsState.lat) * mLat, // north = −Z
+ );
+}
+
+let _lastNearbyFetch = 0;
+const NEARBY_RADIUS = 150; // metres
+const NEARBY_INTERVAL = 15000; // ms
+
+function onGPSPosition(pos) {
+ gpsState.lat = pos.coords.latitude;
+ gpsState.lng = pos.coords.longitude;
+ gpsState.ready = true;
+
+ // Move pinned avatar to its GPS-anchored world position
+ if (gpsPin) {
+ const wp = gpsToWorld(gpsPin.lat, gpsPin.lng);
+ avatarRig.position.set(wp.x, 0, wp.z);
+ }
+
+ // Update world positions of all nearby agents
+ for (const p of nearbyPins) {
+ if (p.group) {
+ const wp = gpsToWorld(p.lat, p.lng);
+ p.group.position.set(wp.x, 0, wp.z);
+ }
+ }
+
+ const now = Date.now();
+ if (now - _lastNearbyFetch > NEARBY_INTERVAL) {
+ _lastNearbyFetch = now;
+ loadNearbyPins();
+ }
+}
+
+function initGPS() {
+ if (!navigator.geolocation) return;
+ gpsState.watchId = navigator.geolocation.watchPosition(
+ onGPSPosition,
+ () => {},
+ { enableHighAccuracy: true, maximumAge: 5000, timeout: 20000 },
+ );
+}
+
+async function savePin(lat, lng) {
+ try {
+ const r = await fetch('/api/irl/pins', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({
+ lat, lng,
+ avatarUrl: resolveAvatarUrl(_currentAvatarId),
+ avatarName: nameEl.textContent,
+ deviceToken: _deviceToken,
+ }),
+ });
+ if (!r.ok) return null;
+ return (await r.json()).pin?.id ?? null;
+ } catch { return null; }
+}
+
+// ── Nearby agents ─────────────────────────────────────────────────────────
+let nearbyPins = []; // [{ id, lat, lng, avatar_url, avatar_name, caption, x402_endpoint, distance_m, group, labelEl, glbLoaded }]
+
+async function loadNearbyPins() {
+ if (!gpsState.ready) return;
+ try {
+ const r = await fetch(
+ `/api/irl/pins?lat=${gpsState.lat}&lng=${gpsState.lng}&radius=${NEARBY_RADIUS}`,
+ );
+ if (!r.ok) return;
+ const { pins } = await r.json();
+
+ const incoming = pins.filter(p => !gpsPin?.id || p.id !== gpsPin.id);
+ const inIds = new Set(incoming.map(p => p.id));
+
+ // Remove disappeared pins
+ nearbyPins = nearbyPins.filter(p => {
+ if (inIds.has(p.id)) return true;
+ if (p.group) scene.remove(p.group);
+ if (p.labelEl) p.labelEl.remove();
+ return false;
+ });
+
+ // Spawn new arrivals
+ for (const pin of incoming) {
+ if (!nearbyPins.find(n => n.id === pin.id)) {
+ const entry = { ...pin, group: null, labelEl: null, glbLoaded: false };
+ nearbyPins.push(entry);
+ spawnNearbyPin(entry);
+ }
+ }
+
+ updateNearbyBadge();
+ } catch {}
+}
+
+function spawnNearbyPin(pin) {
+ const g = new Group();
+ const wp = gpsToWorld(pin.lat, pin.lng);
+ g.position.set(wp.x, 0, wp.z);
+
+ // Glowing beacon placeholder (replaced by real GLB when close)
+ const beacon = new Mesh(
+ new SphereGeometry(0.22, 24, 18),
+ new MeshPhysicalMaterial({
+ color: 0x88bbff, emissive: 0x1a44ff, emissiveIntensity: 0.9,
+ metalness: 0.1, roughness: 0.06, transmission: 0.35, thickness: 0.3,
+ }),
+ );
+ beacon.position.y = 1.2;
+ beacon.castShadow = true;
+ g.add(beacon);
+ pin.group = g;
+ scene.add(g);
+
+ // Floating HTML name label
+ const el = document.createElement('div');
+ el.className = 'irl-agent-label';
+ el.style.display = 'none';
+ el.innerHTML = `<span class="irl-agent-label-name">${_escHtml(pin.avatar_name || 'Agent')}</span>`;
+ el.addEventListener('click', () => openPinSheet(pin));
+ document.body.appendChild(el);
+ pin.labelEl = el;
+
+ // Load real GLB if nearby
+ const loadedCount = nearbyPins.filter(p => p.glbLoaded).length;
+ if (pin.distance_m < 80 && loadedCount < 5 && pin.avatar_url) loadPinGLB(pin);
+}
+
+function _escHtml(s) {
+ return String(s ?? '').replace(/[&<>"']/g, c =>
+ ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
+}
+
+async function loadPinGLB(pin) {
+ try {
+ const gltf = await new GLTFLoader().loadAsync(pin.avatar_url);
+ if (!pin.group) return;
+ const model = gltf.scene;
+ model.traverse(n => { if (n.isMesh) n.castShadow = true; });
+ const box = new Box3().setFromObject(model);
+ model.position.y -= box.min.y;
+ while (pin.group.children.length) pin.group.remove(pin.group.children[0]);
+ pin.group.add(model);
+ pin.glbLoaded = true;
+ } catch {}
+}
+
+function updateNearbyBadge() {
+ const badge = document.getElementById('irl-nearby-badge');
+ if (!badge) return;
+ const n = nearbyPins.length;
+ badge.textContent = n > 0 ? `${n} nearby` : '';
+ badge.hidden = n === 0;
+}
+
+// ── Interaction sheet ─────────────────────────────────────────────────────
+function openPinSheet(pin) {
+ const sheet = document.getElementById('irl-sheet');
+ if (!sheet) return;
+ const safe = (s) => _escHtml(s ?? '');
+ document.getElementById('irl-sheet-name').textContent = pin.avatar_name || 'Agent';
+ document.getElementById('irl-sheet-dist').textContent = `${pin.distance_m ?? '?'}m away`;
+ const cap = document.getElementById('irl-sheet-caption');
+ cap.textContent = pin.caption || '';
+ cap.hidden = !pin.caption;
+ const payBtn = document.getElementById('irl-sheet-pay');
+ if (payBtn) {
+ payBtn.hidden = !pin.x402_endpoint;
+ payBtn.dataset.endpoint = pin.x402_endpoint ?? '';
+ }
+ sheet.classList.add('is-open');
+}
+
+document.getElementById('irl-sheet-close')?.addEventListener('click', () => {
+ document.getElementById('irl-sheet')?.classList.remove('is-open');
+});
+
+// ── Label 3D→2D projection (called each frame) ───────────────────────────
+const _lblVec = new Vector3();
+function updateLabels() {
+ for (const pin of nearbyPins) {
+ if (!pin.labelEl || !pin.group) continue;
+ _lblVec.set(
+ pin.group.position.x,
+ pin.group.position.y + 2.5,
+ pin.group.position.z,
+ );
+ _lblVec.project(camera);
+ if (_lblVec.z > 1) { pin.labelEl.style.display = 'none'; continue; }
+ const sx = (_lblVec.x * 0.5 + 0.5) * window.innerWidth;
+ const sy = (-_lblVec.y * 0.5 + 0.5) * window.innerHeight;
+ const offscreen = sx < -80 || sx > window.innerWidth + 80 || sy < -80 || sy > window.innerHeight + 80;
+ pin.labelEl.style.display = offscreen ? 'none' : 'block';
+ pin.labelEl.style.left = `${sx}px`;
+ pin.labelEl.style.top = `${sy}px`;
+ }
+}
+
// ── Resize ────────────────────────────────────────────────────────────────
function resize() {
renderer.setSize(window.innerWidth, window.innerHeight, false);
@@ -740,11 +989,28 @@ function tick() {
avatarLean += (targetLean - avatarLean) * LEAN_LERP;
if (avatar) avatar.rotation.x = avatarLean;
- // Camera — frozen when AR is active so background stays anchored
- if (arFrozenCamPos) {
+ // Camera ─────────────────────────────────────────────────────────────────
+ if (gpsModeActive && avatarLocked && arActive) {
+ // GPS mode: camera fixed at the user's physical eye level.
+ // The avatar (and nearby agents) are at GPS-derived world positions.
+ // Gyro delta continues to drive cameraYaw/cameraPitch so pointing the
+ // phone at the real spot where the agent was placed reveals it there.
+ camera.position.set(0, EYE_HEIGHT, 0);
+ camera.rotation.order = 'YXZ';
+ camera.rotation.y = cameraYaw;
+ camera.rotation.x = -cameraPitch;
+ camera.rotation.z = 0;
+ camLookCurrent.set(
+ Math.sin(cameraYaw) * Math.cos(cameraPitch),
+ Math.sin(-cameraPitch),
+ -Math.cos(cameraYaw) * Math.cos(cameraPitch),
+ ).add(camera.position);
+ } else if (arFrozenCamPos) {
+ // Plain AR mode: background stays anchored, avatar walks freely
camera.position.copy(arFrozenCamPos);
camera.lookAt(arFrozenCamLook);
} else {
+ // Normal follow camera
const offset = CAM_OFFSET.clone();
offset.applyAxisAngle(new Vector3(1, 0, 0), -cameraPitch);
offset.applyAxisAngle(upY, cameraYaw);
@@ -766,11 +1032,15 @@ function tick() {
}
}
+ // Project nearby agent labels to screen space
+ updateLabels();
+
renderer.render(scene, camera);
requestAnimationFrame(tick);
}
// ── Boot ──────────────────────────────────────────────────────────────────
+initGPS();
loadAvatar()
.then(() => requestAnimationFrame(tick))
.catch(err => {
diff --git a/vercel.json b/vercel.json
index 20305fccd..9645e7df9 100644
--- a/vercel.json
+++ b/vercel.json
@@ -1812,6 +1812,10 @@
"src": "/api/oracle/batch",
"dest": "/api/oracle/batch.js"
},
+ {
+ "src": "/api/oracle/og",
+ "dest": "/api/oracle/og.js"
+ },
{
"src": "/api/oracle/search",
"dest": "/api/oracle/search.js"
@@ -1836,6 +1840,10 @@
"src": "/api/social/sentiment-pulse",
"dest": "/api/social/sentiment-pulse.js"
},
+ {
+ "src": "/api/irl/pins",
+ "dest": "/api/irl/pins.js"
+ },
{
"src": "/api/copy/executions",
"dest": "/api/copy/executions.js"