feat: update access token logic

This commit is contained in:
故璃
2026-06-17 11:58:09 +08:00
parent e9feb380f5
commit 14583cf6d1
7 changed files with 50 additions and 34 deletions
+2 -2
View File
@@ -282,8 +282,6 @@ export default defineCommand({
const windowMinutes = rawPeriod;
const format = detectOutputFormat(config.output);
const credential = await resolveConsoleGatewayCredential(config);
if (config.dryRun) {
emitResult(
{
@@ -295,6 +293,8 @@ export default defineCommand({
return;
}
const credential = await resolveConsoleGatewayCredential(config);
let models = await fetchAllModelsWithQpm(config, credential.token);
if (modelFlag) {
+2 -2
View File
@@ -138,8 +138,6 @@ export default defineCommand({
const modelFilter = (flags.model as string) || undefined;
const format = detectOutputFormat(config.output);
const credential = await resolveConsoleGatewayCredential(config);
const requestData = {
input: { pageNo: page, pageSize },
};
@@ -149,6 +147,8 @@ export default defineCommand({
return;
}
const credential = await resolveConsoleGatewayCredential(config);
let result: unknown;
try {
result = await callConsoleGateway(config, credential.token, {
+2 -2
View File
@@ -192,8 +192,6 @@ export default defineCommand({
const showAll = Boolean(flags.all);
const format = detectOutputFormat(config.output);
const credential = await resolveConsoleGatewayCredential(config);
if (config.dryRun) {
const input: Record<string, unknown> = {
pageNo: 1,
@@ -207,6 +205,8 @@ export default defineCommand({
return;
}
const credential = await resolveConsoleGatewayCredential(config);
let models = await fetchAllModelsWithQpm(config, credential.token, !showAll);
if (modelFlag) {
+11 -5
View File
@@ -128,6 +128,17 @@ export default defineCommand({
const autoConfirm = Boolean(flags.yes) || config.yes;
const format = detectOutputFormat(config.output);
if (config.dryRun) {
const requestData = {
input: {
model: modelName,
limit: { usage_limit: tpmValue },
},
};
emitResult({ api: UPDATE_LIMITS_API, data: requestData }, format);
return;
}
const credential = await resolveConsoleGatewayCredential(config);
const modelInfo = await fetchModelQpmInfo(config, credential.token, modelName);
@@ -162,11 +173,6 @@ export default defineCommand({
} as Record<string, unknown>,
};
if (config.dryRun) {
emitResult({ api: UPDATE_LIMITS_API, data: requestData }, format);
return;
}
const submitRequest = async (confirmedDowngrade?: boolean): Promise<unknown> => {
if (confirmedDowngrade) {
requestData.input.confirmedDowngrade = true;
+22 -17
View File
@@ -240,8 +240,6 @@ export default defineCommand({
}
const format = detectOutputFormat(config.output);
const credential = await resolveConsoleGatewayCredential(config);
let models: string[];
const typeMap = new Map<string, string>();
@@ -254,21 +252,8 @@ export default defineCommand({
.filter(Boolean),
),
];
const searchResults = await Promise.all(
models.map((name) => fetchModelList(config, credential.token, { name, pageSize: 50 })),
);
for (let idx = 0; idx < models.length; idx++) {
const matched = searchResults[idx].models.find((item) => item.model === models[idx]);
if (matched) {
typeMap.set(models[idx], resolveModelType((matched.capabilities as string[]) || []));
}
}
} else {
const modelInfos = await fetchAllModels(config, credential.token);
models = modelInfos.map((info) => info.name);
for (const info of modelInfos) {
typeMap.set(info.name, info.type);
}
models = [];
}
const requestData = {
@@ -280,13 +265,33 @@ export default defineCommand({
{
api: FREE_TIER_API,
data: requestData,
token: credential.token.slice(0, 8) + "...",
},
format,
);
return;
}
const credential = await resolveConsoleGatewayCredential(config);
if (!modelFlag) {
const modelInfos = await fetchAllModels(config, credential.token);
models = modelInfos.map((info) => info.name);
for (const info of modelInfos) {
typeMap.set(info.name, info.type);
}
requestData.queryFreeTierQuotaRequest.models = models;
} else {
const searchResults = await Promise.all(
models.map((name) => fetchModelList(config, credential.token, { name, pageSize: 50 })),
);
for (let idx = 0; idx < models.length; idx++) {
const matched = searchResults[idx].models.find((item) => item.model === models[idx]);
if (matched) {
typeMap.set(models[idx], resolveModelType((matched.capabilities as string[]) || []));
}
}
}
const [quotaResult, stopResult] = await Promise.all([
callConsoleGateway(config, credential.token, {
api: FREE_TIER_API,
+7 -4
View File
@@ -153,8 +153,6 @@ export default defineCommand({
process.exit(1);
}
const credential = await resolveConsoleGatewayCredential(config);
let models: string[];
if (modelFlag) {
models = [
@@ -166,7 +164,7 @@ export default defineCommand({
),
];
} else {
models = await fetchAllModelNames(config, credential.token);
models = [];
}
const api = off ? DEACTIVATE_API : ACTIVATE_API;
@@ -179,13 +177,18 @@ export default defineCommand({
{
api,
data: { [requestKey]: { models } },
token: credential.token.slice(0, 8) + "...",
},
format,
);
return;
}
const credential = await resolveConsoleGatewayCredential(config);
if (!modelFlag) {
models = await fetchAllModelNames(config, credential.token);
}
if (off) {
const [quotaResult, stopResult] = await Promise.all([
callConsoleGateway(config, credential.token, {
+4 -2
View File
@@ -352,8 +352,6 @@ export default defineCommand({
const flagWorkspaceId = (flags.workspaceId as string) || undefined;
const workspaceId = resolveWorkspaceId(config, flagWorkspaceId);
const credential = await resolveConsoleGatewayCredential(config);
const endTime = Date.now();
const startTime = endTime - daysFlag * 24 * 60 * 60 * 1000;
@@ -387,6 +385,8 @@ export default defineCommand({
return;
}
const credential = await resolveConsoleGatewayCredential(config);
const results = await Promise.all(
models.map((model) =>
pollTelemetryApi(config, credential.token, LIST_API, { ...baseReqDTO, model }),
@@ -422,6 +422,8 @@ export default defineCommand({
return;
}
const credential = await resolveConsoleGatewayCredential(config);
const result = await pollTelemetryApi(config, credential.token, OVERVIEW_API, reqDTO);
if (!result) {
process.stderr.write("Error: request timed out.\n");