File size: 682 Bytes
1bb18a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const BASE = '';  // Same origin — FastAPI serves both API and frontend

export const resetEnv = (task = 'easy') =>
  fetch(`${BASE}/reset?task=${task}`).then(r => r.json());

export const stepEnv = (action) =>
  fetch(`${BASE}/step`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(action),
  }).then(r => {
    if (!r.ok) return r.json().then(e => Promise.reject(e));
    return r.json();
  });

export const getState = () =>
  fetch(`${BASE}/state`).then(r => r.json());

export const getGrade = () =>
  fetch(`${BASE}/grade`).then(r => r.json());

export const getTasks = () =>
  fetch(`${BASE}/tasks`).then(r => r.json());