swarm-ui: the cancel badge clears when the next turn starts
This commit is contained in:
parent
2f2b4aa9e2
commit
8060e91939
1 changed files with 65 additions and 6 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue