@@ -9,10 +9,10 @@ import {
99 isAuthCooldownBypassedForProvider ,
1010 isProfileInCooldown ,
1111 resolveProfileUnusableUntil ,
12- shouldBypassModelScopedCooldown ,
1312} from "./usage-state.js" ;
1413export {
1514 clearExpiredCooldowns ,
15+ getSoonestCooldownExpiry ,
1616 isProfileInCooldown ,
1717 resolveProfileUnusableUntil ,
1818} from "./usage-state.js" ;
@@ -309,54 +309,6 @@ export function resolveProfilesUnavailableReason(params: {
309309 return best ;
310310}
311311
312- /**
313- * Return the soonest `unusableUntil` timestamp (ms epoch) among the given
314- * profiles, or `null` when no profile has a recorded cooldown. Note: the
315- * returned timestamp may be in the past if the cooldown has already expired.
316- */
317- export function getSoonestCooldownExpiry (
318- store : AuthProfileStore ,
319- profileIds : string [ ] ,
320- options ?: { now ?: number ; forModel ?: string } ,
321- ) : number | null {
322- const ts = options ?. now ?? Date . now ( ) ;
323- let soonest : number | null = null ;
324- let latestMatchingModelCooldown : number | null = null ;
325- for ( const id of profileIds ) {
326- const stats = store . usageStats ?. [ id ] ;
327- if ( ! stats ) {
328- continue ;
329- }
330- if ( shouldBypassModelScopedCooldown ( stats , ts , options ?. forModel ) ) {
331- continue ;
332- }
333- const until = resolveProfileUnusableUntil ( stats ) ;
334- if ( typeof until !== "number" || ! Number . isFinite ( until ) || until <= 0 ) {
335- continue ;
336- }
337- const matchingModelScopedCooldown =
338- options ?. forModel &&
339- stats . cooldownReason === "rate_limit" &&
340- stats . cooldownModel === options . forModel &&
341- ! isActiveUnusableWindow ( stats . disabledUntil , ts ) ;
342- if ( matchingModelScopedCooldown ) {
343- latestMatchingModelCooldown =
344- latestMatchingModelCooldown === null ? until : Math . max ( latestMatchingModelCooldown , until ) ;
345- continue ;
346- }
347- if ( soonest === null || until < soonest ) {
348- soonest = until ;
349- }
350- }
351- if ( soonest === null ) {
352- return latestMatchingModelCooldown ;
353- }
354- if ( latestMatchingModelCooldown === null ) {
355- return soonest ;
356- }
357- return Math . min ( soonest , latestMatchingModelCooldown ) ;
358- }
359-
360312/**
361313 * Mark a profile as successfully used. Resets error count and updates lastUsed.
362314 * Uses store lock to avoid overwriting concurrent usage updates.
0 commit comments