Skip to content
Merged
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
28 changes: 24 additions & 4 deletions packages/cli/src/args.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,6 +25,15 @@ interface FlagSchema {
arrays: Set<string>;
}

function buildAllowedFlagKeys(options: OptionDef[]): Set<string> {
const keys = new Set<string>();
for (const opt of options) {
const key = flagKey(opt);
if (key) keys.add(key);
}
return keys;
}

function buildSchema(options: OptionDef[]): FlagSchema {
const booleans = new Set<string>();
const numbers = new Set<string>();
Expand DownExpand Up@@ -91,6 +100,7 @@ export function scanCommandPath(argv: string[], globalOptions: OptionDef[] = [])
* - default: string
*/
export function parseFlags(argv: string[], options: OptionDef[]): GlobalFlags {
const allowedKeys = buildAllowedFlagKeys(options);
const schema = buildSchema(options);
const flags: GlobalFlags = {
quiet: false,
Expand DownExpand Up@@ -130,20 +140,30 @@ export function parseFlags(argv: string[], options: OptionDef[]): GlobalFlags {

const camelKey = kebabToCamel(key);

if (!allowedKeys.has(camelKey)) {
throw new BailianError(
`Unknown flag "--${key}". Run with --help to see available options.`,
ExitCode.USAGE,
);
}

// 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++;
value = argv[i];
const next = argv[i];
if (next === undefined || next.startsWith("-")) {
throw new BailianError(`Flag --${key} requires a value.`, ExitCode.USAGE);
}
value = next;
}

if (value === undefined)
throw new BailianError(`Flag --${key} requires a value.`, ExitCode.USAGE);

if (schema.arrays.has(camelKey)) {
const arr = (flags as Record<string, unknown>)[camelKey] as string[] | undefined;
if (arr) arr.push(value);
Expand Down
32 changes: 19 additions & 13 deletions packages/cli/src/commands/image/edit.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,13 +15,19 @@ import {
type DashScopeImageSyncResponse,
ExitCode,
BailianError,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { downloadFile } from "../../utils/download.ts";
import { runConcurrent, downloadParallel, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import { resolveImageSize } from "../../utils/image-size.ts";
import { join } from "path";
import {
BOOL_FLAG_PROMPT_EXTEND_CLI_TRUE,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

export default defineCommand({
name: "image edit",
Expand All@@ -47,9 +53,14 @@ export default defineCommand({
flag: "--negative-prompt <text>",
description: "Negative prompt to exclude unwanted content",
},
{ flag: "--prompt-extend", description: "Enable prompt smart rewrite (default: true)" },
{ flag: "--no-prompt-extend", description: "Disable prompt extend" },
{ flag: "--watermark", description: "Add watermark to output images" },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_CLI_TRUE,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--out-dir <dir>", description: "Download images to directory" },
{ flag: "--out-prefix <prefix>", description: "Filename prefix (default: edited)" },
],
Expand All@@ -58,6 +69,7 @@ export default defineCommand({
'bl image edit --image https://example.com/logo.png --prompt "Change color to blue" --n 3',
'bl image edit --image ./a.png --image ./b.png --prompt "把两张图合并成一张拼图"',
'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) {
// Normalize --image to string array (supports both single and repeated flags)
Expand DownExpand Up@@ -96,22 +108,16 @@ export default defineCommand({
);
const n = (flags.n as number) ?? 1;

// Determine prompt_extend
let promptExtend: boolean | undefined;
if (flags.noPromptExtend === true) {
promptExtend = false;
} else if (flags.promptExtend === true) {
promptExtend = true;
} else {
promptExtend = true; // default on for qwen-image
}
const promptExtend = resolveBooleanFlag(flags.promptExtend, true, "prompt-extend");

// Build content: all images first, then text prompt
const contentItems: Array<{ image?: string; text?: string }> = resolvedImages.map(
(u: string) => ({ image: u }),
);
contentItems.push({ text: prompt! });

const watermark = resolveWatermark(flags.watermark);

const body: DashScopeImageRequest = {
model,
input: {
Expand All@@ -127,7 +133,7 @@ export default defineCommand({
n,
seed: flags.seed as number | undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
negative_prompt: (flags.negativePrompt as string) || undefined,
},
};
Expand Down
38 changes: 23 additions & 15 deletions packages/cli/src/commands/image/generate.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,13 +17,19 @@ import {
type OutputFormat,
type DashScopeTaskResponse,
generateFilename,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile } from "../../utils/download.ts";
import { runConcurrent, downloadParallel, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import { resolveImageSize } from "../../utils/image-size.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_IMAGE_GENERATE,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

import { join } from "path";

Expand DownExpand Up@@ -57,11 +63,13 @@ export default defineCommand({
description: "Negative prompt to exclude unwanted content",
},
{
flag: "--prompt-extend",
description: "Automatically extend prompt for better results (default: true for qwen-image)",
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_IMAGE_GENERATE,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--no-prompt-extend", description: "Disable prompt extend" },
{ flag: "--watermark", description: "Add watermark to generated images" },
{
flag: "--no-wait",
description: "Return task ID immediately without waiting (async models only)",
Expand All@@ -78,7 +86,9 @@ export default defineCommand({
'bl image generate --prompt "一只穿太空服的猫在火星上"',
'bl image generate --prompt "Logo design" --n 3 --out-dir ./generated/',
'bl image generate --prompt "Mountain landscape" --size 2688*1536',
'bl image generate --prompt "A castle" --seed 42 --no-prompt-extend',
'bl image generate --prompt "A castle" --seed 42 --prompt-extend false',
'bl image generate --prompt "Logo" --watermark false',
'bl image generate --prompt "An alien in the space" --watermark false',
'bl image generate --prompt "sunset" --model wan2.6-t2i --no-wait --quiet',
'bl image generate --prompt "Pro quality" --model qwen-image-2.0-pro',
'bl image generate --prompt "Product shots" --n 2 --concurrent 3 # 6 images in parallel',
Expand DownExpand Up@@ -111,15 +121,13 @@ export default defineCommand({
const n = (flags.n as number) ?? 1;
const concurrent = getConcurrency(flags);

// Determine prompt_extend: default true for qwen-image, undefined for others
let promptExtend: boolean | undefined;
if (flags.noPromptExtend === true) {
promptExtend = false;
} else if (flags.promptExtend === true) {
promptExtend = true;
} else if (useSync) {
promptExtend = true; // qwen-image default
}
const promptExtend = resolveBooleanFlag(
flags.promptExtend,
useSync ? true : undefined,
"prompt-extend",
);

const watermark = resolveWatermark(flags.watermark);

const body: DashScopeImageRequest = {
model,
Expand All@@ -131,7 +139,7 @@ export default defineCommand({
n,
seed: flags.seed as number | undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
negative_prompt: (flags.negativePrompt as string) || undefined,
},
};
Expand Down
24 changes: 18 additions & 6 deletions packages/cli/src/commands/video/edit.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,11 +15,17 @@ import {
resolveCredential,
BailianError,
ExitCode,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile, formatBytes } from "../../utils/download.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

export default defineCommand({
name: "video edit",
Expand DownExpand Up@@ -51,9 +57,14 @@ export default defineCommand({
flag: "--audio-setting <mode>",
description: "Audio: auto (default) or origin (keep original)",
},
{ flag: "--prompt-extend", description: "Enable prompt intelligent rewriting (default: true)" },
{ flag: "--no-prompt-extend", description: "Disable prompt intelligent rewriting" },
{ flag: "--watermark", description: 'Add "AI生成" watermark' },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--seed <n>", description: "Random seed for reproducible generation", type: "number" },
{ flag: "--download <path>", description: "Save video to file on completion" },
{ flag: "--no-wait", description: "Return task ID immediately without waiting" },
Expand All@@ -71,6 +82,7 @@ export default defineCommand({
'bl video edit --video https://example.com/input.mp4 --prompt "将整个画面转换为黏土风格"',
'bl video edit --video https://example.com/input.mp4 --prompt "替换衣服为图片中的款式" --ref-image https://example.com/clothes.png',
'bl video edit --video https://example.com/input.mp4 --prompt "Convert to anime style" --resolution 720P --download output.mp4',
'bl video edit --video https://example.com/input.mp4 --prompt "给视频里的小猫穿上衣服" --watermark false',
],
async run(config: Config, flags: GlobalFlags) {
// --- Validate video URL ---
Expand DownExpand Up@@ -127,8 +139,8 @@ export default defineCommand({
}

// --- Build request body ---
const promptExtend =
flags.noPromptExtend === true ? false : flags.promptExtend === true ? true : undefined;
const promptExtend = resolveBooleanFlag(flags.promptExtend, undefined, "prompt-extend");
const watermark = resolveWatermark(flags.watermark);

const body: DashScopeVideoEditRequest = {
model,
Expand All@@ -143,7 +155,7 @@ export default defineCommand({
duration: (flags.duration as number) || undefined,
audio_setting: (flags.audioSetting as "auto" | "origin") || undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
seed: flags.seed as number | undefined,
},
};
Expand Down
24 changes: 20 additions & 4 deletions packages/cli/src/commands/video/generate.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,12 +15,18 @@ import {
resolveCredential,
BailianError,
ExitCode,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile, formatBytes } from "../../utils/download.ts";
import { runConcurrent, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

// Normalize shorthand resolution (720P, 1080P) to pixel format for video generation models
const RESOLUTION_SHORTCUTS: Record<string, string> = {
Expand DownExpand Up@@ -58,8 +64,14 @@ export default defineCommand({
description: "Video duration in seconds (default: 5)",
type: "number",
},
{ flag: "--prompt-extend", description: "Automatically extend prompt for better results" },
{ flag: "--watermark", description: "Add watermark to generated video" },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--seed <n>", description: "Random seed for reproducible generation", type: "number" },
{ flag: "--download <path>", description: "Save video to file on completion" },
{ flag: "--no-wait", description: "Return task ID immediately without waiting" },
Expand All@@ -78,6 +90,7 @@ export default defineCommand({
'bl video generate --prompt "Ocean waves at sunset." --download sunset.mp4',
'bl video generate --image https://example.com/cat.png --prompt "让画面中的猫动起来"',
'bl video generate --prompt "Mountain landscape" --resolution 1280*720 --duration 5',
'bl video generate --prompt "A cat playing with a ball" --watermark false',
],
async run(config: Config, flags: GlobalFlags) {
let prompt = flags.prompt as string | undefined;
Expand DownExpand Up@@ -110,6 +123,9 @@ export default defineCommand({
resolvedImageUrl = await resolveFileUrl(imageUrl, credential.token, model);
}

const watermark = resolveWatermark(flags.watermark);
const promptExtend = resolveBooleanFlag(flags.promptExtend, undefined, "prompt-extend");

const body: DashScopeVideoRequest = {
model,
input: {
Expand All@@ -124,8 +140,8 @@ export default defineCommand({
resolution: normalizeResolution(flags.resolution as string) || undefined,
ratio: (flags.ratio as string) || undefined,
duration: (flags.duration as number) || undefined,
prompt_extend: flags.promptExtend === true ? true : undefined,
watermark: flags.watermark === true ? true : undefined,
prompt_extend: promptExtend,
watermark,
seed: flags.seed as number | undefined,
},
};
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
fix: Fix the issue of the watermark being always on and address the i… by qcq01083097 · Pull Request #13 · modelstudioai/cli · GitHub
Skip to content
Merged
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
28 changes: 24 additions & 4 deletions packages/cli/src/args.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,6 +25,15 @@ interface FlagSchema {
arrays: Set<string>;
}

function buildAllowedFlagKeys(options: OptionDef[]): Set<string> {
const keys = new Set<string>();
for (const opt of options) {
const key = flagKey(opt);
if (key) keys.add(key);
}
return keys;
}

function buildSchema(options: OptionDef[]): FlagSchema {
const booleans = new Set<string>();
const numbers = new Set<string>();
Expand DownExpand Up@@ -91,6 +100,7 @@ export function scanCommandPath(argv: string[], globalOptions: OptionDef[] = [])
* - default: string
*/
export function parseFlags(argv: string[], options: OptionDef[]): GlobalFlags {
const allowedKeys = buildAllowedFlagKeys(options);
const schema = buildSchema(options);
const flags: GlobalFlags = {
quiet: false,
Expand DownExpand Up@@ -130,20 +140,30 @@ export function parseFlags(argv: string[], options: OptionDef[]): GlobalFlags {

const camelKey = kebabToCamel(key);

if (!allowedKeys.has(camelKey)) {
throw new BailianError(
`Unknown flag "--${key}". Run with --help to see available options.`,
ExitCode.USAGE,
);
}

// 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++;
value = argv[i];
const next = argv[i];
if (next === undefined || next.startsWith("-")) {
throw new BailianError(`Flag --${key} requires a value.`, ExitCode.USAGE);
}
value = next;
}

if (value === undefined)
throw new BailianError(`Flag --${key} requires a value.`, ExitCode.USAGE);

if (schema.arrays.has(camelKey)) {
const arr = (flags as Record<string, unknown>)[camelKey] as string[] | undefined;
if (arr) arr.push(value);
Expand Down
32 changes: 19 additions & 13 deletions packages/cli/src/commands/image/edit.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,13 +15,19 @@ import {
type DashScopeImageSyncResponse,
ExitCode,
BailianError,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { downloadFile } from "../../utils/download.ts";
import { runConcurrent, downloadParallel, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import { resolveImageSize } from "../../utils/image-size.ts";
import { join } from "path";
import {
BOOL_FLAG_PROMPT_EXTEND_CLI_TRUE,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

export default defineCommand({
name: "image edit",
Expand All@@ -47,9 +53,14 @@ export default defineCommand({
flag: "--negative-prompt <text>",
description: "Negative prompt to exclude unwanted content",
},
{ flag: "--prompt-extend", description: "Enable prompt smart rewrite (default: true)" },
{ flag: "--no-prompt-extend", description: "Disable prompt extend" },
{ flag: "--watermark", description: "Add watermark to output images" },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_CLI_TRUE,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--out-dir <dir>", description: "Download images to directory" },
{ flag: "--out-prefix <prefix>", description: "Filename prefix (default: edited)" },
],
Expand All@@ -58,6 +69,7 @@ export default defineCommand({
'bl image edit --image https://example.com/logo.png --prompt "Change color to blue" --n 3',
'bl image edit --image ./a.png --image ./b.png --prompt "把两张图合并成一张拼图"',
'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) {
// Normalize --image to string array (supports both single and repeated flags)
Expand DownExpand Up@@ -96,22 +108,16 @@ export default defineCommand({
);
const n = (flags.n as number) ?? 1;

// Determine prompt_extend
let promptExtend: boolean | undefined;
if (flags.noPromptExtend === true) {
promptExtend = false;
} else if (flags.promptExtend === true) {
promptExtend = true;
} else {
promptExtend = true; // default on for qwen-image
}
const promptExtend = resolveBooleanFlag(flags.promptExtend, true, "prompt-extend");

// Build content: all images first, then text prompt
const contentItems: Array<{ image?: string; text?: string }> = resolvedImages.map(
(u: string) => ({ image: u }),
);
contentItems.push({ text: prompt! });

const watermark = resolveWatermark(flags.watermark);

const body: DashScopeImageRequest = {
model,
input: {
Expand All@@ -127,7 +133,7 @@ export default defineCommand({
n,
seed: flags.seed as number | undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
negative_prompt: (flags.negativePrompt as string) || undefined,
},
};
Expand Down
38 changes: 23 additions & 15 deletions packages/cli/src/commands/image/generate.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,13 +17,19 @@ import {
type OutputFormat,
type DashScopeTaskResponse,
generateFilename,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile } from "../../utils/download.ts";
import { runConcurrent, downloadParallel, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import { resolveImageSize } from "../../utils/image-size.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_IMAGE_GENERATE,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

import { join } from "path";

Expand DownExpand Up@@ -57,11 +63,13 @@ export default defineCommand({
description: "Negative prompt to exclude unwanted content",
},
{
flag: "--prompt-extend",
description: "Automatically extend prompt for better results (default: true for qwen-image)",
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_IMAGE_GENERATE,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--no-prompt-extend", description: "Disable prompt extend" },
{ flag: "--watermark", description: "Add watermark to generated images" },
{
flag: "--no-wait",
description: "Return task ID immediately without waiting (async models only)",
Expand All@@ -78,7 +86,9 @@ export default defineCommand({
'bl image generate --prompt "一只穿太空服的猫在火星上"',
'bl image generate --prompt "Logo design" --n 3 --out-dir ./generated/',
'bl image generate --prompt "Mountain landscape" --size 2688*1536',
'bl image generate --prompt "A castle" --seed 42 --no-prompt-extend',
'bl image generate --prompt "A castle" --seed 42 --prompt-extend false',
'bl image generate --prompt "Logo" --watermark false',
'bl image generate --prompt "An alien in the space" --watermark false',
'bl image generate --prompt "sunset" --model wan2.6-t2i --no-wait --quiet',
'bl image generate --prompt "Pro quality" --model qwen-image-2.0-pro',
'bl image generate --prompt "Product shots" --n 2 --concurrent 3 # 6 images in parallel',
Expand DownExpand Up@@ -111,15 +121,13 @@ export default defineCommand({
const n = (flags.n as number) ?? 1;
const concurrent = getConcurrency(flags);

// Determine prompt_extend: default true for qwen-image, undefined for others
let promptExtend: boolean | undefined;
if (flags.noPromptExtend === true) {
promptExtend = false;
} else if (flags.promptExtend === true) {
promptExtend = true;
} else if (useSync) {
promptExtend = true; // qwen-image default
}
const promptExtend = resolveBooleanFlag(
flags.promptExtend,
useSync ? true : undefined,
"prompt-extend",
);

const watermark = resolveWatermark(flags.watermark);

const body: DashScopeImageRequest = {
model,
Expand All@@ -131,7 +139,7 @@ export default defineCommand({
n,
seed: flags.seed as number | undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
negative_prompt: (flags.negativePrompt as string) || undefined,
},
};
Expand Down
24 changes: 18 additions & 6 deletions packages/cli/src/commands/video/edit.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,11 +15,17 @@ import {
resolveCredential,
BailianError,
ExitCode,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile, formatBytes } from "../../utils/download.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

export default defineCommand({
name: "video edit",
Expand DownExpand Up@@ -51,9 +57,14 @@ export default defineCommand({
flag: "--audio-setting <mode>",
description: "Audio: auto (default) or origin (keep original)",
},
{ flag: "--prompt-extend", description: "Enable prompt intelligent rewriting (default: true)" },
{ flag: "--no-prompt-extend", description: "Disable prompt intelligent rewriting" },
{ flag: "--watermark", description: 'Add "AI生成" watermark' },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--seed <n>", description: "Random seed for reproducible generation", type: "number" },
{ flag: "--download <path>", description: "Save video to file on completion" },
{ flag: "--no-wait", description: "Return task ID immediately without waiting" },
Expand All@@ -71,6 +82,7 @@ export default defineCommand({
'bl video edit --video https://example.com/input.mp4 --prompt "将整个画面转换为黏土风格"',
'bl video edit --video https://example.com/input.mp4 --prompt "替换衣服为图片中的款式" --ref-image https://example.com/clothes.png',
'bl video edit --video https://example.com/input.mp4 --prompt "Convert to anime style" --resolution 720P --download output.mp4',
'bl video edit --video https://example.com/input.mp4 --prompt "给视频里的小猫穿上衣服" --watermark false',
],
async run(config: Config, flags: GlobalFlags) {
// --- Validate video URL ---
Expand DownExpand Up@@ -127,8 +139,8 @@ export default defineCommand({
}

// --- Build request body ---
const promptExtend =
flags.noPromptExtend === true ? false : flags.promptExtend === true ? true : undefined;
const promptExtend = resolveBooleanFlag(flags.promptExtend, undefined, "prompt-extend");
const watermark = resolveWatermark(flags.watermark);

const body: DashScopeVideoEditRequest = {
model,
Expand All@@ -143,7 +155,7 @@ export default defineCommand({
duration: (flags.duration as number) || undefined,
audio_setting: (flags.audioSetting as "auto" | "origin") || undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
seed: flags.seed as number | undefined,
},
};
Expand Down
24 changes: 20 additions & 4 deletions packages/cli/src/commands/video/generate.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,12 +15,18 @@ import {
resolveCredential,
BailianError,
ExitCode,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile, formatBytes } from "../../utils/download.ts";
import { runConcurrent, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

// Normalize shorthand resolution (720P, 1080P) to pixel format for video generation models
const RESOLUTION_SHORTCUTS: Record<string, string> = {
Expand DownExpand Up@@ -58,8 +64,14 @@ export default defineCommand({
description: "Video duration in seconds (default: 5)",
type: "number",
},
{ flag: "--prompt-extend", description: "Automatically extend prompt for better results" },
{ flag: "--watermark", description: "Add watermark to generated video" },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--seed <n>", description: "Random seed for reproducible generation", type: "number" },
{ flag: "--download <path>", description: "Save video to file on completion" },
{ flag: "--no-wait", description: "Return task ID immediately without waiting" },
Expand All@@ -78,6 +90,7 @@ export default defineCommand({
'bl video generate --prompt "Ocean waves at sunset." --download sunset.mp4',
'bl video generate --image https://example.com/cat.png --prompt "让画面中的猫动起来"',
'bl video generate --prompt "Mountain landscape" --resolution 1280*720 --duration 5',
'bl video generate --prompt "A cat playing with a ball" --watermark false',
],
async run(config: Config, flags: GlobalFlags) {
let prompt = flags.prompt as string | undefined;
Expand DownExpand Up@@ -110,6 +123,9 @@ export default defineCommand({
resolvedImageUrl = await resolveFileUrl(imageUrl, credential.token, model);
}

const watermark = resolveWatermark(flags.watermark);
const promptExtend = resolveBooleanFlag(flags.promptExtend, undefined, "prompt-extend");

const body: DashScopeVideoRequest = {
model,
input: {
Expand All@@ -124,8 +140,8 @@ export default defineCommand({
resolution: normalizeResolution(flags.resolution as string) || undefined,
ratio: (flags.ratio as string) || undefined,
duration: (flags.duration as number) || undefined,
prompt_extend: flags.promptExtend === true ? true : undefined,
watermark: flags.watermark === true ? true : undefined,
prompt_extend: promptExtend,
watermark,
seed: flags.seed as number | undefined,
},
};
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' fix: Fix the issue of the watermark being always on and address the i… by qcq01083097 · Pull Request #13 · modelstudioai/cli · GitHub
Skip to content
Merged
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
28 changes: 24 additions & 4 deletions packages/cli/src/args.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,6 +25,15 @@ interface FlagSchema {
arrays: Set<string>;
}

function buildAllowedFlagKeys(options: OptionDef[]): Set<string> {
const keys = new Set<string>();
for (const opt of options) {
const key = flagKey(opt);
if (key) keys.add(key);
}
return keys;
}

function buildSchema(options: OptionDef[]): FlagSchema {
const booleans = new Set<string>();
const numbers = new Set<string>();
Expand DownExpand Up@@ -91,6 +100,7 @@ export function scanCommandPath(argv: string[], globalOptions: OptionDef[] = [])
* - default: string
*/
export function parseFlags(argv: string[], options: OptionDef[]): GlobalFlags {
const allowedKeys = buildAllowedFlagKeys(options);
const schema = buildSchema(options);
const flags: GlobalFlags = {
quiet: false,
Expand DownExpand Up@@ -130,20 +140,30 @@ export function parseFlags(argv: string[], options: OptionDef[]): GlobalFlags {

const camelKey = kebabToCamel(key);

if (!allowedKeys.has(camelKey)) {
throw new BailianError(
`Unknown flag "--${key}". Run with --help to see available options.`,
ExitCode.USAGE,
);
}

// 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++;
value = argv[i];
const next = argv[i];
if (next === undefined || next.startsWith("-")) {
throw new BailianError(`Flag --${key} requires a value.`, ExitCode.USAGE);
}
value = next;
}

if (value === undefined)
throw new BailianError(`Flag --${key} requires a value.`, ExitCode.USAGE);

if (schema.arrays.has(camelKey)) {
const arr = (flags as Record<string, unknown>)[camelKey] as string[] | undefined;
if (arr) arr.push(value);
Expand Down
32 changes: 19 additions & 13 deletions packages/cli/src/commands/image/edit.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,13 +15,19 @@ import {
type DashScopeImageSyncResponse,
ExitCode,
BailianError,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { downloadFile } from "../../utils/download.ts";
import { runConcurrent, downloadParallel, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import { resolveImageSize } from "../../utils/image-size.ts";
import { join } from "path";
import {
BOOL_FLAG_PROMPT_EXTEND_CLI_TRUE,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

export default defineCommand({
name: "image edit",
Expand All@@ -47,9 +53,14 @@ export default defineCommand({
flag: "--negative-prompt <text>",
description: "Negative prompt to exclude unwanted content",
},
{ flag: "--prompt-extend", description: "Enable prompt smart rewrite (default: true)" },
{ flag: "--no-prompt-extend", description: "Disable prompt extend" },
{ flag: "--watermark", description: "Add watermark to output images" },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_CLI_TRUE,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--out-dir <dir>", description: "Download images to directory" },
{ flag: "--out-prefix <prefix>", description: "Filename prefix (default: edited)" },
],
Expand All@@ -58,6 +69,7 @@ export default defineCommand({
'bl image edit --image https://example.com/logo.png --prompt "Change color to blue" --n 3',
'bl image edit --image ./a.png --image ./b.png --prompt "把两张图合并成一张拼图"',
'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) {
// Normalize --image to string array (supports both single and repeated flags)
Expand DownExpand Up@@ -96,22 +108,16 @@ export default defineCommand({
);
const n = (flags.n as number) ?? 1;

// Determine prompt_extend
let promptExtend: boolean | undefined;
if (flags.noPromptExtend === true) {
promptExtend = false;
} else if (flags.promptExtend === true) {
promptExtend = true;
} else {
promptExtend = true; // default on for qwen-image
}
const promptExtend = resolveBooleanFlag(flags.promptExtend, true, "prompt-extend");

// Build content: all images first, then text prompt
const contentItems: Array<{ image?: string; text?: string }> = resolvedImages.map(
(u: string) => ({ image: u }),
);
contentItems.push({ text: prompt! });

const watermark = resolveWatermark(flags.watermark);

const body: DashScopeImageRequest = {
model,
input: {
Expand All@@ -127,7 +133,7 @@ export default defineCommand({
n,
seed: flags.seed as number | undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
negative_prompt: (flags.negativePrompt as string) || undefined,
},
};
Expand Down
38 changes: 23 additions & 15 deletions packages/cli/src/commands/image/generate.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,13 +17,19 @@ import {
type OutputFormat,
type DashScopeTaskResponse,
generateFilename,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile } from "../../utils/download.ts";
import { runConcurrent, downloadParallel, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import { resolveImageSize } from "../../utils/image-size.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_IMAGE_GENERATE,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

import { join } from "path";

Expand DownExpand Up@@ -57,11 +63,13 @@ export default defineCommand({
description: "Negative prompt to exclude unwanted content",
},
{
flag: "--prompt-extend",
description: "Automatically extend prompt for better results (default: true for qwen-image)",
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_IMAGE_GENERATE,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--no-prompt-extend", description: "Disable prompt extend" },
{ flag: "--watermark", description: "Add watermark to generated images" },
{
flag: "--no-wait",
description: "Return task ID immediately without waiting (async models only)",
Expand All@@ -78,7 +86,9 @@ export default defineCommand({
'bl image generate --prompt "一只穿太空服的猫在火星上"',
'bl image generate --prompt "Logo design" --n 3 --out-dir ./generated/',
'bl image generate --prompt "Mountain landscape" --size 2688*1536',
'bl image generate --prompt "A castle" --seed 42 --no-prompt-extend',
'bl image generate --prompt "A castle" --seed 42 --prompt-extend false',
'bl image generate --prompt "Logo" --watermark false',
'bl image generate --prompt "An alien in the space" --watermark false',
'bl image generate --prompt "sunset" --model wan2.6-t2i --no-wait --quiet',
'bl image generate --prompt "Pro quality" --model qwen-image-2.0-pro',
'bl image generate --prompt "Product shots" --n 2 --concurrent 3 # 6 images in parallel',
Expand DownExpand Up@@ -111,15 +121,13 @@ export default defineCommand({
const n = (flags.n as number) ?? 1;
const concurrent = getConcurrency(flags);

// Determine prompt_extend: default true for qwen-image, undefined for others
let promptExtend: boolean | undefined;
if (flags.noPromptExtend === true) {
promptExtend = false;
} else if (flags.promptExtend === true) {
promptExtend = true;
} else if (useSync) {
promptExtend = true; // qwen-image default
}
const promptExtend = resolveBooleanFlag(
flags.promptExtend,
useSync ? true : undefined,
"prompt-extend",
);

const watermark = resolveWatermark(flags.watermark);

const body: DashScopeImageRequest = {
model,
Expand All@@ -131,7 +139,7 @@ export default defineCommand({
n,
seed: flags.seed as number | undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
negative_prompt: (flags.negativePrompt as string) || undefined,
},
};
Expand Down
24 changes: 18 additions & 6 deletions packages/cli/src/commands/video/edit.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,11 +15,17 @@ import {
resolveCredential,
BailianError,
ExitCode,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile, formatBytes } from "../../utils/download.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

export default defineCommand({
name: "video edit",
Expand DownExpand Up@@ -51,9 +57,14 @@ export default defineCommand({
flag: "--audio-setting <mode>",
description: "Audio: auto (default) or origin (keep original)",
},
{ flag: "--prompt-extend", description: "Enable prompt intelligent rewriting (default: true)" },
{ flag: "--no-prompt-extend", description: "Disable prompt intelligent rewriting" },
{ flag: "--watermark", description: 'Add "AI生成" watermark' },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--seed <n>", description: "Random seed for reproducible generation", type: "number" },
{ flag: "--download <path>", description: "Save video to file on completion" },
{ flag: "--no-wait", description: "Return task ID immediately without waiting" },
Expand All@@ -71,6 +82,7 @@ export default defineCommand({
'bl video edit --video https://example.com/input.mp4 --prompt "将整个画面转换为黏土风格"',
'bl video edit --video https://example.com/input.mp4 --prompt "替换衣服为图片中的款式" --ref-image https://example.com/clothes.png',
'bl video edit --video https://example.com/input.mp4 --prompt "Convert to anime style" --resolution 720P --download output.mp4',
'bl video edit --video https://example.com/input.mp4 --prompt "给视频里的小猫穿上衣服" --watermark false',
],
async run(config: Config, flags: GlobalFlags) {
// --- Validate video URL ---
Expand DownExpand Up@@ -127,8 +139,8 @@ export default defineCommand({
}

// --- Build request body ---
const promptExtend =
flags.noPromptExtend === true ? false : flags.promptExtend === true ? true : undefined;
const promptExtend = resolveBooleanFlag(flags.promptExtend, undefined, "prompt-extend");
const watermark = resolveWatermark(flags.watermark);

const body: DashScopeVideoEditRequest = {
model,
Expand All@@ -143,7 +155,7 @@ export default defineCommand({
duration: (flags.duration as number) || undefined,
audio_setting: (flags.audioSetting as "auto" | "origin") || undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
seed: flags.seed as number | undefined,
},
};
Expand Down
24 changes: 20 additions & 4 deletions packages/cli/src/commands/video/generate.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,12 +15,18 @@ import {
resolveCredential,
BailianError,
ExitCode,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile, formatBytes } from "../../utils/download.ts";
import { runConcurrent, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

// Normalize shorthand resolution (720P, 1080P) to pixel format for video generation models
const RESOLUTION_SHORTCUTS: Record<string, string> = {
Expand DownExpand Up@@ -58,8 +64,14 @@ export default defineCommand({
description: "Video duration in seconds (default: 5)",
type: "number",
},
{ flag: "--prompt-extend", description: "Automatically extend prompt for better results" },
{ flag: "--watermark", description: "Add watermark to generated video" },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--seed <n>", description: "Random seed for reproducible generation", type: "number" },
{ flag: "--download <path>", description: "Save video to file on completion" },
{ flag: "--no-wait", description: "Return task ID immediately without waiting" },
Expand All@@ -78,6 +90,7 @@ export default defineCommand({
'bl video generate --prompt "Ocean waves at sunset." --download sunset.mp4',
'bl video generate --image https://example.com/cat.png --prompt "让画面中的猫动起来"',
'bl video generate --prompt "Mountain landscape" --resolution 1280*720 --duration 5',
'bl video generate --prompt "A cat playing with a ball" --watermark false',
],
async run(config: Config, flags: GlobalFlags) {
let prompt = flags.prompt as string | undefined;
Expand DownExpand Up@@ -110,6 +123,9 @@ export default defineCommand({
resolvedImageUrl = await resolveFileUrl(imageUrl, credential.token, model);
}

const watermark = resolveWatermark(flags.watermark);
const promptExtend = resolveBooleanFlag(flags.promptExtend, undefined, "prompt-extend");

const body: DashScopeVideoRequest = {
model,
input: {
Expand All@@ -124,8 +140,8 @@ export default defineCommand({
resolution: normalizeResolution(flags.resolution as string) || undefined,
ratio: (flags.ratio as string) || undefined,
duration: (flags.duration as number) || undefined,
prompt_extend: flags.promptExtend === true ? true : undefined,
watermark: flags.watermark === true ? true : undefined,
prompt_extend: promptExtend,
watermark,
seed: flags.seed as number | undefined,
},
};
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' fix: Fix the issue of the watermark being always on and address the i… by qcq01083097 · Pull Request #13 · modelstudioai/cli · GitHub
Skip to content
Merged
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
28 changes: 24 additions & 4 deletions packages/cli/src/args.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,6 +25,15 @@ interface FlagSchema {
arrays: Set<string>;
}

function buildAllowedFlagKeys(options: OptionDef[]): Set<string> {
const keys = new Set<string>();
for (const opt of options) {
const key = flagKey(opt);
if (key) keys.add(key);
}
return keys;
}

function buildSchema(options: OptionDef[]): FlagSchema {
const booleans = new Set<string>();
const numbers = new Set<string>();
Expand DownExpand Up@@ -91,6 +100,7 @@ export function scanCommandPath(argv: string[], globalOptions: OptionDef[] = [])
* - default: string
*/
export function parseFlags(argv: string[], options: OptionDef[]): GlobalFlags {
const allowedKeys = buildAllowedFlagKeys(options);
const schema = buildSchema(options);
const flags: GlobalFlags = {
quiet: false,
Expand DownExpand Up@@ -130,20 +140,30 @@ export function parseFlags(argv: string[], options: OptionDef[]): GlobalFlags {

const camelKey = kebabToCamel(key);

if (!allowedKeys.has(camelKey)) {
throw new BailianError(
`Unknown flag "--${key}". Run with --help to see available options.`,
ExitCode.USAGE,
);
}

// 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++;
value = argv[i];
const next = argv[i];
if (next === undefined || next.startsWith("-")) {
throw new BailianError(`Flag --${key} requires a value.`, ExitCode.USAGE);
}
value = next;
}

if (value === undefined)
throw new BailianError(`Flag --${key} requires a value.`, ExitCode.USAGE);

if (schema.arrays.has(camelKey)) {
const arr = (flags as Record<string, unknown>)[camelKey] as string[] | undefined;
if (arr) arr.push(value);
Expand Down
32 changes: 19 additions & 13 deletions packages/cli/src/commands/image/edit.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,13 +15,19 @@ import {
type DashScopeImageSyncResponse,
ExitCode,
BailianError,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { downloadFile } from "../../utils/download.ts";
import { runConcurrent, downloadParallel, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import { resolveImageSize } from "../../utils/image-size.ts";
import { join } from "path";
import {
BOOL_FLAG_PROMPT_EXTEND_CLI_TRUE,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

export default defineCommand({
name: "image edit",
Expand All@@ -47,9 +53,14 @@ export default defineCommand({
flag: "--negative-prompt <text>",
description: "Negative prompt to exclude unwanted content",
},
{ flag: "--prompt-extend", description: "Enable prompt smart rewrite (default: true)" },
{ flag: "--no-prompt-extend", description: "Disable prompt extend" },
{ flag: "--watermark", description: "Add watermark to output images" },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_CLI_TRUE,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--out-dir <dir>", description: "Download images to directory" },
{ flag: "--out-prefix <prefix>", description: "Filename prefix (default: edited)" },
],
Expand All@@ -58,6 +69,7 @@ export default defineCommand({
'bl image edit --image https://example.com/logo.png --prompt "Change color to blue" --n 3',
'bl image edit --image ./a.png --image ./b.png --prompt "把两张图合并成一张拼图"',
'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) {
// Normalize --image to string array (supports both single and repeated flags)
Expand DownExpand Up@@ -96,22 +108,16 @@ export default defineCommand({
);
const n = (flags.n as number) ?? 1;

// Determine prompt_extend
let promptExtend: boolean | undefined;
if (flags.noPromptExtend === true) {
promptExtend = false;
} else if (flags.promptExtend === true) {
promptExtend = true;
} else {
promptExtend = true; // default on for qwen-image
}
const promptExtend = resolveBooleanFlag(flags.promptExtend, true, "prompt-extend");

// Build content: all images first, then text prompt
const contentItems: Array<{ image?: string; text?: string }> = resolvedImages.map(
(u: string) => ({ image: u }),
);
contentItems.push({ text: prompt! });

const watermark = resolveWatermark(flags.watermark);

const body: DashScopeImageRequest = {
model,
input: {
Expand All@@ -127,7 +133,7 @@ export default defineCommand({
n,
seed: flags.seed as number | undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
negative_prompt: (flags.negativePrompt as string) || undefined,
},
};
Expand Down
38 changes: 23 additions & 15 deletions packages/cli/src/commands/image/generate.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,13 +17,19 @@ import {
type OutputFormat,
type DashScopeTaskResponse,
generateFilename,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile } from "../../utils/download.ts";
import { runConcurrent, downloadParallel, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import { resolveImageSize } from "../../utils/image-size.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_IMAGE_GENERATE,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

import { join } from "path";

Expand DownExpand Up@@ -57,11 +63,13 @@ export default defineCommand({
description: "Negative prompt to exclude unwanted content",
},
{
flag: "--prompt-extend",
description: "Automatically extend prompt for better results (default: true for qwen-image)",
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_IMAGE_GENERATE,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--no-prompt-extend", description: "Disable prompt extend" },
{ flag: "--watermark", description: "Add watermark to generated images" },
{
flag: "--no-wait",
description: "Return task ID immediately without waiting (async models only)",
Expand All@@ -78,7 +86,9 @@ export default defineCommand({
'bl image generate --prompt "一只穿太空服的猫在火星上"',
'bl image generate --prompt "Logo design" --n 3 --out-dir ./generated/',
'bl image generate --prompt "Mountain landscape" --size 2688*1536',
'bl image generate --prompt "A castle" --seed 42 --no-prompt-extend',
'bl image generate --prompt "A castle" --seed 42 --prompt-extend false',
'bl image generate --prompt "Logo" --watermark false',
'bl image generate --prompt "An alien in the space" --watermark false',
'bl image generate --prompt "sunset" --model wan2.6-t2i --no-wait --quiet',
'bl image generate --prompt "Pro quality" --model qwen-image-2.0-pro',
'bl image generate --prompt "Product shots" --n 2 --concurrent 3 # 6 images in parallel',
Expand DownExpand Up@@ -111,15 +121,13 @@ export default defineCommand({
const n = (flags.n as number) ?? 1;
const concurrent = getConcurrency(flags);

// Determine prompt_extend: default true for qwen-image, undefined for others
let promptExtend: boolean | undefined;
if (flags.noPromptExtend === true) {
promptExtend = false;
} else if (flags.promptExtend === true) {
promptExtend = true;
} else if (useSync) {
promptExtend = true; // qwen-image default
}
const promptExtend = resolveBooleanFlag(
flags.promptExtend,
useSync ? true : undefined,
"prompt-extend",
);

const watermark = resolveWatermark(flags.watermark);

const body: DashScopeImageRequest = {
model,
Expand All@@ -131,7 +139,7 @@ export default defineCommand({
n,
seed: flags.seed as number | undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
negative_prompt: (flags.negativePrompt as string) || undefined,
},
};
Expand Down
24 changes: 18 additions & 6 deletions packages/cli/src/commands/video/edit.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,11 +15,17 @@ import {
resolveCredential,
BailianError,
ExitCode,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile, formatBytes } from "../../utils/download.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

export default defineCommand({
name: "video edit",
Expand DownExpand Up@@ -51,9 +57,14 @@ export default defineCommand({
flag: "--audio-setting <mode>",
description: "Audio: auto (default) or origin (keep original)",
},
{ flag: "--prompt-extend", description: "Enable prompt intelligent rewriting (default: true)" },
{ flag: "--no-prompt-extend", description: "Disable prompt intelligent rewriting" },
{ flag: "--watermark", description: 'Add "AI生成" watermark' },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--seed <n>", description: "Random seed for reproducible generation", type: "number" },
{ flag: "--download <path>", description: "Save video to file on completion" },
{ flag: "--no-wait", description: "Return task ID immediately without waiting" },
Expand All@@ -71,6 +82,7 @@ export default defineCommand({
'bl video edit --video https://example.com/input.mp4 --prompt "将整个画面转换为黏土风格"',
'bl video edit --video https://example.com/input.mp4 --prompt "替换衣服为图片中的款式" --ref-image https://example.com/clothes.png',
'bl video edit --video https://example.com/input.mp4 --prompt "Convert to anime style" --resolution 720P --download output.mp4',
'bl video edit --video https://example.com/input.mp4 --prompt "给视频里的小猫穿上衣服" --watermark false',
],
async run(config: Config, flags: GlobalFlags) {
// --- Validate video URL ---
Expand DownExpand Up@@ -127,8 +139,8 @@ export default defineCommand({
}

// --- Build request body ---
const promptExtend =
flags.noPromptExtend === true ? false : flags.promptExtend === true ? true : undefined;
const promptExtend = resolveBooleanFlag(flags.promptExtend, undefined, "prompt-extend");
const watermark = resolveWatermark(flags.watermark);

const body: DashScopeVideoEditRequest = {
model,
Expand All@@ -143,7 +155,7 @@ export default defineCommand({
duration: (flags.duration as number) || undefined,
audio_setting: (flags.audioSetting as "auto" | "origin") || undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
seed: flags.seed as number | undefined,
},
};
Expand Down
24 changes: 20 additions & 4 deletions packages/cli/src/commands/video/generate.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,12 +15,18 @@ import {
resolveCredential,
BailianError,
ExitCode,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile, formatBytes } from "../../utils/download.ts";
import { runConcurrent, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

// Normalize shorthand resolution (720P, 1080P) to pixel format for video generation models
const RESOLUTION_SHORTCUTS: Record<string, string> = {
Expand DownExpand Up@@ -58,8 +64,14 @@ export default defineCommand({
description: "Video duration in seconds (default: 5)",
type: "number",
},
{ flag: "--prompt-extend", description: "Automatically extend prompt for better results" },
{ flag: "--watermark", description: "Add watermark to generated video" },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--seed <n>", description: "Random seed for reproducible generation", type: "number" },
{ flag: "--download <path>", description: "Save video to file on completion" },
{ flag: "--no-wait", description: "Return task ID immediately without waiting" },
Expand All@@ -78,6 +90,7 @@ export default defineCommand({
'bl video generate --prompt "Ocean waves at sunset." --download sunset.mp4',
'bl video generate --image https://example.com/cat.png --prompt "让画面中的猫动起来"',
'bl video generate --prompt "Mountain landscape" --resolution 1280*720 --duration 5',
'bl video generate --prompt "A cat playing with a ball" --watermark false',
],
async run(config: Config, flags: GlobalFlags) {
let prompt = flags.prompt as string | undefined;
Expand DownExpand Up@@ -110,6 +123,9 @@ export default defineCommand({
resolvedImageUrl = await resolveFileUrl(imageUrl, credential.token, model);
}

const watermark = resolveWatermark(flags.watermark);
const promptExtend = resolveBooleanFlag(flags.promptExtend, undefined, "prompt-extend");

const body: DashScopeVideoRequest = {
model,
input: {
Expand All@@ -124,8 +140,8 @@ export default defineCommand({
resolution: normalizeResolution(flags.resolution as string) || undefined,
ratio: (flags.ratio as string) || undefined,
duration: (flags.duration as number) || undefined,
prompt_extend: flags.promptExtend === true ? true : undefined,
watermark: flags.watermark === true ? true : undefined,
prompt_extend: promptExtend,
watermark,
seed: flags.seed as number | undefined,
},
};
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' fix: Fix the issue of the watermark being always on and address the i… by qcq01083097 · Pull Request #13 · modelstudioai/cli · GitHub
Skip to content
Merged
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
28 changes: 24 additions & 4 deletions packages/cli/src/args.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,6 +25,15 @@ interface FlagSchema {
arrays: Set<string>;
}

function buildAllowedFlagKeys(options: OptionDef[]): Set<string> {
const keys = new Set<string>();
for (const opt of options) {
const key = flagKey(opt);
if (key) keys.add(key);
}
return keys;
}

function buildSchema(options: OptionDef[]): FlagSchema {
const booleans = new Set<string>();
const numbers = new Set<string>();
Expand DownExpand Up@@ -91,6 +100,7 @@ export function scanCommandPath(argv: string[], globalOptions: OptionDef[] = [])
* - default: string
*/
export function parseFlags(argv: string[], options: OptionDef[]): GlobalFlags {
const allowedKeys = buildAllowedFlagKeys(options);
const schema = buildSchema(options);
const flags: GlobalFlags = {
quiet: false,
Expand DownExpand Up@@ -130,20 +140,30 @@ export function parseFlags(argv: string[], options: OptionDef[]): GlobalFlags {

const camelKey = kebabToCamel(key);

if (!allowedKeys.has(camelKey)) {
throw new BailianError(
`Unknown flag "--${key}". Run with --help to see available options.`,
ExitCode.USAGE,
);
}

// 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++;
value = argv[i];
const next = argv[i];
if (next === undefined || next.startsWith("-")) {
throw new BailianError(`Flag --${key} requires a value.`, ExitCode.USAGE);
}
value = next;
}

if (value === undefined)
throw new BailianError(`Flag --${key} requires a value.`, ExitCode.USAGE);

if (schema.arrays.has(camelKey)) {
const arr = (flags as Record<string, unknown>)[camelKey] as string[] | undefined;
if (arr) arr.push(value);
Expand Down
32 changes: 19 additions & 13 deletions packages/cli/src/commands/image/edit.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,13 +15,19 @@ import {
type DashScopeImageSyncResponse,
ExitCode,
BailianError,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { downloadFile } from "../../utils/download.ts";
import { runConcurrent, downloadParallel, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import { resolveImageSize } from "../../utils/image-size.ts";
import { join } from "path";
import {
BOOL_FLAG_PROMPT_EXTEND_CLI_TRUE,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

export default defineCommand({
name: "image edit",
Expand All@@ -47,9 +53,14 @@ export default defineCommand({
flag: "--negative-prompt <text>",
description: "Negative prompt to exclude unwanted content",
},
{ flag: "--prompt-extend", description: "Enable prompt smart rewrite (default: true)" },
{ flag: "--no-prompt-extend", description: "Disable prompt extend" },
{ flag: "--watermark", description: "Add watermark to output images" },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_CLI_TRUE,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--out-dir <dir>", description: "Download images to directory" },
{ flag: "--out-prefix <prefix>", description: "Filename prefix (default: edited)" },
],
Expand All@@ -58,6 +69,7 @@ export default defineCommand({
'bl image edit --image https://example.com/logo.png --prompt "Change color to blue" --n 3',
'bl image edit --image ./a.png --image ./b.png --prompt "把两张图合并成一张拼图"',
'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) {
// Normalize --image to string array (supports both single and repeated flags)
Expand DownExpand Up@@ -96,22 +108,16 @@ export default defineCommand({
);
const n = (flags.n as number) ?? 1;

// Determine prompt_extend
let promptExtend: boolean | undefined;
if (flags.noPromptExtend === true) {
promptExtend = false;
} else if (flags.promptExtend === true) {
promptExtend = true;
} else {
promptExtend = true; // default on for qwen-image
}
const promptExtend = resolveBooleanFlag(flags.promptExtend, true, "prompt-extend");

// Build content: all images first, then text prompt
const contentItems: Array<{ image?: string; text?: string }> = resolvedImages.map(
(u: string) => ({ image: u }),
);
contentItems.push({ text: prompt! });

const watermark = resolveWatermark(flags.watermark);

const body: DashScopeImageRequest = {
model,
input: {
Expand All@@ -127,7 +133,7 @@ export default defineCommand({
n,
seed: flags.seed as number | undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
negative_prompt: (flags.negativePrompt as string) || undefined,
},
};
Expand Down
38 changes: 23 additions & 15 deletions packages/cli/src/commands/image/generate.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,13 +17,19 @@ import {
type OutputFormat,
type DashScopeTaskResponse,
generateFilename,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile } from "../../utils/download.ts";
import { runConcurrent, downloadParallel, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import { resolveImageSize } from "../../utils/image-size.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_IMAGE_GENERATE,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

import { join } from "path";

Expand DownExpand Up@@ -57,11 +63,13 @@ export default defineCommand({
description: "Negative prompt to exclude unwanted content",
},
{
flag: "--prompt-extend",
description: "Automatically extend prompt for better results (default: true for qwen-image)",
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_IMAGE_GENERATE,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--no-prompt-extend", description: "Disable prompt extend" },
{ flag: "--watermark", description: "Add watermark to generated images" },
{
flag: "--no-wait",
description: "Return task ID immediately without waiting (async models only)",
Expand All@@ -78,7 +86,9 @@ export default defineCommand({
'bl image generate --prompt "一只穿太空服的猫在火星上"',
'bl image generate --prompt "Logo design" --n 3 --out-dir ./generated/',
'bl image generate --prompt "Mountain landscape" --size 2688*1536',
'bl image generate --prompt "A castle" --seed 42 --no-prompt-extend',
'bl image generate --prompt "A castle" --seed 42 --prompt-extend false',
'bl image generate --prompt "Logo" --watermark false',
'bl image generate --prompt "An alien in the space" --watermark false',
'bl image generate --prompt "sunset" --model wan2.6-t2i --no-wait --quiet',
'bl image generate --prompt "Pro quality" --model qwen-image-2.0-pro',
'bl image generate --prompt "Product shots" --n 2 --concurrent 3 # 6 images in parallel',
Expand DownExpand Up@@ -111,15 +121,13 @@ export default defineCommand({
const n = (flags.n as number) ?? 1;
const concurrent = getConcurrency(flags);

// Determine prompt_extend: default true for qwen-image, undefined for others
let promptExtend: boolean | undefined;
if (flags.noPromptExtend === true) {
promptExtend = false;
} else if (flags.promptExtend === true) {
promptExtend = true;
} else if (useSync) {
promptExtend = true; // qwen-image default
}
const promptExtend = resolveBooleanFlag(
flags.promptExtend,
useSync ? true : undefined,
"prompt-extend",
);

const watermark = resolveWatermark(flags.watermark);

const body: DashScopeImageRequest = {
model,
Expand All@@ -131,7 +139,7 @@ export default defineCommand({
n,
seed: flags.seed as number | undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
negative_prompt: (flags.negativePrompt as string) || undefined,
},
};
Expand Down
24 changes: 18 additions & 6 deletions packages/cli/src/commands/video/edit.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,11 +15,17 @@ import {
resolveCredential,
BailianError,
ExitCode,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile, formatBytes } from "../../utils/download.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

export default defineCommand({
name: "video edit",
Expand DownExpand Up@@ -51,9 +57,14 @@ export default defineCommand({
flag: "--audio-setting <mode>",
description: "Audio: auto (default) or origin (keep original)",
},
{ flag: "--prompt-extend", description: "Enable prompt intelligent rewriting (default: true)" },
{ flag: "--no-prompt-extend", description: "Disable prompt intelligent rewriting" },
{ flag: "--watermark", description: 'Add "AI生成" watermark' },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--seed <n>", description: "Random seed for reproducible generation", type: "number" },
{ flag: "--download <path>", description: "Save video to file on completion" },
{ flag: "--no-wait", description: "Return task ID immediately without waiting" },
Expand All@@ -71,6 +82,7 @@ export default defineCommand({
'bl video edit --video https://example.com/input.mp4 --prompt "将整个画面转换为黏土风格"',
'bl video edit --video https://example.com/input.mp4 --prompt "替换衣服为图片中的款式" --ref-image https://example.com/clothes.png',
'bl video edit --video https://example.com/input.mp4 --prompt "Convert to anime style" --resolution 720P --download output.mp4',
'bl video edit --video https://example.com/input.mp4 --prompt "给视频里的小猫穿上衣服" --watermark false',
],
async run(config: Config, flags: GlobalFlags) {
// --- Validate video URL ---
Expand DownExpand Up@@ -127,8 +139,8 @@ export default defineCommand({
}

// --- Build request body ---
const promptExtend =
flags.noPromptExtend === true ? false : flags.promptExtend === true ? true : undefined;
const promptExtend = resolveBooleanFlag(flags.promptExtend, undefined, "prompt-extend");
const watermark = resolveWatermark(flags.watermark);

const body: DashScopeVideoEditRequest = {
model,
Expand All@@ -143,7 +155,7 @@ export default defineCommand({
duration: (flags.duration as number) || undefined,
audio_setting: (flags.audioSetting as "auto" | "origin") || undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
seed: flags.seed as number | undefined,
},
};
Expand Down
24 changes: 20 additions & 4 deletions packages/cli/src/commands/video/generate.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,12 +15,18 @@ import {
resolveCredential,
BailianError,
ExitCode,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile, formatBytes } from "../../utils/download.ts";
import { runConcurrent, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

// Normalize shorthand resolution (720P, 1080P) to pixel format for video generation models
const RESOLUTION_SHORTCUTS: Record<string, string> = {
Expand DownExpand Up@@ -58,8 +64,14 @@ export default defineCommand({
description: "Video duration in seconds (default: 5)",
type: "number",
},
{ flag: "--prompt-extend", description: "Automatically extend prompt for better results" },
{ flag: "--watermark", description: "Add watermark to generated video" },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--seed <n>", description: "Random seed for reproducible generation", type: "number" },
{ flag: "--download <path>", description: "Save video to file on completion" },
{ flag: "--no-wait", description: "Return task ID immediately without waiting" },
Expand All@@ -78,6 +90,7 @@ export default defineCommand({
'bl video generate --prompt "Ocean waves at sunset." --download sunset.mp4',
'bl video generate --image https://example.com/cat.png --prompt "让画面中的猫动起来"',
'bl video generate --prompt "Mountain landscape" --resolution 1280*720 --duration 5',
'bl video generate --prompt "A cat playing with a ball" --watermark false',
],
async run(config: Config, flags: GlobalFlags) {
let prompt = flags.prompt as string | undefined;
Expand DownExpand Up@@ -110,6 +123,9 @@ export default defineCommand({
resolvedImageUrl = await resolveFileUrl(imageUrl, credential.token, model);
}

const watermark = resolveWatermark(flags.watermark);
const promptExtend = resolveBooleanFlag(flags.promptExtend, undefined, "prompt-extend");

const body: DashScopeVideoRequest = {
model,
input: {
Expand All@@ -124,8 +140,8 @@ export default defineCommand({
resolution: normalizeResolution(flags.resolution as string) || undefined,
ratio: (flags.ratio as string) || undefined,
duration: (flags.duration as number) || undefined,
prompt_extend: flags.promptExtend === true ? true : undefined,
watermark: flags.watermark === true ? true : undefined,
prompt_extend: promptExtend,
watermark,
seed: flags.seed as number | undefined,
},
};
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' fix: Fix the issue of the watermark being always on and address the i… by qcq01083097 · Pull Request #13 · modelstudioai/cli · GitHub
Skip to content
Merged
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
28 changes: 24 additions & 4 deletions packages/cli/src/args.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,6 +25,15 @@ interface FlagSchema {
arrays: Set<string>;
}

function buildAllowedFlagKeys(options: OptionDef[]): Set<string> {
const keys = new Set<string>();
for (const opt of options) {
const key = flagKey(opt);
if (key) keys.add(key);
}
return keys;
}

function buildSchema(options: OptionDef[]): FlagSchema {
const booleans = new Set<string>();
const numbers = new Set<string>();
Expand DownExpand Up@@ -91,6 +100,7 @@ export function scanCommandPath(argv: string[], globalOptions: OptionDef[] = [])
* - default: string
*/
export function parseFlags(argv: string[], options: OptionDef[]): GlobalFlags {
const allowedKeys = buildAllowedFlagKeys(options);
const schema = buildSchema(options);
const flags: GlobalFlags = {
quiet: false,
Expand DownExpand Up@@ -130,20 +140,30 @@ export function parseFlags(argv: string[], options: OptionDef[]): GlobalFlags {

const camelKey = kebabToCamel(key);

if (!allowedKeys.has(camelKey)) {
throw new BailianError(
`Unknown flag "--${key}". Run with --help to see available options.`,
ExitCode.USAGE,
);
}

// 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++;
value = argv[i];
const next = argv[i];
if (next === undefined || next.startsWith("-")) {
throw new BailianError(`Flag --${key} requires a value.`, ExitCode.USAGE);
}
value = next;
}

if (value === undefined)
throw new BailianError(`Flag --${key} requires a value.`, ExitCode.USAGE);

if (schema.arrays.has(camelKey)) {
const arr = (flags as Record<string, unknown>)[camelKey] as string[] | undefined;
if (arr) arr.push(value);
Expand Down
32 changes: 19 additions & 13 deletions packages/cli/src/commands/image/edit.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,13 +15,19 @@ import {
type DashScopeImageSyncResponse,
ExitCode,
BailianError,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { downloadFile } from "../../utils/download.ts";
import { runConcurrent, downloadParallel, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import { resolveImageSize } from "../../utils/image-size.ts";
import { join } from "path";
import {
BOOL_FLAG_PROMPT_EXTEND_CLI_TRUE,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

export default defineCommand({
name: "image edit",
Expand All@@ -47,9 +53,14 @@ export default defineCommand({
flag: "--negative-prompt <text>",
description: "Negative prompt to exclude unwanted content",
},
{ flag: "--prompt-extend", description: "Enable prompt smart rewrite (default: true)" },
{ flag: "--no-prompt-extend", description: "Disable prompt extend" },
{ flag: "--watermark", description: "Add watermark to output images" },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_CLI_TRUE,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--out-dir <dir>", description: "Download images to directory" },
{ flag: "--out-prefix <prefix>", description: "Filename prefix (default: edited)" },
],
Expand All@@ -58,6 +69,7 @@ export default defineCommand({
'bl image edit --image https://example.com/logo.png --prompt "Change color to blue" --n 3',
'bl image edit --image ./a.png --image ./b.png --prompt "把两张图合并成一张拼图"',
'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) {
// Normalize --image to string array (supports both single and repeated flags)
Expand DownExpand Up@@ -96,22 +108,16 @@ export default defineCommand({
);
const n = (flags.n as number) ?? 1;

// Determine prompt_extend
let promptExtend: boolean | undefined;
if (flags.noPromptExtend === true) {
promptExtend = false;
} else if (flags.promptExtend === true) {
promptExtend = true;
} else {
promptExtend = true; // default on for qwen-image
}
const promptExtend = resolveBooleanFlag(flags.promptExtend, true, "prompt-extend");

// Build content: all images first, then text prompt
const contentItems: Array<{ image?: string; text?: string }> = resolvedImages.map(
(u: string) => ({ image: u }),
);
contentItems.push({ text: prompt! });

const watermark = resolveWatermark(flags.watermark);

const body: DashScopeImageRequest = {
model,
input: {
Expand All@@ -127,7 +133,7 @@ export default defineCommand({
n,
seed: flags.seed as number | undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
negative_prompt: (flags.negativePrompt as string) || undefined,
},
};
Expand Down
38 changes: 23 additions & 15 deletions packages/cli/src/commands/image/generate.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,13 +17,19 @@ import {
type OutputFormat,
type DashScopeTaskResponse,
generateFilename,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile } from "../../utils/download.ts";
import { runConcurrent, downloadParallel, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import { resolveImageSize } from "../../utils/image-size.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_IMAGE_GENERATE,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

import { join } from "path";

Expand DownExpand Up@@ -57,11 +63,13 @@ export default defineCommand({
description: "Negative prompt to exclude unwanted content",
},
{
flag: "--prompt-extend",
description: "Automatically extend prompt for better results (default: true for qwen-image)",
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_IMAGE_GENERATE,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--no-prompt-extend", description: "Disable prompt extend" },
{ flag: "--watermark", description: "Add watermark to generated images" },
{
flag: "--no-wait",
description: "Return task ID immediately without waiting (async models only)",
Expand All@@ -78,7 +86,9 @@ export default defineCommand({
'bl image generate --prompt "一只穿太空服的猫在火星上"',
'bl image generate --prompt "Logo design" --n 3 --out-dir ./generated/',
'bl image generate --prompt "Mountain landscape" --size 2688*1536',
'bl image generate --prompt "A castle" --seed 42 --no-prompt-extend',
'bl image generate --prompt "A castle" --seed 42 --prompt-extend false',
'bl image generate --prompt "Logo" --watermark false',
'bl image generate --prompt "An alien in the space" --watermark false',
'bl image generate --prompt "sunset" --model wan2.6-t2i --no-wait --quiet',
'bl image generate --prompt "Pro quality" --model qwen-image-2.0-pro',
'bl image generate --prompt "Product shots" --n 2 --concurrent 3 # 6 images in parallel',
Expand DownExpand Up@@ -111,15 +121,13 @@ export default defineCommand({
const n = (flags.n as number) ?? 1;
const concurrent = getConcurrency(flags);

// Determine prompt_extend: default true for qwen-image, undefined for others
let promptExtend: boolean | undefined;
if (flags.noPromptExtend === true) {
promptExtend = false;
} else if (flags.promptExtend === true) {
promptExtend = true;
} else if (useSync) {
promptExtend = true; // qwen-image default
}
const promptExtend = resolveBooleanFlag(
flags.promptExtend,
useSync ? true : undefined,
"prompt-extend",
);

const watermark = resolveWatermark(flags.watermark);

const body: DashScopeImageRequest = {
model,
Expand All@@ -131,7 +139,7 @@ export default defineCommand({
n,
seed: flags.seed as number | undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
negative_prompt: (flags.negativePrompt as string) || undefined,
},
};
Expand Down
24 changes: 18 additions & 6 deletions packages/cli/src/commands/video/edit.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,11 +15,17 @@ import {
resolveCredential,
BailianError,
ExitCode,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile, formatBytes } from "../../utils/download.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

export default defineCommand({
name: "video edit",
Expand DownExpand Up@@ -51,9 +57,14 @@ export default defineCommand({
flag: "--audio-setting <mode>",
description: "Audio: auto (default) or origin (keep original)",
},
{ flag: "--prompt-extend", description: "Enable prompt intelligent rewriting (default: true)" },
{ flag: "--no-prompt-extend", description: "Disable prompt intelligent rewriting" },
{ flag: "--watermark", description: 'Add "AI生成" watermark' },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--seed <n>", description: "Random seed for reproducible generation", type: "number" },
{ flag: "--download <path>", description: "Save video to file on completion" },
{ flag: "--no-wait", description: "Return task ID immediately without waiting" },
Expand All@@ -71,6 +82,7 @@ export default defineCommand({
'bl video edit --video https://example.com/input.mp4 --prompt "将整个画面转换为黏土风格"',
'bl video edit --video https://example.com/input.mp4 --prompt "替换衣服为图片中的款式" --ref-image https://example.com/clothes.png',
'bl video edit --video https://example.com/input.mp4 --prompt "Convert to anime style" --resolution 720P --download output.mp4',
'bl video edit --video https://example.com/input.mp4 --prompt "给视频里的小猫穿上衣服" --watermark false',
],
async run(config: Config, flags: GlobalFlags) {
// --- Validate video URL ---
Expand DownExpand Up@@ -127,8 +139,8 @@ export default defineCommand({
}

// --- Build request body ---
const promptExtend =
flags.noPromptExtend === true ? false : flags.promptExtend === true ? true : undefined;
const promptExtend = resolveBooleanFlag(flags.promptExtend, undefined, "prompt-extend");
const watermark = resolveWatermark(flags.watermark);

const body: DashScopeVideoEditRequest = {
model,
Expand All@@ -143,7 +155,7 @@ export default defineCommand({
duration: (flags.duration as number) || undefined,
audio_setting: (flags.audioSetting as "auto" | "origin") || undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
seed: flags.seed as number | undefined,
},
};
Expand Down
24 changes: 20 additions & 4 deletions packages/cli/src/commands/video/generate.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,12 +15,18 @@ import {
resolveCredential,
BailianError,
ExitCode,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile, formatBytes } from "../../utils/download.ts";
import { runConcurrent, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

// Normalize shorthand resolution (720P, 1080P) to pixel format for video generation models
const RESOLUTION_SHORTCUTS: Record<string, string> = {
Expand DownExpand Up@@ -58,8 +64,14 @@ export default defineCommand({
description: "Video duration in seconds (default: 5)",
type: "number",
},
{ flag: "--prompt-extend", description: "Automatically extend prompt for better results" },
{ flag: "--watermark", description: "Add watermark to generated video" },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--seed <n>", description: "Random seed for reproducible generation", type: "number" },
{ flag: "--download <path>", description: "Save video to file on completion" },
{ flag: "--no-wait", description: "Return task ID immediately without waiting" },
Expand All@@ -78,6 +90,7 @@ export default defineCommand({
'bl video generate --prompt "Ocean waves at sunset." --download sunset.mp4',
'bl video generate --image https://example.com/cat.png --prompt "让画面中的猫动起来"',
'bl video generate --prompt "Mountain landscape" --resolution 1280*720 --duration 5',
'bl video generate --prompt "A cat playing with a ball" --watermark false',
],
async run(config: Config, flags: GlobalFlags) {
let prompt = flags.prompt as string | undefined;
Expand DownExpand Up@@ -110,6 +123,9 @@ export default defineCommand({
resolvedImageUrl = await resolveFileUrl(imageUrl, credential.token, model);
}

const watermark = resolveWatermark(flags.watermark);
const promptExtend = resolveBooleanFlag(flags.promptExtend, undefined, "prompt-extend");

const body: DashScopeVideoRequest = {
model,
input: {
Expand All@@ -124,8 +140,8 @@ export default defineCommand({
resolution: normalizeResolution(flags.resolution as string) || undefined,
ratio: (flags.ratio as string) || undefined,
duration: (flags.duration as number) || undefined,
prompt_extend: flags.promptExtend === true ? true : undefined,
watermark: flags.watermark === true ? true : undefined,
prompt_extend: promptExtend,
watermark,
seed: flags.seed as number | undefined,
},
};
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' fix: Fix the issue of the watermark being always on and address the i… by qcq01083097 · Pull Request #13 · modelstudioai/cli · GitHub
Skip to content
Merged
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
28 changes: 24 additions & 4 deletions packages/cli/src/args.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,6 +25,15 @@ interface FlagSchema {
arrays: Set<string>;
}

function buildAllowedFlagKeys(options: OptionDef[]): Set<string> {
const keys = new Set<string>();
for (const opt of options) {
const key = flagKey(opt);
if (key) keys.add(key);
}
return keys;
}

function buildSchema(options: OptionDef[]): FlagSchema {
const booleans = new Set<string>();
const numbers = new Set<string>();
Expand DownExpand Up@@ -91,6 +100,7 @@ export function scanCommandPath(argv: string[], globalOptions: OptionDef[] = [])
* - default: string
*/
export function parseFlags(argv: string[], options: OptionDef[]): GlobalFlags {
const allowedKeys = buildAllowedFlagKeys(options);
const schema = buildSchema(options);
const flags: GlobalFlags = {
quiet: false,
Expand DownExpand Up@@ -130,20 +140,30 @@ export function parseFlags(argv: string[], options: OptionDef[]): GlobalFlags {

const camelKey = kebabToCamel(key);

if (!allowedKeys.has(camelKey)) {
throw new BailianError(
`Unknown flag "--${key}". Run with --help to see available options.`,
ExitCode.USAGE,
);
}

// 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++;
value = argv[i];
const next = argv[i];
if (next === undefined || next.startsWith("-")) {
throw new BailianError(`Flag --${key} requires a value.`, ExitCode.USAGE);
}
value = next;
}

if (value === undefined)
throw new BailianError(`Flag --${key} requires a value.`, ExitCode.USAGE);

if (schema.arrays.has(camelKey)) {
const arr = (flags as Record<string, unknown>)[camelKey] as string[] | undefined;
if (arr) arr.push(value);
Expand Down
32 changes: 19 additions & 13 deletions packages/cli/src/commands/image/edit.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,13 +15,19 @@ import {
type DashScopeImageSyncResponse,
ExitCode,
BailianError,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { downloadFile } from "../../utils/download.ts";
import { runConcurrent, downloadParallel, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import { resolveImageSize } from "../../utils/image-size.ts";
import { join } from "path";
import {
BOOL_FLAG_PROMPT_EXTEND_CLI_TRUE,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

export default defineCommand({
name: "image edit",
Expand All@@ -47,9 +53,14 @@ export default defineCommand({
flag: "--negative-prompt <text>",
description: "Negative prompt to exclude unwanted content",
},
{ flag: "--prompt-extend", description: "Enable prompt smart rewrite (default: true)" },
{ flag: "--no-prompt-extend", description: "Disable prompt extend" },
{ flag: "--watermark", description: "Add watermark to output images" },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_CLI_TRUE,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--out-dir <dir>", description: "Download images to directory" },
{ flag: "--out-prefix <prefix>", description: "Filename prefix (default: edited)" },
],
Expand All@@ -58,6 +69,7 @@ export default defineCommand({
'bl image edit --image https://example.com/logo.png --prompt "Change color to blue" --n 3',
'bl image edit --image ./a.png --image ./b.png --prompt "把两张图合并成一张拼图"',
'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) {
// Normalize --image to string array (supports both single and repeated flags)
Expand DownExpand Up@@ -96,22 +108,16 @@ export default defineCommand({
);
const n = (flags.n as number) ?? 1;

// Determine prompt_extend
let promptExtend: boolean | undefined;
if (flags.noPromptExtend === true) {
promptExtend = false;
} else if (flags.promptExtend === true) {
promptExtend = true;
} else {
promptExtend = true; // default on for qwen-image
}
const promptExtend = resolveBooleanFlag(flags.promptExtend, true, "prompt-extend");

// Build content: all images first, then text prompt
const contentItems: Array<{ image?: string; text?: string }> = resolvedImages.map(
(u: string) => ({ image: u }),
);
contentItems.push({ text: prompt! });

const watermark = resolveWatermark(flags.watermark);

const body: DashScopeImageRequest = {
model,
input: {
Expand All@@ -127,7 +133,7 @@ export default defineCommand({
n,
seed: flags.seed as number | undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
negative_prompt: (flags.negativePrompt as string) || undefined,
},
};
Expand Down
38 changes: 23 additions & 15 deletions packages/cli/src/commands/image/generate.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,13 +17,19 @@ import {
type OutputFormat,
type DashScopeTaskResponse,
generateFilename,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile } from "../../utils/download.ts";
import { runConcurrent, downloadParallel, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import { resolveImageSize } from "../../utils/image-size.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_IMAGE_GENERATE,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

import { join } from "path";

Expand DownExpand Up@@ -57,11 +63,13 @@ export default defineCommand({
description: "Negative prompt to exclude unwanted content",
},
{
flag: "--prompt-extend",
description: "Automatically extend prompt for better results (default: true for qwen-image)",
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_IMAGE_GENERATE,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--no-prompt-extend", description: "Disable prompt extend" },
{ flag: "--watermark", description: "Add watermark to generated images" },
{
flag: "--no-wait",
description: "Return task ID immediately without waiting (async models only)",
Expand All@@ -78,7 +86,9 @@ export default defineCommand({
'bl image generate --prompt "一只穿太空服的猫在火星上"',
'bl image generate --prompt "Logo design" --n 3 --out-dir ./generated/',
'bl image generate --prompt "Mountain landscape" --size 2688*1536',
'bl image generate --prompt "A castle" --seed 42 --no-prompt-extend',
'bl image generate --prompt "A castle" --seed 42 --prompt-extend false',
'bl image generate --prompt "Logo" --watermark false',
'bl image generate --prompt "An alien in the space" --watermark false',
'bl image generate --prompt "sunset" --model wan2.6-t2i --no-wait --quiet',
'bl image generate --prompt "Pro quality" --model qwen-image-2.0-pro',
'bl image generate --prompt "Product shots" --n 2 --concurrent 3 # 6 images in parallel',
Expand DownExpand Up@@ -111,15 +121,13 @@ export default defineCommand({
const n = (flags.n as number) ?? 1;
const concurrent = getConcurrency(flags);

// Determine prompt_extend: default true for qwen-image, undefined for others
let promptExtend: boolean | undefined;
if (flags.noPromptExtend === true) {
promptExtend = false;
} else if (flags.promptExtend === true) {
promptExtend = true;
} else if (useSync) {
promptExtend = true; // qwen-image default
}
const promptExtend = resolveBooleanFlag(
flags.promptExtend,
useSync ? true : undefined,
"prompt-extend",
);

const watermark = resolveWatermark(flags.watermark);

const body: DashScopeImageRequest = {
model,
Expand All@@ -131,7 +139,7 @@ export default defineCommand({
n,
seed: flags.seed as number | undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
negative_prompt: (flags.negativePrompt as string) || undefined,
},
};
Expand Down
24 changes: 18 additions & 6 deletions packages/cli/src/commands/video/edit.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,11 +15,17 @@ import {
resolveCredential,
BailianError,
ExitCode,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile, formatBytes } from "../../utils/download.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

export default defineCommand({
name: "video edit",
Expand DownExpand Up@@ -51,9 +57,14 @@ export default defineCommand({
flag: "--audio-setting <mode>",
description: "Audio: auto (default) or origin (keep original)",
},
{ flag: "--prompt-extend", description: "Enable prompt intelligent rewriting (default: true)" },
{ flag: "--no-prompt-extend", description: "Disable prompt intelligent rewriting" },
{ flag: "--watermark", description: 'Add "AI生成" watermark' },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--seed <n>", description: "Random seed for reproducible generation", type: "number" },
{ flag: "--download <path>", description: "Save video to file on completion" },
{ flag: "--no-wait", description: "Return task ID immediately without waiting" },
Expand All@@ -71,6 +82,7 @@ export default defineCommand({
'bl video edit --video https://example.com/input.mp4 --prompt "将整个画面转换为黏土风格"',
'bl video edit --video https://example.com/input.mp4 --prompt "替换衣服为图片中的款式" --ref-image https://example.com/clothes.png',
'bl video edit --video https://example.com/input.mp4 --prompt "Convert to anime style" --resolution 720P --download output.mp4',
'bl video edit --video https://example.com/input.mp4 --prompt "给视频里的小猫穿上衣服" --watermark false',
],
async run(config: Config, flags: GlobalFlags) {
// --- Validate video URL ---
Expand DownExpand Up@@ -127,8 +139,8 @@ export default defineCommand({
}

// --- Build request body ---
const promptExtend =
flags.noPromptExtend === true ? false : flags.promptExtend === true ? true : undefined;
const promptExtend = resolveBooleanFlag(flags.promptExtend, undefined, "prompt-extend");
const watermark = resolveWatermark(flags.watermark);

const body: DashScopeVideoEditRequest = {
model,
Expand All@@ -143,7 +155,7 @@ export default defineCommand({
duration: (flags.duration as number) || undefined,
audio_setting: (flags.audioSetting as "auto" | "origin") || undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
seed: flags.seed as number | undefined,
},
};
Expand Down
24 changes: 20 additions & 4 deletions packages/cli/src/commands/video/generate.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,12 +15,18 @@ import {
resolveCredential,
BailianError,
ExitCode,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile, formatBytes } from "../../utils/download.ts";
import { runConcurrent, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

// Normalize shorthand resolution (720P, 1080P) to pixel format for video generation models
const RESOLUTION_SHORTCUTS: Record<string, string> = {
Expand DownExpand Up@@ -58,8 +64,14 @@ export default defineCommand({
description: "Video duration in seconds (default: 5)",
type: "number",
},
{ flag: "--prompt-extend", description: "Automatically extend prompt for better results" },
{ flag: "--watermark", description: "Add watermark to generated video" },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--seed <n>", description: "Random seed for reproducible generation", type: "number" },
{ flag: "--download <path>", description: "Save video to file on completion" },
{ flag: "--no-wait", description: "Return task ID immediately without waiting" },
Expand All@@ -78,6 +90,7 @@ export default defineCommand({
'bl video generate --prompt "Ocean waves at sunset." --download sunset.mp4',
'bl video generate --image https://example.com/cat.png --prompt "让画面中的猫动起来"',
'bl video generate --prompt "Mountain landscape" --resolution 1280*720 --duration 5',
'bl video generate --prompt "A cat playing with a ball" --watermark false',
],
async run(config: Config, flags: GlobalFlags) {
let prompt = flags.prompt as string | undefined;
Expand DownExpand Up@@ -110,6 +123,9 @@ export default defineCommand({
resolvedImageUrl = await resolveFileUrl(imageUrl, credential.token, model);
}

const watermark = resolveWatermark(flags.watermark);
const promptExtend = resolveBooleanFlag(flags.promptExtend, undefined, "prompt-extend");

const body: DashScopeVideoRequest = {
model,
input: {
Expand All@@ -124,8 +140,8 @@ export default defineCommand({
resolution: normalizeResolution(flags.resolution as string) || undefined,
ratio: (flags.ratio as string) || undefined,
duration: (flags.duration as number) || undefined,
prompt_extend: flags.promptExtend === true ? true : undefined,
watermark: flags.watermark === true ? true : undefined,
prompt_extend: promptExtend,
watermark,
seed: flags.seed as number | undefined,
},
};
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); fix: Fix the issue of the watermark being always on and address the i… by qcq01083097 · Pull Request #13 · modelstudioai/cli · GitHub
Skip to content
Merged
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
28 changes: 24 additions & 4 deletions packages/cli/src/args.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,6 +25,15 @@ interface FlagSchema {
arrays: Set<string>;
}

function buildAllowedFlagKeys(options: OptionDef[]): Set<string> {
const keys = new Set<string>();
for (const opt of options) {
const key = flagKey(opt);
if (key) keys.add(key);
}
return keys;
}

function buildSchema(options: OptionDef[]): FlagSchema {
const booleans = new Set<string>();
const numbers = new Set<string>();
Expand DownExpand Up@@ -91,6 +100,7 @@ export function scanCommandPath(argv: string[], globalOptions: OptionDef[] = [])
* - default: string
*/
export function parseFlags(argv: string[], options: OptionDef[]): GlobalFlags {
const allowedKeys = buildAllowedFlagKeys(options);
const schema = buildSchema(options);
const flags: GlobalFlags = {
quiet: false,
Expand DownExpand Up@@ -130,20 +140,30 @@ export function parseFlags(argv: string[], options: OptionDef[]): GlobalFlags {

const camelKey = kebabToCamel(key);

if (!allowedKeys.has(camelKey)) {
throw new BailianError(
`Unknown flag "--${key}". Run with --help to see available options.`,
ExitCode.USAGE,
);
}

// 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++;
value = argv[i];
const next = argv[i];
if (next === undefined || next.startsWith("-")) {
throw new BailianError(`Flag --${key} requires a value.`, ExitCode.USAGE);
}
value = next;
}

if (value === undefined)
throw new BailianError(`Flag --${key} requires a value.`, ExitCode.USAGE);

if (schema.arrays.has(camelKey)) {
const arr = (flags as Record<string, unknown>)[camelKey] as string[] | undefined;
if (arr) arr.push(value);
Expand Down
32 changes: 19 additions & 13 deletions packages/cli/src/commands/image/edit.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,13 +15,19 @@ import {
type DashScopeImageSyncResponse,
ExitCode,
BailianError,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { downloadFile } from "../../utils/download.ts";
import { runConcurrent, downloadParallel, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import { resolveImageSize } from "../../utils/image-size.ts";
import { join } from "path";
import {
BOOL_FLAG_PROMPT_EXTEND_CLI_TRUE,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

export default defineCommand({
name: "image edit",
Expand All@@ -47,9 +53,14 @@ export default defineCommand({
flag: "--negative-prompt <text>",
description: "Negative prompt to exclude unwanted content",
},
{ flag: "--prompt-extend", description: "Enable prompt smart rewrite (default: true)" },
{ flag: "--no-prompt-extend", description: "Disable prompt extend" },
{ flag: "--watermark", description: "Add watermark to output images" },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_CLI_TRUE,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--out-dir <dir>", description: "Download images to directory" },
{ flag: "--out-prefix <prefix>", description: "Filename prefix (default: edited)" },
],
Expand All@@ -58,6 +69,7 @@ export default defineCommand({
'bl image edit --image https://example.com/logo.png --prompt "Change color to blue" --n 3',
'bl image edit --image ./a.png --image ./b.png --prompt "把两张图合并成一张拼图"',
'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) {
// Normalize --image to string array (supports both single and repeated flags)
Expand DownExpand Up@@ -96,22 +108,16 @@ export default defineCommand({
);
const n = (flags.n as number) ?? 1;

// Determine prompt_extend
let promptExtend: boolean | undefined;
if (flags.noPromptExtend === true) {
promptExtend = false;
} else if (flags.promptExtend === true) {
promptExtend = true;
} else {
promptExtend = true; // default on for qwen-image
}
const promptExtend = resolveBooleanFlag(flags.promptExtend, true, "prompt-extend");

// Build content: all images first, then text prompt
const contentItems: Array<{ image?: string; text?: string }> = resolvedImages.map(
(u: string) => ({ image: u }),
);
contentItems.push({ text: prompt! });

const watermark = resolveWatermark(flags.watermark);

const body: DashScopeImageRequest = {
model,
input: {
Expand All@@ -127,7 +133,7 @@ export default defineCommand({
n,
seed: flags.seed as number | undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
negative_prompt: (flags.negativePrompt as string) || undefined,
},
};
Expand Down
38 changes: 23 additions & 15 deletions packages/cli/src/commands/image/generate.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,13 +17,19 @@ import {
type OutputFormat,
type DashScopeTaskResponse,
generateFilename,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile } from "../../utils/download.ts";
import { runConcurrent, downloadParallel, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import { resolveImageSize } from "../../utils/image-size.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_IMAGE_GENERATE,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

import { join } from "path";

Expand DownExpand Up@@ -57,11 +63,13 @@ export default defineCommand({
description: "Negative prompt to exclude unwanted content",
},
{
flag: "--prompt-extend",
description: "Automatically extend prompt for better results (default: true for qwen-image)",
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_IMAGE_GENERATE,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--no-prompt-extend", description: "Disable prompt extend" },
{ flag: "--watermark", description: "Add watermark to generated images" },
{
flag: "--no-wait",
description: "Return task ID immediately without waiting (async models only)",
Expand All@@ -78,7 +86,9 @@ export default defineCommand({
'bl image generate --prompt "一只穿太空服的猫在火星上"',
'bl image generate --prompt "Logo design" --n 3 --out-dir ./generated/',
'bl image generate --prompt "Mountain landscape" --size 2688*1536',
'bl image generate --prompt "A castle" --seed 42 --no-prompt-extend',
'bl image generate --prompt "A castle" --seed 42 --prompt-extend false',
'bl image generate --prompt "Logo" --watermark false',
'bl image generate --prompt "An alien in the space" --watermark false',
'bl image generate --prompt "sunset" --model wan2.6-t2i --no-wait --quiet',
'bl image generate --prompt "Pro quality" --model qwen-image-2.0-pro',
'bl image generate --prompt "Product shots" --n 2 --concurrent 3 # 6 images in parallel',
Expand DownExpand Up@@ -111,15 +121,13 @@ export default defineCommand({
const n = (flags.n as number) ?? 1;
const concurrent = getConcurrency(flags);

// Determine prompt_extend: default true for qwen-image, undefined for others
let promptExtend: boolean | undefined;
if (flags.noPromptExtend === true) {
promptExtend = false;
} else if (flags.promptExtend === true) {
promptExtend = true;
} else if (useSync) {
promptExtend = true; // qwen-image default
}
const promptExtend = resolveBooleanFlag(
flags.promptExtend,
useSync ? true : undefined,
"prompt-extend",
);

const watermark = resolveWatermark(flags.watermark);

const body: DashScopeImageRequest = {
model,
Expand All@@ -131,7 +139,7 @@ export default defineCommand({
n,
seed: flags.seed as number | undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
negative_prompt: (flags.negativePrompt as string) || undefined,
},
};
Expand Down
24 changes: 18 additions & 6 deletions packages/cli/src/commands/video/edit.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,11 +15,17 @@ import {
resolveCredential,
BailianError,
ExitCode,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile, formatBytes } from "../../utils/download.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

export default defineCommand({
name: "video edit",
Expand DownExpand Up@@ -51,9 +57,14 @@ export default defineCommand({
flag: "--audio-setting <mode>",
description: "Audio: auto (default) or origin (keep original)",
},
{ flag: "--prompt-extend", description: "Enable prompt intelligent rewriting (default: true)" },
{ flag: "--no-prompt-extend", description: "Disable prompt intelligent rewriting" },
{ flag: "--watermark", description: 'Add "AI生成" watermark' },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--seed <n>", description: "Random seed for reproducible generation", type: "number" },
{ flag: "--download <path>", description: "Save video to file on completion" },
{ flag: "--no-wait", description: "Return task ID immediately without waiting" },
Expand All@@ -71,6 +82,7 @@ export default defineCommand({
'bl video edit --video https://example.com/input.mp4 --prompt "将整个画面转换为黏土风格"',
'bl video edit --video https://example.com/input.mp4 --prompt "替换衣服为图片中的款式" --ref-image https://example.com/clothes.png',
'bl video edit --video https://example.com/input.mp4 --prompt "Convert to anime style" --resolution 720P --download output.mp4',
'bl video edit --video https://example.com/input.mp4 --prompt "给视频里的小猫穿上衣服" --watermark false',
],
async run(config: Config, flags: GlobalFlags) {
// --- Validate video URL ---
Expand DownExpand Up@@ -127,8 +139,8 @@ export default defineCommand({
}

// --- Build request body ---
const promptExtend =
flags.noPromptExtend === true ? false : flags.promptExtend === true ? true : undefined;
const promptExtend = resolveBooleanFlag(flags.promptExtend, undefined, "prompt-extend");
const watermark = resolveWatermark(flags.watermark);

const body: DashScopeVideoEditRequest = {
model,
Expand All@@ -143,7 +155,7 @@ export default defineCommand({
duration: (flags.duration as number) || undefined,
audio_setting: (flags.audioSetting as "auto" | "origin") || undefined,
prompt_extend: promptExtend,
watermark: flags.watermark === true ? true : undefined,
watermark,
seed: flags.seed as number | undefined,
},
};
Expand Down
24 changes: 20 additions & 4 deletions packages/cli/src/commands/video/generate.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,12 +15,18 @@ import {
resolveCredential,
BailianError,
ExitCode,
resolveBooleanFlag,
resolveWatermark,
} from "bailian-cli-core";
import { poll } from "../../utils/polling.ts";
import { downloadFile, formatBytes } from "../../utils/download.ts";
import { runConcurrent, getConcurrency } from "../../utils/concurrent.ts";
import { promptText, failIfMissing } from "../../output/prompt.ts";
import { emitResult, emitBare } from "../../output/output.ts";
import {
BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
BOOL_FLAG_WATERMARK,
} from "../../utils/flag-descriptions.ts";

// Normalize shorthand resolution (720P, 1080P) to pixel format for video generation models
const RESOLUTION_SHORTCUTS: Record<string, string> = {
Expand DownExpand Up@@ -58,8 +64,14 @@ export default defineCommand({
description: "Video duration in seconds (default: 5)",
type: "number",
},
{ flag: "--prompt-extend", description: "Automatically extend prompt for better results" },
{ flag: "--watermark", description: "Add watermark to generated video" },
{
flag: "--prompt-extend <bool>",
description: BOOL_FLAG_PROMPT_EXTEND_API_DEFAULT,
},
{
flag: "--watermark <bool>",
description: BOOL_FLAG_WATERMARK,
},
{ flag: "--seed <n>", description: "Random seed for reproducible generation", type: "number" },
{ flag: "--download <path>", description: "Save video to file on completion" },
{ flag: "--no-wait", description: "Return task ID immediately without waiting" },
Expand All@@ -78,6 +90,7 @@ export default defineCommand({
'bl video generate --prompt "Ocean waves at sunset." --download sunset.mp4',
'bl video generate --image https://example.com/cat.png --prompt "让画面中的猫动起来"',
'bl video generate --prompt "Mountain landscape" --resolution 1280*720 --duration 5',
'bl video generate --prompt "A cat playing with a ball" --watermark false',
],
async run(config: Config, flags: GlobalFlags) {
let prompt = flags.prompt as string | undefined;
Expand DownExpand Up@@ -110,6 +123,9 @@ export default defineCommand({
resolvedImageUrl = await resolveFileUrl(imageUrl, credential.token, model);
}

const watermark = resolveWatermark(flags.watermark);
const promptExtend = resolveBooleanFlag(flags.promptExtend, undefined, "prompt-extend");

const body: DashScopeVideoRequest = {
model,
input: {
Expand All@@ -124,8 +140,8 @@ export default defineCommand({
resolution: normalizeResolution(flags.resolution as string) || undefined,
ratio: (flags.ratio as string) || undefined,
duration: (flags.duration as number) || undefined,
prompt_extend: flags.promptExtend === true ? true : undefined,
watermark: flags.watermark === true ? true : undefined,
prompt_extend: promptExtend,
watermark,
seed: flags.seed as number | undefined,
},
};
Expand Down
Loading