This repository has been archived on 2026-10-29. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
Epiphany/apps/epiphany-gui/src/operatorApi.ts
2026-04-29 16:50:18 +01:00

31 lines
1.1 KiB
TypeScript

import { invoke } from "@tauri-apps/api/core";
import type { OperatorAction, OperatorActionResult, OperatorSnapshot, StatusRequest } from "./types";
export async function loadOperatorSnapshot(request: StatusRequest): Promise<OperatorSnapshot> {
if (hasTauriRuntime()) {
return invoke<OperatorSnapshot>("load_operator_snapshot", { request });
}
const response = await fetch("/operator-snapshot.sample.json", { cache: "no-store" });
if (!response.ok) {
throw new Error(`sample operator snapshot failed: ${response.status}`);
}
return (await response.json()) as OperatorSnapshot;
}
export async function runOperatorAction(action: OperatorAction, request: StatusRequest): Promise<OperatorActionResult> {
if (hasTauriRuntime()) {
return invoke<OperatorActionResult>("run_operator_action", { action, request });
}
await new Promise((resolve) => setTimeout(resolve, 250));
return {
action,
artifactPath: "E:\\Projects\\EpiphanyAgent\\.epiphany-gui\\sample-action",
summary: `${action} sample completed.`,
};
}
function hasTauriRuntime(): boolean {
return typeof window !== "undefined" && "__TAURI_INTERNALS__" in window;
}