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.
This commit is contained in:
iris 2026-08-30 03:37:27 +02:00 committed by mara
commit 3747d46fae
2 changed files with 24 additions and 15 deletions

View file

@ -202,7 +202,9 @@ export function Root() {
costLabel={cost !== null ? fmtTokens(cost) : undefined} costLabel={cost !== null ? fmtTokens(cost) : undefined}
paused={state.paused} paused={state.paused}
onTogglePause={() => { onTogglePause={() => {
submitPauseResume(resolveDashboardBase(state.dashboard_port), state.label, state.paused ? 'resume' : 'pause'); submitPauseResume(resolveDashboardBase(state.dashboard_port), state.label, state.paused ? 'resume' : 'pause').then(
() => refresh(),
);
}} }}
/> />
</Header> </Header>

View file

@ -1,16 +1,23 @@
// Pause/resume POST to the *dashboard's* origin (hive-c0re, not this // Pause/resume POST to the *dashboard's* origin (hive-c0re, not this
// agent's own `/api/*`) — see dashboardBase.ts. A real `<form>` submit // agent's own `/api/*`) — see dashboardBase.ts. `fetch` with
// rather than `fetch`, kept unchanged from app.js: accessed directly // `mode: 'no-cors'` rather than a normal request: the POST is cross-
// (not through the gateway proxy), the dashboard is a different origin/ // origin (behind the gateway this page and the dashboard share an
// port, and a cross-origin `fetch` POST needs the response readable // origin, but accessed directly they're different ports) and this way
// under CORS to report success/failure — a full navigation form submit // hive-c0re doesn't need to grow CORS headers for it — the tradeoff is
// sidesteps that (the browser reloads to whatever the endpoint // an opaque, unreadable response, which is fine here since the caller
// returns) without needing hive-c0re to grow CORS headers for what's // doesn't need to read it, only trigger a state refresh afterward (same
// otherwise a same-origin action behind the gateway. // shape as `postModel`/`postEffort` in modelEffort.ts). `credentials:
export function submitPauseResume(dashboardBase: string, label: string, verb: 'pause' | 'resume'): void { // 'include'` matches the cookie-sending behavior of the plain <form>
const form = document.createElement('form'); // submit this replaces.
form.method = 'POST'; //
form.action = `${dashboardBase}api/${verb}/${label}`; // mara flagged: the previous version was a real `<form>` submit, which
document.body.appendChild(form); // navigates the whole page to whatever hive-c0re's endpoint returns —
form.submit(); // 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(() => {});
} }