diff --git a/admin.tsx b/admin.tsx index 423c1d2..aa9ae4c 100644 --- a/admin.tsx +++ b/admin.tsx @@ -2,6 +2,13 @@ import React, { useEffect, useMemo, useState } from "react"; import { createRoot } from "react-dom/client"; import "./admin.css"; +type BenchSummary = { + id: string; + status: string; + totalRounds: number; + completedRounds: number; +} | null; + type AdminSnapshot = { isPaused: boolean; isRunningRound: boolean; @@ -9,6 +16,7 @@ type AdminSnapshot = { completedInMemory: number; persistedRounds: number; viewerCount: number; + bench?: BenchSummary; }; type AdminResponse = { ok: true } & AdminSnapshot; @@ -61,6 +69,7 @@ function App() { const [pending, setPending] = useState(null); const [isResetOpen, setIsResetOpen] = useState(false); const [resetText, setResetText] = useState(""); + const [benchRoundsPerPairing, setBenchRoundsPerPairing] = useState(1); useEffect(() => { let mounted = true; @@ -173,6 +182,53 @@ function App() { } } + async function onBenchStart() { + setError(null); + setPending("bench-start"); + try { + const response = await fetch("/api/bench/start", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ roundsPerPairing: benchRoundsPerPairing }), + cache: "no-store", + }); + if (!response.ok) { + const text = await response.text(); + throw new Error(text || `Request failed (${response.status})`); + } + try { + const statusData = await requestAdminJson("/api/admin/status"); + setSnapshot(statusData); + } catch {} + } catch (err) { + setError(err instanceof Error ? err.message : "Failed to start benchmark"); + } finally { + setPending(null); + } + } + + async function onBenchCancel() { + setError(null); + setPending("bench-cancel"); + try { + const response = await fetch("/api/bench/cancel", { + method: "POST", + cache: "no-store", + }); + if (!response.ok) { + throw new Error(await readErrorMessage(response)); + } + try { + const statusData = await requestAdminJson("/api/admin/status"); + setSnapshot(statusData); + } catch {} + } catch (err) { + setError(err instanceof Error ? err.message : "Failed to cancel benchmark"); + } finally { + setPending(null); + } + } + async function onLogout() { setError(null); setPending("logout"); @@ -263,6 +319,7 @@ function App() {