const BASE = "/api/rlm-eval"; async function fetchJson(url: string, init?: RequestInit): Promise { const res = await fetch(`${BASE}${url}`, { headers: { "Content-Type": "application/json" }, ...init, }); if (!res.ok) { const body = await res.json().catch(() => ({})); throw new Error(body.error || `HTTP ${res.status}`); } return res.json(); } const PRESETS_BASE = "/api/presets/rlm-eval"; async function fetchPresetsJson(url: string, init?: RequestInit): Promise { const res = await fetch(`${PRESETS_BASE}${url}`, { headers: { "Content-Type": "application/json" }, ...init, }); if (!res.ok) { const body = await res.json().catch(() => ({})); throw new Error(body.error || `HTTP ${res.status}`); } return res.json(); } export const api = { loadDataset: (repo: string, config?: string, split?: string) => fetchJson<{ id: string; repo: string; name: string; config: string; split: string; metadata: Record; n_examples: number; n_rows: number; }>("/datasets/load", { method: "POST", body: JSON.stringify({ repo, config: config || "rlm_call_traces", split: split || "train", }), }), getOverview: (dsId: string) => fetchJson>(`/datasets/${dsId}/overview`), getExampleDetail: (dsId: string, exampleIdx: number) => fetchJson>(`/datasets/${dsId}/example/${exampleIdx}`), getIterDetail: (dsId: string, exampleIdx: number, rlmIter: number) => fetchJson>( `/datasets/${dsId}/example/${exampleIdx}/iter/${rlmIter}` ), unloadDataset: (dsId: string) => fetchJson<{ status: string }>(`/datasets/${dsId}`, { method: "DELETE" }), listPresets: () => fetchPresetsJson[]>(""), createPreset: (preset: { name: string; repo: string; config: string; split: string }) => fetchPresetsJson>("", { method: "POST", body: JSON.stringify(preset), }), updatePreset: (id: string, data: { name: string }) => fetchPresetsJson>(`/${id}`, { method: "PUT", body: JSON.stringify(data), }), deletePreset: (id: string) => fetchPresetsJson<{ status: string }>(`/${id}`, { method: "DELETE" }), };