|
| 1 | +import { isReplyOperationSuperseded } from "./reply-operation-abort.js"; |
1 | 2 | import type { ReplyOperationRunState } from "./reply-operation-run-state.js"; |
| 3 | +import type { ReplyOperation } from "./reply-run-registry.js"; |
2 | 4 |
|
3 | 5 | type ReplyOperationAgentTurnStatus = "ok" | "failed" | "superseded"; |
4 | 6 |
|
5 | | -const agentTurns = new WeakMap<ReplyOperationRunState, ReplyOperationAgentTurnStatus>(); |
| 7 | +type ReplyOperationAgentTurn = { |
| 8 | + status: ReplyOperationAgentTurnStatus; |
| 9 | + owner?: ReplyOperation; |
| 10 | +}; |
| 11 | + |
| 12 | +const agentTurns = new WeakMap<ReplyOperationRunState, ReplyOperationAgentTurn>(); |
6 | 13 |
|
7 | 14 | export function recordReplyOperationAgentTurn( |
8 | 15 | state: ReplyOperationRunState | undefined, |
9 | 16 | status: ReplyOperationAgentTurnStatus, |
| 17 | + owner?: ReplyOperation, |
10 | 18 | ): void { |
11 | 19 | if (state) { |
12 | | - agentTurns.set(state, status); |
| 20 | + agentTurns.set(state, { status, owner }); |
13 | 21 | } |
14 | 22 | } |
15 | 23 |
|
16 | 24 | export function resolveReplyOperationAgentTurn( |
17 | 25 | state: ReplyOperationRunState | undefined, |
18 | 26 | ): ReplyOperationAgentTurnStatus | undefined { |
19 | | - return state ? agentTurns.get(state) : undefined; |
| 27 | + if (!state) { |
| 28 | + return undefined; |
| 29 | + } |
| 30 | + const turn = agentTurns.get(state); |
| 31 | + return isReplyOperationSuperseded(turn?.owner) ? "superseded" : turn?.status; |
20 | 32 | } |
0 commit comments