Skip to content

Commit 14583cf

Browse files
committed
feat: update access token logic
1 parent e9feb38 commit 14583cf

7 files changed

Lines changed: 50 additions & 34 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,6 @@ export default defineCommand({
282282
const windowMinutes = rawPeriod;
283283
const format = detectOutputFormat(config.output);
284284

285-
const credential = await resolveConsoleGatewayCredential(config);
286-
287285
if (config.dryRun) {
288286
emitResult(
289287
{
@@ -295,6 +293,8 @@ export default defineCommand({
295293
return;
296294
}
297295

296+
const credential = await resolveConsoleGatewayCredential(config);
297+
298298
let models = await fetchAllModelsWithQpm(config, credential.token);
299299

300300
if (modelFlag) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ export default defineCommand({
138138
const modelFilter = (flags.model as string) || undefined;
139139
const format = detectOutputFormat(config.output);
140140

141-
const credential = await resolveConsoleGatewayCredential(config);
142-
143141
const requestData = {
144142
input: { pageNo: page, pageSize },
145143
};
@@ -149,6 +147,8 @@ export default defineCommand({
149147
return;
150148
}
151149

150+
const credential = await resolveConsoleGatewayCredential(config);
151+
152152
let result: unknown;
153153
try {
154154
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
@@ -192,8 +192,6 @@ export default defineCommand({
192192
const showAll = Boolean(flags.all);
193193
const format = detectOutputFormat(config.output);
194194

195-
const credential = await resolveConsoleGatewayCredential(config);
196-
197195
if (config.dryRun) {
198196
const input: Record<string, unknown> = {
199197
pageNo: 1,
@@ -207,6 +205,8 @@ export default defineCommand({
207205
return;
208206
}
209207

208+
const credential = await resolveConsoleGatewayCredential(config);
209+
210210
let models = await fetchAllModelsWithQpm(config, credential.token, !showAll);
211211

212212
if (modelFlag) {

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ export default defineCommand({
128128
const autoConfirm = Boolean(flags.yes) || config.yes;
129129
const format = detectOutputFormat(config.output);
130130

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

133144
const modelInfo = await fetchModelQpmInfo(config, credential.token, modelName);
@@ -162,11 +173,6 @@ export default defineCommand({
162173
} as Record<string, unknown>,
163174
};
164175

165-
if (config.dryRun) {
166-
emitResult({ api: UPDATE_LIMITS_API, data: requestData }, format);
167-
return;
168-
}
169-
170176
const submitRequest = async (confirmedDowngrade?: boolean): Promise<unknown> => {
171177
if (confirmedDowngrade) {
172178
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
@@ -240,8 +240,6 @@ export default defineCommand({
240240
}
241241
const format = detectOutputFormat(config.output);
242242

243-
const credential = await resolveConsoleGatewayCredential(config);
244-
245243
let models: string[];
246244
const typeMap = new Map<string, string>();
247245

@@ -254,21 +252,8 @@ export default defineCommand({
254252
.filter(Boolean),
255253
),
256254
];
257-
const searchResults = await Promise.all(
258-
models.map((name) => fetchModelList(config, credential.token, { name, pageSize: 50 })),
259-
);
260-
for (let idx = 0; idx < models.length; idx++) {
261-
const matched = searchResults[idx].models.find((item) => item.model === models[idx]);
262-
if (matched) {
263-
typeMap.set(models[idx], resolveModelType((matched.capabilities as string[]) || []));
264-
}
265-
}
266255
} else {
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-
}
256+
models = [];
272257
}
273258

274259
const requestData = {
@@ -280,13 +265,33 @@ export default defineCommand({
280265
{
281266
api: FREE_TIER_API,
282267
data: requestData,
283-
token: credential.token.slice(0, 8) + "...",
284268
},
285269
format,
286270
);
287271
return;
288272
}
289273

274+
const credential = await resolveConsoleGatewayCredential(config);
275+
276+
if (!modelFlag) {
277+
const modelInfos = await fetchAllModels(config, credential.token);
278+
models = modelInfos.map((info) => info.name);
279+
for (const info of modelInfos) {
280+
typeMap.set(info.name, info.type);
281+
}
282+
requestData.queryFreeTierQuotaRequest.models = models;
283+
} else {
284+
const searchResults = await Promise.all(
285+
models.map((name) => fetchModelList(config, credential.token, { name, pageSize: 50 })),
286+
);
287+
for (let idx = 0; idx < models.length; idx++) {
288+
const matched = searchResults[idx].models.find((item) => item.model === models[idx]);
289+
if (matched) {
290+
typeMap.set(models[idx], resolveModelType((matched.capabilities as string[]) || []));
291+
}
292+
}
293+
}
294+
290295
const [quotaResult, stopResult] = await Promise.all([
291296
callConsoleGateway(config, credential.token, {
292297
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
@@ -153,8 +153,6 @@ export default defineCommand({
153153
process.exit(1);
154154
}
155155

156-
const credential = await resolveConsoleGatewayCredential(config);
157-
158156
let models: string[];
159157
if (modelFlag) {
160158
models = [
@@ -166,7 +164,7 @@ export default defineCommand({
166164
),
167165
];
168166
} else {
169-
models = await fetchAllModelNames(config, credential.token);
167+
models = [];
170168
}
171169

172170
const api = off ? DEACTIVATE_API : ACTIVATE_API;
@@ -179,13 +177,18 @@ export default defineCommand({
179177
{
180178
api,
181179
data: { [requestKey]: { models } },
182-
token: credential.token.slice(0, 8) + "...",
183180
},
184181
format,
185182
);
186183
return;
187184
}
188185

186+
const credential = await resolveConsoleGatewayCredential(config);
187+
188+
if (!modelFlag) {
189+
models = await fetchAllModelNames(config, credential.token);
190+
}
191+
189192
if (off) {
190193
const [quotaResult, stopResult] = await Promise.all([
191194
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
@@ -352,8 +352,6 @@ export default defineCommand({
352352
const flagWorkspaceId = (flags.workspaceId as string) || undefined;
353353
const workspaceId = resolveWorkspaceId(config, flagWorkspaceId);
354354

355-
const credential = await resolveConsoleGatewayCredential(config);
356-
357355
const endTime = Date.now();
358356
const startTime = endTime - daysFlag * 24 * 60 * 60 * 1000;
359357

@@ -387,6 +385,8 @@ export default defineCommand({
387385
return;
388386
}
389387

388+
const credential = await resolveConsoleGatewayCredential(config);
389+
390390
const results = await Promise.all(
391391
models.map((model) =>
392392
pollTelemetryApi(config, credential.token, LIST_API, { ...baseReqDTO, model }),
@@ -422,6 +422,8 @@ export default defineCommand({
422422
return;
423423
}
424424

425+
const credential = await resolveConsoleGatewayCredential(config);
426+
425427
const result = await pollTelemetryApi(config, credential.token, OVERVIEW_API, reqDTO);
426428
if (!result) {
427429
process.stderr.write("Error: request timed out.\n");

0 commit comments

Comments
 (0)