@@ -1149,6 +1149,9 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
11491149 const persistedAccountIndicators = new Map < string , PersistedAccountIndicatorEntry > ( ) ;
11501150 let persistedAccountIndicatorRevision = 0 ;
11511151 let persistedAccountCountHint = 0 ;
1152+ let runtimePersistAccountFooter = false ;
1153+ let runtimePersistAccountFooterStyle : PersistAccountFooterStyle =
1154+ "label-masked-email" ;
11521155
11531156 const nextPersistedAccountIndicatorRevision = ( ) : number => {
11541157 persistedAccountIndicatorRevision += 1 ;
@@ -1191,17 +1194,25 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
11911194 accountCount : number ,
11921195 style : PersistAccountFooterStyle ,
11931196 revision : number = nextPersistedAccountIndicatorRevision ( ) ,
1197+ options ?: { preserveOrder ?: boolean } ,
11941198 ) : boolean => {
11951199 if ( ! sessionID ) return false ;
11961200 const existing = persistedAccountIndicators . get ( sessionID ) ;
11971201 if ( existing && existing . revision > revision ) {
11981202 return false ;
11991203 }
1200- persistedAccountIndicators . delete ( sessionID ) ;
1201- persistedAccountIndicators . set ( sessionID , {
1204+ const nextEntry = {
12021205 label : formatPersistedAccountIndicator ( account , index , accountCount , style ) ,
12031206 revision,
1204- } ) ;
1207+ } ;
1208+ if ( existing && options ?. preserveOrder ) {
1209+ persistedAccountIndicators . set ( sessionID , nextEntry ) ;
1210+ return true ;
1211+ }
1212+ if ( existing ) {
1213+ persistedAccountIndicators . delete ( sessionID ) ;
1214+ }
1215+ persistedAccountIndicators . set ( sessionID , nextEntry ) ;
12051216 trimPersistedAccountIndicators ( ) ;
12061217 return true ;
12071218 } ;
@@ -1223,6 +1234,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
12231234 accountCount ,
12241235 style ,
12251236 revision ,
1237+ { preserveOrder : true } ,
12261238 ) ;
12271239 }
12281240 return true ;
@@ -1393,8 +1405,17 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
13931405 } ) ;
13941406 } ;
13951407
1408+ const syncRuntimePluginConfig = (
1409+ pluginConfig : ReturnType < typeof loadPluginConfig > ,
1410+ ) : UiRuntimeOptions => {
1411+ runtimePersistAccountFooter = getPersistAccountFooter ( pluginConfig ) ;
1412+ runtimePersistAccountFooterStyle =
1413+ getPersistAccountFooterStyle ( pluginConfig ) ;
1414+ return applyUiRuntimeFromConfig ( pluginConfig ) ;
1415+ } ;
1416+
13961417 const resolveUiRuntime = ( ) : UiRuntimeOptions => {
1397- return applyUiRuntimeFromConfig ( loadPluginConfig ( ) ) ;
1418+ return syncRuntimePluginConfig ( loadPluginConfig ( ) ) ;
13981419 } ;
13991420
14001421 const getStatusMarker = (
@@ -1861,13 +1882,12 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
18611882 accountManagerPromise = Promise . resolve ( reloadedManager ) ;
18621883 }
18631884
1864- const pluginConfig = loadPluginConfig ( ) ;
1865- if ( getPersistAccountFooter ( pluginConfig ) ) {
1885+ if ( runtimePersistAccountFooter ) {
18661886 refreshVisiblePersistedAccountIndicators (
18671887 account ,
18681888 index ,
18691889 storage . accounts . length ,
1870- getPersistAccountFooterStyle ( pluginConfig ) ,
1890+ runtimePersistAccountFooterStyle ,
18711891 ) ;
18721892 } else {
18731893 await showToast ( `Switched to account ${ index + 1 } ` , "info" ) ;
@@ -1957,7 +1977,7 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
19571977 async loader ( getAuth : ( ) => Promise < Auth > , provider : unknown ) {
19581978 const auth = await getAuth ( ) ;
19591979 const pluginConfig = loadPluginConfig ( ) ;
1960- applyUiRuntimeFromConfig ( pluginConfig ) ;
1980+ syncRuntimePluginConfig ( pluginConfig ) ;
19611981 const perProjectAccounts = getPerProjectAccounts ( pluginConfig ) ;
19621982 setStoragePath ( perProjectAccounts ? process . cwd ( ) : null ) ;
19631983 const authFallback = auth . type === "oauth" ? ( auth as OAuthAuthDetails ) : undefined ;
@@ -2949,7 +2969,7 @@ while (attempted.size < Math.max(1, accountCount)) {
29492969 type : "oauth" as const ,
29502970 authorize : async ( inputs ?: Record < string , string > ) => {
29512971 const authPluginConfig = loadPluginConfig ( ) ;
2952- applyUiRuntimeFromConfig ( authPluginConfig ) ;
2972+ syncRuntimePluginConfig ( authPluginConfig ) ;
29532973 const authPerProjectAccounts = getPerProjectAccounts ( authPluginConfig ) ;
29542974 setStoragePath ( authPerProjectAccounts ? process . cwd ( ) : null ) ;
29552975
@@ -3924,7 +3944,7 @@ while (attempted.size < Math.max(1, accountCount)) {
39243944 // Initialize storage path for manual OAuth flow
39253945 // Must happen BEFORE persistAccountPool to ensure correct storage location
39263946 const manualPluginConfig = loadPluginConfig ( ) ;
3927- applyUiRuntimeFromConfig ( manualPluginConfig ) ;
3947+ syncRuntimePluginConfig ( manualPluginConfig ) ;
39283948 const manualPerProjectAccounts = getPerProjectAccounts ( manualPluginConfig ) ;
39293949 setStoragePath ( manualPerProjectAccounts ? process . cwd ( ) : null ) ;
39303950
0 commit comments