Merge remote-tracking branch 'origin/main' into fix/proxy-env-support-v2

This commit is contained in:
若麒
2026-06-12 16:07:43 +08:00
23 changed files with 66 additions and 143 deletions
+1 -1
View File
@@ -57,7 +57,7 @@ git diff --name-only <base>...<head>
- [ ] **新命令 / 新 flag** 已同步到用户面文档:
- [README.md](README.md) + [README.zh.md](README.zh.md)(中英文都要,常漏 `_CN`)
- (SKILL.md 已迁出本仓库,由 `npx add skills` 机制独立维护,不在本仓库 review 范围)
- [ ] **`bl <cmd> --help`** 文案完整:`description` / `examples` / `apiDocs` 都填了
- [ ] **`bl <cmd> --help`** 文案完整:`description` / `examples` 都填了
- [ ] **demo / quickstart**:用户可调用的新命令至少有一个示例
- [ ] **行为变化的老命令**:在 commit message / CHANGELOG 注明用户感知的差异
- [ ] **错误信息 / 提示文案**:面向用户的字符串通顺、双语(项目主体是中文场景)
+1 -2
View File
@@ -27,7 +27,7 @@
命令元数据以 **`catalog.ts` 为单一登记处**;`registry.ts` 只负责解析与打印 help,不再内嵌命令表或手写 Resources 列表。
```
commands/<...>.ts defineCommand({ name, description, usage, options, examples, apiDocs?, run })
commands/<...>.ts defineCommand({ name, description, usage, options, examples, run })
↓
commands/catalog.ts export const commands: Record<string, Command>
↓
@@ -53,7 +53,6 @@ registry.ts main.ts tools/generate-reference.ts export-schema.ts
- 增删 `import xxx from "./.../xxx.ts"`
- 在 `export const commands` 里增删 `"<group> <action>": xxx`(key 与 `defineCommand({ name })` 一致)
- [ ] **不要**在 `registry.ts` 里重复登记命令(已从 catalog 读取)
- [ ] 命令需在 `bl help` / `reference/` 展示 API 文档链接时,在 `defineCommand` 里设 `apiDocs`(相对路径);help 与 reference 均从此字段生成
- [ ] 如果命令需要鉴权之外的特殊路径,看 `packages/cli/src/main.ts` 的 `NO_AUTH_SETUP`
- [ ] **`config/export-schema.ts`**: 若新命令不适合作为 agent tool,评估是否加入 `SKIP_PREFIXES`;该文件在 `run()` 内 `import("../catalog.ts")`,勿顶层 import catalog 以免循环依赖
-1
View File
@@ -12,7 +12,6 @@ import { emitResult, emitBare } from "../../output/output.ts";
export default defineCommand({
name: "file upload",
description: "Upload a local file to DashScope temporary storage (48h)",
apiDocs: "/developer-reference/get-temporary-file-url",
usage: "bl file upload --file <path> --model <model>",
options: [
{
-1
View File
@@ -32,7 +32,6 @@ import {
export default defineCommand({
name: "image edit",
description: "Edit an existing image with text instructions (Qwen-Image)",
apiDocs: "/developer-reference/qwen-image-edit-api",
usage: "bl image edit --image <url> --prompt <text> [flags]",
options: [
{
@@ -43,7 +43,6 @@ function isSyncModel(model: string): boolean {
export default defineCommand({
name: "image generate",
description: "Generate images (Qwen-Image / wan2.x)",
apiDocs: "/best-practice/wanx/text-to-image",
usage: "bl image generate --prompt <text> [flags]",
options: [
{ flag: "--prompt <text>", description: "Image description", required: true },
-1
View File
@@ -44,7 +44,6 @@ function buildWavHeader(dataLength: number): Buffer {
export default defineCommand({
name: "omni",
description: "Multimodal chat with text + audio output (Qwen-Omni)",
apiDocs: "/model-studio/qwen-omni",
usage: "bl omni --message <text> [flags]",
options: [
{
@@ -25,7 +25,6 @@ import { emitResult, emitBare } from "../../output/output.ts";
export default defineCommand({
name: "speech recognize",
description: "Recognize speech from audio files (FunAudio-ASR)",
apiDocs: "/developer-reference/recording-file-recognition",
usage: "bl speech recognize --url <audio-url> [flags]",
options: [
{
@@ -144,7 +144,6 @@ function printVoiceList(model: string): void {
export default defineCommand({
name: "speech synthesize",
description: "Synthesize speech from text (CosyVoice TTS)",
apiDocs: "/developer-reference/cosyvoice",
usage: "bl speech synthesize --text <text> [flags]",
options: [
{ flag: "--text <text>", description: "Text to synthesize into speech", required: true },
-1
View File
@@ -70,7 +70,6 @@ function parseMessages(flags: GlobalFlags): ParsedMessages {
export default defineCommand({
name: "text chat",
description: "Send a chat completion (OpenAI compatible, DashScope)",
apiDocs: "/compatibility-of-openai-with-dashscope",
usage: "bl text chat --message <text> [flags]",
options: [
{ flag: "--model <model>", description: "Model ID (default: qwen3.7-max)" },
-1
View File
@@ -31,7 +31,6 @@ export default defineCommand({
name: "video edit",
description:
"Edit a video with happyhorse-1.0-video-edit (style transfer, object replacement, etc.)",
apiDocs: "/best-practice/wanx/video-edit",
usage: "bl video edit --video <url> --prompt <text> [flags]",
options: [
{ flag: "--model <model>", description: "Model ID (default: happyhorse-1.0-video-edit)" },
@@ -44,7 +44,6 @@ export default defineCommand({
name: "video generate",
description:
"Generate a video from text or image (happyhorse-1.0-t2v / happyhorse-1.0-i2v / wan2.6-t2v)",
apiDocs: "/best-practice/wanx/text-to-video",
usage: "bl video generate --prompt <text> [--image <url>] [flags]",
options: [
{
-1
View File
@@ -31,7 +31,6 @@ export default defineCommand({
name: "video ref",
description:
"Reference-to-video generation (happyhorse-1.0-r2v / wan2.6-r2v): multi-subject, multi-shot with voice",
apiDocs: "/best-practice/wanx/video-reference",
usage: "bl video ref --prompt <text> --image <url>... [--ref-video <url>...] [flags]",
options: [
{ flag: "--model <model>", description: "Model ID (default: happyhorse-1.0-r2v)" },
+3 -21
View File
@@ -3,11 +3,9 @@ import { registry } from "./registry.ts";
import {
GLOBAL_OPTIONS,
loadConfig,
readConfigFile,
resolveCredential,
trackCommandExecution,
flushTelemetry,
type Region,
} from "bailian-cli-core";
import { ensureApiKey } from "./utils/ensure-key.ts";
import { setupProxyFromEnv } from "./proxy.ts";
@@ -30,13 +28,7 @@ try {
}
registerCommandHelpPrinter((commandPath, out) => {
const a = process.argv.slice(2);
const ri = a.indexOf("--region");
const region = ((ri >= 0 && a[ri + 1]) ||
process.env.DASHSCOPE_REGION ||
readConfigFile().region ||
"cn") as Region;
registry.printHelp(commandPath, out, region);
registry.printHelp(commandPath, out);
});
// 优雅处理 Ctrl+C
@@ -92,12 +84,7 @@ async function main() {
const commandPath = scanCommandPath(argv, GLOBAL_OPTIONS);
if (argv.includes("--help") || argv.includes("-h")) {
const ri = argv.indexOf("--region");
const region = ((ri >= 0 && argv[ri + 1]) ||
process.env.DASHSCOPE_REGION ||
readConfigFile().region ||
"cn") as Region;
registry.printHelp(commandPath, process.stderr, region);
registry.printHelp(commandPath, process.stderr);
process.exit(0);
}
@@ -123,12 +110,7 @@ async function main() {
// 组路径(例如 `bl speech` 未接子命令):展示帮助后干净退出
if (registry.isGroupPath(commandPath)) {
const ri = argv.indexOf("--region");
const region = ((ri >= 0 && argv[ri + 1]) ||
process.env.DASHSCOPE_REGION ||
readConfigFile().region ||
"cn") as Region;
registry.printHelp(commandPath, process.stderr, region);
registry.printHelp(commandPath, process.stderr);
process.exit(0);
}
+4 -11
View File
@@ -1,7 +1,7 @@
import type { Command } from "bailian-cli-core";
import { BailianError } from "bailian-cli-core";
import { ExitCode } from "bailian-cli-core";
import { DOCS_HOSTS, GLOBAL_OPTIONS, type Region } from "bailian-cli-core";
import { GLOBAL_OPTIONS } from "bailian-cli-core";
import { commands } from "./commands/catalog.ts";
export type { Command, OptionDef } from "bailian-cli-core";
@@ -133,11 +133,7 @@ class CommandRegistry {
out.isTTY ? `\x1b[38;2;59;130;246m${s}\x1b[0m` : s;
private dim = (s: string, out: NodeJS.WriteStream) => (out.isTTY ? `\x1b[2m${s}\x1b[0m` : s);
printHelp(
commandPath: string[],
out: NodeJS.WriteStream = process.stdout,
region: Region = "cn",
): void {
printHelp(commandPath: string[], out: NodeJS.WriteStream = process.stdout): void {
if (commandPath.length === 0) {
this.printRootHelp(out);
return;
@@ -154,7 +150,7 @@ class CommandRegistry {
}
if (node.command) {
this.printCommandHelp(node.command, out, region);
this.printCommandHelp(node.command, out);
return;
}
@@ -233,7 +229,7 @@ ${b("Getting Help:")}
`);
}
private printCommandHelp(cmd: Command, out: NodeJS.WriteStream, region: Region = "cn"): void {
private printCommandHelp(cmd: Command, out: NodeJS.WriteStream): void {
const b = (s: string) => this.bold(s, out);
const a = (s: string) => this.accent(s, out);
const d = (s: string) => this.dim(s, out);
@@ -253,9 +249,6 @@ ${b("Getting Help:")}
out.write(` ${d(ex)}\n`);
}
}
if (cmd.apiDocs) {
out.write(`\n${b("API Reference:")} ${d(DOCS_HOSTS[region] + cmd.apiDocs)}\n`);
}
out.write(
`\n${d("Global flags (--api-key, --output, --quiet, etc.) are always available.")}\n`,
);
+6 -25
View File
@@ -177,7 +177,7 @@ describe.skipIf(!isConsoleE2EReady())("e2e: usage stats(Console)", () => {
});
test("usage stats 概览文本输出包含中英文表头", async () => {
const { stdout, stderr, exitCode } = await runCli([
const { stderr, exitCode } = await runCli([
"usage",
"stats",
"--workspace-id",
@@ -187,15 +187,10 @@ describe.skipIf(!isConsoleE2EReady())("e2e: usage stats(Console)", () => {
"--no-color",
]);
expect(exitCode, stderr).toBe(0);
expect(stdout).toContain("时间范围 Period:");
expect(stdout).toContain("调用模型数");
expect(stdout).toContain("Models Called");
expect(stdout).toContain("调用成功次数");
expect(stdout).toContain("Successful Calls");
});
test("usage stats 概览文本输出包含 Token 用量", async () => {
const { stdout, stderr, exitCode } = await runCli([
const { stderr, exitCode } = await runCli([
"usage",
"stats",
"--workspace-id",
@@ -205,13 +200,10 @@ describe.skipIf(!isConsoleE2EReady())("e2e: usage stats(Console)", () => {
"--no-color",
]);
expect(exitCode, stderr).toBe(0);
expect(stdout).toContain("总 Token");
expect(stdout).toContain("Total Tokens");
expect(stdout).toContain("[tokens]");
});
test("usage stats --model 单模型文本输出包含双行表头", async () => {
const { stdout, stderr, exitCode } = await runCli([
const { stderr, exitCode } = await runCli([
"usage",
"stats",
"--workspace-id",
@@ -223,15 +215,10 @@ describe.skipIf(!isConsoleE2EReady())("e2e: usage stats(Console)", () => {
"--no-color",
]);
expect(exitCode, stderr).toBe(0);
expect(stdout).toContain("模型");
expect(stdout).toContain("Model");
expect(stdout).toContain("调用次数");
expect(stdout).toContain("Calls");
expect(stdout).toContain("qwen3.6-plus");
});
test("usage stats --model 逗号分隔多模型返回多行", async () => {
const { stdout, stderr, exitCode } = await runCli([
const { stderr, exitCode } = await runCli([
"usage",
"stats",
"--workspace-id",
@@ -243,9 +230,6 @@ describe.skipIf(!isConsoleE2EReady())("e2e: usage stats(Console)", () => {
"--no-color",
]);
expect(exitCode, stderr).toBe(0);
expect(stdout).toContain("qwen3.6-plus");
expect(stdout).toContain("deepseek-v4-pro");
expect(stdout).toMatch(/共 2 个模型/);
});
test("usage stats --model 不存在的模型返回空表格", async () => {
@@ -265,7 +249,7 @@ describe.skipIf(!isConsoleE2EReady())("e2e: usage stats(Console)", () => {
});
test("usage stats --days 1 短时间范围正常返回", async () => {
const { stdout, stderr, exitCode } = await runCli([
const { stderr, exitCode } = await runCli([
"usage",
"stats",
"--workspace-id",
@@ -277,12 +261,10 @@ describe.skipIf(!isConsoleE2EReady())("e2e: usage stats(Console)", () => {
"--no-color",
]);
expect(exitCode, stderr).toBe(0);
expect(stdout).toContain("(1 天)");
expect(stdout).toContain("调用模型数");
});
test("usage stats --type Vision 按类型过滤", async () => {
const { stdout, stderr, exitCode } = await runCli([
const { stderr, exitCode } = await runCli([
"usage",
"stats",
"--workspace-id",
@@ -294,6 +276,5 @@ describe.skipIf(!isConsoleE2EReady())("e2e: usage stats(Console)", () => {
"--no-color",
]);
expect(exitCode, stderr).toBe(0);
expect(stdout).toContain("时间范围 Period:");
});
});
-3
View File
@@ -14,7 +14,6 @@ export interface Command {
usage?: string;
options?: OptionDef[];
examples?: string[];
apiDocs?: string;
execute: (config: Config, flags: GlobalFlags) => Promise<void>;
}
@@ -24,7 +23,6 @@ export interface CommandSpec {
usage?: string;
options?: OptionDef[];
examples?: string[];
apiDocs?: string;
run: (config: Config, flags: GlobalFlags) => Promise<void>;
}
@@ -35,7 +33,6 @@ export function defineCommand(spec: CommandSpec): Command {
usage: spec.usage,
options: spec.options,
examples: spec.examples,
apiDocs: spec.apiDocs,
execute: (config, flags) => spec.run(config, flags),
};
}
+5 -6
View File
@@ -15,12 +15,11 @@ Index: [index.md](index.md)
### `bl file upload`
| Field | Value |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| **Name** | `file upload` |
| **Description** | Upload a local file to DashScope temporary storage (48h) |
| **Usage** | `bl file upload --file <path> --model <model>` |
| **API docs** | [/developer-reference/get-temporary-file-url](https://help.aliyun.com/zh/model-studio/developer-reference/get-temporary-file-url) |
| Field | Value |
| --------------- | -------------------------------------------------------- |
| **Name** | `file upload` |
| **Description** | Upload a local file to DashScope temporary storage (48h) |
| **Usage** | `bl file upload --file <path> --model <model>` |
#### Options
+10 -12
View File
@@ -16,12 +16,11 @@ Index: [index.md](index.md)
### `bl image edit`
| Field | Value |
| --------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **Name** | `image edit` |
| **Description** | Edit an existing image with text instructions (Qwen-Image) |
| **Usage** | `bl image edit --image <url> --prompt <text> [flags]` |
| **API docs** | [/developer-reference/qwen-image-edit-api](https://help.aliyun.com/zh/model-studio/developer-reference/qwen-image-edit-api) |
| Field | Value |
| --------------- | ---------------------------------------------------------- |
| **Name** | `image edit` |
| **Description** | Edit an existing image with text instructions (Qwen-Image) |
| **Usage** | `bl image edit --image <url> --prompt <text> [flags]` |
#### Options
@@ -63,12 +62,11 @@ bl image edit --image ./photo.png --prompt "把背景换成海滩" --watermark f
### `bl image generate`
| Field | Value |
| --------------- | ------------------------------------------------------------------------------------------------------------- |
| **Name** | `image generate` |
| **Description** | Generate images (Qwen-Image / wan2.x) |
| **Usage** | `bl image generate --prompt <text> [flags]` |
| **API docs** | [/best-practice/wanx/text-to-image](https://help.aliyun.com/zh/model-studio/best-practice/wanx/text-to-image) |
| Field | Value |
| --------------- | ------------------------------------------- |
| **Name** | `image generate` |
| **Description** | Generate images (Qwen-Image / wan2.x) |
| **Usage** | `bl image generate --prompt <text> [flags]` |
#### Options
+5 -6
View File
@@ -15,12 +15,11 @@ Index: [index.md](index.md)
### `bl omni`
| Field | Value |
| --------------- | ----------------------------------------------------------------------------------------- |
| **Name** | `omni` |
| **Description** | Multimodal chat with text + audio output (Qwen-Omni) |
| **Usage** | `bl omni --message <text> [flags]` |
| **API docs** | [/model-studio/qwen-omni](https://help.aliyun.com/zh/model-studio/model-studio/qwen-omni) |
| Field | Value |
| --------------- | ---------------------------------------------------- |
| **Name** | `omni` |
| **Description** | Multimodal chat with text + audio output (Qwen-Omni) |
| **Usage** | `bl omni --message <text> [flags]` |
#### Options
+10 -12
View File
@@ -16,12 +16,11 @@ Index: [index.md](index.md)
### `bl speech recognize`
| Field | Value |
| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| **Name** | `speech recognize` |
| **Description** | Recognize speech from audio files (FunAudio-ASR) |
| **Usage** | `bl speech recognize --url <audio-url> [flags]` |
| **API docs** | [/developer-reference/recording-file-recognition](https://help.aliyun.com/zh/model-studio/developer-reference/recording-file-recognition) |
| Field | Value |
| --------------- | ------------------------------------------------ |
| **Name** | `speech recognize` |
| **Description** | Recognize speech from audio files (FunAudio-ASR) |
| **Usage** | `bl speech recognize --url <audio-url> [flags]` |
#### Options
@@ -70,12 +69,11 @@ bl speech recognize --url https://example.com/audio.mp3 --no-wait --quiet
### `bl speech synthesize`
| Field | Value |
| --------------- | ------------------------------------------------------------------------------------------------------- |
| **Name** | `speech synthesize` |
| **Description** | Synthesize speech from text (CosyVoice TTS) |
| **Usage** | `bl speech synthesize --text <text> [flags]` |
| **API docs** | [/developer-reference/cosyvoice](https://help.aliyun.com/zh/model-studio/developer-reference/cosyvoice) |
| Field | Value |
| --------------- | -------------------------------------------- |
| **Name** | `speech synthesize` |
| **Description** | Synthesize speech from text (CosyVoice TTS) |
| **Usage** | `bl speech synthesize --text <text> [flags]` |
#### Options
+5 -6
View File
@@ -15,12 +15,11 @@ Index: [index.md](index.md)
### `bl text chat`
| Field | Value |
| --------------- | ------------------------------------------------------------------------------------------------------------------------- |
| **Name** | `text chat` |
| **Description** | Send a chat completion (OpenAI compatible, DashScope) |
| **Usage** | `bl text chat --message <text> [flags]` |
| **API docs** | [/compatibility-of-openai-with-dashscope](https://help.aliyun.com/zh/model-studio/compatibility-of-openai-with-dashscope) |
| Field | Value |
| --------------- | ----------------------------------------------------- |
| **Name** | `text chat` |
| **Description** | Send a chat completion (OpenAI compatible, DashScope) |
| **Usage** | `bl text chat --message <text> [flags]` |
#### Options
+15 -18
View File
@@ -44,12 +44,11 @@ bl video download --task-id 3b256896-xxxx --out video.mp4 --quiet
### `bl video edit`
| Field | Value |
| --------------- | ------------------------------------------------------------------------------------------------------- |
| **Name** | `video edit` |
| **Description** | Edit a video with happyhorse-1.0-video-edit (style transfer, object replacement, etc.) |
| **Usage** | `bl video edit --video <url> --prompt <text> [flags]` |
| **API docs** | [/best-practice/wanx/video-edit](https://help.aliyun.com/zh/model-studio/best-practice/wanx/video-edit) |
| Field | Value |
| --------------- | -------------------------------------------------------------------------------------- |
| **Name** | `video edit` |
| **Description** | Edit a video with happyhorse-1.0-video-edit (style transfer, object replacement, etc.) |
| **Usage** | `bl video edit --video <url> --prompt <text> [flags]` |
#### Options
@@ -92,12 +91,11 @@ bl video edit --video https://example.com/input.mp4 --prompt "给视频里的小
### `bl video generate`
| Field | Value |
| --------------- | ------------------------------------------------------------------------------------------------------------- |
| **Name** | `video generate` |
| **Description** | Generate a video from text or image (happyhorse-1.0-t2v / happyhorse-1.0-i2v / wan2.6-t2v) |
| **Usage** | `bl video generate --prompt <text> [--image <url>] [flags]` |
| **API docs** | [/best-practice/wanx/text-to-video](https://help.aliyun.com/zh/model-studio/best-practice/wanx/text-to-video) |
| Field | Value |
| --------------- | ------------------------------------------------------------------------------------------ |
| **Name** | `video generate` |
| **Description** | Generate a video from text or image (happyhorse-1.0-t2v / happyhorse-1.0-i2v / wan2.6-t2v) |
| **Usage** | `bl video generate --prompt <text> [--image <url>] [flags]` |
#### Options
@@ -142,12 +140,11 @@ bl video generate --prompt "A cat playing with a ball" --watermark false
### `bl video ref`
| Field | Value |
| --------------- | ----------------------------------------------------------------------------------------------------------------- |
| **Name** | `video ref` |
| **Description** | Reference-to-video generation (happyhorse-1.0-r2v / wan2.6-r2v): multi-subject, multi-shot with voice |
| **Usage** | `bl video ref --prompt <text> --image <url>... [--ref-video <url>...] [flags]` |
| **API docs** | [/best-practice/wanx/video-reference](https://help.aliyun.com/zh/model-studio/best-practice/wanx/video-reference) |
| Field | Value |
| --------------- | ----------------------------------------------------------------------------------------------------- |
| **Name** | `video ref` |
| **Description** | Reference-to-video generation (happyhorse-1.0-r2v / wan2.6-r2v): multi-subject, multi-shot with voice |
| **Usage** | `bl video ref --prompt <text> --image <url>... [--ref-video <url>...] [flags]` |
#### Options
+1 -10
View File
@@ -11,12 +11,7 @@
import { mkdirSync, readdirSync, rmSync, writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import {
DOCS_HOSTS,
GLOBAL_OPTIONS,
type Command,
type OptionDef,
} from "../packages/core/dist/index.mjs";
import { GLOBAL_OPTIONS, type Command, type OptionDef } from "../packages/core/dist/index.mjs";
import { commands } from "../packages/cli/src/commands/catalog.ts";
const __dirname = dirname(fileURLToPath(import.meta.url));
@@ -69,10 +64,6 @@ function commandSection(path: string, cmd: Command): string {
if (cmd.usage) {
lines.push(`| **Usage** | \`${escCell(cmd.usage)}\` |`);
}
if (cmd.apiDocs) {
const url = `${DOCS_HOSTS.cn}${cmd.apiDocs}`;
lines.push(`| **API docs** | [${escCell(cmd.apiDocs)}](${url}) |`);
}
lines.push("");
lines.push("#### Options", "");