feat(ui): hydrate session diffs on open

Fetch session-level diffs when a session is opened and keep them updated via session.diff SSE events so UI state stays in sync with server changes.
This commit is contained in:
Shantur Rathore
2026-02-09 12:02:15 +00:00
parent 0e755b721c
commit 4279b25ff4
5 changed files with 88 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ import type {
} from "../types/message"
import type {
EventSessionCompacted,
EventSessionDiff,
EventSessionError,
EventSessionIdle,
EventSessionUpdated,
@@ -428,6 +429,31 @@ function handleSessionUpdate(instanceId: string, event: EventSessionUpdated): vo
}
}
function handleSessionDiff(instanceId: string, event: EventSessionDiff): void {
const sessionId = event.properties?.sessionID
if (!sessionId) return
const diffs = event.properties?.diff
if (!Array.isArray(diffs)) return
const existing = sessions().get(instanceId)?.get(sessionId)
if (existing) {
withSession(instanceId, sessionId, (session) => {
session.diff = diffs
})
return
}
// A diff event can arrive before we have hydrated the session list.
// Best-effort: fetch the session record so the diff has somewhere to live.
void (async () => {
await fetchSessionInfo(instanceId, sessionId, (event as any)?.directory)
withSession(instanceId, sessionId, (session) => {
session.diff = diffs
})
})().catch((error) => log.warn("Failed to hydrate session for diff event", { instanceId, sessionId, error }))
}
function handleSessionIdle(instanceId: string, event: EventSessionIdle): void {
const sessionId = event.properties?.sessionID
if (!sessionId) return
@@ -605,6 +631,7 @@ export {
handleQuestionAsked,
handleQuestionAnswered,
handleSessionCompacted,
handleSessionDiff,
handleSessionError,
handleSessionIdle,
handleSessionStatus,