Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/cli/src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,12 @@ export function parseFlags(argv: string[], options: OptionDef[]): GlobalFlags {
);
}

// Switch-style flags (--quiet, --dry-run): no value. Value flags need a non-flag next token.
if (schema.booleans.has(camelKey)) {
(flags as Record<string, unknown>)[camelKey] = true;
i++;
continue;
}

// --prompt <text>, --watermark <bool>, …
if (value === undefined) {
i++;
const next = argv[i];
Expand Down
6 changes: 2 additions & 4 deletions packages/cli/src/commands/advisor/recommend.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import {
analyzeIntent,
buildDocLink,
type Config,
defineCommand,
detectOutputFormat,
type GetModelsOptions,
type GlobalFlags,
getModels,
type IntentProfile,
isInteractive,
Expand Down Expand Up @@ -241,9 +239,9 @@ export default defineCommand({
'bl advisor recommend --message "Long document summarization" --dry-run',
"bl advisor recommend # Interactive input",
],
async run(config: Config, flags: GlobalFlags) {
async run(config, flags) {
const positional = ((flags as Record<string, unknown>)._positional as string[]) ?? [];
let userInput = (flags.message as string) || positional.join(" ");
let userInput = flags.message || positional.join(" ");

if (!userInput.trim()) {
if (isInteractive({ nonInteractive: config.nonInteractive })) {
Expand Down
20 changes: 9 additions & 11 deletions packages/cli/src/commands/app/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
appCompletionEndpoint,
parseSSE,
detectOutputFormat,
type Config,
type GlobalFlags,
type AppCompletionRequest,
type AppStreamChunk,
type AppCompletionResponse,
Expand Down Expand Up @@ -42,11 +40,11 @@ export default defineCommand({
'bl app call --app-id abc123 --prompt "搜索资料" --pipeline-ids pipe1,pipe2',
'bl app call --app-id abc123 --prompt "开始" --biz-params \'{"key":"value"}\'',
],
async run(config: Config, flags: GlobalFlags) {
const appId = flags.appId as string;
async run(config, flags) {
const appId = flags.appId;
if (!appId) failIfMissing("app-id", "bl app call --app-id <id> --prompt <text>");

const prompt = flags.prompt as string;
const prompt = flags.prompt;
if (!prompt) failIfMissing("prompt", "bl app call --app-id <id> --prompt <text>");

const shouldStream =
Expand All @@ -61,17 +59,17 @@ export default defineCommand({
};

if (flags.sessionId) {
body.input.session_id = flags.sessionId as string;
body.input.session_id = flags.sessionId;
}

// Pass image URLs via image_list
const imageUrls = flags.image as string[] | undefined;
const imageUrls = flags.image;
if (imageUrls && imageUrls.length > 0) {
body.input.image_list = imageUrls;
}

// Pass pre-uploaded file IDs
const fileIds = flags.fileId as string[] | undefined;
const fileIds = flags.fileId;
if (fileIds && fileIds.length > 0) {
body.input.file_ids = fileIds;
}
Expand All @@ -81,20 +79,20 @@ export default defineCommand({
}

if (flags.pipelineIds) {
const ids = (flags.pipelineIds as string)
const ids = flags.pipelineIds
.split(",")
.map((s) => s.trim())
.filter(Boolean);
body.parameters!.rag_options = { pipeline_ids: ids };
}

if (flags.memoryId) {
body.parameters!.memory_id = flags.memoryId as string;
body.parameters!.memory_id = flags.memoryId;
}

if (flags.bizParams) {
try {
body.input.biz_params = JSON.parse(flags.bizParams as string);
body.input.biz_params = JSON.parse(flags.bizParams);
} catch {
process.stderr.write("Error: --biz-params must be valid JSON\n");
process.exit(1);
Expand Down
10 changes: 4 additions & 6 deletions packages/cli/src/commands/app/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import {
callConsoleGateway,
resolveConsoleGatewayCredential,
detectOutputFormat,
type Config,
type GlobalFlags,
} from "bailian-cli-core";
import { emitResult } from "../../output/output.ts";

Expand Down Expand Up @@ -46,10 +44,10 @@ export default defineCommand({
"bl app list --page 2 --page-size 10",
"bl app list --output json",
],
async run(config: Config, flags: GlobalFlags) {
const name = (flags.name as string) || "";
const pageNo = (flags.page as number) || 1;
const pageSize = (flags.pageSize as number) || 30;
async run(config, flags) {
const name = flags.name || "";
const pageNo = flags.page || 1;
const pageSize = flags.pageSize || 30;
const format = detectOutputFormat(config.output);

const credential = await resolveConsoleGatewayCredential(config);
Expand Down
8 changes: 3 additions & 5 deletions packages/cli/src/commands/auth/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import {
maskToken,
readConfigFile,
writeConfigFile,
type Config,
type GlobalFlags,
} from "bailian-cli-core";
import { printQuickStart } from "../../output/banner.ts";
import { emitBare } from "../../output/output.ts";
Expand Down Expand Up @@ -34,7 +32,7 @@ export default defineCommand({
},
],
examples: ["bl auth login --api-key sk-xxxxx", "bl auth login --console"],
async run(config: Config, flags: GlobalFlags) {
async run(config, flags) {
if (flags.console) {
if (config.dryRun) {
emitBare(
Expand Down Expand Up @@ -66,13 +64,13 @@ export default defineCommand({
}
}

const key = (flags.apiKey as string) || config.apiKey;
const key = flags.apiKey || config.apiKey;
if (!key) {
printCurrentCommandHelp(process.stderr);
process.exit(0);
}

const baseUrl = (flags.baseUrl as string) || undefined;
const baseUrl = flags.baseUrl || undefined;
const effectiveConfig = baseUrl ? { ...config, baseUrl } : config;

if (!config.dryRun) {
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/src/commands/auth/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import {
readConfigFile,
writeConfigFile,
getConfigPath,
type Config,
type GlobalFlags,
} from "bailian-cli-core";
import { emitBare } from "../../output/output.ts";

Expand Down Expand Up @@ -35,7 +33,7 @@ export default defineCommand({
"bl auth logout --dry-run",
"bl auth logout --yes",
],
async run(config: Config, flags: GlobalFlags) {
async run(config, flags) {
const file = readConfigFile();

if (flags.console) {
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/commands/auth/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
detectOutputFormat,
maskToken,
type Config,
type GlobalFlags,
type ResolvedCredential,
} from "bailian-cli-core";
import { emitResult, emitBare } from "../../output/output.ts";
Expand Down Expand Up @@ -155,7 +154,7 @@ export default defineCommand({
},
],
examples: ["bl auth status", "bl auth status --output json"],
async run(config: Config, _flags: GlobalFlags) {
async run(config, _flags) {
const format = detectOutputFormat(config.output);
const status = await buildStatus(config);

Expand Down
6 changes: 2 additions & 4 deletions packages/cli/src/commands/config/export-schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { defineCommand, generateToolSchema } from "bailian-cli-core";
import type { Config } from "bailian-cli-core";
import type { GlobalFlags } from "bailian-cli-core";
import { BailianError } from "bailian-cli-core";
import { ExitCode } from "bailian-cli-core";

Expand All @@ -21,9 +19,9 @@ export default defineCommand({
},
],
examples: ["bl config export-schema", 'bl config export-schema --command "video generate"'],
async run(config: Config, flags: GlobalFlags) {
async run(config, flags) {
const { commands } = await import("../catalog.ts");
const targetCommand = flags.command as string | undefined;
const targetCommand = flags.command;

if (targetCommand) {
const command = commands[targetCommand];
Expand Down
8 changes: 3 additions & 5 deletions packages/cli/src/commands/config/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
readConfigFile,
writeConfigFile,
BailianError,
type Config,
type GlobalFlags,
ExitCode,
} from "bailian-cli-core";
import { emitResult } from "../../output/output.ts";
Expand Down Expand Up @@ -67,9 +65,9 @@ export default defineCommand({
"bl config set --key timeout --value 600",
"bl config set --key base_url --value https://dashscope.aliyuncs.com",
],
async run(config: Config, flags: GlobalFlags) {
const key = flags.key as string | undefined;
const value = flags.value as string | undefined;
async run(config, flags) {
const key = flags.key;
const value = flags.value;

if (!key || value === undefined) {
throw new BailianError(
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/src/commands/config/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import {
getConfigPath,
detectOutputFormat,
maskToken,
type Config,
type GlobalFlags,
} from "bailian-cli-core";
import { emitResult } from "../../output/output.ts";

Expand All @@ -14,7 +12,7 @@ export default defineCommand({
description: "Display current configuration",
usage: "bl config show",
examples: ["bl config show", "bl config show --output json"],
async run(config: Config, _flags: GlobalFlags) {
async run(config, _flags) {
const file = loadConfigFile();
const format = detectOutputFormat(config.output);

Expand Down
8 changes: 3 additions & 5 deletions packages/cli/src/commands/console/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {
CONSOLE_GATEWAY_NO_TOKEN_MESSAGE,
BailianError,
detectOutputFormat,
type Config,
type GlobalFlags,
} from "bailian-cli-core";
import { failIfMissing } from "../../output/prompt.ts";
import { emitResult } from "../../output/output.ts";
Expand Down Expand Up @@ -42,11 +40,11 @@ export default defineCommand({
`bl console call --api zeldaEasy.broadscope-bailian.freeTrial.queryFreeTierQuota --data '{"queryFreeTierQuotaRequest":{"models":["qwen3-max"]}}'`,
`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;
async run(config, flags) {
const api = flags.api;
if (!api) failIfMissing("api", "bl console call --api <api> --data <json>");

const dataRaw = flags.data as string;
const dataRaw = flags.data;
if (!dataRaw) failIfMissing("data", "bl console call --api <api> --data <json>");

let data: Record<string, unknown>;
Expand Down
15 changes: 4 additions & 11 deletions packages/cli/src/commands/file/upload.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
defineCommand,
resolveCredential,
detectOutputFormat,
type Config,
type GlobalFlags,
uploadFile,
} from "bailian-cli-core";
import { defineCommand, resolveCredential, detectOutputFormat, uploadFile } from "bailian-cli-core";
import { failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";

Expand All @@ -31,13 +24,13 @@ export default defineCommand({
"bl file upload --file audio.wav --model qwen3-asr-flash",
"bl file upload --file cat.png --model qwen-image-2.0",
],
async run(config: Config, flags: GlobalFlags) {
const filePath = flags.file as string | undefined;
async run(config, flags) {
const filePath = flags.file;
if (!filePath) {
failIfMissing("file", "bl file upload --file <path> --model <model>");
}

const model = flags.model as string | undefined;
const model = flags.model;
if (!model) {
failIfMissing("model", "bl file upload --file <path> --model <model>");
}
Expand Down
23 changes: 10 additions & 13 deletions packages/cli/src/commands/image/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import {
requestJson,
imageSyncEndpoint,
detectOutputFormat,
type Config,
type GlobalFlags,
resolveCredential,
resolveFileUrl,
resolveOutputDir,
Expand Down Expand Up @@ -70,19 +68,19 @@ export default defineCommand({
'bl image edit --image https://example.com/photo.png --prompt "Remove the person" --model qwen-image-2.0-pro',
'bl image edit --image ./photo.png --prompt "把背景换成海滩" --watermark false',
],
async run(config: Config, flags: GlobalFlags) {
async run(config, flags) {
// Normalize --image to string array (supports both single and repeated flags)
let rawImages: string[] = [];
if (Array.isArray(flags.image)) {
rawImages = flags.image as string[];
rawImages = flags.image;
} else if (typeof flags.image === "string") {
rawImages = [flags.image];
}
if (rawImages.length === 0) {
failIfMissing("image", "bl image edit --image <url> --prompt <text>");
}

let prompt = flags.prompt as string | undefined;
let prompt = flags.prompt;
if (!prompt) {
if (isInteractive({ nonInteractive: config.nonInteractive })) {
const hint = await promptText({
Expand All @@ -98,14 +96,14 @@ export default defineCommand({
}
}

const model = (flags.model as string) || config.defaultImageModel || "qwen-image-2.0";
const model = flags.model || config.defaultImageModel || "qwen-image-2.0";

// Auto-upload local files (resolve all images in parallel)
const credential = await resolveCredential(config);
const resolvedImages = await Promise.all(
rawImages.map((img) => resolveFileUrl(img, credential.token, model)),
);
const n = (flags.n as number) ?? 1;
const n = flags.n ?? 1;

const promptExtend = resolveBooleanFlag(flags.promptExtend, true, "prompt-extend");

Expand All @@ -128,12 +126,12 @@ export default defineCommand({
],
},
parameters: {
size: resolveImageSize(flags.size as string | undefined, true),
size: resolveImageSize(flags.size, true),
n,
seed: flags.seed as number | undefined,
seed: flags.seed,
prompt_extend: promptExtend,
watermark,
negative_prompt: (flags.negativePrompt as string) || undefined,
negative_prompt: flags.negativePrompt || undefined,
},
};

Expand Down Expand Up @@ -174,12 +172,11 @@ export default defineCommand({
}

const outDir = resolveOutputDir(config, {
flagDir: flags.outDir as string | undefined,
flagDir: flags.outDir,
subDir: flags.outDir ? undefined : "images",
});

const prefix =
(flags.outPrefix as string) || generateFilename("edited", flags?.prompt as string);
const prefix = flags.outPrefix || generateFilename("edited", flags.prompt as string);

// Parallel download all images
const items =
Expand Down
Loading
Loading