@@ -103,7 +103,10 @@ export const loadSession = createAsyncThunk<
103103 ThunkApiType
104104> (
105105 "session/load" ,
106- async ( { sessionId, saveCurrentSession : save } , { extra, dispatch } ) => {
106+ async (
107+ { sessionId, saveCurrentSession : save } ,
108+ { extra, dispatch, getState } ,
109+ ) => {
107110 if ( save ) {
108111 const result = await dispatch (
109112 saveCurrentSession ( {
@@ -115,6 +118,32 @@ export const loadSession = createAsyncThunk<
115118 }
116119 const session = await getSession ( extra . ideMessenger , sessionId ) ;
117120 dispatch ( newSession ( session ) ) ;
121+
122+ // Restore selected chat model from session, if present
123+ const chatModelTitle = ( session as any ) . chatModelTitle as
124+ | string
125+ | null
126+ | undefined ;
127+ if ( chatModelTitle ) {
128+ const state = getState ( ) ;
129+ const org = state . profiles . organizations . find (
130+ ( o ) => o . id === state . profiles . selectedOrganizationId ,
131+ ) ;
132+ const selectedProfile =
133+ org ?. profiles . find ( ( p ) => p . id === state . profiles . selectedProfileId ) ??
134+ null ;
135+ if ( selectedProfile ) {
136+ await dispatch (
137+ (
138+ await import ( "../thunks/updateSelectedModelByRole" )
139+ ) . updateSelectedModelByRole ( {
140+ role : "chat" ,
141+ modelTitle : chatModelTitle ,
142+ selectedProfile,
143+ } ) as any ,
144+ ) ;
145+ }
146+ }
118147 } ,
119148) ;
120149
@@ -127,7 +156,10 @@ export const loadRemoteSession = createAsyncThunk<
127156 ThunkApiType
128157> (
129158 "session/loadRemote" ,
130- async ( { remoteId, saveCurrentSession : save } , { extra, dispatch } ) => {
159+ async (
160+ { remoteId, saveCurrentSession : save } ,
161+ { extra, dispatch, getState } ,
162+ ) => {
131163 if ( save ) {
132164 const result = await dispatch (
133165 saveCurrentSession ( {
@@ -139,6 +171,32 @@ export const loadRemoteSession = createAsyncThunk<
139171 }
140172 const session = await getRemoteSession ( extra . ideMessenger , remoteId ) ;
141173 dispatch ( newSession ( session ) ) ;
174+
175+ // Restore selected chat model from session, if present
176+ const chatModelTitle = ( session as any ) . chatModelTitle as
177+ | string
178+ | null
179+ | undefined ;
180+ if ( chatModelTitle ) {
181+ const state = getState ( ) ;
182+ const org = state . profiles . organizations . find (
183+ ( o ) => o . id === state . profiles . selectedOrganizationId ,
184+ ) ;
185+ const selectedProfile =
186+ org ?. profiles . find ( ( p ) => p . id === state . profiles . selectedProfileId ) ??
187+ null ;
188+ if ( selectedProfile ) {
189+ await dispatch (
190+ (
191+ await import ( "../thunks/updateSelectedModelByRole" )
192+ ) . updateSelectedModelByRole ( {
193+ role : "chat" ,
194+ modelTitle : chatModelTitle ,
195+ selectedProfile,
196+ } ) as any ,
197+ ) ;
198+ }
199+ }
142200 } ,
143201) ;
144202
@@ -168,6 +226,32 @@ export const loadLastSession = createAsyncThunk<void, void, ThunkApiType>(
168226 session = await getSession ( extra . ideMessenger , lastSessionId ) ;
169227 }
170228 dispatch ( newSession ( session ) ) ;
229+
230+ // Restore selected chat model from session, if present
231+ const chatModelTitle = ( session as any ) . chatModelTitle as
232+ | string
233+ | null
234+ | undefined ;
235+ if ( chatModelTitle ) {
236+ const state = getState ( ) ;
237+ const org = state . profiles . organizations . find (
238+ ( o ) => o . id === state . profiles . selectedOrganizationId ,
239+ ) ;
240+ const selectedProfile =
241+ org ?. profiles . find ( ( p ) => p . id === state . profiles . selectedProfileId ) ??
242+ null ;
243+ if ( selectedProfile ) {
244+ await dispatch (
245+ (
246+ await import ( "../thunks/updateSelectedModelByRole" )
247+ ) . updateSelectedModelByRole ( {
248+ role : "chat" ,
249+ modelTitle : chatModelTitle ,
250+ selectedProfile,
251+ } ) as any ,
252+ ) ;
253+ }
254+ }
171255 } ,
172256) ;
173257
@@ -246,12 +330,16 @@ export const saveCurrentSession = createAsyncThunk<
246330 title = NEW_SESSION_TITLE ;
247331 }
248332
333+ const selectedChatModel = selectSelectedChatModel ( state ) ;
334+
249335 const session : Session = {
250336 sessionId : state . session . id ,
251337 title,
252338 workspaceDirectory : window . workspacePaths ?. [ 0 ] || "" ,
253339 history : state . session . history ,
254- } ;
340+ mode : state . session . mode ,
341+ chatModelTitle : selectedChatModel ?. title ?? null ,
342+ } as Session ;
255343
256344 const result = await dispatch ( updateSession ( session ) ) ;
257345 unwrapResult ( result ) ;
0 commit comments