Skip to content

Commit 8cb24b7

Browse files
committed
feat: merge main
1 parent b01d35c commit 8cb24b7

6 files changed

Lines changed: 48 additions & 32 deletions

File tree

packages/cli/src/commands/quota/history.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ export default defineCommand({
127127
const region = (flags.region as string) || "cn-beijing";
128128
const format = detectOutputFormat(config.output);
129129

130-
const credential = await resolveConsoleGatewayCredential(config);
131-
132130
const requestData = {
133131
input: { pageNo: page, pageSize },
134132
};
@@ -138,6 +136,8 @@ export default defineCommand({
138136
return;
139137
}
140138

139+
const credential = await resolveConsoleGatewayCredential(config);
140+
141141
let result: unknown;
142142
try {
143143
result = await callConsoleGateway(config, credential.token, {

packages/cli/src/commands/quota/list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ export default defineCommand({
183183
const region = (flags.region as string) || "cn-beijing";
184184
const format = detectOutputFormat(config.output);
185185

186-
const credential = await resolveConsoleGatewayCredential(config);
187-
188186
if (config.dryRun) {
189187
const input: Record<string, unknown> = {
190188
pageNo: 1,
@@ -198,6 +196,8 @@ export default defineCommand({
198196
return;
199197
}
200198

199+
const credential = await resolveConsoleGatewayCredential(config);
200+
201201
let models = await fetchAllModelsWithQpm(config, credential.token, region, !showAll);
202202

203203
if (modelFlag) {

packages/cli/src/commands/quota/request.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ export default defineCommand({
126126
const region = (flags.region as string) || "cn-beijing";
127127
const format = detectOutputFormat(config.output);
128128

129+
if (config.dryRun) {
130+
const requestData = {
131+
input: {
132+
model: modelName,
133+
limit: { usage_limit: tpmValue },
134+
},
135+
};
136+
emitResult({ api: UPDATE_LIMITS_API, data: requestData, region }, format);
137+
return;
138+
}
139+
129140
const credential = await resolveConsoleGatewayCredential(config);
130141

131142
const modelInfo = await fetchModelQpmInfo(config, credential.token, region, modelName);
@@ -160,11 +171,6 @@ export default defineCommand({
160171
} as Record<string, unknown>,
161172
};
162173

163-
if (config.dryRun) {
164-
emitResult({ api: UPDATE_LIMITS_API, data: requestData, region }, format);
165-
return;
166-
}
167-
168174
const submitRequest = async (confirmedDowngrade?: boolean): Promise<unknown> => {
169175
if (confirmedDowngrade) {
170176
requestData.input.confirmedDowngrade = true;

packages/cli/src/commands/usage/free.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,6 @@ export default defineCommand({
229229
const region = (flags.region as string) || "cn-beijing";
230230
const format = detectOutputFormat(config.output);
231231

232-
const credential = await resolveConsoleGatewayCredential(config);
233-
234232
let models: string[];
235233
const typeMap = new Map<string, string>();
236234

@@ -243,21 +241,8 @@ export default defineCommand({
243241
.filter(Boolean),
244242
),
245243
];
246-
const searchResults = await Promise.all(
247-
models.map((name) => fetchModelList(config, credential.token, { name, pageSize: 50 })),
248-
);
249-
for (let idx = 0; idx < models.length; idx++) {
250-
const matched = searchResults[idx].models.find((item) => item.model === models[idx]);
251-
if (matched) {
252-
typeMap.set(models[idx], resolveModelType((matched.capabilities as string[]) || []));
253-
}
254-
}
255244
} else {
256-
const modelInfos = await fetchAllModels(config, credential.token);
257-
models = modelInfos.map((info) => info.name);
258-
for (const info of modelInfos) {
259-
typeMap.set(info.name, info.type);
260-
}
245+
models = [];
261246
}
262247

263248
const requestData = {
@@ -270,13 +255,33 @@ export default defineCommand({
270255
api: FREE_TIER_API,
271256
data: requestData,
272257
region,
273-
token: credential.token.slice(0, 8) + "...",
274258
},
275259
format,
276260
);
277261
return;
278262
}
279263

264+
const credential = await resolveConsoleGatewayCredential(config);
265+
266+
if (!modelFlag) {
267+
const modelInfos = await fetchAllModels(config, credential.token);
268+
models = modelInfos.map((info) => info.name);
269+
for (const info of modelInfos) {
270+
typeMap.set(info.name, info.type);
271+
}
272+
requestData.queryFreeTierQuotaRequest.models = models;
273+
} else {
274+
const searchResults = await Promise.all(
275+
models.map((name) => fetchModelList(config, credential.token, { name, pageSize: 50 })),
276+
);
277+
for (let idx = 0; idx < models.length; idx++) {
278+
const matched = searchResults[idx].models.find((item) => item.model === models[idx]);
279+
if (matched) {
280+
typeMap.set(models[idx], resolveModelType((matched.capabilities as string[]) || []));
281+
}
282+
}
283+
}
284+
280285
const [quotaResult, stopResult] = await Promise.all([
281286
callConsoleGateway(config, credential.token, {
282287
api: FREE_TIER_API,

packages/cli/src/commands/usage/freetier.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ export default defineCommand({
151151
process.exit(1);
152152
}
153153

154-
const credential = await resolveConsoleGatewayCredential(config);
155-
156154
let models: string[];
157155
if (modelFlag) {
158156
models = [
@@ -164,7 +162,7 @@ export default defineCommand({
164162
),
165163
];
166164
} else {
167-
models = await fetchAllModelNames(config, credential.token);
165+
models = [];
168166
}
169167

170168
const api = off ? DEACTIVATE_API : ACTIVATE_API;
@@ -178,13 +176,18 @@ export default defineCommand({
178176
api,
179177
data: { [requestKey]: { models } },
180178
region,
181-
token: credential.token.slice(0, 8) + "...",
182179
},
183180
format,
184181
);
185182
return;
186183
}
187184

185+
const credential = await resolveConsoleGatewayCredential(config);
186+
187+
if (!modelFlag) {
188+
models = await fetchAllModelNames(config, credential.token);
189+
}
190+
188191
if (off) {
189192
const [quotaResult, stopResult] = await Promise.all([
190193
callConsoleGateway(config, credential.token, {

packages/cli/src/commands/usage/stats.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,6 @@ export default defineCommand({
330330
const flagWorkspaceId = (flags.workspaceId as string) || undefined;
331331
const workspaceId = resolveWorkspaceId(config, flagWorkspaceId);
332332

333-
const credential = await resolveConsoleGatewayCredential(config);
334-
335333
const endTime = Date.now();
336334
const startTime = endTime - daysFlag * 24 * 60 * 60 * 1000;
337335

@@ -365,6 +363,8 @@ export default defineCommand({
365363
return;
366364
}
367365

366+
const credential = await resolveConsoleGatewayCredential(config);
367+
368368
const results = await Promise.all(
369369
models.map((model) =>
370370
pollTelemetryApi(config, credential.token, LIST_API, { ...baseReqDTO, model }, region),
@@ -415,6 +415,8 @@ export default defineCommand({
415415
return;
416416
}
417417

418+
const credential = await resolveConsoleGatewayCredential(config);
419+
418420
const result = await pollTelemetryApi(config, credential.token, OVERVIEW_API, reqDTO, region);
419421
if (!result) {
420422
process.stderr.write("Error: request timed out.\n");

0 commit comments

Comments
 (0)