diff --git a/src/images/plan.ts b/src/images/plan.ts index b8780d0fb..9ea2bdcbb 100644 --- a/src/images/plan.ts +++ b/src/images/plan.ts @@ -48,11 +48,12 @@ export async function planImageBridge( if (config.images?.bridgeEnabled !== true) return undefined; if (!parsed._imageGeneration) return undefined; const toolAllowed = toolChoiceToolPredicate(parsed.options.toolChoice); - const toolNames = new Set( - [...parsed._imageGeneration.toolNames, IMAGE_GEN_TOOL_NAME] - .filter(name => toolAllowed({ name })), - ); + const toolNames = new Set([...parsed._imageGeneration.toolNames].filter(name => toolAllowed({ name }))); + if (toolAllowed({ name: IMAGE_GEN_TOOL_NAME })) toolNames.add(IMAGE_GEN_TOOL_NAME); if (toolNames.size === 0) return undefined; + // Responses advertises and rewrites authorized aliases to this synthetic name, so the loop + // must always intercept it once any image-generation name has armed the bridge. + toolNames.add(IMAGE_GEN_TOOL_NAME); // Don't intercept for OpenAI native passthrough const host = (() => { try { return new URL(routedProvider.baseUrl).hostname; } catch { return ""; } })(); if (host === "api.openai.com") return undefined; diff --git a/tests/images/plan.test.ts b/tests/images/plan.test.ts index dfff91063..e71445a41 100644 --- a/tests/images/plan.test.ts +++ b/tests/images/plan.test.ts @@ -116,7 +116,7 @@ describe("planImageBridge", () => { parsed.options.toolChoice = { name: "generate_image" }; const aliasPlan = await planImageBridge(cfg, parsed, routed); expect(aliasPlan).toBeDefined(); - expect(aliasPlan!.toolNames.has("image_gen")).toBe(false); + expect(aliasPlan!.toolNames.has("image_gen")).toBe(true); expect(aliasPlan!.toolNames.has("generate_image")).toBe(true); });