fix(baoyu-imagine): tighten Replicate Seedream and Wan validation

This commit is contained in:
justnodejs 2026-04-11 17:02:18 +08:00
parent 8c0b0d3a3b
commit 959a9de8d4
2 changed files with 39 additions and 22 deletions

View File

@ -182,6 +182,22 @@ test("Replicate input builder maps Wan models to their native schema", () => {
thinking_mode: true, thinking_mode: true,
}, },
); );
assert.deepEqual(
buildInput(
"A robot painter",
"wan-video/wan-2.7-image",
makeArgs({
size: "1536x1024",
}),
[],
),
{
prompt: "A robot painter",
size: "1536*1024",
thinking_mode: true,
},
);
}); });
test("Replicate input builder falls back to nano-banana schema for unknown models", () => { test("Replicate input builder falls back to nano-banana schema for unknown models", () => {
@ -245,9 +261,22 @@ test("Replicate validation catches unsupported Seedream and Wan argument combina
/Wan image models on Replicate require --size/, /Wan image models on Replicate require --size/,
); );
assert.doesNotThrow(
() => validateArgs("wan-video/wan-2.7-image", makeArgs({ size: "1536x1024" })),
);
assert.doesNotThrow(
() => validateArgs("wan-video/wan-2.7-image-pro", makeArgs({ size: "1920x1080" })),
);
assert.throws(
() => validateArgs("wan-video/wan-2.7-image-pro", makeArgs({ referenceImages: Array.from({ length: 10 }, () => "ref.png") })),
/support at most 9 reference images/,
);
assert.throws( assert.throws(
() => validateArgs("wan-video/wan-2.7-image", makeArgs({ size: "4K" })), () => validateArgs("wan-video/wan-2.7-image", makeArgs({ size: "4K" })),
/Wan image models on Replicate require --size to be one of/, /Wan image models on Replicate require --size to be one of 1K, 2K or custom dimensions/,
); );
assert.throws( assert.throws(

View File

@ -9,24 +9,8 @@ const MAX_POLL_MS = 300_000;
const SIZE_PRESET_PATTERN = /^\d+K$/i; const SIZE_PRESET_PATTERN = /^\d+K$/i;
const SEEDREAM_45_SIZES = new Set(["2K", "4K"]); const SEEDREAM_45_SIZES = new Set(["2K", "4K"]);
const SEEDREAM_5_LITE_SIZES = new Set(["2K", "3K"]); const SEEDREAM_5_LITE_SIZES = new Set(["2K", "3K"]);
const WAN_PRO_SIZES = new Set([ const WAN_PRO_PRESET_SIZES = new Set(["1K", "2K", "4K"]);
"1K", "2K", "4K", const WAN_PRESET_SIZES = new Set(["1K", "2K"]);
"1024*1024", "2048*2048", "4096*4096",
"1280*720", "720*1280",
"2048*1152", "1152*2048",
"4096*2304", "2304*4096",
"1024*768", "768*1024",
"2048*1536", "1536*2048",
"4096*3072", "3072*4096",
]);
const WAN_SIZES = new Set([
"1K", "2K",
"1024*1024", "2048*2048",
"1280*720", "720*1280",
"2048*1152", "1152*2048",
"1024*768", "768*1024",
"2048*1536", "1536*2048",
]);
export function getDefaultModel(): string { export function getDefaultModel(): string {
return process.env.REPLICATE_IMAGE_MODEL || DEFAULT_MODEL; return process.env.REPLICATE_IMAGE_MODEL || DEFAULT_MODEL;
@ -116,7 +100,7 @@ function getAllowedSeedreamSizes(model: string): Set<string> {
} }
function getAllowedWanSizes(model: string): Set<string> { function getAllowedWanSizes(model: string): Set<string> {
return isWanProModel(model) ? WAN_PRO_SIZES : WAN_SIZES; return isWanProModel(model) ? WAN_PRO_PRESET_SIZES : WAN_PRESET_SIZES;
} }
function normalizePresetSize(size: string): string { function normalizePresetSize(size: string): string {
@ -265,11 +249,15 @@ export function validateArgs(model: string, args: CliArgs): void {
throw new Error("Wan image models on Replicate require --size when using --ar. This provider does not infer size from aspect ratio."); throw new Error("Wan image models on Replicate require --size when using --ar. This provider does not infer size from aspect ratio.");
} }
if (args.referenceImages.length > 9) {
throw new Error("Wan image models on Replicate support at most 9 reference images per request.");
}
if (args.size) { if (args.size) {
const normalizedSize = parsePixelSize(args.size) ? normalizePixelSize(args.size) : normalizePresetSize(args.size); const normalizedSize = parsePixelSize(args.size) ? normalizePixelSize(args.size) : normalizePresetSize(args.size);
if (!getAllowedWanSizes(model).has(normalizedSize)) { if (!parsePixelSize(args.size) && !getAllowedWanSizes(model).has(normalizedSize)) {
throw new Error( throw new Error(
`Wan image models on Replicate require --size to be one of ${Array.from(getAllowedWanSizes(model)).join(", ")}. Received: ${args.size}` `Wan image models on Replicate require --size to be one of ${Array.from(getAllowedWanSizes(model)).join(", ")} or custom dimensions like 1920x1080. Received: ${args.size}`
); );
} }
} }