unknown1321's picture
Clean deploy to HF Space
e9ce6e9
Raw
History Blame Contribute Delete
1.14 kB
import type { AEPOAction, StepResult, StateResult, ResetResult, TaskDifficulty } from "./types";
// Static export has no Next.js server-side rewrite proxy, so API calls go
// directly to FastAPI at the same origin. FastAPI routes: /reset /step /state
const BASE = "";
export async function fetchState(): Promise<StateResult> {
const res = await fetch(`${BASE}/state`, { cache: "no-store" });
if (!res.ok) throw new Error(`GET /state → ${res.status}`);
return res.json();
}
export async function postReset(task: TaskDifficulty = "easy"): Promise<ResetResult> {
const res = await fetch(`${BASE}/reset`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ task }),
});
if (!res.ok) throw new Error(`POST /reset → ${res.status}`);
return res.json();
}
export async function postStep(action: AEPOAction): Promise<StepResult> {
const res = await fetch(`${BASE}/step`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ action }),
});
if (!res.ok) throw new Error(`POST /step → ${res.status}`);
return res.json();
}