(event: SyncEvent)
| 262 | } |
| 263 | |
| 264 | handleRealtimeEvent(event: SyncEvent): void { |
| 265 | if (event.type === 'session-updated' && event.sessionId) { |
| 266 | // Snapshot agent session IDs before refresh — safe because JS is single-threaded |
| 267 | // and refreshSession replaces the Map entry with a new object. |
| 268 | const before = this.sessionCache.getSession(event.sessionId) |
| 269 | this.sessionCache.refreshSession(event.sessionId) |
| 270 | const after = this.sessionCache.getSession(event.sessionId) |
| 271 | if (after?.metadata && !this.hasSameAgentSessionIds(before?.metadata ?? null, after.metadata)) { |
| 272 | void this.sessionCache.deduplicateByAgentSessionId(event.sessionId).catch(() => { |
| 273 | // best-effort: dedup failure is harmless, web-side safety net hides remaining duplicates |
| 274 | }) |
| 275 | } |
| 276 | return |
| 277 | } |
| 278 | |
| 279 | if (event.type === 'machine-updated' && event.machineId) { |
| 280 | this.machineCache.refreshMachine(event.machineId) |
| 281 | return |
| 282 | } |
| 283 | |
| 284 | if (event.type === 'message-received' && event.sessionId) { |
| 285 | if (!this.getSession(event.sessionId)) { |
| 286 | this.sessionCache.refreshSession(event.sessionId) |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | this.eventPublisher.emit(event) |
| 291 | } |
| 292 | |
| 293 | handleSessionAlive(payload: { |
| 294 | sid: string |
no test coverage detected