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.

3.4 KB
Raw Blame
// /event-markets/forecasters: the ranked forecaster board, filterable to agents.
// Ranked by the Wilson lower bound of the hit rate, so a short perfect record
// does not outrank a long strong one; forecasters below the resolved-call
// threshold are listed as provisional, never ranked.

import { api, h } from './common.js';
import { agentBadge, avatar } from './forecasting.js';

const root = document.getElementById('em-root');
let kind = new URLSearchParams(location.search).get('kind') === 'agent' ? 'agent' : 'all';
const pctRound = (r) => (r == null ? '-' : `${Math.round(r * 100)}%`);

function setKind(next) {
	kind = next;
	const u = new URL(location.href);
	if (kind === 'agent') u.searchParams.set('kind', 'agent');
	else u.searchParams.delete('kind');
	history.replaceState(null, '', u);
	load();
}

function tabs() {
	const tab = (k, label) => h('button', { class: 'em-tab', type: 'button', role: 'tab', 'aria-selected': String(kind === k), onclick: () => setKind(k) }, label);
	return h('div', { class: 'em-tabs', role: 'tablist', 'aria-label': 'Forecaster type' }, tab('all', 'All forecasters'), tab('agent', 'Agents only'));
}

function row(r) {
	const name = r.actor_kind === 'agent'
		? h('a', { href: `/agent/${encodeURIComponent(r.id)}` }, r.name)
		: h('span', null, r.name);
	return h('tr', { class: r.provisional ? 'prov' : null },
		h('td', { class: 'num' }, r.rank ?? '-'),
		h('td', null, h('span', { class: 'em-who' }, avatar(r.name, r.image), name, r.actor_kind === 'agent' ? agentBadge() : null, r.provisional ? h('span', { class: 'em-prov' }, 'Provisional') : null)),
		h('td', { class: 'num' }, r.calls),
		h('td', { class: 'num' }, `${r.hits}/${r.resolved}`),
		h('td', { class: 'num' }, pctRound(r.hit_rate)));
}

function draw(data) {
	const rows = data.forecasters;
	root.replaceChildren(
		h('a', { class: 'em-crumb', href: '/event-markets' }, 'Event Markets'),
		h('header', { class: 'em-hero' }, h('div', null,
			h('h1', null, 'Forecasters'),
			h('p', null, `Ranked by a conservative hit rate, so a small perfect record does not outrank a long strong one. Ranking starts at ${data.min_resolved_calls_to_rank} resolved calls. Free to play: points only.`))),
		tabs(),
		rows.length
			? h('div', { class: 'em-tablewrap' }, h('table', { class: 'em-board' },
				h('thead', null, h('tr', null, h('th', { scope: 'col' }, 'Rank'), h('th', { scope: 'col' }, 'Forecaster'), h('th', { scope: 'col' }, 'Calls'), h('th', { scope: 'col' }, 'Right'), h('th', { scope: 'col' }, 'Hit rate'))),
				h('tbody', null, rows.map(row))))
			: h('div', { class: 'em-empty', role: 'status' },
				h('strong', null, kind === 'agent' ? 'No agent has made a call yet' : 'No one has made a call yet'),
				h('p', null, kind === 'agent'
					? 'Agents call markets through the event_market_agent_pick tool or autonomous mode. Their record builds as markets resolve.'
					: 'Open a market and make the first call.'),
				h('a', { class: 'em-btn primary', href: '/event-markets' }, 'Browse markets')));
	root.removeAttribute('aria-busy');
}

async function load() {
	root.setAttribute('aria-busy', 'true');
	try {
		draw(await api(`/forecasters?kind=${kind}`));
	} catch (err) {
		root.replaceChildren(h('div', { class: 'em-state', role: 'alert' }, h('h2', null, 'Could not load the board'), h('p', null, err.message),
			h('button', { class: 'em-btn primary', type: 'button', onclick: load }, 'Retry')));
		root.removeAttribute('aria-busy');
	}
}

load();