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.

Add oracle track record panel to agent detail page

nirholas4349dd95ea1f
diff --git a/api/_lib/trader-stats.js b/api/_lib/trader-stats.js
index e7a58375b..ecbeb39fd 100644
--- a/api/_lib/trader-stats.js
+++ b/api/_lib/trader-stats.js
@@ -27,6 +27,7 @@
import { sql } from './db.js';
import { solUsdPrice } from './avatar-wallet.js';
+import { actionsSummary } from './oracle/store.js';
const LAMPORTS_PER_SOL = 1e9;
@@ -386,7 +387,7 @@ export function shapeOpen(p, network) {
* + open positions. Returns null if the agent has no positions on this network.
*/
export async function getTraderStats({ agentId, network, window = 'all', now = Date.now() }) {
- const [idRows, positions, solUsd, copiers] = await Promise.all([
+ const [idRows, positions, solUsd, copiers, oracleSummary] = await Promise.all([
sql`
select id, name, description, avatar_url, profile_image_url, is_public
from agent_identities where id = ${agentId} limit 1
@@ -394,6 +395,7 @@ export async function getTraderStats({ agentId, network, window = 'all', now = D
fetchTraderPositions({ agentId, network, window, now }),
cachedSolUsd(),
copierCountForAgent(agentId, network),
+ actionsSummary(agentId, network).catch(() => null),
]);
const identity = idRows[0];
if (!identity) return null;
@@ -421,6 +423,7 @@ export async function getTraderStats({ agentId, network, window = 'all', now = D
metrics,
closed,
open,
+ oracle: oracleSummary && oracleSummary.total > 0 ? oracleSummary : null,
};
}
diff --git a/api/oracle/agent-stats.js b/api/oracle/agent-stats.js
new file mode 100644
index 000000000..8ea396ff4
--- /dev/null
+++ b/api/oracle/agent-stats.js
@@ -0,0 +1,94 @@
+/**
+ * Oracle — public agent track record.
+ *
+ * GET /api/oracle/agent-stats?agent_id=<uuid>&network=mainnet&limit=20
+ *
+ * Returns an agent's oracle trading summary (win rate, realized PnL, ROI) plus
+ * the N most recent actions so any visitor can verify the track record.
+ * This endpoint is public — no auth required. It's the evidence behind copy-
+ * trading: followers can see exactly which conviction calls were made and how
+ * they resolved before choosing to mirror a leader.
+ *
+ * Cache: 60s public CDN (the data changes only when the settle-loop runs).
+ */
+
+import { cors, json, method, rateLimited } from '../_lib/http.js';
+import { limits, clientIp } from '../_lib/rate-limit.js';
+import { sql } from '../_lib/db.js';
+import { recentActions, actionsSummary } from '../_lib/oracle/store.js';
+
+const NETWORKS = new Set(['mainnet', 'devnet']);
+const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
+
+export default async function handleAgentStats(req, res) {
+ if (cors(req, res, { methods: 'GET,OPTIONS', origins: '*' })) return;
+ if (!method(req, res, ['GET'])) return;
+
+ const ip = clientIp(req);
+ if (await rateLimited(res, limits.moderate, ip)) return;
+
+ const params = new URL(req.url, 'http://x').searchParams;
+ const agentId = params.get('agent_id') || '';
+ const network = NETWORKS.has(params.get('network')) ? params.get('network') : 'mainnet';
+ const limit = Math.min(50, Math.max(1, parseInt(params.get('limit') || '20', 10)));
+
+ if (!UUID_RE.test(agentId)) {
+ return json(res, 400, { error: 'invalid_agent_id', message: 'agent_id must be a UUID' });
+ }
+
+ // Load agent name so callers don't need a separate /api/agents fetch.
+ const [agentRow] = await sql`
+ select name, description, image_url from agent_identities where id = ${agentId}
+ `.catch(() => []);
+
+ if (!agentRow) {
+ return json(res, 404, { error: 'agent_not_found', message: 'No agent with that ID' });
+ }
+
+ const [summary, actions] = await Promise.all([
+ actionsSummary(agentId, network),
+ recentActions(agentId, network, limit),
+ ]);
+
+ // Per-tier breakdown from the action ledger.
+ const byTier = {};
+ for (const a of actions) {
+ if (!a.tier) continue;
+ if (!byTier[a.tier]) byTier[a.tier] = { total: 0, wins: 0, losses: 0 };
+ byTier[a.tier].total++;
+ if (a.outcome === 'win') byTier[a.tier].wins++;
+ else if (a.outcome === 'loss') byTier[a.tier].losses++;
+ }
+ for (const t of Object.values(byTier)) {
+ const res = t.wins + t.losses;
+ t.win_rate = res > 0 ? Math.round((t.wins / res) * 100) : null;
+ }
+
+ return json(res, 200, {
+ agent: {
+ id: agentId,
+ name: agentRow.name,
+ description: agentRow.description || null,
+ image_url: agentRow.image_url || null,
+ },
+ network,
+ summary,
+ by_tier: byTier,
+ recent_actions: actions.map((a) => ({
+ mint: a.mint,
+ symbol: a.symbol,
+ conviction: a.conviction,
+ tier: a.tier,
+ mode: a.mode,
+ size_sol: a.size_sol != null ? Number(a.size_sol) : null,
+ status: a.status,
+ reason: a.reason,
+ peak_multiple: a.peak_multiple != null ? Number(a.peak_multiple) : null,
+ realized_pnl_sol: a.realized_pnl_sol != null ? Number(a.realized_pnl_sol) : null,
+ outcome: a.outcome || 'open',
+ acted_at: a.acted_at,
+ pump_url: `https://pump.fun/coin/${a.mint}`,
+ oracle_url: `https://three.ws/oracle?mint=${a.mint}`,
+ })),
+ }, { 'cache-control': 'public, max-age=60, s-maxage=60' });
+}
diff --git a/pages/agent-detail.html b/pages/agent-detail.html
index 333003dc2..4485e09ba 100644
--- a/pages/agent-detail.html
+++ b/pages/agent-detail.html
@@ -122,6 +122,23 @@
.ad-main.loading .ad-card .skeleton-text-short {
width: 30%;
}
+
+ /* Trading record card */
+ .ad-pill { display: inline-flex; align-items: center; font-size: 10px; font-weight: 700; letter-spacing: .06em; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; vertical-align: middle; margin-left: 8px; }
+ .ad-pill-sim { background: rgba(255,190,0,.15); color: #fbbe00; border: 1px solid rgba(255,190,0,.25); }
+ .ad-trade-history { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
+ .ad-trade-row { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px; background: var(--surface2, rgba(255,255,255,.04)); font-size: 13px; line-height: 1.3; }
+ .ad-trade-outcome { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
+ .ad-trade-outcome.win { background: #22d160; }
+ .ad-trade-outcome.loss { background: #ff4545; }
+ .ad-trade-outcome.flat { background: #888; }
+ .ad-trade-outcome.open { background: #fbbe00; }
+ .ad-trade-symbol { font-weight: 700; flex-shrink: 0; min-width: 54px; }
+ .ad-trade-tier { font-size: 11px; color: var(--ink-dim, #888); flex-shrink: 0; }
+ .ad-trade-peak { margin-left: auto; font-weight: 700; font-size: 12px; }
+ .ad-trade-pnl { font-size: 12px; color: var(--ink-dim, #888); min-width: 64px; text-align: right; }
+ .ad-trade-pnl.positive { color: #22d160; }
+ .ad-trade-pnl.negative { color: #ff4545; }
</style>
<link rel="stylesheet" href="/nav.css" />
<link rel="stylesheet" href="/footer.css" />
@@ -399,6 +416,33 @@
</div>
</section>
+ <section class="ad-card" id="ad-trading-card" style="display:none">
+ <div class="ad-card-head">
+ <span class="ad-bullet ad-bullet-amber"></span>
+ <h2>TRADING RECORD</h2>
+ <span class="ad-pill ad-pill-sim" id="ad-trade-mode-pill" hidden>SIM</span>
+ </div>
+ <div class="ad-row ad-row-split">
+ <span class="ad-muted">Win rate</span>
+ <span><b id="ad-trade-winrate">—</b></span>
+ </div>
+ <div class="ad-row ad-row-split">
+ <span class="ad-muted">Wins / Losses</span>
+ <span id="ad-trade-wl">—</span>
+ </div>
+ <div class="ad-row ad-row-split">
+ <span class="ad-muted">Realized PnL</span>
+ <span id="ad-trade-pnl">—</span>
+ </div>
+ <div class="ad-row ad-row-split">
+ <span class="ad-muted">ROI</span>
+ <span id="ad-trade-roi">—</span>
+ </div>
+ <div class="ad-sub" style="margin-top:12px">RECENT TRADES</div>
+ <div id="ad-trade-history" class="ad-trade-history"></div>
+ <a class="ad-cta" id="ad-trade-copy-link" href="#" hidden>Copy this trader →</a>
+ </section>
+
<section class="ad-card">
<div class="ad-card-head">
<span class="ad-bullet"></span>
diff --git a/src/agent-detail.js b/src/agent-detail.js
index 289a0c3c2..642c92f99 100644
--- a/src/agent-detail.js
+++ b/src/agent-detail.js
@@ -1218,6 +1218,71 @@ function renderReputation(r) {
card.style.display = '';
}
+const TIER_EMOJI_MAP = { prime: '🟣', strong: '🔵', lean: '🟡', watch: '⚪', avoid: '🔴' };
+
+async function renderOracleTrackRecord(agentId) {
+ const card = document.getElementById('ad-trading-card');
+ if (!card || !agentId) return;
+ let data;
+ try {
+ const r = await fetch(`/api/oracle/agent-stats?agent_id=${encodeURIComponent(agentId)}&limit=8`);
+ if (!r.ok) return;
+ data = await r.json();
+ } catch { return; }
+
+ const s = data.summary;
+ if (!s || s.total === 0) return; // agent has no oracle actions — keep card hidden
+
+ card.style.display = '';
+
+ const allSim = (data.recent_actions || []).every((a) => a.mode === 'simulate');
+ const modePill = document.getElementById('ad-trade-mode-pill');
+ if (modePill && allSim) modePill.hidden = false;
+
+ const winRateEl = document.getElementById('ad-trade-winrate');
+ if (winRateEl) winRateEl.textContent = s.win_rate != null ? `${s.win_rate}%` : '—';
+
+ const wlEl = document.getElementById('ad-trade-wl');
+ if (wlEl) wlEl.textContent = `${s.wins}W / ${s.losses}L / ${s.open} open`;
+
+ const pnlEl = document.getElementById('ad-trade-pnl');
+ if (pnlEl) {
+ const pnl = s.realized_pnl_sol;
+ pnlEl.textContent = pnl != null ? `${pnl >= 0 ? '+' : ''}${Number(pnl).toFixed(4)} SOL` : '—';
+ pnlEl.className = pnl > 0 ? 'ad-trade-pnl positive' : pnl < 0 ? 'ad-trade-pnl negative' : '';
+ }
+
+ const roiEl = document.getElementById('ad-trade-roi');
+ if (roiEl) roiEl.textContent = s.roi_pct != null ? `${s.roi_pct >= 0 ? '+' : ''}${s.roi_pct}%` : '—';
+
+ const histEl = document.getElementById('ad-trade-history');
+ if (histEl) {
+ histEl.innerHTML = '';
+ for (const a of (data.recent_actions || [])) {
+ const outcome = a.outcome || 'open';
+ const tierE = TIER_EMOJI_MAP[a.tier] || '';
+ const peak = a.peak_multiple != null ? `${Number(a.peak_multiple).toFixed(1)}×` : '';
+ const pnlVal = a.realized_pnl_sol;
+ const pnlText = pnlVal != null
+ ? `${pnlVal >= 0 ? '+' : ''}${Number(pnlVal).toFixed(3)} SOL`
+ : '';
+ const row = document.createElement('a');
+ row.className = 'ad-trade-row';
+ row.href = a.oracle_url || `https://three.ws/oracle?mint=${a.mint}`;
+ row.target = '_blank';
+ row.rel = 'noopener noreferrer';
+ row.innerHTML = `<span class="ad-trade-outcome ${outcome}"></span><span class="ad-trade-symbol">$${(a.symbol || '?').toUpperCase()}</span><span class="ad-trade-tier">${tierE} ${a.tier || ''}</span><span class="ad-trade-peak">${peak}</span><span class="ad-trade-pnl ${pnlVal != null && pnlVal >= 0 ? 'positive' : pnlVal != null ? 'negative' : ''}">${pnlText}</span>`;
+ histEl.appendChild(row);
+ }
+ }
+
+ const copyLink = document.getElementById('ad-trade-copy-link');
+ if (copyLink && s.wins > 0) {
+ copyLink.href = `/dashboard?tab=copy&follow=${encodeURIComponent(agentId)}`;
+ copyLink.hidden = false;
+ }
+}
+
function renderEmbedPolicy(p) {
if (!p || typeof p !== 'object') return;
const card = document.getElementById('ad-embed-policy-card');
@@ -1831,7 +1896,7 @@ function runLoad() {
loadAgent(id)
.then(({ agent, error, notFound, redirecting }) => {
if (redirecting) return;
- if (agent) return render(agent);
+ if (agent) { render(agent); renderOracleTrackRecord(agent.id); return; }
if (notFound) return renderNotFound(id, typeof error === 'string' ? error : '');
renderLoadError(error);
})
diff --git a/src/trader.css b/src/trader.css
index 0c1d6e799..ccb1aea78 100644
--- a/src/trader.css
+++ b/src/trader.css
@@ -227,6 +227,51 @@
.tp-error h1, .tp-empty h1 { font-family: var(--font-display); font-size: var(--text-xl); margin-bottom: var(--space-2xs); }
.tp-error p, .tp-empty p { color: var(--ink-dim); max-width: 44ch; margin: 0 auto var(--space-md); }
+/* Oracle conviction block */
+.tp-oracle-block {
+ margin: 20px 0;
+ border: 1px solid var(--stroke);
+ border-radius: var(--radius-lg);
+ overflow: hidden;
+ background: color-mix(in srgb, var(--accent, #7c83ff) 4%, var(--bg-1));
+}
+.tp-oracle-head {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ padding: 12px 16px;
+ border-bottom: 1px solid var(--stroke);
+}
+.tp-oracle-label {
+ font: 700 11px/1 var(--mono);
+ text-transform: uppercase;
+ letter-spacing: .08em;
+ color: var(--accent, #7c83ff);
+}
+.tp-oracle-link { font-size: 12px; color: var(--ink-dim); text-decoration: none; }
+.tp-oracle-link:hover { color: var(--ink); }
+.tp-oracle-kpis {
+ display: grid;
+ grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
+ gap: 0;
+}
+.tp-oracle-kpi {
+ padding: 12px 14px;
+ border-right: 1px solid var(--stroke);
+ border-bottom: 1px solid var(--stroke);
+}
+.tp-oracle-kpi:nth-child(n + 999) { border-right: none; }
+.tp-oracle-kpi span {
+ font: 600 10px/1 var(--mono);
+ text-transform: uppercase;
+ letter-spacing: .05em;
+ color: var(--ink-faint);
+ display: block;
+ margin-bottom: 6px;
+}
+.tp-oracle-kpi b { font: 700 15px/1 var(--mono); }
+.tp-oracle-note { font-size: 11.5px; color: var(--ink-faint); margin: 0; padding: 10px 16px; }
+
/* Toast for copy-link */
.tp-toast {
position: fixed;
diff --git a/src/trader.js b/src/trader.js
index 11bd129a3..3d3627781 100644
--- a/src/trader.js
+++ b/src/trader.js
@@ -117,6 +117,36 @@ function metricsGrid(m) {
`;
}
+// --- Oracle conviction block -------------------------------------------------
+function oracleBlock(oracle, agentId) {
+ const pnlStr = oracle.realized_pnl_sol != null
+ ? `<span class="${pnlClass(oracle.realized_pnl_sol)}">${fmtSol(oracle.realized_pnl_sol)}</span>`
+ : '—';
+ const wrStr = oracle.win_rate != null
+ ? `<span class="${oracle.win_rate >= 50 ? 'lb-pos' : 'lb-neg'}">${oracle.win_rate}%</span>`
+ : '—';
+ const roiStr = oracle.roi_pct != null
+ ? `<span class="${pnlClass(oracle.roi_pct)}">${oracle.roi_pct > 0 ? '+' : ''}${oracle.roi_pct}%</span>`
+ : '—';
+ return `
+ <div class="tp-oracle-block">
+ <div class="tp-oracle-head">
+ <span class="tp-oracle-label">Oracle conviction</span>
+ <a class="tp-oracle-link" href="/oracle" target="_blank" rel="noopener">View live ↗</a>
+ </div>
+ <div class="tp-oracle-kpis">
+ <div class="tp-oracle-kpi"><span>Actions</span><b>${oracle.total}</b></div>
+ <div class="tp-oracle-kpi"><span>Win rate</span><b>${wrStr}</b></div>
+ <div class="tp-oracle-kpi"><span>Wins</span><b class="lb-pos">${oracle.wins}</b></div>
+ <div class="tp-oracle-kpi"><span>Losses</span><b class="lb-neg">${oracle.losses}</b></div>
+ <div class="tp-oracle-kpi"><span>Open</span><b>${oracle.open}</b></div>
+ <div class="tp-oracle-kpi"><span>Realized</span><b>${pnlStr}</b></div>
+ ${oracle.roi_pct != null ? `<div class="tp-oracle-kpi"><span>ROI</span><b>${roiStr}</b></div>` : ''}
+ </div>
+ <p class="tp-oracle-note">Conviction actions are scored against ground truth — did the coin graduate? The win rate above is the engine's accuracy on this agent's calls, not wallet trades.</p>
+ </div>`;
+}
+
// --- Trade tables ------------------------------------------------------------
function closedRows(closed) {
if (!closed.length) return '<tr><td colspan="6" style="text-align:center;color:var(--ink-faint)">No closed trades in this window.</td></tr>';
@@ -201,6 +231,8 @@ function render(data) {
<div class="tp-metrics">${metricsGrid(m)}</div>
+ ${data.oracle ? oracleBlock(data.oracle, a.id) : ''}
+
<div class="tp-curve-wrap">
<div class="tp-curve-head">
<span class="tp-curve-title">Realized equity · ${WINDOW_LABEL[ctx.window]}</span>