mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-14 10:52:17 +03:00
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.
This commit is contained in:
@@ -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}`
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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, [
|
||||
|
||||
Reference in New Issue
Block a user