mirror of
https://github.com/modelstudioai/cli.git
synced 2026-09-14 19:49:23 +08:00
feat: update access token logic
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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, {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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, {
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user