@@ -160,6 +160,10 @@ import { applyFastSessionDefaults } from "./lib/request/request-transformer.js";
160160import { isEmptyResponse } from "./lib/request/response-handler.js" ;
161161import { withStreamingFailover } from "./lib/request/stream-failover.js" ;
162162import { addJitter } from "./lib/rotation.js" ;
163+ import {
164+ invalidateRuntimeAccountManagerCache ,
165+ reloadRuntimeAccountManager ,
166+ } from "./lib/runtime/account-manager-cache.js" ;
163167import { persistAccountPool } from "./lib/runtime/account-pool.js" ;
164168import { applyAccountStorageScope } from "./lib/runtime/account-scope.js" ;
165169import { handleAccountSelectEvent } from "./lib/runtime/account-select-event.js" ;
@@ -413,28 +417,33 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
413417 ) : string => getRuntimeStatusMarker ( ui , status ) ;
414418
415419 const invalidateAccountManagerCache = ( ) : void => {
416- cachedAccountManager = null ;
417- accountManagerPromise = null ;
420+ invalidateRuntimeAccountManagerCache ( {
421+ setCachedAccountManager : ( value ) => {
422+ cachedAccountManager = value as AccountManager | null ;
423+ } ,
424+ setAccountManagerPromise : ( value ) => {
425+ accountManagerPromise = value as Promise < AccountManager > | null ;
426+ } ,
427+ } ) ;
418428 } ;
419429
420430 const reloadAccountManagerFromDisk = async (
421431 authFallback ?: OAuthAuthDetails ,
422- ) : Promise < AccountManager > => {
423- if ( accountReloadInFlight ) {
424- return accountReloadInFlight ;
425- }
426- accountReloadInFlight = ( async ( ) => {
427- const reloaded = await AccountManager . loadFromDisk ( authFallback ) ;
428- cachedAccountManager = reloaded ;
429- accountManagerPromise = Promise . resolve ( reloaded ) ;
430- return reloaded ;
431- } ) ( ) ;
432- try {
433- return await accountReloadInFlight ;
434- } finally {
435- accountReloadInFlight = null ;
436- }
437- } ;
432+ ) : Promise < AccountManager > =>
433+ reloadRuntimeAccountManager < AccountManager > ( {
434+ currentReloadInFlight : accountReloadInFlight ,
435+ loadFromDisk : ( fallback ) => AccountManager . loadFromDisk ( fallback ) ,
436+ setCachedAccountManager : ( value ) => {
437+ cachedAccountManager = value ;
438+ } ,
439+ setAccountManagerPromise : ( value ) => {
440+ accountManagerPromise = value ;
441+ } ,
442+ setReloadInFlight : ( value ) => {
443+ accountReloadInFlight = value ;
444+ } ,
445+ authFallback,
446+ } ) ;
438447
439448 const applyStorageScope = (
440449 pluginConfig : ReturnType < typeof loadPluginConfig > ,
0 commit comments