From 5228cef34e42c17ecf3eaac32a263064be1bc0ed Mon Sep 17 00:00:00 2001 From: WuYongJie <549727955@qq.com> Date: Mon, 23 Nov 2026 15:42:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E7=95=99=2098K=20=E7=94=9F=E5=9B=BE?= =?UTF-8?q?=E7=9A=84=E8=87=AA=E5=8A=A8=E6=AF=94=E4=BE=8B=E5=92=8C=E6=B8=85?= =?UTF-8?q?=E6=99=B0=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ai/providers/vip98k.ts | 15 +++++++++++--- tests/routes/vip98k-model-expansion.test.ts | 23 +++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/lib/ai/providers/vip98k.ts b/lib/ai/providers/vip98k.ts index 8d4ed8312..88e7121bd 100644 --- a/lib/ai/providers/vip98k.ts +++ b/lib/ai/providers/vip98k.ts @@ -1796,16 +1796,25 @@ export function buildTaskBody(params: Vip98kTaskParams, invocation: Vip98kInvoca Array.isArray(configuredSizes) && configuredSizes.length === 1 && configuredSizes[0] === "1K"; - if (!aspectRatio && automaticRatioField && hasNativeResolution && sizes?.includes(resolution)) { + const acceptsResolutionAsSize = sizes?.includes(resolution); + const acceptsAutomaticSize = + sizes?.includes("auto") && + [body.resolution, body.imageSize, body.image_size].includes(resolution); + if ( + !aspectRatio && + automaticRatioField && + hasNativeResolution && + (acceptsResolutionAsSize || acceptsAutomaticSize) + ) { body[automaticRatioField] = "auto"; - body.size = resolution; + body.size = acceptsResolutionAsSize ? resolution : "auto"; } else if (hasSeparateAspectRatio && fixedOneK && sizes?.includes("auto") && ratios.includes(selectedRatio)) { // A fixed-tier route can use its explicit ratio without a second geometry // constraint. Its published pixel presets may round the nominal ratio. body.size = "auto"; } else if (ratios.includes(selectedRatio)) { body.size = selectedRatio; - } else if (sizes?.includes(resolution) && hasNativeAspectRatio) body.size = resolution; + } else if (acceptsResolutionAsSize && hasNativeAspectRatio) body.size = resolution; else if (pixels.length && (resolution || aspectRatio)) { const [rw, rh] = selectedRatio.split(":").map(Number); const matching = pixels.filter(size => Math.abs(size.width / size.height - rw / rh) < 0.025); diff --git a/tests/routes/vip98k-model-expansion.test.ts b/tests/routes/vip98k-model-expansion.test.ts index 5faeddeee..4a3fb7eaf 100644 --- a/tests/routes/vip98k-model-expansion.test.ts +++ b/tests/routes/vip98k-model-expansion.test.ts @@ -131,6 +131,29 @@ test("automatic proportions stay automatic at every published resolution with re } }); +test("async image contracts keep automatic size when resolution is a separate field", () => { + const contract = { + ...invocation({ + size: { enum: ["auto", "1024x1024", "2048x2048", "4096x4096"] }, + resolution: { enum: ["1K", "2K", "4K"] }, + aspect_ratio: { enum: ["auto", "1:1", "3:4", "16:9"] }, + file_urls: { type: "array", items: { type: "string" } }, + }, { size: "auto", resolution: "1K", aspect_ratio: "auto" }), + path: "/extensions/v1/tasks", + }; + const imageUrls = ["https://example.com/reference.png"]; + for (const imageSize of ["1K", "2K", "4K"]) { + const { body } = buildTaskBody({ + ...params, modelId: "nano-banana-2.1", imageUrls, imageParams: { imageSize, aspectRatio: "auto" }, + }, contract); + expect(body).toMatchObject({ size: "auto", resolution: imageSize, aspect_ratio: "auto", file_urls: imageUrls }); + } + const { body } = buildTaskBody({ + ...params, modelId: "nano-banana-2.1", imageUrls, imageParams: { imageSize: "4K", aspectRatio: "1:1" }, + }, contract); + expect(body).toMatchObject({ size: "4096x4096", resolution: "4K", aspect_ratio: "1:1" }); +}); + test("4K uses the largest published square size for area-based image contracts", () => { const result=buildTaskBody({...params,imageParams:{imageSize:"4K",aspectRatio:"1:1"}},invocation({size:{enum:["1024x1024","2048x2048","2880x2880"]},resolution:{enum:["1K","2K","4K"]}})); expect(result.body).toMatchObject({size:"2880x2880",resolution:"4K"});