File size: 1,280 Bytes
c8cd24f
48f3216
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c8cd24f
 
 
 
 
 
 
 
 
 
48f3216
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import type { BattleStartRequest, BattleStateSnapshot, RegistryEntry } from "./types";

const base = "";

export async function startBattle(payload: BattleStartRequest): Promise<{ session_id: string }> {
  const res = await fetch(`${base}/api/battle/start`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(payload),
  });
  return res.json();
}

export async function runBattle(sessionId: string): Promise<any> {
  const res = await fetch(`${base}/api/battle/run/${sessionId}`, { method: "POST" });
  return res.json();
}

export async function stopBattle(sessionId: string): Promise<{ status: string; session_id: string }> {
  const res = await fetch(`${base}/api/battle/stop/${sessionId}`, { method: "POST" });
  return res.json();
}

export async function getBattleState(sessionId: string): Promise<BattleStateSnapshot> {
  const res = await fetch(`${base}/api/battle/state/${sessionId}`);
  return res.json();
}

export async function getRegistry(): Promise<RegistryEntry[]> {
  const res = await fetch(`${base}/api/registry`);
  return res.json();
}

export async function getMetrics(): Promise<{ registry_size: number; emergent_attacks: number }> {
  const res = await fetch(`${base}/api/metrics`);
  return res.json();
}