MCPcopy Create free account
hub / github.com/tiann/hapi / handleRealtimeEvent

Method handleRealtimeEvent

hub/src/sync/syncEngine.ts:264–291  ·  view source on GitHub ↗
(event: SyncEvent)

Source from the content-addressed store, hash-verified

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

Callers 4

startHubFunction · 0.80
importSingleCodexSessionFunction · 0.80

Calls 6

getSessionMethod · 0.95
refreshSessionMethod · 0.80
refreshMachineMethod · 0.80
emitMethod · 0.45

Tested by

no test coverage detected