From 0ec35bf9308ffa590038c3db1cfc4c40ff09868e Mon Sep 17 00:00:00 2001 From: justnodejs Date: Sat, 11 Apr 2026 16:15:01 +0800 Subject: [PATCH] fix(baoyu-imagine): tighten Replicate schema validation and fallback handling --- .../scripts/providers/replicate.test.ts | 11 +++++++++++ .../scripts/providers/replicate.ts | 18 ++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/skills/baoyu-imagine/scripts/providers/replicate.test.ts b/skills/baoyu-imagine/scripts/providers/replicate.test.ts index 88949e5..c255f6a 100644 --- a/skills/baoyu-imagine/scripts/providers/replicate.test.ts +++ b/skills/baoyu-imagine/scripts/providers/replicate.test.ts @@ -162,6 +162,7 @@ test("Replicate input builder maps Wan models to their native schema", () => { size: "2K", num_outputs: 2, images: ["data:image/png;base64,AAAA"], + thinking_mode: false, }, ); @@ -214,6 +215,16 @@ test("Replicate validation catches unsupported Seedream and Wan argument combina /Seedream on Replicate requires --size to be one of 2K, 3K/, ); + assert.throws( + () => validateArgs("bytedance/seedream-4.5", makeArgs({ referenceImages: Array.from({ length: 15 }, () => "ref.png") })), + /supports at most 14 reference images/, + ); + + assert.throws( + () => validateArgs("bytedance/seedream-5-lite", makeArgs({ referenceImages: Array.from({ length: 10 }, () => "ref.png"), n: 10 })), + /allows at most 15 total images per request/, + ); + assert.throws( () => validateArgs("google/nano-banana-2", makeArgs({ n: 2 })), /Nano Banana models on Replicate do not support --n yet/, diff --git a/skills/baoyu-imagine/scripts/providers/replicate.ts b/skills/baoyu-imagine/scripts/providers/replicate.ts index cb89625..dd8e4ef 100644 --- a/skills/baoyu-imagine/scripts/providers/replicate.ts +++ b/skills/baoyu-imagine/scripts/providers/replicate.ts @@ -196,10 +196,8 @@ function buildWanInput(prompt: string, model: string, args: CliArgs, referenceIm } // thinking_mode only applies to pure text-to-image. - // image_set_mode is not exposed by the current CLI, so no extra check is needed here yet. - if (referenceImages.length === 0) { - input.thinking_mode = true; - } + // image_set_mode is not exposed by the current CLI, so switch only on input-image presence for now. + input.thinking_mode = referenceImages.length === 0; return input; } @@ -216,6 +214,8 @@ export function validateArgs(model: string, args: CliArgs): void { } if (isSeedreamModel(model)) { + const referenceCount = args.referenceImages.length; + if (args.size) { const normalizedSize = normalizePresetSize(args.size); if (!getAllowedSeedreamSizes(model).has(normalizedSize)) { @@ -225,9 +225,19 @@ export function validateArgs(model: string, args: CliArgs): void { } } + if (referenceCount > 14) { + throw new Error("Seedream on Replicate supports at most 14 reference images per request."); + } + if (args.n < 1 || args.n > 15) { throw new Error("Seedream on Replicate supports --n values from 1 to 15."); } + + if (referenceCount + args.n > 15) { + throw new Error( + `Seedream on Replicate allows at most 15 total images per request (reference images + generated images). Received ${referenceCount} reference images and --n ${args.n}.` + ); + } } if (isWanModel(model)) {