Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | 2209x 2209x 2209x 6x 6x 2209x 4x 4x 2209x 3x 3x 2209x 3x 3x 2209x 3x 3x 2209x 4x 4x 2209x 3x 3x 2209x 3x 3x 2209x 3x 3x 2209x 3x 3x 2209x 4x 4x 2209x 3x 3x 2209x 3x 3x 2209x 3x 3x 2209x 3x 3x | import {
Simulation,
SimulationScenario,
SimulationWorld,
} from "@/objects/Simulation";
import { Dictionary } from "@/types/ext";
import { AxiosRequestConfig } from "axios";
import { HistoricalAPIRouter } from "../HistoricalApiRouter";
export class SimulationRouter extends HistoricalAPIRouter {
constructor(
host: string,
token: string | null = null,
default_config: AxiosRequestConfig | null = null,
headers: Dictionary<string> = {},
) {
super("simulations", host, token, default_config, headers);
}
/** Worlds are the historied resource here; scenarios and runs are children. */
protected historyBasePath = "worlds";
// ── Worlds ───────────────────────────────────────────────────────────────────
listWorlds = async (): Promise<SimulationWorld[]> => {
const res = await this.api.get<SimulationWorld[]>(super.endpoint("worlds"));
Eif (super.validRes(res) && Array.isArray(res.data)) return res.data;
return [];
};
getWorld = async (id: string): Promise<SimulationWorld | null> => {
const res = await this.api.get<SimulationWorld>(
super.endpoint(`worlds/${id}`),
);
Eif (super.validRes(res)) return res.data;
return null;
};
createWorld = async (
data: Partial<SimulationWorld>,
): Promise<SimulationWorld | null> => {
const res = await this.api.post(super.endpoint("worlds"), data);
Eif (super.validRes(res)) return res.data as SimulationWorld;
return null;
};
updateWorld = async (
id: string,
data: Partial<SimulationWorld>,
): Promise<SimulationWorld | null> => {
const res = await this.api.patch(super.endpoint(`worlds/${id}`), data);
Eif (super.validRes(res)) return res.data as SimulationWorld;
return null;
};
deleteWorld = async (id: string): Promise<boolean> => {
const res = await this.api.delete(super.endpoint(`worlds/${id}`));
return res.status === 204;
};
// ── Scenarios ────────────────────────────────────────────────────────────────
listScenarios = async (worldId: string): Promise<SimulationScenario[]> => {
const res = await this.api.get<SimulationScenario[]>(
super.endpoint(`worlds/${worldId}/scenarios`),
);
Eif (super.validRes(res) && Array.isArray(res.data)) return res.data;
return [];
};
getScenario = async (
worldId: string,
scenarioId: string,
): Promise<SimulationScenario | null> => {
const res = await this.api.get<SimulationScenario>(
super.endpoint(`worlds/${worldId}/scenarios/${scenarioId}`),
);
Eif (super.validRes(res)) return res.data;
return null;
};
createScenario = async (
worldId: string,
data: Partial<SimulationScenario>,
): Promise<SimulationScenario | null> => {
const res = await this.api.post(
super.endpoint(`worlds/${worldId}/scenarios`),
data,
);
Eif (super.validRes(res)) return res.data as SimulationScenario;
return null;
};
updateScenario = async (
worldId: string,
scenarioId: string,
data: Partial<SimulationScenario>,
): Promise<SimulationScenario | null> => {
const res = await this.api.patch(
super.endpoint(`worlds/${worldId}/scenarios/${scenarioId}`),
data,
);
Eif (super.validRes(res)) return res.data as SimulationScenario;
return null;
};
deleteScenario = async (
worldId: string,
scenarioId: string,
): Promise<boolean> => {
const res = await this.api.delete(
super.endpoint(`worlds/${worldId}/scenarios/${scenarioId}`),
);
return res.status === 204;
};
// ── Simulations ──────────────────────────────────────────────────────────────
listSimulations = async (worldId: string): Promise<Simulation[]> => {
const res = await this.api.get<Simulation[]>(
super.endpoint(`worlds/${worldId}/simulations`),
);
Eif (super.validRes(res) && Array.isArray(res.data)) return res.data;
return [];
};
getSimulation = async (
worldId: string,
simulationId: string,
): Promise<Simulation | null> => {
const res = await this.api.get<Simulation>(
super.endpoint(`worlds/${worldId}/simulations/${simulationId}`),
);
Eif (super.validRes(res)) return res.data;
return null;
};
createSimulation = async (
worldId: string,
data: Partial<Simulation>,
): Promise<Simulation | null> => {
const res = await this.api.post(
super.endpoint(`worlds/${worldId}/simulations`),
data,
);
Eif (super.validRes(res)) return res.data as Simulation;
return null;
};
runSimulation = async (
worldId: string,
simulationId: string,
initialPrompt?: string,
): Promise<Simulation | null> => {
const res = await this.api.post(
super.endpoint(
`worlds/${worldId}/simulations/${simulationId}/run`,
initialPrompt ? { initial_prompt: initialPrompt } : undefined,
),
{},
);
Eif (super.validRes(res)) return res.data as Simulation;
return null;
};
deleteSimulation = async (
worldId: string,
simulationId: string,
): Promise<boolean> => {
const res = await this.api.delete(
super.endpoint(`worlds/${worldId}/simulations/${simulationId}`),
);
return res.status === 204;
};
}
|