From e96e40c035dc0814754ff959b0b9bd2c757dcf7d Mon Sep 17 00:00:00 2001 From: Bl0ck <36800583+Bl0ck154@users.noreply.github.com> Date: Sun, 30 Aug 2026 11:10:11 +0300 Subject: [PATCH] fix(images): forward Antigravity image size (#11952) Boarded with #11954/#11953/#11951/#11948 in one combined worktree: typecheck:core, check:file-size, check:changelog-integrity, check:complexity, check:cognitive-complexity, check:cycles all green; 85/85 focused tests pass. Confirmed the Antigravity Gemini path only forwarded aspectRatio into generationConfig, dropping the requested size tier entirely. Thanks for the fix and the 3:4/2K regression coverage. --- open-sse/handlers/imageGeneration.ts | 17 +++++++++++++++-- tests/unit/image-generation-handler.test.ts | 5 +++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/open-sse/handlers/imageGeneration.ts b/open-sse/handlers/imageGeneration.ts index 6e0405d7fa..25b7a3482f 100644 --- a/open-sse/handlers/imageGeneration.ts +++ b/open-sse/handlers/imageGeneration.ts @@ -175,6 +175,7 @@ const OPENAI_IMAGE_TO_IMAGE_MODELS = new Set([ ]); const IMAGE_ASPECT_RATIO_PATTERN = /^\d+:\d+$/; +const IMAGE_SIZE_PATTERN = /^(?:1K|2K|4K)$/; /** * Resolve the upstream images endpoint for a custom (OpenAI-compatible) image @@ -235,6 +236,13 @@ function normalizeImageAspectRatio(value: unknown, fallbackSize: unknown): strin return mapImageSize(typeof fallbackSize === "string" ? fallbackSize : null); } +function normalizeImageGenerationSize(snakeCaseValue: unknown, camelCaseValue: unknown): string { + const value = snakeCaseValue ?? camelCaseValue; + if (typeof value !== "string") return "1K"; + const normalized = value.trim().toUpperCase(); + return IMAGE_SIZE_PATTERN.test(normalized) ? normalized : "1K"; +} + function parseJsonOrNull(value: string): unknown | null { try { return JSON.parse(value); @@ -996,12 +1004,16 @@ async function handleGeminiImageGeneration({ model, providerConfig, body, creden const candidateCount = typeof body.n === "number" && Number.isFinite(body.n) && body.n > 0 ? Math.floor(body.n) : 1; const promptText = typeof body.prompt === "string" ? body.prompt : String(body.prompt ?? ""); + const aspectRatio = normalizeImageAspectRatio(body.aspect_ratio, body.size); + const imageSize = normalizeImageGenerationSize(body.image_size, body.imageSize); // Summarized request for call log const logRequestBody = { model: body.model, prompt: promptText.slice(0, 200), size: body.size || "default", + aspect_ratio: aspectRatio, + image_size: imageSize, n: candidateCount, }; @@ -1030,7 +1042,8 @@ async function handleGeminiImageGeneration({ model, providerConfig, body, creden generationConfig: { candidateCount, imageConfig: { - aspectRatio: normalizeImageAspectRatio(body.aspect_ratio, body.size), + aspectRatio, + imageSize, }, }, }, @@ -1050,7 +1063,7 @@ async function handleGeminiImageGeneration({ model, providerConfig, body, creden const promptPreview = promptText.slice(0, 60); log.info( "IMAGE", - `antigravity/${model} (gemini) | prompt: "${promptPreview}..." | format: gemini-image` + `antigravity/${model} (gemini) | prompt: "${promptPreview}..." | ${aspectRatio} ${imageSize}` ); } diff --git a/tests/unit/image-generation-handler.test.ts b/tests/unit/image-generation-handler.test.ts index 49709a13c3..0caa469564 100644 --- a/tests/unit/image-generation-handler.test.ts +++ b/tests/unit/image-generation-handler.test.ts @@ -752,7 +752,8 @@ test("handleImageGeneration sends Antigravity image requests with native image_g model: "antigravity/gemini-3.1-flash-image-preview", prompt: "painted beach", size: "1024x1024", - aspect_ratio: "not-a-ratio", + aspect_ratio: "3:4", + image_size: "2K", }, credentials: { accessToken: "ag-token", projectId: "project-123" }, log: null, @@ -777,7 +778,7 @@ test("handleImageGeneration sends Antigravity image requests with native image_g contents: [{ role: "user", parts: [{ text: "painted beach" }] }], generationConfig: { candidateCount: 1, - imageConfig: { aspectRatio: "1:1" }, + imageConfig: { aspectRatio: "3:4", imageSize: "2K" }, }, }); assert.deepEqual(result.data.data, [