Spaces:
Running
Running
| import { API_BASE } from "./constants"; | |
| import type { | |
| EnvCatalog, | |
| EnvObservation, | |
| ResetEnvOptions, | |
| StepCandidatePayload, | |
| StepResponse, | |
| } from "./types"; | |
| async function fetchJson<T>(path: string, init?: RequestInit): Promise<T> { | |
| const res = await fetch(`${API_BASE}${path}`, init); | |
| if (!res.ok) { | |
| const body = await res.text(); | |
| throw new Error(`API ${path} failed (${res.status}): ${body.slice(0, 240)}`); | |
| } | |
| return (await res.json()) as T; | |
| } | |
| export async function fetchCatalog(): Promise<EnvCatalog> { | |
| return fetchJson<EnvCatalog>("/env/catalog"); | |
| } | |
| export async function resetEnv(options: ResetEnvOptions = {}): Promise<EnvObservation> { | |
| return fetchJson<EnvObservation>("/env/reset", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify(options), | |
| }); | |
| } | |
| export async function orchestrateStep(): Promise<Record<string, unknown>> { | |
| return fetchJson<Record<string, unknown>>("/agents/orchestrate", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({}), | |
| }); | |
| } | |
| export async function stepCandidate(payload: StepCandidatePayload): Promise<StepResponse> { | |
| return fetchJson<StepResponse>("/env/step_candidate", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify(payload), | |
| }); | |
| } | |
| export async function fetchTrace(): Promise<Array<Record<string, unknown>>> { | |
| return fetchJson<Array<Record<string, unknown>>>("/env/trace"); | |
| } | |
| export async function fetchTrainingMetrics(): Promise<Record<string, unknown>> { | |
| return fetchJson<Record<string, unknown>>("/metrics/training"); | |
| } | |
| export async function fetchBaselines(): Promise<Record<string, unknown>> { | |
| return fetchJson<Record<string, unknown>>("/eval/run_baselines", { method: "POST" }); | |
| } | |
| export async function fetchRewardBreakdown(): Promise<Record<string, unknown>> { | |
| return fetchJson<Record<string, unknown>>("/env/reward_breakdown"); | |
| } | |
| export async function fetchLegalActions(): Promise<Array<Record<string, unknown>>> { | |
| return fetchJson<Array<Record<string, unknown>>>("/env/legal_actions"); | |
| } | |
| export async function fetchUncertainty(): Promise<Record<string, unknown>> { | |
| return fetchJson<Record<string, unknown>>("/env/uncertainty"); | |
| } | |
| export async function fetchDosingEval(): Promise<Record<string, unknown>> { | |
| return fetchJson<Record<string, unknown>>("/eval/run_dosing", { method: "POST" }); | |
| } | |