Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/frontend/packages/agent/src/lib/pauseAction.ts
iris 3747d46fae agent ui: stop pause/resume from navigating to hive-c0re's raw response
pauseAction.ts submitted a real <form> POST, so clicking pause/resume
navigated the whole page to hive-c0re's plain-text "ok" response body
instead of staying on the agent terminal. Switch to a fetch with
mode: 'no-cors' (still cross-origin-safe, no CORS headers needed from
hive-c0re) + credentials: 'include' to match the form's cookie
behavior, then refresh() the agent state afterward, matching the
existing postModel/postEffort pattern right next to it in Root.tsx.
2026-08-30 03:57:11 +02:00

23 lines
1.2 KiB
TypeScript

// Pause/resume POST to the *dashboard's* origin (hive-c0re, not this
// agent's own `/api/*`) — see dashboardBase.ts. `fetch` with
// `mode: 'no-cors'` rather than a normal request: the POST is cross-
// origin (behind the gateway this page and the dashboard share an
// origin, but accessed directly they're different ports) and this way
// hive-c0re doesn't need to grow CORS headers for it — the tradeoff is
// an opaque, unreadable response, which is fine here since the caller
// doesn't need to read it, only trigger a state refresh afterward (same
// shape as `postModel`/`postEffort` in modelEffort.ts). `credentials:
// 'include'` matches the cookie-sending behavior of the plain <form>
// submit this replaces.
//
// mara flagged: the previous version was a real `<form>` submit, which
// navigates the whole page to whatever hive-c0re's endpoint returns —
// here, the literal text "ok". Fire-and-forget `fetch` keeps the click
// on the agent page.
export async function submitPauseResume(dashboardBase: string, label: string, verb: 'pause' | 'resume'): Promise<void> {
await fetch(`${dashboardBase}api/${verb}/${label}`, {
method: 'POST',
mode: 'no-cors',
credentials: 'include',
}).catch(() => {});
}