@@ -60,7 +60,7 @@ class LocalSessionAdapter implements ISession {
6060 readonly updatedAt : ISettableObservable < Date > ;
6161 readonly status = observableValue < SessionStatus > ( 'status' , SessionStatus . Completed ) ;
6262 readonly changes = observableValue < readonly IChatSessionFileChange [ ] > ( 'changes' , [ ] ) ;
63- readonly modelId = observableValue < string | undefined > ( 'modelId' , undefined ) ;
63+ readonly modelId : ISettableObservable < string | undefined > ;
6464 readonly mode = observableValue < { readonly id : string ; readonly kind : string } | undefined > ( 'mode' , undefined ) ;
6565 readonly loading = observableValue ( 'loading' , false ) ;
6666 readonly isArchived = observableValue ( 'isArchived' , false ) ;
@@ -89,6 +89,7 @@ class LocalSessionAdapter implements ISession {
8989 this . createdAt = new Date ( metadata . startTime ) ;
9090 this . title = observableValue ( 'title' , metadata . summary ?? `Session ${ rawId . substring ( 0 , 8 ) } ` ) ;
9191 this . updatedAt = observableValue ( 'updatedAt' , new Date ( metadata . modifiedTime ) ) ;
92+ this . modelId = observableValue < string | undefined > ( 'modelId' , metadata . model ? `${ logicalSessionType } :${ metadata . model } ` : undefined ) ;
9293 this . lastTurnEnd = observableValue ( 'lastTurnEnd' , metadata . modifiedTime ? new Date ( metadata . modifiedTime ) : undefined ) ;
9394 this . description = observableValue ( 'description' , new MarkdownString ( ) . appendText ( localize ( 'localAgentHostDescription' , "Local" ) ) ) ;
9495 this . workspace = observableValue ( 'workspace' , LocalAgentHostSessionsProvider . buildWorkspace ( metadata . project , metadata . workingDirectory ) ) ;
@@ -155,6 +156,12 @@ class LocalSessionAdapter implements ISession {
155156 didChange = true ;
156157 }
157158
159+ const modelId = metadata . model ? `${ this . sessionType } :${ metadata . model } ` : undefined ;
160+ if ( modelId !== this . modelId . get ( ) ) {
161+ this . modelId . set ( modelId , undefined ) ;
162+ didChange = true ;
163+ }
164+
158165 return didChange ;
159166 }
160167}
@@ -209,6 +216,7 @@ export class LocalAgentHostSessionsProvider extends Disposable implements ISessi
209216 private _selectedModelId : string | undefined ;
210217 private _currentNewSession : ISession | undefined ;
211218 private _currentNewSessionStatus : ISettableObservable < SessionStatus > | undefined ;
219+ private _currentNewSessionModelId : ISettableObservable < string | undefined > | undefined ;
212220
213221 private _cacheInitialized = false ;
214222
@@ -245,6 +253,8 @@ export class LocalAgentHostSessionsProvider extends Disposable implements ISessi
245253 this . _refreshSessions ( ) ;
246254 } else if ( e . action . type === ActionType . SessionTitleChanged && isSessionAction ( e . action ) ) {
247255 this . _handleTitleChanged ( e . action . session , e . action . title ) ;
256+ } else if ( e . action . type === ActionType . SessionModelChanged && isSessionAction ( e . action ) ) {
257+ this . _handleModelChanged ( e . action . session , e . action . model ) ;
248258 } else if ( e . action . type === ActionType . SessionIsReadChanged && isSessionAction ( e . action ) ) {
249259 this . _handleIsReadChanged ( e . action . session , e . action . isRead ) ;
250260 } else if ( e . action . type === ActionType . SessionIsDoneChanged && isSessionAction ( e . action ) ) {
@@ -376,6 +386,7 @@ export class LocalAgentHostSessionsProvider extends Disposable implements ISessi
376386
377387 this . _currentNewSession = undefined ;
378388 this . _selectedModelId = undefined ;
389+ this . _currentNewSessionModelId = undefined ;
379390
380391 const defaultType = this . sessionTypes [ 0 ] ;
381392 if ( ! defaultType ) {
@@ -429,6 +440,7 @@ export class LocalAgentHostSessionsProvider extends Disposable implements ISessi
429440 } ;
430441 this . _currentNewSession = session ;
431442 this . _currentNewSessionStatus = status ;
443+ this . _currentNewSessionModelId = modelId ;
432444 return session ;
433445 }
434446
@@ -458,6 +470,18 @@ export class LocalAgentHostSessionsProvider extends Disposable implements ISessi
458470 setModel ( sessionId : string , modelId : string ) : void {
459471 if ( this . _currentNewSession ?. sessionId === sessionId ) {
460472 this . _selectedModelId = modelId ;
473+ this . _currentNewSessionModelId ?. set ( modelId , undefined ) ;
474+ return ;
475+ }
476+
477+ const rawId = this . _rawIdFromChatId ( sessionId ) ;
478+ const cached = rawId ? this . _sessionCache . get ( rawId ) : undefined ;
479+ if ( cached && rawId ) {
480+ cached . modelId . set ( modelId , undefined ) ;
481+ this . _onDidChangeSessions . fire ( { added : [ ] , removed : [ ] , changed : [ cached ] } ) ;
482+ const rawModelId = modelId . startsWith ( `${ cached . sessionType } :` ) ? modelId . substring ( cached . sessionType . length + 1 ) : modelId ;
483+ const action = { type : ActionType . SessionModelChanged as const , session : AgentSession . uri ( cached . agentProvider , rawId ) . toString ( ) , model : rawModelId } ;
484+ this . _agentHostService . dispatch ( action ) ;
461485 }
462486 }
463487
@@ -581,11 +605,13 @@ export class LocalAgentHostSessionsProvider extends Disposable implements ISessi
581605
582606 this . _selectedModelId = undefined ;
583607 this . _currentNewSessionStatus = undefined ;
608+ this . _currentNewSessionModelId = undefined ;
584609
585610 try {
586611 const committedSession = await this . _waitForNewSession ( existingKeys ) ;
587612 if ( committedSession ) {
588613 this . _currentNewSession = undefined ;
614+ this . _currentNewSessionModelId = undefined ;
589615 this . _onDidReplaceSession . fire ( { from : newSession , to : committedSession } ) ;
590616 return committedSession ;
591617 }
@@ -596,6 +622,7 @@ export class LocalAgentHostSessionsProvider extends Disposable implements ISessi
596622 }
597623
598624 this . _currentNewSession = undefined ;
625+ this . _currentNewSessionModelId = undefined ;
599626 return newSession ;
600627 }
601628
@@ -676,7 +703,7 @@ export class LocalAgentHostSessionsProvider extends Disposable implements ISessi
676703 }
677704 }
678705
679- private _handleSessionAdded ( summary : { resource : string ; provider : string ; title : string ; createdAt : number ; modifiedAt : number ; project ?: { uri : string ; displayName : string } ; workingDirectory ?: string ; isRead ?: boolean ; isDone ?: boolean } ) : void {
706+ private _handleSessionAdded ( summary : { resource : string ; provider : string ; title : string ; createdAt : number ; modifiedAt : number ; project ?: { uri : string ; displayName : string } ; model ?: string ; workingDirectory ?: string ; isRead ?: boolean ; isDone ?: boolean } ) : void {
680707 const sessionUri = URI . parse ( summary . resource ) ;
681708 const rawId = AgentSession . id ( sessionUri ) ;
682709 if ( this . _sessionCache . has ( rawId ) ) {
@@ -692,6 +719,7 @@ export class LocalAgentHostSessionsProvider extends Disposable implements ISessi
692719 modifiedTime : summary . modifiedAt ,
693720 summary : summary . title ,
694721 ...( summary . project ? { project : { uri : URI . parse ( summary . project . uri ) , displayName : summary . project . displayName } } : { } ) ,
722+ model : summary . model ,
695723 workingDirectory : workingDir ,
696724 isRead : summary . isRead ,
697725 isDone : summary . isDone ,
@@ -725,6 +753,16 @@ export class LocalAgentHostSessionsProvider extends Disposable implements ISessi
725753 }
726754 }
727755
756+ private _handleModelChanged ( session : string , model : string ) : void {
757+ const rawId = AgentSession . id ( session ) ;
758+ const cached = this . _sessionCache . get ( rawId ) ;
759+ const modelId = cached ? `${ cached . sessionType } :${ model } ` : undefined ;
760+ if ( cached && cached . modelId . get ( ) !== modelId ) {
761+ cached . modelId . set ( modelId , undefined ) ;
762+ this . _onDidChangeSessions . fire ( { added : [ ] , removed : [ ] , changed : [ cached ] } ) ;
763+ }
764+ }
765+
728766 private _handleIsReadChanged ( session : string , isRead : boolean ) : void {
729767 const rawId = AgentSession . id ( session ) ;
730768 const cached = this . _sessionCache . get ( rawId ) ;
0 commit comments