// Thin wrappers around the FastAPI endpoints. export async function envReset(params = {}) { const r = await fetch('/reset', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(params), }) if (!r.ok) throw new Error(`reset failed: ${r.status}`) return r.json() } export async function envStep(action) { const r = await fetch('/step', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action }), }) if (!r.ok) throw new Error(`step failed: ${r.status}`) return r.json() } export async function getLandscape(params) { const r = await fetch('/api/landscape', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(params), }) if (!r.ok) throw new Error(`landscape failed: ${r.status}`) return r.json() } export async function getBaselineRace(params) { const r = await fetch('/api/baseline_race', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(params), }) if (!r.ok) throw new Error(`baseline_race failed: ${r.status}`) return r.json() } export async function runArena(params) { const r = await fetch('/api/arena', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(params), }) if (!r.ok) throw new Error(`arena failed: ${r.status}`) return r.json() } export function llmRunStream(params, onEvent) { // SSE stream: each chunk is a JSON event const url = '/api/llm_run?' + new URLSearchParams(params).toString() const es = new EventSource(url) es.onmessage = ev => { try { onEvent(JSON.parse(ev.data)) } catch (e) { console.error('bad SSE payload', ev.data, e) } } es.addEventListener('end', () => es.close()) es.onerror = () => es.close() return () => es.close() }