@@ -2,12 +2,15 @@ import { defineCommand } from '../../command';
22import { resolveCredential } from '../../auth/resolver' ;
33import { loadCredentials } from '../../auth/credentials' ;
44import { formatOutput , detectOutputFormat } from '../../output/formatter' ;
5+ import { requestJson } from '../../client/http' ;
6+ import { quotaEndpoint } from '../../client/endpoints' ;
57import type { Config } from '../../config/schema' ;
68import type { GlobalFlags } from '../../types/flags' ;
9+ import type { QuotaResponse } from '../../types/api' ;
710
811export default defineCommand ( {
912 name : 'auth status' ,
10- description : 'Show current authentication state' ,
13+ description : 'Show current authentication state and quota snapshot ' ,
1114 usage : 'minimax auth status' ,
1215 examples : [
1316 'minimax auth status' ,
@@ -18,26 +21,71 @@ export default defineCommand({
1821 const credential = await resolveCredential ( config ) ;
1922 const format = detectOutputFormat ( config . output ) ;
2023
21- const result : Record < string , unknown > = {
22- method : credential . method ,
23- source : credential . source ,
24- } ;
24+ if ( format !== 'text' ) {
25+ const result : Record < string , unknown > = {
26+ method : credential . method ,
27+ source : credential . source ,
28+ } ;
29+ if ( credential . method === 'oauth' ) {
30+ const creds = await loadCredentials ( ) ;
31+ if ( creds ) {
32+ result . token_expires = creds . expires_at ;
33+ if ( creds . account ) result . account = creds . account ;
34+ }
35+ } else {
36+ result . key = credential . token . slice ( 0 , 6 ) + '...' + credential . token . slice ( - 4 ) ;
37+ }
38+ console . log ( formatOutput ( result , format ) ) ;
39+ return ;
40+ }
41+
42+ // Text format — rich output
43+ console . log ( 'Authentication Status:' ) ;
44+ console . log ( ` Method: ${ credential . method } ` ) ;
45+ console . log ( ` Source: ${ credential . source } ` ) ;
46+
47+ const token = credential . token ;
48+ const maskedToken = token . length > 8 ? `${ token . slice ( 0 , 4 ) } ...${ token . slice ( - 4 ) } ` : '***' ;
49+ console . log ( ` Key: ${ maskedToken } ` ) ;
2550
2651 if ( credential . method === 'oauth' ) {
2752 const creds = await loadCredentials ( ) ;
2853 if ( creds ) {
29- result . token_expires = creds . expires_at ;
30- if ( creds . account ) result . account = creds . account ;
54+ if ( creds . account ) console . log ( ` Account: ${ creds . account } ` ) ;
3155 const expiresAt = new Date ( creds . expires_at ) ;
3256 const minutesLeft = Math . round ( ( expiresAt . getTime ( ) - Date . now ( ) ) / 60000 ) ;
33- result . expires_in = ` ${ minutesLeft } minutes`;
57+ console . log ( ` Expires in: ${ minutesLeft } minutes`) ;
3458 }
35- result . credentials_path = '~/.minimax/credentials.json' ;
36- } else {
37- result . key = credential . token . slice ( 0 , 6 ) + '...' + credential . token . slice ( - 4 ) ;
3859 }
3960
40- console . log ( formatOutput ( result , format ) ) ;
61+ // Fetch quota snapshot
62+ console . log ( '' ) ;
63+ process . stderr . write ( 'Fetching quota snapshot...\n' ) ;
64+ try {
65+ const url = quotaEndpoint ( config . baseUrl ) ;
66+ const quota = await requestJson < QuotaResponse > ( config , { url, method : 'GET' } ) ;
67+ const models = quota . model_remains || [ ] ;
68+ if ( models . length > 0 ) {
69+ console . log ( 'Available Quotas:' ) ;
70+ for ( const m of models . slice ( 0 , 5 ) ) {
71+ const remaining = m . current_interval_total_count - m . current_interval_usage_count ;
72+ const pct = m . current_interval_total_count > 0
73+ ? Math . round ( ( remaining / m . current_interval_total_count ) * 100 )
74+ : 0 ;
75+ console . log ( ` ${ m . model_name . padEnd ( 24 ) } ${ String ( remaining ) . padStart ( 6 ) } / ${ m . current_interval_total_count } (${ pct } %)` ) ;
76+ }
77+ if ( models . length > 5 ) {
78+ console . log ( ` ... and ${ models . length - 5 } more (run 'minimax quota show' for full details)` ) ;
79+ }
80+ } else {
81+ console . log ( ' No quota data available.' ) ;
82+ }
83+ } catch ( e ) {
84+ console . log ( ` Quota fetch failed: ${ ( e as Error ) . message } ` ) ;
85+ }
86+ console . log ( '' ) ;
87+ console . log ( "Run 'minimax quota show' for full details." ) ;
88+
4189 } catch {
4290 const format = detectOutputFormat ( config . output ) ;
4391 const result = {
0 commit comments