import type { DatasetInfo, IterationDetail, Preset } from "./types"; const BASE = "/api/adaevolve"; const PRESETS_BASE = "/api/presets/adaevolve"; async function fetchJson(url: string, opts?: RequestInit): Promise { const res = await fetch(url, opts); if (!res.ok) { const body = await res.json().catch(() => ({})); throw new Error(body.error || `HTTP ${res.status}`); } return res.json(); } // Datasets export async function loadDataset(repo: string, split = "train"): Promise { return fetchJson(`${BASE}/datasets/load`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ repo, split }), }); } export async function listDatasets(): Promise { return fetchJson(`${BASE}/datasets/`); } export async function getIterationDetail(dsId: string, idx: number): Promise { return fetchJson(`${BASE}/datasets/${dsId}/iteration/${idx}`); } export async function unloadDataset(dsId: string): Promise { await fetchJson(`${BASE}/datasets/${dsId}`, { method: "DELETE" }); } // Presets export async function listPresets(): Promise { return fetchJson(PRESETS_BASE); } export async function createPreset(name: string, repo: string, split = "train"): Promise { return fetchJson(PRESETS_BASE, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name, repo, split }), }); } export async function deletePreset(id: string): Promise { await fetchJson(`${PRESETS_BASE}/${id}`, { method: "DELETE" }); }