@@ -22,6 +22,11 @@ import {
2222 ASYNC_FLAG ,
2323 CONCURRENT_FLAG ,
2424 redactDataUri ,
25+ bailianMcpPath ,
26+ AIGC_MCP_SERVER ,
27+ AIGC_MCP_TOOL ,
28+ buildImageEditArgs ,
29+ parseAigcImageResults ,
2530} from "bailian-cli-core" ;
2631import { poll } from "bailian-cli-runtime" ;
2732import { downloadFile } from "bailian-cli-runtime" ;
@@ -30,6 +35,15 @@ import { emitResult, emitBare } from "bailian-cli-runtime";
3035import { resolveImageSize } from "bailian-cli-runtime" ;
3136import { join } from "path" ;
3237import { BOOL_FLAG_PROMPT_EXTEND_CLI_TRUE , BOOL_FLAG_WATERMARK } from "bailian-cli-runtime" ;
38+ import {
39+ isAutoModel ,
40+ assertAutoMcpAvailable ,
41+ assertMcpCompatible ,
42+ withAigcMcpSession ,
43+ resolveAutoImageInput ,
44+ mcpSingleImageOnlyError ,
45+ type Localize ,
46+ } from "../shared/aigc-mcp.ts" ;
3347
3448const EDIT_FLAGS = {
3549 image : {
@@ -181,6 +195,14 @@ export default defineCommand({
181195 "zh-CN" : '--image ./photo.png --prompt "将背景替换为海滩" --watermark false' ,
182196 } ,
183197 ] ,
198+ notes : [
199+ {
200+ "en-US" :
201+ 'Model "auto" (via --model auto or a config default model of "auto") routes to the official Bailian MCP with a reduced parameter set; MCP-incompatible flags fail fast with a usage error instead of falling back to REST. Auto edit accepts a single --image only.' ,
202+ "zh-CN" :
203+ '模型 "auto"(通过 --model auto 或将配置默认模型设为 "auto")改走百炼官方 MCP,参数面更小;MCP 不支持的参数会直接报用法错误,而不回退 REST。auto 编辑仅支持单个 --image。' ,
204+ } ,
205+ ] ,
184206 async run ( ctx ) {
185207 const { settings, flags } = ctx ;
186208 // Normalize --image to string array (supports both single and repeated flags)
@@ -192,7 +214,20 @@ export default defineCommand({
192214 }
193215 const prompt = flags . prompt ;
194216
195- const model = flags . model || settings . defaultImageModel || "qwen-image-3.0" ;
217+ const resolvedModel = flags . model || settings . defaultImageModel ;
218+ if ( isAutoModel ( resolvedModel ) ) {
219+ await handleAutoMcpMode (
220+ ctx . client ,
221+ ctx . localize ,
222+ settings ,
223+ flags ,
224+ rawImages ,
225+ detectOutputFormat ( settings . output ) ,
226+ ) ;
227+ return ;
228+ }
229+
230+ const model = resolvedModel || "qwen-image-3.0" ;
196231 const route = resolveImageEditApi ( model ) ;
197232
198233 // Auto-upload local files (resolve all images in parallel)
@@ -329,6 +364,70 @@ export default defineCommand({
329364 } ,
330365} ) ;
331366
367+ async function handleAutoMcpMode (
368+ client : Client ,
369+ localize : Localize ,
370+ settings : Settings ,
371+ flags : EditFlags ,
372+ rawImages : string [ ] ,
373+ format : OutputFormat ,
374+ ) : Promise < void > {
375+ assertAutoMcpAvailable ( client , localize ) ;
376+ assertMcpCompatible ( "imageEdit" , flags , localize ) ;
377+
378+ // bailian_image_edit takes a single source image; bailian_image_fusion is out
379+ // of scope, so multi-image merge is rejected in auto mode.
380+ if ( rawImages . length > 1 ) {
381+ throw mcpSingleImageOnlyError ( localize ) ;
382+ }
383+ const source = rawImages [ 0 ] ;
384+ if ( ! source ) {
385+ throw new BailianError ( "Provide one --image to edit." , ExitCode . USAGE ) ;
386+ }
387+
388+ const imageUrl = resolveAutoImageInput ( source ) ;
389+ const concurrent = getConcurrency ( flags ) ;
390+ const args = buildImageEditArgs ( {
391+ imageUrl,
392+ prompt : flags . prompt ,
393+ negativePrompt : flags . negativePrompt || undefined ,
394+ } ) ;
395+
396+ if ( settings . dryRun ) {
397+ emitResult (
398+ {
399+ server : AIGC_MCP_SERVER . image ,
400+ url : client . url ( bailianMcpPath ( AIGC_MCP_SERVER . image ) ) ,
401+ tool : AIGC_MCP_TOOL . imageEdit ,
402+ arguments : { ...args , image_url : redactDataUri ( imageUrl ) } ,
403+ mode : "mcp" ,
404+ concurrent,
405+ } ,
406+ format ,
407+ ) ;
408+ return ;
409+ }
410+
411+ if ( ! settings . quiet ) {
412+ process . stderr . write ( "[Model: auto] [Mode: mcp] [Images: 1]\n" ) ;
413+ }
414+
415+ // One shared MCP session; --concurrent fans out parallel tools/call on it.
416+ await withAigcMcpSession ( client , AIGC_MCP_SERVER . image , localize , async ( callTool ) => {
417+ const perRequest = await runConcurrent ( concurrent , settings , async ( ) => {
418+ const inner = await callTool ( AIGC_MCP_TOOL . imageEdit , args ) ;
419+ return parseAigcImageResults ( inner ) ;
420+ } ) ;
421+
422+ const imageUrls = perRequest . flat ( ) ;
423+ if ( imageUrls . length === 0 ) {
424+ throw new BailianError ( "Edit completed but no images returned." , ExitCode . GENERAL ) ;
425+ }
426+
427+ await saveImages ( imageUrls , flags , settings , format ) ;
428+ } ) ;
429+ }
430+
332431async function handleSyncMode (
333432 client : Client ,
334433 settings : Settings ,
0 commit comments