| 249 | } |
| 250 | |
| 251 | export function applyTurnState(state, reason = '') { |
| 252 | if (!state) return; |
| 253 | const nextVersion = Number.isInteger(state.version) ? state.version : 0; |
| 254 | if (nextVersion < S.turnStateVersion) return; |
| 255 | S.turnStateVersion = nextVersion; |
| 256 | S.pendingTurnState = null; |
| 257 | const shouldWait = state.phase === 'running'; |
| 258 | if (S.waiting !== shouldWait) { |
| 259 | setWaiting(shouldWait, reason || `turn_state:${state.phase || 'idle'}`); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | // ---- Optimistic bubble ---- |
| 264 | export function finalizeOptimisticBubble() { |