1- import { defineCommand , BailianError , detectOutputFormat , type Client } from "bailian-cli-core" ;
1+ import {
2+ defineCommand ,
3+ BailianError ,
4+ ExitCode ,
5+ detectOutputFormat ,
6+ unwrapResponse ,
7+ MODEL_LIST_API ,
8+ type Client ,
9+ } from "bailian-cli-core" ;
210import { emitResult , renderBoxTable } from "bailian-cli-runtime" ;
311
4- const MODEL_LIST_API = "zeldaHttp.dashscopeModel./zelda/api/v1/modelCenter/listFoundationModels" ;
512const MONITOR_API = "zeldaEasy.bailian-telemetry.monitor.getMonitorData" ;
613
714interface QpmInfoItem {
@@ -72,7 +79,7 @@ async function fetchMonitorData(
7279 } ,
7380 } ) ;
7481
75- const resp = extractResponseData ( raw as Record < string , unknown > ) ;
82+ const resp = unwrapResponse ( raw as Record < string , unknown > ) ;
7683 const metrics = ( resp . data ?? resp ) as MonitorMetric [ ] | Record < string , unknown > ;
7784 if ( ! Array . isArray ( metrics ) ) {
7885 return { rpm : 0 , tpm : 0 } ;
@@ -90,37 +97,15 @@ async function fetchMonitorData(
9097
9198 return { rpm, tpm } ;
9299 } catch ( error ) {
93- // Re-throw console authentication errors, but catch other errors
94- if ( error instanceof Error && error . message ?. includes ( "Console session" ) ) {
100+ // Re-throw authentication errors (BailianError with ExitCode.AUTH);
101+ // other errors are treated as "no data" and show "-" in the table.
102+ if ( error instanceof BailianError && error . exitCode === ExitCode . AUTH ) {
95103 throw error ;
96104 }
97- // Return -1 to indicate no data (same as check.ts for consistency)
98105 return { rpm : - 1 , tpm : - 1 } ;
99106 }
100107}
101108
102- function getNestedRecord (
103- obj : Record < string , unknown > ,
104- key : string ,
105- ) : Record < string , unknown > | undefined {
106- const val = obj [ key ] ;
107- if ( val && typeof val === "object" && ! Array . isArray ( val ) ) return val as Record < string , unknown > ;
108- return undefined ;
109- }
110-
111- function extractResponseData ( result : Record < string , unknown > ) : Record < string , unknown > {
112- const data = getNestedRecord ( result , "data" ) ;
113- if ( ! data ) return result ;
114- const dataV2 = getNestedRecord ( data , "DataV2" ) ;
115- if ( dataV2 ) {
116- const inner = getNestedRecord ( dataV2 , "data" ) ;
117- const innerData = inner ? getNestedRecord ( inner , "data" ) : undefined ;
118- return innerData ?? inner ?? dataV2 ;
119- }
120- const direct = getNestedRecord ( data , "data" ) ;
121- return direct ?? data ;
122- }
123-
124109async function fetchAllModelsWithQpm ( client : Client ) : Promise < ModelWithQpm [ ] > {
125110 const allModels : ModelWithQpm [ ] = [ ] ;
126111 let pageNo = 1 ;
@@ -137,7 +122,7 @@ async function fetchAllModelsWithQpm(client: Client): Promise<ModelWithQpm[]> {
137122
138123 const raw = await client . console ( MODEL_LIST_API , { input } ) ;
139124
140- const resp = extractResponseData ( raw as Record < string , unknown > ) ;
125+ const resp = unwrapResponse ( raw as Record < string , unknown > ) ;
141126 const list = ( resp . list as ModelWithQpm [ ] ) ?? [ ] ;
142127 const total = ( resp . total as number ) ?? 0 ;
143128
@@ -153,7 +138,6 @@ interface ListRow {
153138 model : string ;
154139 rpm : string ;
155140 tpm : string ;
156- maxTpm : string ;
157141 rpmQuotaLeft : number | null ;
158142 tpmQuotaLeft : number | null ;
159143 rpmQuotaLabel : string | null ;
@@ -193,22 +177,11 @@ export default defineCommand({
193177 valueHint : "<model>" ,
194178 description : "Model name(s), comma-separated" ,
195179 } ,
196- all : {
197- type : "switch" ,
198- description : "Show all models, not just self-service ones" ,
199- } ,
200180 } ,
201- exampleArgs : [
202- "" ,
203- "--model qwen3.6-plus" ,
204- "--model qwen3.6-plus,qwen-turbo" ,
205- "--all" ,
206- "--output json" ,
207- ] ,
181+ exampleArgs : [ "" , "--model qwen3.6-plus" , "--model qwen3.6-plus,qwen-turbo" , "--output json" ] ,
208182 async run ( ctx ) {
209183 const { settings, flags } = ctx ;
210184 const modelFlag = flags . model || undefined ;
211- const showAll = Boolean ( flags . all ) ;
212185 const format = detectOutputFormat ( settings . output ) ;
213186
214187 if ( settings . dryRun ) {
@@ -218,9 +191,18 @@ export default defineCommand({
218191 group : false ,
219192 queryQpmInfo : true ,
220193 ignoreWorkspaceServiceSite : true ,
194+ supports : { selfServiceLimitIncrease : true } ,
221195 } ;
222- if ( ! showAll ) input . supports = { selfServiceLimitIncrease : true } ;
223- emitResult ( { api : MODEL_LIST_API , data : { input } } , format ) ;
196+ emitResult (
197+ {
198+ apis : [
199+ MODEL_LIST_API ,
200+ { api : MONITOR_API , note : "called per-model for text output with gauges" } ,
201+ ] ,
202+ modelListInput : { input } ,
203+ } ,
204+ format ,
205+ ) ;
224206 return ;
225207 }
226208
@@ -249,13 +231,11 @@ export default defineCommand({
249231 const defaultTPM = calculateTPM ( modelDefault ) ;
250232 const currentRPM = calculateRPM ( userSpec , modelDefault ?. count_limit_period ) || defaultRPM ;
251233 const currentTPM = calculateTPM ( userSpec , modelDefault ?. usage_limit_period ) || defaultTPM ;
252- const maxTPM = defaultTPM * 2 ;
253234
254235 return {
255236 model : m . model ,
256237 rpm : currentRPM > 0 ? currentRPM : null ,
257238 tpm : currentTPM > 0 ? currentTPM : null ,
258- maxTPM : maxTPM > 0 ? maxTPM : null ,
259239 } ;
260240 } ) ;
261241 emitResult ( items , format ) ;
@@ -276,7 +256,6 @@ export default defineCommand({
276256 const defaultTPM = calculateTPM ( modelDefault ) ;
277257 const currentRPM = calculateRPM ( userSpec , modelDefault ?. count_limit_period ) || defaultRPM ;
278258 const currentTPM = calculateTPM ( userSpec , modelDefault ?. usage_limit_period ) || defaultTPM ;
279- const maxTPM = defaultTPM * 2 ;
280259
281260 const rpmUsage = monitorResults [ idx ] . rpm ;
282261 const tpmUsage = monitorResults [ idx ] . tpm ;
@@ -301,7 +280,6 @@ export default defineCommand({
301280 model : m . model ,
302281 rpm : currentRPM > 0 ? formatNumber ( currentRPM ) : "-" ,
303282 tpm : currentTPM > 0 ? formatNumber ( currentTPM ) : "-" ,
304- maxTpm : maxTPM > 0 ? formatNumber ( maxTPM ) : "-" ,
305283 rpmQuotaLeft : rpmQuotaPercent ,
306284 tpmQuotaLeft : tpmQuotaPercent ,
307285 rpmQuotaLabel,
0 commit comments