// Same-origin fetch POST helpers for the state badge's actions // ({ ok, detail } rather than throwing). async function post(path: string): Promise<{ ok: boolean; detail?: string }> { try { const resp = await fetch(path, { method: "POST", redirect: "manual", }); const ok = resp.ok || resp.type === "opaqueredirect" || (resp.status >= 200 && resp.status < 400); if (ok) return { ok: true }; const detail = await resp.text().catch(() => ""); return { ok: false, detail: `http ${resp.status}${detail ? " — " + detail : ""}`, }; } catch (err) { return { ok: false, detail: err instanceof Error ? err.message : String(err), }; } } export const postCancelTurn = () => post("api/cancel"); export const postNewSession = () => post("api/new-session"); export const postLogout = () => post("api/logout");