@@ -78,7 +78,6 @@ function printTable(
7878 typeMap : Map < string , string > ,
7979 noColor : boolean ,
8080) : void {
81- const headersCn = [ "模型" , "类型" , "剩余/总量" , "使用率" , "过期时间" , "用完即停" ] ;
8281 const headersEn = [ "Model" , "Type" , "Remaining/Total" , "Usage" , "Expires" , "Auto-Stop" ] ;
8382
8483 const rows = quotas . map ( ( quota ) => {
@@ -102,25 +101,19 @@ function printTable(
102101 ] ;
103102 } ) ;
104103
105- const widths = headersCn . map ( ( label , col ) =>
106- Math . max (
107- displayWidth ( label ) ,
108- displayWidth ( headersEn [ col ] ) ,
109- ...rows . map ( ( row ) => displayWidth ( row [ col ] ) ) ,
110- ) ,
104+ const widths = headersEn . map ( ( label , col ) =>
105+ Math . max ( displayWidth ( label ) , ...rows . map ( ( row ) => displayWidth ( row [ col ] ) ) ) ,
111106 ) ;
112107
113108 const dim = noColor ? ( text : string ) => text : ( text : string ) => `\x1b[2m${ text } \x1b[0m` ;
114109 const bold = noColor ? ( text : string ) => text : ( text : string ) => `\x1b[1m${ text } \x1b[0m` ;
115110 const green = noColor ? ( text : string ) => text : ( text : string ) => `\x1b[32m${ text } \x1b[0m` ;
116111 const yellow = noColor ? ( text : string ) => text : ( text : string ) => `\x1b[33m${ text } \x1b[0m` ;
117112
118- const autoStopCol = headersCn . length - 1 ;
119- const cnLine = headersCn . map ( ( label , col ) => bold ( padEnd ( label , widths [ col ] ) ) ) . join ( " " ) ;
120- const enLine = headersEn . map ( ( label , col ) => dim ( padEnd ( label , widths [ col ] ) ) ) . join ( " " ) ;
113+ const autoStopCol = headersEn . length - 1 ;
114+ const enLine = headersEn . map ( ( label , col ) => bold ( padEnd ( label , widths [ col ] ) ) ) . join ( " " ) ;
121115 const separator = widths . map ( ( width ) => dim ( "─" . repeat ( width ) ) ) . join ( "──" ) ;
122116
123- process . stdout . write ( cnLine + "\n" ) ;
124117 process . stdout . write ( enLine + "\n" ) ;
125118 process . stdout . write ( separator + "\n" ) ;
126119
@@ -296,11 +289,6 @@ export default defineCommand({
296289 } ) ,
297290 ] ) ;
298291
299- if ( format === "json" ) {
300- emitResult ( quotaResult , format ) ;
301- return ;
302- }
303-
304292 const allQuotas = extractQuotas ( quotaResult ) ;
305293 let quotas = modelFlag
306294 ? allQuotas
@@ -321,14 +309,44 @@ export default defineCommand({
321309 quotas . sort ( ( a , b ) => ( a . quotaValidityPeriod ?? 0 ) - ( b . quotaValidityPeriod ?? 0 ) ) ;
322310 }
323311
312+ const stopStatuses = extractFreeTierOnlyStatuses ( stopResult ) ;
313+ const stopMap = new Map ( stopStatuses . map ( ( status ) => [ status . model , status . freeTierOnly ] ) ) ;
314+
315+ if ( format === "json" ) {
316+ const items = quotas . map ( ( quota ) => {
317+ const hasQuota = quota . quotaInitTotal != null && quota . quotaTotal != null ;
318+ const used = hasQuota ? quota . quotaInitTotal - quota . quotaTotal : 0 ;
319+ const stopStatus = stopMap . get ( quota . model ) ;
320+ const autoStop =
321+ quota . quotaStatus === "UNKNOWN"
322+ ? "unsupported"
323+ : stopStatus === true
324+ ? true
325+ : stopStatus === false
326+ ? false
327+ : null ;
328+ return {
329+ model : quota . model ,
330+ type : typeMap . get ( quota . model ) || null ,
331+ remaining : hasQuota ? quota . quotaTotal : null ,
332+ total : hasQuota ? quota . quotaInitTotal : null ,
333+ usagePercent :
334+ hasQuota && quota . quotaInitTotal > 0
335+ ? Math . round ( ( used / quota . quotaInitTotal ) * 1000 ) / 10
336+ : null ,
337+ expires : quota . quotaValidityPeriod ? formatDate ( quota . quotaValidityPeriod ) : null ,
338+ autoStop,
339+ } ;
340+ } ) ;
341+ emitResult ( items , format ) ;
342+ return ;
343+ }
344+
324345 if ( quotas . length === 0 ) {
325346 process . stdout . write ( "No free-tier quota found.\n" ) ;
326347 return ;
327348 }
328349
329- const stopStatuses = extractFreeTierOnlyStatuses ( stopResult ) ;
330- const stopMap = new Map ( stopStatuses . map ( ( status ) => [ status . model , status . freeTierOnly ] ) ) ;
331-
332350 printTable ( quotas , stopMap , typeMap , config . noColor ) ;
333351 } ,
334352} ) ;
0 commit comments