@@ -400,7 +400,9 @@ const decodeLegacyProviderSettingsJsonExit = Schema.decodeUnknownExit(LegacyProv
400400
401401// Drivers that start disabled, so a session in the history means the user
402402// turned them on before the instance kept an explicit flag.
403- const HISTORY_RESTORED_DRIVERS = [ "cursor" , "grok" , "opencode" ] as const ;
403+ const HISTORY_RESTORED_DRIVERS : ReadonlySet < ProviderDriverKind > = new Set (
404+ [ "cursor" , "grok" , "opencode" ] . map ( ( driver ) => ProviderDriverKind . make ( driver ) ) ,
405+ ) ;
404406
405407/**
406408 * Move each customized legacy `providers.<kind>` blob into the driver's
@@ -421,25 +423,25 @@ function migrateLegacyProviderSettings(
421423 readonly providerInstanceId : string | null ;
422424 } > ,
423425) : ServerSettings {
424- const usedProviders = new Set ( providerHistory . map ( ( { providerName } ) => providerName ) ) ;
425- const usedProviderInstances = new Set (
426+ // History rows are raw SQL text; compare them as strings.
427+ const usedProviders = new Set < string > ( providerHistory . map ( ( { providerName } ) => providerName ) ) ;
428+ const usedProviderInstances = new Set < string > (
426429 providerHistory . map (
427430 ( { providerName, providerInstanceId } ) => providerInstanceId ?? providerName ,
428431 ) ,
429432 ) ;
430- const isHistoryRestored = ( driver : string ) =>
431- ( HISTORY_RESTORED_DRIVERS as ReadonlyArray < string > ) . includes ( driver ) ;
432433
433- const providerInstances : Record < string , ProviderInstanceConfig > = Object . fromEntries (
434- Object . entries ( settings . providerInstances ) . map ( ( [ instanceId , instance ] ) => [
435- instanceId ,
434+ const providerInstances : Record < ProviderInstanceId , ProviderInstanceConfig > = { } ;
435+ for ( const [ instanceId , instance ] of Object . entries ( settings . providerInstances ) as Array <
436+ [ ProviderInstanceId , ProviderInstanceConfig ]
437+ > ) {
438+ providerInstances [ instanceId ] =
436439 instance . enabled === undefined &&
437- isHistoryRestored ( instance . driver ) &&
440+ HISTORY_RESTORED_DRIVERS . has ( instance . driver ) &&
438441 usedProviderInstances . has ( instanceId )
439442 ? { ...instance , enabled : true }
440- : instance ,
441- ] ) ,
442- ) ;
443+ : instance ;
444+ }
443445
444446 // History restores a never-configured cursor/grok/opencode slot too.
445447 const legacyEntries = new Map ( Object . entries ( legacyProviders ) ) ;
@@ -457,7 +459,7 @@ function migrateLegacyProviderSettings(
457459 const explicitEnabled = typeof rawEnabled === "boolean" ? rawEnabled : undefined ;
458460 const enabled =
459461 explicitEnabled ??
460- ( isHistoryRestored ( driver ) && usedProviders . has ( driver ) ? true : undefined ) ;
462+ ( HISTORY_RESTORED_DRIVERS . has ( driver ) && usedProviders . has ( driver ) ? true : undefined ) ;
461463 const driverDefault = resolveProviderInstanceEnabled ( { driver, config : { } } ) ;
462464 if ( Object . keys ( config ) . length === 0 && ( enabled === undefined || enabled === driverDefault ) ) {
463465 continue ;
@@ -471,7 +473,7 @@ function migrateLegacyProviderSettings(
471473
472474 return {
473475 ...settings ,
474- providerInstances : providerInstances as ServerSettings [ "providerInstances" ] ,
476+ providerInstances,
475477 } ;
476478}
477479
0 commit comments