| 207 | } |
| 208 | |
| 209 | function active(event: Event, sessionID: string): boolean { |
| 210 | if (sid(event) !== sessionID) { |
| 211 | return false |
| 212 | } |
| 213 | |
| 214 | if (event.type === "message.updated") { |
| 215 | return event.properties.info.role === "assistant" |
| 216 | } |
| 217 | |
| 218 | if (event.type === "message.part.delta" || event.type === "message.part.updated") { |
| 219 | return false |
| 220 | } |
| 221 | |
| 222 | if (event.type !== "session.status") { |
| 223 | return true |
| 224 | } |
| 225 | |
| 226 | return event.properties.status.type !== "idle" |
| 227 | } |
| 228 | |
| 229 | // Races the turn's deferred completion against an abort signal. |
| 230 | function waitTurn(done: Wait["done"], signal: AbortSignal) { |