@@ -1177,10 +1177,14 @@ export function deriveEffectiveComposerModelState(input: {
11771177 } ) ;
11781178 const draftOptions = optionsFrom ( input . draft ?. modelSelectionByProvider ?? null ) ;
11791179 const storedSelection = input . threadModelSelection ?? input . projectModelSelection ;
1180+ const storedIsShownModel =
1181+ storedSelection != null &&
1182+ isSameModel ( input , storedSelection , {
1183+ instanceId : input . selectedInstanceId ?? storedSelection . instanceId ,
1184+ model : selectedModel ,
1185+ } ) ;
11801186 const storedOptions = optionsFrom (
1181- draftOptions === null || storedSelection ?. model === selectedModel
1182- ? selectionsByInstance ( storedSelection )
1183- : null ,
1187+ draftOptions === null || storedIsShownModel ? selectionsByInstance ( storedSelection ) : null ,
11841188 ) ;
11851189
11861190 return {
@@ -1218,9 +1222,36 @@ function withFallbackInstanceOptions(input: {
12181222 const requestedProvider = input . providers . find (
12191223 ( provider ) => provider . instanceId === requestedInstanceId ,
12201224 ) ;
1221- const requestedModel = input . optionSelections ?. [ requestedInstanceId ] ?. model ;
1225+ const sameModel = isSameModel (
1226+ input ,
1227+ {
1228+ instanceId : requestedInstanceId ,
1229+ model : input . optionSelections ?. [ requestedInstanceId ] ?. model ,
1230+ } ,
1231+ { instanceId : selectedInstanceId , model : input . selectedModel } ,
1232+ ) ;
1233+ if ( ! requestedOptions || requestedProvider ?. driver !== input . selectedProvider || ! sameModel ) {
1234+ return modelOptions ;
1235+ }
1236+ return { ...modelOptions , [ selectedInstanceId ] : requestedOptions } ;
1237+ }
1238+
1239+ interface InstanceModel {
1240+ readonly instanceId : ProviderInstanceId ;
1241+ readonly model : string | undefined ;
1242+ }
1243+
1244+ function isSameModel (
1245+ input : {
1246+ readonly providers : ReadonlyArray < ServerProvider > ;
1247+ readonly selectedProvider : ProviderDriverKind ;
1248+ readonly settings : UnifiedSettings ;
1249+ } ,
1250+ a : InstanceModel ,
1251+ b : InstanceModel ,
1252+ ) : boolean {
12221253 // Static aliases are shared across instances; exact custom slugs and catalog aliases are not.
1223- const modelIdentity = ( instanceId : ProviderInstanceId , model : string | undefined ) => {
1254+ const modelIdentity = ( { instanceId , model } : InstanceModel ) => {
12241255 const isCustom =
12251256 input . providers
12261257 . find ( ( provider ) => provider . instanceId === instanceId )
@@ -1230,14 +1261,7 @@ function withFallbackInstanceOptions(input: {
12301261 ) ;
12311262 return isCustom ? model : normalizeModelSlug ( model , input . selectedProvider ) ;
12321263 } ;
1233- const sameModel =
1234- requestedModel === input . selectedModel ||
1235- modelIdentity ( requestedInstanceId , requestedModel ) ===
1236- modelIdentity ( selectedInstanceId , input . selectedModel ) ;
1237- if ( ! requestedOptions || requestedProvider ?. driver !== input . selectedProvider || ! sameModel ) {
1238- return modelOptions ;
1239- }
1240- return { ...modelOptions , [ selectedInstanceId ] : requestedOptions } ;
1264+ return a . model === b . model || modelIdentity ( a ) === modelIdentity ( b ) ;
12411265}
12421266
12431267function revokeObjectPreviewUrl ( previewUrl : string ) : void {
0 commit comments