xonecas.io
64875
Mc

mini-coder / commit 22e5dd4

feat: enable image output for Google models via responseModalities

Set providerOptions.google.responseModalities to ["TEXT", "IMAGE"] for
all Gemini models, using the existing isGeminiModelFamily predicate.
Merges correctly with thinking config when both are present.

This enables multimodal models like gemini-3.1-flash-image to return
inline images via the AI SDK's file stream chunks, which our existing
file-generated handler saves to disk.

xonecas2026-03-22 22e5dd41ea4dfc49aa045f0e65a57f24aa03ecd0 parent 69e87ad

2 files changed

src/llm-api/turn-provider-options.test.ts+46−0
@@ -0,0 +1,46 @@
1+import { describe, expect, test } from "bun:test";
2+
3+import { buildTurnProviderOptions } from "./turn-provider-options.ts";
4+
5+describe("buildTurnProviderOptions", () => {
6+ test("sets responseModalities for google models", () => {
7+ const result = buildTurnProviderOptions({
8+ modelString: "google/gemini-2.5-flash",
9+ thinkingEffort: undefined,
10+ });
11+ expect(result.providerOptions).toEqual({
12+ google: { responseModalities: ["TEXT", "IMAGE"] },
13+ });
14+ });
15+
16+ test("merges responseModalities with thinking config for google models", () => {
17+ const result = buildTurnProviderOptions({
18+ modelString: "google/gemini-2.5-flash",
19+ thinkingEffort: "high",
20+ });
21+ expect(result.providerOptions).toMatchObject({
22+ google: {
23+ responseModalities: ["TEXT", "IMAGE"],
24+ thinkingConfig: expect.any(Object),
25+ },
26+ });
27+ });
28+
29+ test("does not set responseModalities for non-google models", () => {
30+ const result = buildTurnProviderOptions({
31+ modelString: "anthropic/claude-sonnet-4-5",
32+ thinkingEffort: undefined,
33+ });
34+ expect(result.providerOptions).toEqual({});
35+ });
36+
37+ test("sets responseModalities for zen google models", () => {
38+ const result = buildTurnProviderOptions({
39+ modelString: "zen/gemini-3.1-pro",
40+ thinkingEffort: undefined,
41+ });
42+ expect(result.providerOptions).toEqual({
43+ google: { responseModalities: ["TEXT", "IMAGE"] },
44+ });
45+ });
46+});
src/llm-api/turn-provider-options.ts+13−0
@@ -1,5 +1,6 @@
11 import { isRecord } from "./history/shared.ts";
22 import { isOpenAIGPT } from "./history-transforms.ts";
3+import { isGeminiModelFamily } from "./model-routing.ts";
34 import {
45 getCacheFamily,
56 getThinkingProviderOptions,
@@ -34,6 +35,17 @@ export function buildTurnProviderOptions(
3435
3536 const cacheFamily = getCacheFamily(modelString);
3637
38+ const googleOpts = isGeminiModelFamily(modelString)
39+ ? {
40+ google: {
41+ responseModalities: ["TEXT", "IMAGE"],
42+ ...(isRecord(thinkingOpts?.google)
43+ ? (thinkingOpts.google as object)
44+ : {}),
45+ },
46+ }
47+ : {};
48+
3749 const providerOptions = {
3850 ...(thinkingOpts ?? {}),
3951 ...(isOpenAIGPT(modelString)
@@ -46,6 +58,7 @@ export function buildTurnProviderOptions(
4658 },
4759 }
4860 : {}),
61+ ...googleOpts,
4962 };
5063
5164 return {