@@ -16,6 +16,7 @@ function createDeps() {
1616 const toastCalls : Array < [ string , string | null | undefined , string | undefined , number | undefined ] > = [ ] ;
1717 const clearQueueCalls : number [ ] = [ ] ;
1818 let refreshQueueCalls = 0 ;
19+ let agentStatus : any = null ;
1920
2021 const deps : HandleAppSseEventDependencies = {
2122 currentChatJid : 'chat:alpha' ,
@@ -46,7 +47,9 @@ function createDeps() {
4647 setFloatingWidget : ( ) => undefined ,
4748 clearLastActivityFlag : ( ) => undefined ,
4849 handleUiVersionDrift : ( ) => false ,
49- setAgentStatus : ( ) => undefined ,
50+ setAgentStatus : ( next ) => {
51+ agentStatus = applyUpdate ( agentStatus , next ) ;
52+ } ,
5053 setAgentDraft : ( ) => undefined ,
5154 setAgentPlan : ( ) => undefined ,
5255 setAgentThought : ( ) => undefined ,
@@ -98,6 +101,7 @@ function createDeps() {
98101 getToastCalls : ( ) => toastCalls ,
99102 getClearQueueCalls : ( ) => clearQueueCalls ,
100103 getRefreshQueueCalls : ( ) => refreshQueueCalls ,
104+ getAgentStatusState : ( ) => agentStatus ,
101105 } ;
102106}
103107
@@ -129,6 +133,35 @@ test('handleAppSseEvent removes followup rows on removal events and schedules qu
129133 expect ( state . getRefreshQueueCalls ( ) ) . toBe ( 1 ) ;
130134} ) ;
131135
136+ test ( 'handleAppSseEvent restores active agent status on reconnect' , async ( ) => {
137+ const state = createDeps ( ) ;
138+ state . deps . getAgentStatus = async ( ) => ( {
139+ status : 'active' ,
140+ data : {
141+ chat_jid : 'chat:alpha' ,
142+ type : 'intent' ,
143+ title : 'Compacting context' ,
144+ intent_key : 'compaction' ,
145+ turn_id : 'turn-42' ,
146+ started_at : '2026-03-30T21:00:00.000Z' ,
147+ } ,
148+ thought : { text : 'thought preview' , totalLines : 2 } ,
149+ draft : { text : 'draft preview' , totalLines : 3 } ,
150+ } ) ;
151+
152+ handleAppSseEvent ( 'connected' , { app_asset_version : 'test' } , state . deps ) ;
153+ await Promise . resolve ( ) ;
154+
155+ expect ( state . getAgentStatusState ( ) ) . toEqual ( {
156+ chat_jid : 'chat:alpha' ,
157+ type : 'intent' ,
158+ title : 'Compacting context' ,
159+ intent_key : 'compaction' ,
160+ turn_id : 'turn-42' ,
161+ started_at : '2026-03-30T21:00:00.000Z' ,
162+ } ) ;
163+ } ) ;
164+
132165test ( 'handleAppSseEvent maps extension notify events into intent toasts' , ( ) => {
133166 const state = createDeps ( ) ;
134167
0 commit comments