@@ -60,6 +60,19 @@ const CLAUDE_WINDOW_LABELS: Record<string, string> = {
6060 overage : "Overage" ,
6161} ;
6262
63+ function statusFromWindows (
64+ windows : ReadonlyArray < RateLimitWindow > ,
65+ ) : ProviderUsageSnapshot [ "status" ] {
66+ const maxPercent = Math . max ( ...windows . map ( ( window ) => window . usedPercent ) , 0 ) ;
67+ if ( maxPercent >= 90 ) {
68+ return "rejected" ;
69+ }
70+ if ( maxPercent >= 70 ) {
71+ return "warning" ;
72+ }
73+ return "ok" ;
74+ }
75+
6376function normalizeClaudeRateLimitEvent (
6477 payload : Record < string , unknown > ,
6578) : Omit < ProviderUsageSnapshot , "updatedAt" > | null {
@@ -103,13 +116,10 @@ function normalizeClaudeRateLimitEvent(
103116 return null ;
104117 }
105118
106- const status : ProviderUsageSnapshot [ "status" ] =
107- statusRaw === "rejected" ? "rejected" : statusRaw === "allowed_warning" ? "warning" : "ok" ;
108-
109119 return {
110120 providerLabel : "Claude" ,
111121 windows,
112- status,
122+ status : statusFromWindows ( windows ) ,
113123 } ;
114124}
115125
@@ -189,14 +199,10 @@ function normalizeCodexRateLimits(
189199 return null ;
190200 }
191201
192- const maxPercent = Math . max ( ...windows . map ( ( w ) => w . usedPercent ) ) ;
193- const status : ProviderUsageSnapshot [ "status" ] =
194- maxPercent >= 100 ? "rejected" : maxPercent >= 80 ? "warning" : "ok" ;
195-
196202 return {
197203 providerLabel : "Codex" ,
198204 windows,
199- status,
205+ status : statusFromWindows ( windows ) ,
200206 } ;
201207}
202208
@@ -257,7 +263,6 @@ export function deriveLatestProviderUsageSnapshot(
257263) : ProviderUsageSnapshot | null {
258264 const windowsByLabel = new Map < string , RateLimitWindow > ( ) ;
259265 let providerLabel : string | null = null ;
260- let latestStatus : ProviderUsageSnapshot [ "status" ] = "ok" ;
261266 let latestUpdatedAt : string | null = null ;
262267
263268 // Walk backwards so the first match for each label wins (most recent).
@@ -274,7 +279,6 @@ export function deriveLatestProviderUsageSnapshot(
274279
275280 if ( providerLabel === null ) {
276281 providerLabel = result . providerLabel ;
277- latestStatus = result . status ;
278282 latestUpdatedAt = activity . createdAt ;
279283 }
280284
@@ -288,23 +292,18 @@ export function deriveLatestProviderUsageSnapshot(
288292 windowsByLabel . set ( window . label , window ) ;
289293 }
290294 }
291-
292- // Escalate status if a worse status was seen in an older event.
293- if ( result . status === "rejected" ) {
294- latestStatus = "rejected" ;
295- } else if ( result . status === "warning" && latestStatus === "ok" ) {
296- latestStatus = "warning" ;
297- }
298295 }
299296
300297 if ( providerLabel === null || windowsByLabel . size === 0 || latestUpdatedAt === null ) {
301298 return null ;
302299 }
303300
301+ const windows = Array . from ( windowsByLabel . values ( ) ) ;
302+
304303 return {
305304 providerLabel,
306- windows : Array . from ( windowsByLabel . values ( ) ) ,
307- status : latestStatus ,
305+ windows,
306+ status : statusFromWindows ( windows ) ,
308307 updatedAt : latestUpdatedAt ,
309308 } ;
310309}
0 commit comments