From 8c398bae573e02e490a2a5dd33a15445362d28e4 Mon Sep 17 00:00:00 2001 From: lishengzxc <306009337@qq.com> Date: Tue, 16 Jun 2026 13:56:20 +0800 Subject: [PATCH] refactor(console): promote --console-region, --console-site, --console-switch-agent to global flags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- packages/cli/src/commands/app/list.ts | 11 +------ .../cli/src/commands/auth/login-console.ts | 10 +++--- packages/cli/src/commands/auth/login.ts | 8 ++--- packages/cli/src/commands/console/call.ts | 23 ++----------- packages/cli/src/commands/mcp/list.ts | 5 +-- packages/cli/src/commands/quota/check.ts | 19 ++--------- packages/cli/src/commands/quota/history.ts | 8 +---- packages/cli/src/commands/quota/list.ts | 11 ++----- packages/cli/src/commands/quota/request.ts | 12 ++----- packages/cli/src/commands/usage/free.ts | 10 +----- packages/cli/src/commands/usage/freetier.ts | 14 ++------ packages/cli/src/commands/usage/stats.ts | 15 +++------ packages/cli/src/commands/workspace/list.ts | 8 +---- packages/cli/tests/e2e/mcp.e2e.test.ts | 8 ++--- packages/cli/tests/e2e/usage-free.e2e.test.ts | 4 +-- packages/core/src/config/loader.ts | 7 ++-- packages/core/src/console/gateway.ts | 17 +++++++--- packages/core/src/types/command.ts | 10 ++++++ packages/core/src/types/flags.ts | 3 ++ skills/bailian-cli/reference/app.md | 11 +++---- skills/bailian-cli/reference/auth.md | 10 +++--- skills/bailian-cli/reference/console.md | 13 +++----- skills/bailian-cli/reference/index.md | 33 ++++++++++--------- skills/bailian-cli/reference/mcp.md | 13 ++++---- skills/bailian-cli/reference/quota.md | 32 ++++++++---------- skills/bailian-cli/reference/usage.md | 17 ++++------ skills/bailian-cli/reference/workspace.md | 7 ++-- 27 files changed, 128 insertions(+), 211 deletions(-) diff --git a/packages/cli/src/commands/app/list.ts b/packages/cli/src/commands/app/list.ts index d4f8784..28e55b2 100644 --- a/packages/cli/src/commands/app/list.ts +++ b/packages/cli/src/commands/app/list.ts @@ -29,10 +29,6 @@ export default defineCommand({ description: "Results per page (default: 30)", type: "number", }, - { - flag: "--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 ?? []; diff --git a/packages/cli/src/commands/auth/login-console.ts b/packages/cli/src/commands/auth/login-console.ts index ddb159b..bfe3193 100644 --- a/packages/cli/src/commands/auth/login-console.ts +++ b/packages/cli/src/commands/auth/login-console.ts @@ -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 = { + 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 { diff --git a/packages/cli/src/commands/auth/login.ts b/packages/cli/src/commands/auth/login.ts index 1327ba6..9c3c7eb 100644 --- a/packages/cli/src/commands/auth/login.ts +++ b/packages/cli/src/commands/auth/login.ts @@ -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 ", + 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; diff --git a/packages/cli/src/commands/console/call.ts b/packages/cli/src/commands/console/call.ts index ae4e552..4bf9ee6 100644 --- a/packages/cli/src/commands/console/call.ts +++ b/packages/cli/src/commands/console/call.ts @@ -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 ", - description: "Console region (e.g. cn-beijing, ap-southeast-1)", - }, - { - flag: "--site ", - description: "Console site: domestic or international", - }, - { - flag: "--switch-agent ", - 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); diff --git a/packages/cli/src/commands/mcp/list.ts b/packages/cli/src/commands/mcp/list.ts index 5edd6f0..1e6e747 100644 --- a/packages/cli/src/commands/mcp/list.ts +++ b/packages/cli/src/commands/mcp/list.ts @@ -35,7 +35,6 @@ export default defineCommand({ }, { flag: "--page ", description: "Page number (default: 1)", type: "number" }, { flag: "--page-size ", description: "Results per page (default: 30)", type: "number" }, - { flag: "--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; const dataField = (result?.data as Record | undefined) ?? {}; diff --git a/packages/cli/src/commands/quota/check.ts b/packages/cli/src/commands/quota/check.ts index ba7a225..f00ab44 100644 --- a/packages/cli/src/commands/quota/check.ts +++ b/packages/cli/src/commands/quota/check.ts @@ -91,11 +91,7 @@ function extractResponseData(result: Record): Record { +async function fetchAllModelsWithQpm(config: Config, token: string): Promise { const allModels: ModelWithQpm[] = []; let pageNo = 1; @@ -112,7 +108,6 @@ async function fetchAllModelsWithQpm( supports: { selfServiceLimitIncrease: true }, }, }, - region, }); const resp = extractResponseData(raw as Record); @@ -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); @@ -260,10 +253,6 @@ export default defineCommand({ flag: "--period ", description: "Query usage for the last N minutes (default: 2)", }, - { - flag: "--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) => { diff --git a/packages/cli/src/commands/quota/history.ts b/packages/cli/src/commands/quota/history.ts index 033bb85..284cea4 100644 --- a/packages/cli/src/commands/quota/history.ts +++ b/packages/cli/src/commands/quota/history.ts @@ -114,10 +114,6 @@ export default defineCommand({ flag: "--model ", description: "Filter by model name", }, - { - flag: "--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")) { diff --git a/packages/cli/src/commands/quota/list.ts b/packages/cli/src/commands/quota/list.ts index 1f4761d..40e9a80 100644 --- a/packages/cli/src/commands/quota/list.ts +++ b/packages/cli/src/commands/quota/list.ts @@ -68,7 +68,6 @@ function extractResponseData(result: Record): Record { 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); @@ -171,10 +169,6 @@ export default defineCommand({ flag: "--all", description: "Show all models, not just self-service ones", }, - { - flag: "--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( diff --git a/packages/cli/src/commands/quota/request.ts b/packages/cli/src/commands/quota/request.ts index c18045e..c554c42 100644 --- a/packages/cli/src/commands/quota/request.ts +++ b/packages/cli/src/commands/quota/request.ts @@ -53,7 +53,6 @@ function extractResponseData(result: Record): Record } | undefined> { const raw = await callConsoleGateway(config, token, { @@ -69,7 +68,6 @@ async function fetchModelQpmInfo( supports: { selfServiceLimitIncrease: true }, }, }, - region, }); const resp = extractResponseData(raw as Record); @@ -98,10 +96,6 @@ export default defineCommand({ flag: "--yes", description: "Skip downgrade confirmation", }, - { - flag: "--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")) { diff --git a/packages/cli/src/commands/usage/free.ts b/packages/cli/src/commands/usage/free.ts index 4ac1eb7..433085e 100644 --- a/packages/cli/src/commands/usage/free.ts +++ b/packages/cli/src/commands/usage/free.ts @@ -207,10 +207,6 @@ export default defineCommand({ flag: "--sort ", description: "Sort by: remaining (ascending), expires (ascending)", }, - { - flag: "--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, }), ]); diff --git a/packages/cli/src/commands/usage/freetier.ts b/packages/cli/src/commands/usage/freetier.ts index 671bb89..5b1d191 100644 --- a/packages/cli/src/commands/usage/freetier.ts +++ b/packages/cli/src/commands/usage/freetier.ts @@ -63,7 +63,6 @@ async function pollUntilDone( api: string, requestKey: string, models: string[], - region: string | undefined, ): Promise { 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); @@ -123,10 +121,6 @@ export default defineCommand({ flag: "--off", description: "Disable auto-stop", }, - { - flag: "--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; diff --git a/packages/cli/src/commands/usage/stats.ts b/packages/cli/src/commands/usage/stats.ts index 35e5c0b..9587bfc 100644 --- a/packages/cli/src/commands/usage/stats.ts +++ b/packages/cli/src/commands/usage/stats.ts @@ -70,7 +70,6 @@ async function pollTelemetryApi( token: string, api: string, reqDTO: Record, - region: string | undefined, ): Promise { 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); @@ -325,10 +323,6 @@ export default defineCommand({ flag: "--workspace-id ", description: "Workspace ID (env: BAILIAN_WORKSPACE_ID)", }, - { - flag: "--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); diff --git a/packages/cli/src/commands/workspace/list.ts b/packages/cli/src/commands/workspace/list.ts index 58857ef..4e869e6 100644 --- a/packages/cli/src/commands/workspace/list.ts +++ b/packages/cli/src/commands/workspace/list.ts @@ -93,28 +93,22 @@ export default defineCommand({ flag: "--list ", description: "Limit number of results", }, - { - flag: "--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") { diff --git a/packages/cli/tests/e2e/mcp.e2e.test.ts b/packages/cli/tests/e2e/mcp.e2e.test.ts index bc5ef52..c3757e5 100644 --- a/packages/cli/tests/e2e/mcp.e2e.test.ts +++ b/packages/cli/tests/e2e/mcp.e2e.test.ts @@ -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 --dry-run 输出 /api/v1/mcps//mcp 形态 URL", async () => { diff --git a/packages/cli/tests/e2e/usage-free.e2e.test.ts b/packages/cli/tests/e2e/usage-free.e2e.test.ts index 064f027..589239b 100644 --- a/packages/cli/tests/e2e/usage-free.e2e.test.ts +++ b/packages/cli/tests/e2e/usage-free.e2e.test.ts @@ -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", diff --git a/packages/core/src/config/loader.ts b/packages/core/src/config/loader.ts index 4e5f39e..dbcbfc5 100644 --- a/packages/core/src/config/loader.ts +++ b/packages/core/src/config/loader.ts @@ -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, diff --git a/packages/core/src/console/gateway.ts b/packages/core/src/console/gateway.ts index d391784..ddda2ee 100644 --- a/packages/core/src/console/gateway.ts +++ b/packages/core/src/console/gateway.ts @@ -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 { - 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)}`, { diff --git a/packages/core/src/types/command.ts b/packages/core/src/types/command.ts index 02bbcf5..cff3bc1 100644 --- a/packages/core/src/types/command.ts +++ b/packages/core/src/types/command.ts @@ -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 ", description: "Run N parallel requests (default: 1)", type: "number" }, + { + flag: "--console-region ", + description: "Console gateway region (e.g. cn-beijing, ap-southeast-1)", + }, + { flag: "--console-site ", description: "Console site: domestic, international" }, + { + flag: "--console-switch-agent ", + description: "Switch agent UID for delegated access", + type: "number", + }, { flag: "--help", description: "Show help" }, { flag: "--version", description: "Print version" }, ]; diff --git a/packages/core/src/types/flags.ts b/packages/core/src/types/flags.ts index 4f29f85..41e1a5a 100644 --- a/packages/core/src/types/flags.ts +++ b/packages/core/src/types/flags.ts @@ -11,5 +11,8 @@ export interface GlobalFlags { help: boolean; nonInteractive: boolean; async: boolean; + consoleRegion?: string; + consoleSite?: string; + consoleSwitchAgent?: number; [key: string]: unknown; } diff --git a/skills/bailian-cli/reference/app.md b/skills/bailian-cli/reference/app.md index e486673..edbd154 100644 --- a/skills/bailian-cli/reference/app.md +++ b/skills/bailian-cli/reference/app.md @@ -73,12 +73,11 @@ bl app call --app-id abc123 --prompt "开始" --biz-params '{"key":"value"}' #### Options -| Flag | Type | Required | Description | -| ------------------- | ------ | -------- | ----------------------------------- | -| `--name ` | string | no | Filter by app name (keyword search) | -| `--page ` | number | no | Page number (default: 1) | -| `--page-size ` | number | no | Results per page (default: 30) | -| `--region ` | string | no | API region (default: cn-beijing) | +| Flag | Type | Required | Description | +| ----------------- | ------ | -------- | ----------------------------------- | +| `--name ` | string | no | Filter by app name (keyword search) | +| `--page ` | number | no | Page number (default: 1) | +| `--page-size ` | number | no | Results per page (default: 30) | #### Examples diff --git a/skills/bailian-cli/reference/auth.md b/skills/bailian-cli/reference/auth.md index e51eb1a..a67cd51 100644 --- a/skills/bailian-cli/reference/auth.md +++ b/skills/bailian-cli/reference/auth.md @@ -25,11 +25,11 @@ Index: [index.md](index.md) #### Options -| Flag | Type | Required | Description | -| ------------------ | ------- | -------- | ------------------------------------------------------------------------ | -| `--api-key ` | string | no | DashScope API key to store | -| `--base-url ` | string | no | DashScope API base URL (used with --api-key for validation) | -| `--console` | boolean | no | Sign in via browser; opens the console login URL in your default browser | +| Flag | Type | Required | Description | +| ------------------ | ------ | -------- | ------------------------------------------------------------------------------------- | +| `--api-key ` | string | no | DashScope API key to store | +| `--base-url ` | string | no | DashScope API base URL (used with --api-key for validation) | +| `--console ` | string | no | Sign in via browser; use --console-site to choose domestic (default) or international | #### Examples diff --git a/skills/bailian-cli/reference/console.md b/skills/bailian-cli/reference/console.md index 12e4e95..bb3a0c8 100644 --- a/skills/bailian-cli/reference/console.md +++ b/skills/bailian-cli/reference/console.md @@ -23,13 +23,10 @@ Index: [index.md](index.md) #### Options -| Flag | Type | Required | Description | -| ---------------------- | ------ | -------- | ------------------------------------------------------------------------ | -| `--api ` | string | yes | API name (e.g. zeldaEasy.broadscope-bailian.memory-library.getLibraries) | -| `--data ` | string | yes | Request data as JSON string | -| `--region ` | string | no | Console region (e.g. cn-beijing, ap-southeast-1) | -| `--site ` | string | no | Console site: domestic or international | -| `--switch-agent ` | string | no | Switch agent UID for delegated access | +| Flag | Type | Required | Description | +| --------------- | ------ | -------- | ------------------------------------------------------------------------ | +| `--api ` | string | yes | API name (e.g. zeldaEasy.broadscope-bailian.memory-library.getLibraries) | +| `--data ` | string | yes | Request data as JSON string | #### Examples @@ -38,5 +35,5 @@ bl console call --api zeldaEasy.broadscope-bailian.freeTrial.queryFreeTierQuota ``` ```bash -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 ``` diff --git a/skills/bailian-cli/reference/index.md b/skills/bailian-cli/reference/index.md index 0da2213..5a19012 100644 --- a/skills/bailian-cli/reference/index.md +++ b/skills/bailian-cli/reference/index.md @@ -87,21 +87,24 @@ Use this index for the full quick index and global flags. Available on every command (in addition to command-specific options): -| Flag | Type | Required | Description | -| --------------------- | ------- | -------- | ------------------------------------ | -| `--api-key ` | string | no | API key | -| `--region ` | string | no | API region: cn (default), us, intl | -| `--base-url ` | string | no | API base URL | -| `--output ` | string | no | Output format: text, json | -| `--timeout ` | number | no | Request timeout | -| `--quiet` | boolean | no | Suppress non-essential output | -| `--verbose` | boolean | no | Print HTTP request/response details | -| `--no-color` | boolean | no | Disable ANSI colors | -| `--dry-run` | boolean | no | Dry run mode | -| `--non-interactive` | boolean | no | Disable interactive prompts | -| `--concurrent ` | number | no | Run N parallel requests (default: 1) | -| `--help` | boolean | no | Show help | -| `--version` | boolean | no | Print version | +| Flag | Type | Required | Description | +| ------------------------------ | ------- | -------- | -------------------------------------------------------- | +| `--api-key ` | string | no | API key | +| `--region ` | string | no | API region: cn (default), us, intl | +| `--base-url ` | string | no | API base URL | +| `--output ` | string | no | Output format: text, json | +| `--timeout ` | number | no | Request timeout | +| `--quiet` | boolean | no | Suppress non-essential output | +| `--verbose` | boolean | no | Print HTTP request/response details | +| `--no-color` | boolean | no | Disable ANSI colors | +| `--dry-run` | boolean | no | Dry run mode | +| `--non-interactive` | boolean | no | Disable interactive prompts | +| `--concurrent ` | number | no | Run N parallel requests (default: 1) | +| `--console-region ` | string | no | Console gateway region (e.g. cn-beijing, ap-southeast-1) | +| `--console-site ` | string | no | Console site: domestic, international | +| `--console-switch-agent ` | number | no | Switch agent UID for delegated access | +| `--help` | boolean | no | Show help | +| `--version` | boolean | no | Print version | ## Notes diff --git a/skills/bailian-cli/reference/mcp.md b/skills/bailian-cli/reference/mcp.md index 9c71795..b84b94e 100644 --- a/skills/bailian-cli/reference/mcp.md +++ b/skills/bailian-cli/reference/mcp.md @@ -57,13 +57,12 @@ bl mcp call market-cmapi00073529.SmartFundSelection --arg riskLevel=R3 --arg min #### Options -| Flag | Type | Required | Description | -| ------------------- | ------ | -------- | ---------------------------------------------------- | -| `--name ` | string | no | Filter by server name (substring match) | -| `--type ` | string | no | Server type: OFFICIAL \| PRIVATE (default: OFFICIAL) | -| `--page ` | number | no | Page number (default: 1) | -| `--page-size ` | number | no | Results per page (default: 30) | -| `--region ` | string | no | API region (default: cn-beijing) | +| Flag | Type | Required | Description | +| ----------------- | ------ | -------- | ---------------------------------------------------- | +| `--name ` | string | no | Filter by server name (substring match) | +| `--type ` | string | no | Server type: OFFICIAL \| PRIVATE (default: OFFICIAL) | +| `--page ` | number | no | Page number (default: 1) | +| `--page-size ` | number | no | Results per page (default: 30) | #### Examples diff --git a/skills/bailian-cli/reference/quota.md b/skills/bailian-cli/reference/quota.md index 86aa355..9b4ad06 100644 --- a/skills/bailian-cli/reference/quota.md +++ b/skills/bailian-cli/reference/quota.md @@ -30,7 +30,6 @@ Index: [index.md](index.md) | -------------------- | ------ | -------- | ----------------------------------------------- | | `--model ` | string | no | Model name(s), comma-separated | | `--period ` | string | no | Query usage for the last N minutes (default: 2) | -| `--region ` | string | no | API region (default: cn-beijing) | #### Examples @@ -64,12 +63,11 @@ bl quota check --output json #### Options -| Flag | Type | Required | Description | -| ------------------- | ------ | -------- | -------------------------------- | -| `--page ` | string | no | Page number (default: 1) | -| `--page-size ` | string | no | Page size (default: 10) | -| `--model ` | string | no | Filter by model name | -| `--region ` | string | no | API region (default: cn-beijing) | +| Flag | Type | Required | Description | +| ----------------- | ------ | -------- | ------------------------ | +| `--page ` | string | no | Page number (default: 1) | +| `--page-size ` | string | no | Page size (default: 10) | +| `--model ` | string | no | Filter by model name | #### Examples @@ -103,11 +101,10 @@ bl quota history --output json #### Options -| Flag | Type | Required | Description | -| ------------------- | ------- | -------- | ------------------------------------------- | -| `--model ` | string | no | Model name(s), comma-separated | -| `--all` | boolean | no | Show all models, not just self-service ones | -| `--region ` | string | no | API region (default: cn-beijing) | +| Flag | Type | Required | Description | +| ----------------- | ------- | -------- | ------------------------------------------- | +| `--model ` | string | no | Model name(s), comma-separated | +| `--all` | boolean | no | Show all models, not just self-service ones | #### Examples @@ -141,12 +138,11 @@ bl quota list --output json #### Options -| Flag | Type | Required | Description | -| ------------------- | ------- | -------- | -------------------------------- | -| `--model ` | string | yes | Model name (required) | -| `--tpm ` | string | yes | Target TPM value (required) | -| `--yes` | boolean | no | Skip downgrade confirmation | -| `--region ` | string | no | API region (default: cn-beijing) | +| Flag | Type | Required | Description | +| ----------------- | ------- | -------- | --------------------------- | +| `--model ` | string | yes | Model name (required) | +| `--tpm ` | string | yes | Target TPM value (required) | +| `--yes` | boolean | no | Skip downgrade confirmation | #### Examples diff --git a/skills/bailian-cli/reference/usage.md b/skills/bailian-cli/reference/usage.md index 52ccd11..9b9449c 100644 --- a/skills/bailian-cli/reference/usage.md +++ b/skills/bailian-cli/reference/usage.md @@ -30,7 +30,6 @@ Index: [index.md](index.md) | `--model ` | string | no | Model name(s) to query, comma-separated for multiple; omit for all models | | `--expiring ` | string | no | Only show quotas expiring within N days | | `--sort ` | string | no | Sort by: remaining (ascending), expires (ascending) | -| `--region ` | string | no | API region (default: cn-beijing) | #### Examples @@ -59,7 +58,7 @@ bl usage free --model qwen-turbo --output json ``` ```bash -bl usage free --model qwen3-max --region cn-beijing +bl usage free --model qwen3-max --console-region cn-beijing ``` ### `bl usage freetier` @@ -72,13 +71,12 @@ bl usage free --model qwen3-max --region cn-beijing #### Options -| Flag | Type | Required | Description | -| ------------------- | ------- | -------- | ------------------------------------------- | -| `--model ` | string | no | Model name(s), comma-separated for multiple | -| `--all` | boolean | no | Apply to all free-tier models | -| `--on` | boolean | no | Enable auto-stop (default behavior) | -| `--off` | boolean | no | Disable auto-stop | -| `--region ` | string | no | API region (default: cn-beijing) | +| Flag | Type | Required | Description | +| ----------------- | ------- | -------- | ------------------------------------------- | +| `--model ` | string | no | Model name(s), comma-separated for multiple | +| `--all` | boolean | no | Apply to all free-tier models | +| `--on` | boolean | no | Enable auto-stop (default behavior) | +| `--off` | boolean | no | Disable auto-stop | #### Examples @@ -122,7 +120,6 @@ bl usage freetier --off --all | `--days ` | string | no | Number of days (default: 7) | | `--type ` | string | no | Model type: Text, Vision, Multimodal, Audio, Embedding | | `--workspace-id ` | string | no | Workspace ID (env: BAILIAN_WORKSPACE_ID) | -| `--region ` | string | no | API region (default: cn-beijing) | #### Examples diff --git a/skills/bailian-cli/reference/workspace.md b/skills/bailian-cli/reference/workspace.md index 2428721..3606bb0 100644 --- a/skills/bailian-cli/reference/workspace.md +++ b/skills/bailian-cli/reference/workspace.md @@ -23,10 +23,9 @@ Index: [index.md](index.md) #### Options -| Flag | Type | Required | Description | -| ------------------- | ------ | -------- | -------------------------------- | -| `--list ` | string | no | Limit number of results | -| `--region ` | string | no | API region (default: cn-beijing) | +| Flag | Type | Required | Description | +| ------------ | ------ | -------- | ----------------------- | +| `--list ` | string | no | Limit number of results | #### Examples