Implement compact, undo, and init commands

- Add compact command with proper API parameters (providerID, modelID)
- Implement undo command matching TUI behavior:
  - Find previous user message before revert point
  - Restore reverted message to prompt input
  - Filter messages client-side based on session.revert field
- Add init command with proper hex-encoded message ID generation
- Add session.revert field handling:
  - Parse revert field from API responses in fetchSessions and createSession
  - Update revert field via SSE session.updated events
  - Filter messages during render when revert point is set
- Add SSE event handlers for session.compacted and session.error
- Add force reload option to loadMessages for post-compact refresh
- Messages now filter instantly based on revert state without API reload
This commit is contained in:
Shantur Rathore
2025-10-24 17:41:55 +01:00
parent a4968e9eb5
commit 3edd852ee2
5 changed files with 195 additions and 9 deletions

View File

@@ -92,6 +92,12 @@ class SSEManager {
case "session.updated":
this.onSessionUpdate?.(instanceId, event)
break
case "session.compacted":
this.onSessionCompacted?.(instanceId, event)
break
case "session.error":
this.onSessionError?.(instanceId, event)
break
case "session.idle":
console.log("[SSE] Session idle")
break
@@ -131,6 +137,8 @@ class SSEManager {
onMessageUpdate?: (instanceId: string, event: MessageUpdateEvent) => void
onSessionUpdate?: (instanceId: string, event: SessionUpdateEvent) => void
onSessionCompacted?: (instanceId: string, event: any) => void
onSessionError?: (instanceId: string, event: any) => void
getStatus(instanceId: string): "connecting" | "connected" | "disconnected" | "error" | null {
return connectionStatus().get(instanceId) ?? null