Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/images/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/images/plan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
Loading