@@ -270,7 +270,7 @@ function collectUsageCandidates(root: Record<string, unknown>): Record<string, u
270270function deriveWindowLabelFromTimestamps ( record : Record < string , unknown > ) : string | undefined {
271271 const startTime = parseEpoch ( record . start_time ?? record . startTime ) ;
272272 const endTime = parseEpoch ( record . end_time ?? record . endTime ) ;
273- if ( startTime && endTime && endTime > startTime ) {
273+ if ( startTime !== undefined && endTime !== undefined && endTime > startTime ) {
274274 const durationHours = ( endTime - startTime ) / 3_600_000 ;
275275 if ( durationHours >= 1 && Number . isFinite ( durationHours ) ) {
276276 const rounded = Math . round ( durationHours ) ;
@@ -336,15 +336,10 @@ function deriveUsedPercent(payload: Record<string, unknown>): number | null {
336336 return null ;
337337}
338338
339- /**
340- * When the API returns a `model_remains` array, prefer the entry whose
341- * `model_name` matches a chat/text model (e.g. "MiniMax-M*") and that has
342- * a non-zero `current_interval_total_count`. Models with total_count === 0
343- * (speech, video, image) are not relevant to the coding-plan budget.
344- */
345- function pickChatModelRemains (
346- modelRemains : unknown [ ] ,
347- ) : Record < string , unknown > | undefined {
339+ // Prefer the entry whose model_name matches a chat/text model (e.g. "MiniMax-M*")
340+ // and that has a non-zero current_interval_total_count. Models with total_count === 0
341+ // (speech, video, image) are not relevant to the coding-plan budget.
342+ function pickChatModelRemains ( modelRemains : unknown [ ] ) : Record < string , unknown > | undefined {
348343 const records = modelRemains . filter ( isRecord ) ;
349344 if ( records . length === 0 ) {
350345 return undefined ;
@@ -354,7 +349,7 @@ function pickChatModelRemains(
354349 const name = typeof r . model_name === "string" ? r . model_name : "" ;
355350 const total = parseFiniteNumber ( r . current_interval_total_count ) ;
356351 return (
357- ( name . toLowerCase ( ) . startsWith ( "minimax-m" ) || name === "MiniMax-M* ") &&
352+ name . toLowerCase ( ) . startsWith ( "minimax-m" ) &&
358353 total !== undefined &&
359354 total > 0
360355 ) ;
@@ -424,8 +419,9 @@ export async function fetchMinimaxUsage(
424419 const modelRemains = Array . isArray ( payload . model_remains ) ? payload . model_remains : null ;
425420 const chatRemains = modelRemains ? pickChatModelRemains ( modelRemains ) : undefined ;
426421
427- const candidates = collectUsageCandidates ( chatRemains ?? payload ) ;
428- let usageRecord : Record < string , unknown > = chatRemains ?? payload ;
422+ const usageSource = chatRemains ?? payload ;
423+ const candidates = collectUsageCandidates ( usageSource ) ;
424+ let usageRecord : Record < string , unknown > = usageSource ;
429425 let usedPercent : number | null = null ;
430426 for ( const candidate of candidates ) {
431427 const candidatePercent = deriveUsedPercent ( candidate ) ;
@@ -436,7 +432,7 @@ export async function fetchMinimaxUsage(
436432 }
437433 }
438434 if ( usedPercent === null ) {
439- usedPercent = deriveUsedPercent ( chatRemains ?? payload ) ;
435+ usedPercent = deriveUsedPercent ( usageSource ) ;
440436 }
441437 if ( usedPercent === null ) {
442438 return {
@@ -452,9 +448,12 @@ export async function fetchMinimaxUsage(
452448 parseEpoch ( pickNumber ( usageRecord , RESET_KEYS ) ) ??
453449 parseEpoch ( pickString ( payload , RESET_KEYS ) ) ??
454450 parseEpoch ( pickNumber ( payload , RESET_KEYS ) ) ;
451+ const windowLabel = chatRemains
452+ ? deriveWindowLabel ( chatRemains )
453+ : deriveWindowLabel ( usageRecord ) ;
455454 const windows : UsageWindow [ ] = [
456455 {
457- label : deriveWindowLabel ( usageRecord ) ,
456+ label : windowLabel ,
458457 usedPercent,
459458 resetAt,
460459 } ,
0 commit comments