Skip to content

Commit 8c398ba

Browse files
lishengzxcclaude
andcommitted
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>
1 parent e5abd1b commit 8c398ba

27 files changed

Lines changed: 128 additions & 211 deletions

File tree

packages/cli/src/commands/app/list.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ export default defineCommand({
2929
description: "Results per page (default: 30)",
3030
type: "number",
3131
},
32-
{
33-
flag: "--region <region>",
34-
description: "API region (default: cn-beijing)",
35-
},
3632
],
3733
examples: [
3834
"bl app list",
@@ -44,7 +40,6 @@ export default defineCommand({
4440
const name = (flags.name as string) || "";
4541
const pageNo = (flags.page as number) || 1;
4642
const pageSize = (flags.pageSize as number) || 30;
47-
const region = (flags.region as string) || undefined;
4843
const format = detectOutputFormat(config.output);
4944

5045
const credential = await resolveConsoleGatewayCredential(config);
@@ -61,17 +56,13 @@ export default defineCommand({
6156
};
6257

6358
if (config.dryRun) {
64-
emitResult(
65-
{ api: APP_LIST_API, data, region, token: credential.token.slice(0, 8) + "..." },
66-
format,
67-
);
59+
emitResult({ api: APP_LIST_API, data, token: credential.token.slice(0, 8) + "..." }, format);
6860
return;
6961
}
7062

7163
const result = (await callConsoleGateway(config, credential.token, {
7264
api: APP_LIST_API,
7365
data,
74-
region,
7566
})) as any;
7667

7768
const list: unknown[] = result?.data?.DataV2?.data?.data?.list ?? [];

packages/cli/src/commands/auth/login-console.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ import {
1616
const CONSOLE_LOGIN_TIMEOUT_MS = 15 * 60 * 1000;
1717
const MAX_AUTH_CALLBACK_BODY = 65536;
1818

19-
// 总是默认打开 中国站的登录页
20-
const DEFAULT_CONSOLE_ORIGIN = "https://bailian.console.aliyun.com";
19+
const CONSOLE_ORIGINS: Record<string, string> = {
20+
domestic: "https://bailian.console.aliyun.com",
21+
international: "https://modelstudio.console.alibabacloud.com",
22+
};
2123

22-
export function resolveConsoleOrigin(): string {
23-
return DEFAULT_CONSOLE_ORIGIN;
24+
export function resolveConsoleOrigin(site?: string): string {
25+
return (site && CONSOLE_ORIGINS[site]) || CONSOLE_ORIGINS.domestic!;
2426
}
2527

2628
function readBodyBounded(req: http.IncomingMessage): Promise<string> {

packages/cli/src/commands/auth/login.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ export default defineCommand({
2828
description: "DashScope API base URL (used with --api-key for validation)",
2929
},
3030
{
31-
flag: "--console",
32-
description: "Sign in via browser; opens the console login URL in your default browser",
33-
type: "boolean",
31+
flag: "--console <site>",
32+
description:
33+
"Sign in via browser; use --console-site to choose domestic (default) or international",
3434
},
3535
],
3636
examples: ["bl auth login --api-key sk-xxxxx", "bl auth login --console"],
@@ -43,7 +43,7 @@ export default defineCommand({
4343
return;
4444
}
4545
const hasApiKey = !!(config.apiKey || config.fileApiKey);
46-
await runConsoleLogin(resolveConsoleOrigin(), config, {
46+
await runConsoleLogin(resolveConsoleOrigin(config.consoleSite), config, {
4747
needApiKey: !hasApiKey,
4848
});
4949
return;

packages/cli/src/commands/console/call.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
detectOutputFormat,
88
type Config,
99
type GlobalFlags,
10-
type ConsoleSite,
1110
} from "bailian-cli-core";
1211
import { failIfMissing } from "../../output/prompt.ts";
1312
import { emitResult } from "../../output/output.ts";
@@ -27,22 +26,10 @@ export default defineCommand({
2726
description: "Request data as JSON string",
2827
required: true,
2928
},
30-
{
31-
flag: "--region <region>",
32-
description: "Console region (e.g. cn-beijing, ap-southeast-1)",
33-
},
34-
{
35-
flag: "--site <site>",
36-
description: "Console site: domestic or international",
37-
},
38-
{
39-
flag: "--switch-agent <uid>",
40-
description: "Switch agent UID for delegated access",
41-
},
4229
],
4330
examples: [
4431
`bl console call --api zeldaEasy.broadscope-bailian.freeTrial.queryFreeTierQuota --data '{"queryFreeTierQuotaRequest":{"models":["qwen3-max"]}}'`,
45-
`bl console call --api some.api.name --data '{"key":"value"}' --region cn-beijing`,
32+
`bl console call --api some.api.name --data '{"key":"value"}' --console-region cn-beijing`,
4633
],
4734
async run(config: Config, flags: GlobalFlags) {
4835
const api = flags.api as string;
@@ -59,9 +46,6 @@ export default defineCommand({
5946
process.exit(1);
6047
}
6148

62-
const region = (flags.region as string) || undefined;
63-
const site = ((flags.site as string) || undefined) as ConsoleSite | undefined;
64-
const switchAgent = flags.switchAgent ? Number(flags.switchAgent) : undefined;
6549
const format = detectOutputFormat(config.output);
6650

6751
let token: string | undefined;
@@ -74,16 +58,13 @@ export default defineCommand({
7458
}
7559

7660
if (config.dryRun) {
77-
emitResult({ api, data, region, token: token ? token.slice(0, 8) + "..." : null }, format);
61+
emitResult({ api, data, token: token ? token.slice(0, 8) + "..." : null }, format);
7862
return;
7963
}
8064

8165
const result = await callConsoleGateway(config, token, {
8266
api,
8367
data,
84-
region,
85-
site,
86-
switchAgent,
8768
});
8869

8970
emitResult(result, format);

packages/cli/src/commands/mcp/list.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,13 @@ export default defineCommand({
3535
},
3636
{ flag: "--page <n>", description: "Page number (default: 1)", type: "number" },
3737
{ flag: "--page-size <n>", description: "Results per page (default: 30)", type: "number" },
38-
{ flag: "--region <region>", description: "API region (default: cn-beijing)" },
3938
],
4039
examples: ["bl mcp list", "bl mcp list --name 金融", "bl mcp list --output json"],
4140
async run(config: Config, flags: GlobalFlags) {
4241
const serverName = (flags.name as string) || "";
4342
const type = (flags.type as string) || "OFFICIAL";
4443
const pageNo = (flags.page as number) || 1;
4544
const pageSize = (flags.pageSize as number) || 30;
46-
const region = (flags.region as string) || undefined;
4745
const format = detectOutputFormat(config.output);
4846

4947
const data = {
@@ -58,7 +56,7 @@ export default defineCommand({
5856
};
5957

6058
if (config.dryRun) {
61-
emitResult({ api: MCP_LIST_API, data, region }, format);
59+
emitResult({ api: MCP_LIST_API, data }, format);
6260
return;
6361
}
6462

@@ -67,7 +65,6 @@ export default defineCommand({
6765
const result = (await callConsoleGateway(config, credential.token, {
6866
api: MCP_LIST_API,
6967
data,
70-
region,
7168
})) as Record<string, unknown>;
7269

7370
const dataField = (result?.data as Record<string, unknown> | undefined) ?? {};

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

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,7 @@ function extractResponseData(result: Record<string, unknown>): Record<string, un
9191
return direct ?? data;
9292
}
9393

94-
async function fetchAllModelsWithQpm(
95-
config: Config,
96-
token: string,
97-
region: string | undefined,
98-
): Promise<ModelWithQpm[]> {
94+
async function fetchAllModelsWithQpm(config: Config, token: string): Promise<ModelWithQpm[]> {
9995
const allModels: ModelWithQpm[] = [];
10096
let pageNo = 1;
10197

@@ -112,7 +108,6 @@ async function fetchAllModelsWithQpm(
112108
supports: { selfServiceLimitIncrease: true },
113109
},
114110
},
115-
region,
116111
});
117112

118113
const resp = extractResponseData(raw as Record<string, unknown>);
@@ -130,7 +125,6 @@ async function fetchAllModelsWithQpm(
130125
async function fetchMonitorData(
131126
config: Config,
132127
token: string,
133-
region: string | undefined,
134128
modelName: string,
135129
windowMinutes: number,
136130
): Promise<{ rpm: number; tpm: number }> {
@@ -155,7 +149,6 @@ async function fetchMonitorData(
155149
endTime: now,
156150
},
157151
},
158-
region,
159152
});
160153

161154
const resp = extractResponseData(raw as Record<string, unknown>);
@@ -260,10 +253,6 @@ export default defineCommand({
260253
flag: "--period <minutes>",
261254
description: "Query usage for the last N minutes (default: 2)",
262255
},
263-
{
264-
flag: "--region <region>",
265-
description: "API region (default: cn-beijing)",
266-
},
267256
],
268257
examples: [
269258
"bl quota check",
@@ -280,7 +269,6 @@ export default defineCommand({
280269
process.exit(1);
281270
}
282271
const windowMinutes = rawPeriod;
283-
const region = (flags.region as string) || undefined;
284272
const format = detectOutputFormat(config.output);
285273

286274
const credential = await resolveConsoleGatewayCredential(config);
@@ -289,14 +277,13 @@ export default defineCommand({
289277
emitResult(
290278
{
291279
apis: [MODEL_LIST_API, MONITOR_API],
292-
region,
293280
},
294281
format,
295282
);
296283
return;
297284
}
298285

299-
let models = await fetchAllModelsWithQpm(config, credential.token, region);
286+
let models = await fetchAllModelsWithQpm(config, credential.token);
300287

301288
if (modelFlag) {
302289
const names = new Set(
@@ -316,7 +303,7 @@ export default defineCommand({
316303
}
317304

318305
const monitorResults = await Promise.all(
319-
models.map((m) => fetchMonitorData(config, credential.token, region, m.model, windowMinutes)),
306+
models.map((m) => fetchMonitorData(config, credential.token, m.model, windowMinutes)),
320307
);
321308

322309
const checkRows: CheckRow[] = models.map((m, idx) => {

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,6 @@ export default defineCommand({
114114
flag: "--model <model>",
115115
description: "Filter by model name",
116116
},
117-
{
118-
flag: "--region <region>",
119-
description: "API region (default: cn-beijing)",
120-
},
121117
],
122118
examples: [
123119
"bl quota history",
@@ -130,7 +126,6 @@ export default defineCommand({
130126
const page = Number(flags.page) || 1;
131127
const pageSize = Number(flags.pageSize) || 10;
132128
const modelFilter = (flags.model as string) || undefined;
133-
const region = (flags.region as string) || undefined;
134129
const format = detectOutputFormat(config.output);
135130

136131
const credential = await resolveConsoleGatewayCredential(config);
@@ -140,7 +135,7 @@ export default defineCommand({
140135
};
141136

142137
if (config.dryRun) {
143-
emitResult({ api: HISTORY_API, data: requestData, region }, format);
138+
emitResult({ api: HISTORY_API, data: requestData }, format);
144139
return;
145140
}
146141

@@ -149,7 +144,6 @@ export default defineCommand({
149144
result = await callConsoleGateway(config, credential.token, {
150145
api: HISTORY_API,
151146
data: requestData,
152-
region,
153147
});
154148
} catch (err) {
155149
if (err instanceof BailianError && err.message.includes("NotLogined")) {

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ function extractResponseData(result: Record<string, unknown>): Record<string, un
6868
async function fetchAllModelsWithQpm(
6969
config: Config,
7070
token: string,
71-
region: string | undefined,
7271
onlySelfService: boolean,
7372
): Promise<ModelWithQpm[]> {
7473
const allModels: ModelWithQpm[] = [];
@@ -89,7 +88,6 @@ async function fetchAllModelsWithQpm(
8988
const raw = await callConsoleGateway(config, token, {
9089
api: MODEL_LIST_API,
9190
data: { input },
92-
region,
9391
});
9492

9593
const resp = extractResponseData(raw as Record<string, unknown>);
@@ -171,10 +169,6 @@ export default defineCommand({
171169
flag: "--all",
172170
description: "Show all models, not just self-service ones",
173171
},
174-
{
175-
flag: "--region <region>",
176-
description: "API region (default: cn-beijing)",
177-
},
178172
],
179173
examples: [
180174
"bl quota list",
@@ -186,7 +180,6 @@ export default defineCommand({
186180
async run(config: Config, flags: GlobalFlags) {
187181
const modelFlag = (flags.model as string) || undefined;
188182
const showAll = Boolean(flags.all);
189-
const region = (flags.region as string) || undefined;
190183
const format = detectOutputFormat(config.output);
191184

192185
const credential = await resolveConsoleGatewayCredential(config);
@@ -200,11 +193,11 @@ export default defineCommand({
200193
ignoreWorkspaceServiceSite: true,
201194
};
202195
if (!showAll) input.supports = { selfServiceLimitIncrease: true };
203-
emitResult({ api: MODEL_LIST_API, data: { input }, region }, format);
196+
emitResult({ api: MODEL_LIST_API, data: { input } }, format);
204197
return;
205198
}
206199

207-
let models = await fetchAllModelsWithQpm(config, credential.token, region, !showAll);
200+
let models = await fetchAllModelsWithQpm(config, credential.token, !showAll);
208201

209202
if (modelFlag) {
210203
const names = new Set(

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ function extractResponseData(result: Record<string, unknown>): Record<string, un
5353
async function fetchModelQpmInfo(
5454
config: Config,
5555
token: string,
56-
region: string | undefined,
5756
modelName: string,
5857
): Promise<{ model: string; qpmInfo: Record<string, QpmInfoItem> } | undefined> {
5958
const raw = await callConsoleGateway(config, token, {
@@ -69,7 +68,6 @@ async function fetchModelQpmInfo(
6968
supports: { selfServiceLimitIncrease: true },
7069
},
7170
},
72-
region,
7371
});
7472

7573
const resp = extractResponseData(raw as Record<string, unknown>);
@@ -98,10 +96,6 @@ export default defineCommand({
9896
flag: "--yes",
9997
description: "Skip downgrade confirmation",
10098
},
101-
{
102-
flag: "--region <region>",
103-
description: "API region (default: cn-beijing)",
104-
},
10599
],
106100
examples: [
107101
"bl quota request --model qwen-turbo --tpm 100000",
@@ -122,12 +116,11 @@ export default defineCommand({
122116
}
123117

124118
const autoConfirm = Boolean(flags.yes) || config.yes;
125-
const region = (flags.region as string) || undefined;
126119
const format = detectOutputFormat(config.output);
127120

128121
const credential = await resolveConsoleGatewayCredential(config);
129122

130-
const modelInfo = await fetchModelQpmInfo(config, credential.token, region, modelName);
123+
const modelInfo = await fetchModelQpmInfo(config, credential.token, modelName);
131124
if (!modelInfo) {
132125
process.stderr.write(
133126
`Error: model "${modelName}" not found or does not support self-service quota increase.\n`,
@@ -160,7 +153,7 @@ export default defineCommand({
160153
};
161154

162155
if (config.dryRun) {
163-
emitResult({ api: UPDATE_LIMITS_API, data: requestData, region }, format);
156+
emitResult({ api: UPDATE_LIMITS_API, data: requestData }, format);
164157
return;
165158
}
166159

@@ -172,7 +165,6 @@ export default defineCommand({
172165
return await callConsoleGateway(config, credential.token, {
173166
api: UPDATE_LIMITS_API,
174167
data: requestData,
175-
region,
176168
});
177169
} catch (err) {
178170
if (err instanceof BailianError && err.message.includes("NotLogined")) {

0 commit comments

Comments
 (0)