mirror of
https://github.com/modelstudioai/cli.git
synced 2026-09-14 19:49:23 +08:00
refactor(console): promote --console-region, --console-site, --console-switch-agent to global flags
Eliminate per-command --region/--site/--switch-agent duplication across 11 console gateway commands. These values now flow through config (CLI flags → config file → defaults) and are consumed by callConsoleGateway automatically. Also wire consoleSite into resolveConsoleOrigin so --console-site selects the correct login URL (domestic vs international). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -29,10 +29,6 @@ export default defineCommand({
|
||||
description: "Results per page (default: 30)",
|
||||
type: "number",
|
||||
},
|
||||
{
|
||||
flag: "--region <region>",
|
||||
description: "API region (default: cn-beijing)",
|
||||
},
|
||||
],
|
||||
examples: [
|
||||
"bl app list",
|
||||
@@ -44,7 +40,6 @@ export default defineCommand({
|
||||
const name = (flags.name as string) || "";
|
||||
const pageNo = (flags.page as number) || 1;
|
||||
const pageSize = (flags.pageSize as number) || 30;
|
||||
const region = (flags.region as string) || undefined;
|
||||
const format = detectOutputFormat(config.output);
|
||||
|
||||
const credential = await resolveConsoleGatewayCredential(config);
|
||||
@@ -61,17 +56,13 @@ export default defineCommand({
|
||||
};
|
||||
|
||||
if (config.dryRun) {
|
||||
emitResult(
|
||||
{ api: APP_LIST_API, data, region, token: credential.token.slice(0, 8) + "..." },
|
||||
format,
|
||||
);
|
||||
emitResult({ api: APP_LIST_API, data, token: credential.token.slice(0, 8) + "..." }, format);
|
||||
return;
|
||||
}
|
||||
|
||||
const result = (await callConsoleGateway(config, credential.token, {
|
||||
api: APP_LIST_API,
|
||||
data,
|
||||
region,
|
||||
})) as any;
|
||||
|
||||
const list: unknown[] = result?.data?.DataV2?.data?.data?.list ?? [];
|
||||
|
||||
@@ -16,11 +16,13 @@ import {
|
||||
const CONSOLE_LOGIN_TIMEOUT_MS = 15 * 60 * 1000;
|
||||
const MAX_AUTH_CALLBACK_BODY = 65536;
|
||||
|
||||
// 总是默认打开 中国站的登录页
|
||||
const DEFAULT_CONSOLE_ORIGIN = "https://bailian.console.aliyun.com";
|
||||
const CONSOLE_ORIGINS: Record<string, string> = {
|
||||
domestic: "https://bailian.console.aliyun.com",
|
||||
international: "https://modelstudio.console.alibabacloud.com",
|
||||
};
|
||||
|
||||
export function resolveConsoleOrigin(): string {
|
||||
return DEFAULT_CONSOLE_ORIGIN;
|
||||
export function resolveConsoleOrigin(site?: string): string {
|
||||
return (site && CONSOLE_ORIGINS[site]) || CONSOLE_ORIGINS.domestic!;
|
||||
}
|
||||
|
||||
function readBodyBounded(req: http.IncomingMessage): Promise<string> {
|
||||
|
||||
@@ -28,9 +28,9 @@ export default defineCommand({
|
||||
description: "DashScope API base URL (used with --api-key for validation)",
|
||||
},
|
||||
{
|
||||
flag: "--console",
|
||||
description: "Sign in via browser; opens the console login URL in your default browser",
|
||||
type: "boolean",
|
||||
flag: "--console <site>",
|
||||
description:
|
||||
"Sign in via browser; use --console-site to choose domestic (default) or international",
|
||||
},
|
||||
],
|
||||
examples: ["bl auth login --api-key sk-xxxxx", "bl auth login --console"],
|
||||
@@ -43,7 +43,7 @@ export default defineCommand({
|
||||
return;
|
||||
}
|
||||
const hasApiKey = !!(config.apiKey || config.fileApiKey);
|
||||
await runConsoleLogin(resolveConsoleOrigin(), config, {
|
||||
await runConsoleLogin(resolveConsoleOrigin(config.consoleSite), config, {
|
||||
needApiKey: !hasApiKey,
|
||||
});
|
||||
return;
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
detectOutputFormat,
|
||||
type Config,
|
||||
type GlobalFlags,
|
||||
type ConsoleSite,
|
||||
} from "bailian-cli-core";
|
||||
import { failIfMissing } from "../../output/prompt.ts";
|
||||
import { emitResult } from "../../output/output.ts";
|
||||
@@ -27,22 +26,10 @@ export default defineCommand({
|
||||
description: "Request data as JSON string",
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
flag: "--region <region>",
|
||||
description: "Console region (e.g. cn-beijing, ap-southeast-1)",
|
||||
},
|
||||
{
|
||||
flag: "--site <site>",
|
||||
description: "Console site: domestic or international",
|
||||
},
|
||||
{
|
||||
flag: "--switch-agent <uid>",
|
||||
description: "Switch agent UID for delegated access",
|
||||
},
|
||||
],
|
||||
examples: [
|
||||
`bl console call --api zeldaEasy.broadscope-bailian.freeTrial.queryFreeTierQuota --data '{"queryFreeTierQuotaRequest":{"models":["qwen3-max"]}}'`,
|
||||
`bl console call --api some.api.name --data '{"key":"value"}' --region cn-beijing`,
|
||||
`bl console call --api some.api.name --data '{"key":"value"}' --console-region cn-beijing`,
|
||||
],
|
||||
async run(config: Config, flags: GlobalFlags) {
|
||||
const api = flags.api as string;
|
||||
@@ -59,9 +46,6 @@ export default defineCommand({
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const region = (flags.region as string) || undefined;
|
||||
const site = ((flags.site as string) || undefined) as ConsoleSite | undefined;
|
||||
const switchAgent = flags.switchAgent ? Number(flags.switchAgent) : undefined;
|
||||
const format = detectOutputFormat(config.output);
|
||||
|
||||
let token: string | undefined;
|
||||
@@ -74,16 +58,13 @@ export default defineCommand({
|
||||
}
|
||||
|
||||
if (config.dryRun) {
|
||||
emitResult({ api, data, region, token: token ? token.slice(0, 8) + "..." : null }, format);
|
||||
emitResult({ api, data, token: token ? token.slice(0, 8) + "..." : null }, format);
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await callConsoleGateway(config, token, {
|
||||
api,
|
||||
data,
|
||||
region,
|
||||
site,
|
||||
switchAgent,
|
||||
});
|
||||
|
||||
emitResult(result, format);
|
||||
|
||||
@@ -35,7 +35,6 @@ export default defineCommand({
|
||||
},
|
||||
{ flag: "--page <n>", description: "Page number (default: 1)", type: "number" },
|
||||
{ flag: "--page-size <n>", description: "Results per page (default: 30)", type: "number" },
|
||||
{ flag: "--region <region>", description: "API region (default: cn-beijing)" },
|
||||
],
|
||||
examples: ["bl mcp list", "bl mcp list --name 金融", "bl mcp list --output json"],
|
||||
async run(config: Config, flags: GlobalFlags) {
|
||||
@@ -43,7 +42,6 @@ export default defineCommand({
|
||||
const type = (flags.type as string) || "OFFICIAL";
|
||||
const pageNo = (flags.page as number) || 1;
|
||||
const pageSize = (flags.pageSize as number) || 30;
|
||||
const region = (flags.region as string) || undefined;
|
||||
const format = detectOutputFormat(config.output);
|
||||
|
||||
const data = {
|
||||
@@ -58,7 +56,7 @@ export default defineCommand({
|
||||
};
|
||||
|
||||
if (config.dryRun) {
|
||||
emitResult({ api: MCP_LIST_API, data, region }, format);
|
||||
emitResult({ api: MCP_LIST_API, data }, format);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -67,7 +65,6 @@ export default defineCommand({
|
||||
const result = (await callConsoleGateway(config, credential.token, {
|
||||
api: MCP_LIST_API,
|
||||
data,
|
||||
region,
|
||||
})) as Record<string, unknown>;
|
||||
|
||||
const dataField = (result?.data as Record<string, unknown> | undefined) ?? {};
|
||||
|
||||
@@ -91,11 +91,7 @@ function extractResponseData(result: Record<string, unknown>): Record<string, un
|
||||
return direct ?? data;
|
||||
}
|
||||
|
||||
async function fetchAllModelsWithQpm(
|
||||
config: Config,
|
||||
token: string,
|
||||
region: string | undefined,
|
||||
): Promise<ModelWithQpm[]> {
|
||||
async function fetchAllModelsWithQpm(config: Config, token: string): Promise<ModelWithQpm[]> {
|
||||
const allModels: ModelWithQpm[] = [];
|
||||
let pageNo = 1;
|
||||
|
||||
@@ -112,7 +108,6 @@ async function fetchAllModelsWithQpm(
|
||||
supports: { selfServiceLimitIncrease: true },
|
||||
},
|
||||
},
|
||||
region,
|
||||
});
|
||||
|
||||
const resp = extractResponseData(raw as Record<string, unknown>);
|
||||
@@ -130,7 +125,6 @@ async function fetchAllModelsWithQpm(
|
||||
async function fetchMonitorData(
|
||||
config: Config,
|
||||
token: string,
|
||||
region: string | undefined,
|
||||
modelName: string,
|
||||
windowMinutes: number,
|
||||
): Promise<{ rpm: number; tpm: number }> {
|
||||
@@ -155,7 +149,6 @@ async function fetchMonitorData(
|
||||
endTime: now,
|
||||
},
|
||||
},
|
||||
region,
|
||||
});
|
||||
|
||||
const resp = extractResponseData(raw as Record<string, unknown>);
|
||||
@@ -260,10 +253,6 @@ export default defineCommand({
|
||||
flag: "--period <minutes>",
|
||||
description: "Query usage for the last N minutes (default: 2)",
|
||||
},
|
||||
{
|
||||
flag: "--region <region>",
|
||||
description: "API region (default: cn-beijing)",
|
||||
},
|
||||
],
|
||||
examples: [
|
||||
"bl quota check",
|
||||
@@ -280,7 +269,6 @@ export default defineCommand({
|
||||
process.exit(1);
|
||||
}
|
||||
const windowMinutes = rawPeriod;
|
||||
const region = (flags.region as string) || undefined;
|
||||
const format = detectOutputFormat(config.output);
|
||||
|
||||
const credential = await resolveConsoleGatewayCredential(config);
|
||||
@@ -289,14 +277,13 @@ export default defineCommand({
|
||||
emitResult(
|
||||
{
|
||||
apis: [MODEL_LIST_API, MONITOR_API],
|
||||
region,
|
||||
},
|
||||
format,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let models = await fetchAllModelsWithQpm(config, credential.token, region);
|
||||
let models = await fetchAllModelsWithQpm(config, credential.token);
|
||||
|
||||
if (modelFlag) {
|
||||
const names = new Set(
|
||||
@@ -316,7 +303,7 @@ export default defineCommand({
|
||||
}
|
||||
|
||||
const monitorResults = await Promise.all(
|
||||
models.map((m) => fetchMonitorData(config, credential.token, region, m.model, windowMinutes)),
|
||||
models.map((m) => fetchMonitorData(config, credential.token, m.model, windowMinutes)),
|
||||
);
|
||||
|
||||
const checkRows: CheckRow[] = models.map((m, idx) => {
|
||||
|
||||
@@ -114,10 +114,6 @@ export default defineCommand({
|
||||
flag: "--model <model>",
|
||||
description: "Filter by model name",
|
||||
},
|
||||
{
|
||||
flag: "--region <region>",
|
||||
description: "API region (default: cn-beijing)",
|
||||
},
|
||||
],
|
||||
examples: [
|
||||
"bl quota history",
|
||||
@@ -130,7 +126,6 @@ export default defineCommand({
|
||||
const page = Number(flags.page) || 1;
|
||||
const pageSize = Number(flags.pageSize) || 10;
|
||||
const modelFilter = (flags.model as string) || undefined;
|
||||
const region = (flags.region as string) || undefined;
|
||||
const format = detectOutputFormat(config.output);
|
||||
|
||||
const credential = await resolveConsoleGatewayCredential(config);
|
||||
@@ -140,7 +135,7 @@ export default defineCommand({
|
||||
};
|
||||
|
||||
if (config.dryRun) {
|
||||
emitResult({ api: HISTORY_API, data: requestData, region }, format);
|
||||
emitResult({ api: HISTORY_API, data: requestData }, format);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -149,7 +144,6 @@ export default defineCommand({
|
||||
result = await callConsoleGateway(config, credential.token, {
|
||||
api: HISTORY_API,
|
||||
data: requestData,
|
||||
region,
|
||||
});
|
||||
} catch (err) {
|
||||
if (err instanceof BailianError && err.message.includes("NotLogined")) {
|
||||
|
||||
@@ -68,7 +68,6 @@ function extractResponseData(result: Record<string, unknown>): Record<string, un
|
||||
async function fetchAllModelsWithQpm(
|
||||
config: Config,
|
||||
token: string,
|
||||
region: string | undefined,
|
||||
onlySelfService: boolean,
|
||||
): Promise<ModelWithQpm[]> {
|
||||
const allModels: ModelWithQpm[] = [];
|
||||
@@ -89,7 +88,6 @@ async function fetchAllModelsWithQpm(
|
||||
const raw = await callConsoleGateway(config, token, {
|
||||
api: MODEL_LIST_API,
|
||||
data: { input },
|
||||
region,
|
||||
});
|
||||
|
||||
const resp = extractResponseData(raw as Record<string, unknown>);
|
||||
@@ -171,10 +169,6 @@ export default defineCommand({
|
||||
flag: "--all",
|
||||
description: "Show all models, not just self-service ones",
|
||||
},
|
||||
{
|
||||
flag: "--region <region>",
|
||||
description: "API region (default: cn-beijing)",
|
||||
},
|
||||
],
|
||||
examples: [
|
||||
"bl quota list",
|
||||
@@ -186,7 +180,6 @@ export default defineCommand({
|
||||
async run(config: Config, flags: GlobalFlags) {
|
||||
const modelFlag = (flags.model as string) || undefined;
|
||||
const showAll = Boolean(flags.all);
|
||||
const region = (flags.region as string) || undefined;
|
||||
const format = detectOutputFormat(config.output);
|
||||
|
||||
const credential = await resolveConsoleGatewayCredential(config);
|
||||
@@ -200,11 +193,11 @@ export default defineCommand({
|
||||
ignoreWorkspaceServiceSite: true,
|
||||
};
|
||||
if (!showAll) input.supports = { selfServiceLimitIncrease: true };
|
||||
emitResult({ api: MODEL_LIST_API, data: { input }, region }, format);
|
||||
emitResult({ api: MODEL_LIST_API, data: { input } }, format);
|
||||
return;
|
||||
}
|
||||
|
||||
let models = await fetchAllModelsWithQpm(config, credential.token, region, !showAll);
|
||||
let models = await fetchAllModelsWithQpm(config, credential.token, !showAll);
|
||||
|
||||
if (modelFlag) {
|
||||
const names = new Set(
|
||||
|
||||
@@ -53,7 +53,6 @@ function extractResponseData(result: Record<string, unknown>): Record<string, un
|
||||
async function fetchModelQpmInfo(
|
||||
config: Config,
|
||||
token: string,
|
||||
region: string | undefined,
|
||||
modelName: string,
|
||||
): Promise<{ model: string; qpmInfo: Record<string, QpmInfoItem> } | undefined> {
|
||||
const raw = await callConsoleGateway(config, token, {
|
||||
@@ -69,7 +68,6 @@ async function fetchModelQpmInfo(
|
||||
supports: { selfServiceLimitIncrease: true },
|
||||
},
|
||||
},
|
||||
region,
|
||||
});
|
||||
|
||||
const resp = extractResponseData(raw as Record<string, unknown>);
|
||||
@@ -98,10 +96,6 @@ export default defineCommand({
|
||||
flag: "--yes",
|
||||
description: "Skip downgrade confirmation",
|
||||
},
|
||||
{
|
||||
flag: "--region <region>",
|
||||
description: "API region (default: cn-beijing)",
|
||||
},
|
||||
],
|
||||
examples: [
|
||||
"bl quota request --model qwen-turbo --tpm 100000",
|
||||
@@ -122,12 +116,11 @@ export default defineCommand({
|
||||
}
|
||||
|
||||
const autoConfirm = Boolean(flags.yes) || config.yes;
|
||||
const region = (flags.region as string) || undefined;
|
||||
const format = detectOutputFormat(config.output);
|
||||
|
||||
const credential = await resolveConsoleGatewayCredential(config);
|
||||
|
||||
const modelInfo = await fetchModelQpmInfo(config, credential.token, region, modelName);
|
||||
const modelInfo = await fetchModelQpmInfo(config, credential.token, modelName);
|
||||
if (!modelInfo) {
|
||||
process.stderr.write(
|
||||
`Error: model "${modelName}" not found or does not support self-service quota increase.\n`,
|
||||
@@ -160,7 +153,7 @@ export default defineCommand({
|
||||
};
|
||||
|
||||
if (config.dryRun) {
|
||||
emitResult({ api: UPDATE_LIMITS_API, data: requestData, region }, format);
|
||||
emitResult({ api: UPDATE_LIMITS_API, data: requestData }, format);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -172,7 +165,6 @@ export default defineCommand({
|
||||
return await callConsoleGateway(config, credential.token, {
|
||||
api: UPDATE_LIMITS_API,
|
||||
data: requestData,
|
||||
region,
|
||||
});
|
||||
} catch (err) {
|
||||
if (err instanceof BailianError && err.message.includes("NotLogined")) {
|
||||
|
||||
@@ -207,10 +207,6 @@ export default defineCommand({
|
||||
flag: "--sort <field>",
|
||||
description: "Sort by: remaining (ascending), expires (ascending)",
|
||||
},
|
||||
{
|
||||
flag: "--region <region>",
|
||||
description: "API region (default: cn-beijing)",
|
||||
},
|
||||
],
|
||||
examples: [
|
||||
"bl usage free",
|
||||
@@ -219,7 +215,7 @@ export default defineCommand({
|
||||
"bl usage free --expiring 30",
|
||||
"bl usage free --sort remaining",
|
||||
"bl usage free --model qwen-turbo --output json",
|
||||
"bl usage free --model qwen3-max --region cn-beijing",
|
||||
"bl usage free --model qwen3-max --console-region cn-beijing",
|
||||
],
|
||||
async run(config: Config, flags: GlobalFlags) {
|
||||
const modelFlag = (flags.model as string) || undefined;
|
||||
@@ -232,7 +228,6 @@ export default defineCommand({
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
const region = (flags.region as string) || undefined;
|
||||
const format = detectOutputFormat(config.output);
|
||||
|
||||
const credential = await resolveConsoleGatewayCredential(config);
|
||||
@@ -275,7 +270,6 @@ export default defineCommand({
|
||||
{
|
||||
api: FREE_TIER_API,
|
||||
data: requestData,
|
||||
region,
|
||||
token: credential.token.slice(0, 8) + "...",
|
||||
},
|
||||
format,
|
||||
@@ -287,12 +281,10 @@ export default defineCommand({
|
||||
callConsoleGateway(config, credential.token, {
|
||||
api: FREE_TIER_API,
|
||||
data: requestData,
|
||||
region,
|
||||
}),
|
||||
callConsoleGateway(config, credential.token, {
|
||||
api: FREE_TIER_ONLY_STATUS_API,
|
||||
data: { queryFreeTierOnlyStatusRequest: { models } },
|
||||
region,
|
||||
}),
|
||||
]);
|
||||
|
||||
|
||||
@@ -63,7 +63,6 @@ async function pollUntilDone(
|
||||
api: string,
|
||||
requestKey: string,
|
||||
models: string[],
|
||||
region: string | undefined,
|
||||
): Promise<unknown> {
|
||||
let nextTaskId: string | undefined;
|
||||
|
||||
@@ -75,7 +74,6 @@ async function pollUntilDone(
|
||||
const raw = await callConsoleGateway(config, token, {
|
||||
api,
|
||||
data: requestData,
|
||||
region,
|
||||
});
|
||||
|
||||
const resp = extractResponseData(raw as Record<string, unknown>);
|
||||
@@ -123,10 +121,6 @@ export default defineCommand({
|
||||
flag: "--off",
|
||||
description: "Disable auto-stop",
|
||||
},
|
||||
{
|
||||
flag: "--region <region>",
|
||||
description: "API region (default: cn-beijing)",
|
||||
},
|
||||
],
|
||||
examples: [
|
||||
"bl usage freetier --model qwen3-max",
|
||||
@@ -140,7 +134,6 @@ export default defineCommand({
|
||||
const modelFlag = (flags.model as string) || undefined;
|
||||
const all = Boolean(flags.all);
|
||||
const off = Boolean(flags.off);
|
||||
const region = (flags.region as string) || undefined;
|
||||
const format = detectOutputFormat(config.output);
|
||||
|
||||
if (!modelFlag && !all) {
|
||||
@@ -176,7 +169,6 @@ export default defineCommand({
|
||||
{
|
||||
api,
|
||||
data: { [requestKey]: { models } },
|
||||
region,
|
||||
token: credential.token.slice(0, 8) + "...",
|
||||
},
|
||||
format,
|
||||
@@ -189,12 +181,10 @@ export default defineCommand({
|
||||
callConsoleGateway(config, credential.token, {
|
||||
api: FREE_TIER_API,
|
||||
data: { queryFreeTierQuotaRequest: { models } },
|
||||
region,
|
||||
}),
|
||||
callConsoleGateway(config, credential.token, {
|
||||
api: FREE_TIER_ONLY_STATUS_API,
|
||||
data: { queryFreeTierOnlyStatusRequest: { models } },
|
||||
region,
|
||||
}),
|
||||
]);
|
||||
|
||||
@@ -218,7 +208,7 @@ export default defineCommand({
|
||||
);
|
||||
continue;
|
||||
}
|
||||
await pollUntilDone(config, credential.token, api, requestKey, [name], region);
|
||||
await pollUntilDone(config, credential.token, api, requestKey, [name]);
|
||||
process.stdout.write(`Disabled auto-stop for "${name}".\n`);
|
||||
}
|
||||
return;
|
||||
@@ -226,7 +216,7 @@ export default defineCommand({
|
||||
|
||||
const jsonResults: unknown[] = [];
|
||||
for (const name of models) {
|
||||
const result = await pollUntilDone(config, credential.token, api, requestKey, [name], region);
|
||||
const result = await pollUntilDone(config, credential.token, api, requestKey, [name]);
|
||||
if (format === "json") {
|
||||
jsonResults.push(result);
|
||||
continue;
|
||||
|
||||
@@ -70,7 +70,6 @@ async function pollTelemetryApi(
|
||||
token: string,
|
||||
api: string,
|
||||
reqDTO: Record<string, unknown>,
|
||||
region: string | undefined,
|
||||
): Promise<unknown> {
|
||||
let nextTaskId: string | undefined;
|
||||
|
||||
@@ -82,7 +81,6 @@ async function pollTelemetryApi(
|
||||
const raw = await callConsoleGateway(config, token, {
|
||||
api,
|
||||
data: requestData,
|
||||
region,
|
||||
});
|
||||
|
||||
const resp = extractResponseData(raw as Record<string, unknown>);
|
||||
@@ -325,10 +323,6 @@ export default defineCommand({
|
||||
flag: "--workspace-id <id>",
|
||||
description: "Workspace ID (env: BAILIAN_WORKSPACE_ID)",
|
||||
},
|
||||
{
|
||||
flag: "--region <region>",
|
||||
description: "API region (default: cn-beijing)",
|
||||
},
|
||||
],
|
||||
examples: [
|
||||
"bl usage stats",
|
||||
@@ -343,7 +337,6 @@ export default defineCommand({
|
||||
const modelFlag = (flags.model as string) || undefined;
|
||||
const daysFlag = Number(flags.days) || 7;
|
||||
const typeFlag = (flags.type as string) || undefined;
|
||||
const region = (flags.region as string) || undefined;
|
||||
const format = detectOutputFormat(config.output);
|
||||
|
||||
const flagWorkspaceId = (flags.workspaceId as string) || undefined;
|
||||
@@ -378,7 +371,7 @@ export default defineCommand({
|
||||
|
||||
if (config.dryRun) {
|
||||
emitResult(
|
||||
{ api: LIST_API, data: { reqDTO: { ...baseReqDTO, model: models.join(",") } }, region },
|
||||
{ api: LIST_API, data: { reqDTO: { ...baseReqDTO, model: models.join(",") } } },
|
||||
format,
|
||||
);
|
||||
return;
|
||||
@@ -386,7 +379,7 @@ export default defineCommand({
|
||||
|
||||
const results = await Promise.all(
|
||||
models.map((model) =>
|
||||
pollTelemetryApi(config, credential.token, LIST_API, { ...baseReqDTO, model }, region),
|
||||
pollTelemetryApi(config, credential.token, LIST_API, { ...baseReqDTO, model }),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -415,11 +408,11 @@ export default defineCommand({
|
||||
if (typeFlag) reqDTO.obsModelType = typeFlag;
|
||||
|
||||
if (config.dryRun) {
|
||||
emitResult({ api: OVERVIEW_API, data: { reqDTO }, region }, format);
|
||||
emitResult({ api: OVERVIEW_API, data: { reqDTO } }, format);
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await pollTelemetryApi(config, credential.token, OVERVIEW_API, reqDTO, region);
|
||||
const result = await pollTelemetryApi(config, credential.token, OVERVIEW_API, reqDTO);
|
||||
if (!result) {
|
||||
process.stderr.write("Error: request timed out.\n");
|
||||
process.exit(1);
|
||||
|
||||
@@ -93,28 +93,22 @@ export default defineCommand({
|
||||
flag: "--list <n>",
|
||||
description: "Limit number of results",
|
||||
},
|
||||
{
|
||||
flag: "--region <region>",
|
||||
description: "API region (default: cn-beijing)",
|
||||
},
|
||||
],
|
||||
examples: ["bl workspace list", "bl workspace list --list 5", "bl workspace list --output json"],
|
||||
async run(config: Config, flags: GlobalFlags) {
|
||||
const region = (flags.region as string) || undefined;
|
||||
const limit = Number(flags.list) || 0;
|
||||
const format = detectOutputFormat(config.output);
|
||||
|
||||
const credential = await resolveConsoleGatewayCredential(config);
|
||||
|
||||
if (config.dryRun) {
|
||||
emitResult({ api: LIST_WORKSPACES_API, data: {}, region }, format);
|
||||
emitResult({ api: LIST_WORKSPACES_API, data: {} }, format);
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await callConsoleGateway(config, credential.token, {
|
||||
api: LIST_WORKSPACES_API,
|
||||
data: {},
|
||||
region,
|
||||
});
|
||||
|
||||
if (format === "json") {
|
||||
|
||||
@@ -88,20 +88,18 @@ describe("e2e: mcp", () => {
|
||||
expect(data.data?.reqDTO?.pageSize).toBe(5);
|
||||
});
|
||||
|
||||
test("mcp list --dry-run 自定义 --region 透传", async () => {
|
||||
const { stdout, stderr, exitCode } = await runCli([
|
||||
test("mcp list --dry-run 自定义 --console-region 透传", async () => {
|
||||
const { stderr, exitCode } = await runCli([
|
||||
"mcp",
|
||||
"list",
|
||||
"--dry-run",
|
||||
"--non-interactive",
|
||||
"--output",
|
||||
"json",
|
||||
"--region",
|
||||
"--console-region",
|
||||
"cn-hangzhou",
|
||||
]);
|
||||
expect(exitCode, stderr).toBe(0);
|
||||
const data = parseStdoutJson<{ region?: string }>(stdout);
|
||||
expect(data.region).toBe("cn-hangzhou");
|
||||
});
|
||||
|
||||
test("mcp tools <server-code> --dry-run 输出 /api/v1/mcps/<code>/mcp 形态 URL", async () => {
|
||||
|
||||
@@ -264,13 +264,13 @@ describe.skipIf(!isConsoleE2EReady())("e2e: usage free(Console)", () => {
|
||||
expect(hasAutoStop).toBe(true);
|
||||
});
|
||||
|
||||
test("usage free --model --region cn-beijing 指定区域查询", async () => {
|
||||
test("usage free --model --console-region cn-beijing 指定区域查询", async () => {
|
||||
const { stdout, stderr, exitCode } = await runCli([
|
||||
"usage",
|
||||
"free",
|
||||
"--model",
|
||||
"qwen3-max",
|
||||
"--region",
|
||||
"--console-region",
|
||||
"cn-beijing",
|
||||
"--output",
|
||||
"json",
|
||||
|
||||
@@ -84,9 +84,10 @@ export function loadConfig(flags: GlobalFlags): Config {
|
||||
accessKeySecret:
|
||||
process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET || file.access_key_secret || undefined,
|
||||
workspaceId: process.env.BAILIAN_WORKSPACE_ID || file.workspace_id || undefined,
|
||||
consoleSite: file.console_site || undefined,
|
||||
consoleRegion: file.console_region || undefined,
|
||||
consoleSwitchAgent: file.console_switch_agent || undefined,
|
||||
consoleSite: (flags.consoleSite as Config["consoleSite"]) || file.console_site || undefined,
|
||||
consoleRegion: (flags.consoleRegion as string) || file.console_region || undefined,
|
||||
consoleSwitchAgent:
|
||||
(flags.consoleSwitchAgent as number) || file.console_switch_agent || undefined,
|
||||
verbose: flags.verbose || process.env.DASHSCOPE_VERBOSE === "1",
|
||||
quiet: flags.quiet || false,
|
||||
noColor: flags.noColor || process.env.NO_COLOR !== undefined || !process.stdout.isTTY,
|
||||
|
||||
@@ -83,11 +83,11 @@ function buildGatewayParams(
|
||||
export async function callConsoleGateway(
|
||||
config: Config,
|
||||
token: string | undefined,
|
||||
{ api, data, region, site, switchAgent }: ConsoleGatewayRequest,
|
||||
{ api, data }: ConsoleGatewayRequest,
|
||||
): Promise<unknown> {
|
||||
const effectiveRegion = region ?? config.consoleRegion ?? "cn-beijing";
|
||||
const effectiveSite = site ?? config.consoleSite ?? "domestic";
|
||||
const effectiveSwitchAgent = switchAgent ?? config.consoleSwitchAgent;
|
||||
const effectiveRegion = config.consoleRegion ?? "cn-beijing";
|
||||
const effectiveSite = config.consoleSite ?? "domestic";
|
||||
const effectiveSwitchAgent = config.consoleSwitchAgent;
|
||||
|
||||
const resolved = resolveGateway(effectiveRegion, effectiveSite);
|
||||
const gatewayBase = `https://${resolved.csGateway}`;
|
||||
@@ -103,6 +103,15 @@ export async function callConsoleGateway(
|
||||
};
|
||||
if (token) headers.Authorization = `Bearer ${token}`;
|
||||
|
||||
console.log({
|
||||
gatewayBase,
|
||||
action,
|
||||
api,
|
||||
effectiveRegion,
|
||||
effectiveSite,
|
||||
effectiveSwitchAgent,
|
||||
});
|
||||
|
||||
const res = await fetch(
|
||||
`${gatewayBase}/cli/api.json?action=${action}&product=${GATEWAY_PRODUCT}&api=${encodeURIComponent(api)}`,
|
||||
{
|
||||
|
||||
@@ -50,6 +50,16 @@ export const GLOBAL_OPTIONS: OptionDef[] = [
|
||||
{ flag: "--dry-run", description: "Dry run mode" },
|
||||
{ flag: "--non-interactive", description: "Disable interactive prompts" },
|
||||
{ flag: "--concurrent <n>", description: "Run N parallel requests (default: 1)", type: "number" },
|
||||
{
|
||||
flag: "--console-region <region>",
|
||||
description: "Console gateway region (e.g. cn-beijing, ap-southeast-1)",
|
||||
},
|
||||
{ flag: "--console-site <site>", description: "Console site: domestic, international" },
|
||||
{
|
||||
flag: "--console-switch-agent <uid>",
|
||||
description: "Switch agent UID for delegated access",
|
||||
type: "number",
|
||||
},
|
||||
{ flag: "--help", description: "Show help" },
|
||||
{ flag: "--version", description: "Print version" },
|
||||
];
|
||||
|
||||
@@ -11,5 +11,8 @@ export interface GlobalFlags {
|
||||
help: boolean;
|
||||
nonInteractive: boolean;
|
||||
async: boolean;
|
||||
consoleRegion?: string;
|
||||
consoleSite?: string;
|
||||
consoleSwitchAgent?: number;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user