Watch
0
0
Fork
You've already forked hyperhive
0

swarm-ui: the cancel badge clears when the next turn starts

This commit is contained in:
iris 2026-10-28 20:16:11 +01:00
commit 8060e91939

View file

@ -16,3 +16,26 @@ export function cancelPath(agentName: string): string {
export function cancelNote(acted: boolean): string {
return acted ? "turn cancelled" : "nothing was running";
}
/** What the cancel badge is showing. */
export type CancelStatus = "idle" | "cancelling" | "done" | "error";
/**
* The badge's status once the agent's turn state moves from `prev` to `now`.
* The answer ("turn cancelled") stays up after the turn it stopped ends, and
* clears when the next turn starts, so that turn can be cancelled too. A
* failure clears as soon as its turn ends: with no turn running, there is
* nothing left to retry.
*/
export function statusOnTurnChange(
status: CancelStatus,
prev: string | undefined,
now: string | undefined,
): CancelStatus {
if (status === "cancelling") return status;
const wasIn = canCancel(prev);
const isIn = canCancel(now);
if (isIn && !wasIn) return "idle";
if (!isIn && wasIn && status === "error") return "idle";
return status;
}