Skip to content

Commit 3e92e8d

Browse files
committed
fix(google): use public model id in system identity; cover rename opt-out
- identifyRoutedModel now names parsed.modelId so a -tiered wire rename never leaks into the system prompt identity (CodeRabbit finding) - document that directGeminiWireRenames affects only AI Studio direct requests; Vertex and Cloud Code Assist are unchanged - add adapter tests for explicit true and Cloud Code Assist opt-out
1 parent 4c3dab5 commit 3e92e8d

3 files changed

Lines changed: 34 additions & 7 deletions

File tree

‎docs-site/src/content/docs/reference/configuration/providers.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ differing backup and rewrites known legacy namespaced selected ids to bare ids.
121121
| `escapeBuiltinToolNames?` | `boolean` | Escape built-in tool names for Anthropic-compatible gateways and restore them in returned calls. |
122122
| `anthropicEofTolerance?` | `boolean` | Let an Anthropic-compatible gateway complete a stream that ends before `message_stop`, only when visible text or a complete JSON-object tool input was received. Off by default. |
123123
| `googleMode?` | `"ai-studio" \| "vertex" \| "cloud-code-assist"` | Google transport/auth mode. Default `ai-studio`. |
124-
| `directGeminiWireRenames?` | `boolean` | Google only. When `false`, the AI Studio (direct) path sends Gemini Flash ids to the wire unchanged instead of applying the `-tiered` suffix (`gemini-3.7-flash` -> `gemini-3.7-flash-tiered`). Defaults to the rename; set `false` when the configured upstream still serves the bare ids. |
124+
| `directGeminiWireRenames?` | `boolean` | Google only. This affects only direct AI Studio requests. When `false`, the AI Studio path sends Gemini Flash ids to the wire unchanged instead of applying the `-tiered` suffix (`gemini-3.7-flash` -> `gemini-3.7-flash-tiered`). Vertex preserves the requested model ID, and Cloud Code Assist routing is unchanged. Defaults to the rename; set `false` when the configured upstream still serves the bare ids. |
125125
| `project?` | `string` | Vertex or Antigravity Cloud Code Assist project id. |
126126
| `location?` | `string` | Vertex location; environment fallback is `GOOGLE_CLOUD_LOCATION`. |
127127
| `mcpServers?` | `Record<string, CursorMcpServerConfig>` | Cursor only: stdio or Streamable HTTP MCP servers. |

‎src/adapters/google.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,15 @@ function geminiToolResultText(content: string | OcxContentPart[]): string {
148148
return hasContent ? contentPartsToText(content) : GEMINI_EMPTY_TOOL_OUTPUT_PLACEHOLDER;
149149
}
150150

151-
function messagesToGeminiFormat(
152-
parsed: OcxParsedRequest,
153-
routedModelId = parsed.modelId,
154-
): { systemInstruction?: unknown; contents: unknown[] } {
151+
function messagesToGeminiFormat(parsed: OcxParsedRequest): { systemInstruction?: unknown; contents: unknown[] } {
155152
// Neutralize Codex's GPT-5 identity line (Gemini/Antigravity share this path) so a routed model
156153
// never misreports as GPT-5/OpenAI, and never leaks the proxy identity upstream.
157154
const toolCatalogNudge = buildNonOpenAIToolCatalogNudgeForTools(parsed.context.tools, parsed.options.toolChoice);
158155
const systemText = identifyRoutedModel([
159156
...(parsed.context.systemPrompt ?? []),
160157
...(toolCatalogNudge ? [toolCatalogNudge] : []),
161158
GOOGLE_BREVITY_INSTRUCTION,
162-
].join("\n\n"), routedModelId);
159+
].join("\n\n"), parsed.modelId);
163160
const systemInstruction = { parts: [{ text: systemText }] };
164161

165162
const contents: unknown[] = [];
@@ -391,7 +388,9 @@ export function createGoogleAdapter(provider: OcxProviderConfig): ProviderAdapte
391388
: provider.googleMode === "vertex"
392389
? parsed.modelId
393390
: resolveDirectGeminiWireModelId(parsed.modelId, provider.directGeminiWireRenames !== false);
394-
const { systemInstruction, contents } = messagesToGeminiFormat(parsed, routedModelId);
391+
// System identity names the public model id (parsed.modelId) so the model never
392+
// self-reports as its -tiered wire spelling; routedModelId is only the wire id in the URL.
393+
const { systemInstruction, contents } = messagesToGeminiFormat(parsed);
395394
const tools = toolsToGeminiFormat(parsed);
396395

397396
const body: Record<string, unknown> = { contents };

‎tests/google-adapter.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,34 @@ describe("google adapter — direct -tiered wire renames", () => {
304304
}
305305
});
306306

307+
test("directGeminiWireRenames: true still maps to the -tiered wire id", async () => {
308+
const adapter = createGoogleAdapter({ ...provider, directGeminiWireRenames: true });
309+
for (const modelId of ["gemini-3.7-flash", "gemini-3.6-flash"]) {
310+
const { url } = await adapter.buildRequest(renamedParsed(modelId));
311+
expect(url).toContain(`/v1beta/models/${modelId}-tiered:generateContent`);
312+
}
313+
});
314+
315+
test("directGeminiWireRenames does not affect Cloud Code Assist requests", async () => {
316+
const ccaProvider = {
317+
...provider,
318+
googleMode: "cloud-code-assist",
319+
baseUrl: "https://daily-cloudcode-pa.googleapis.com",
320+
project: "proj-123",
321+
} as const;
322+
for (const modelId of ["gemini-3.7-flash", "gemini-3.6-flash"]) {
323+
const parsed = renamedParsed(modelId);
324+
const defaultRequest = await createGoogleAdapter(ccaProvider).buildRequest(parsed);
325+
const optOutRequest = await createGoogleAdapter({ ...ccaProvider, directGeminiWireRenames: false })
326+
.buildRequest(parsed);
327+
expect(optOutRequest.url).toBe(defaultRequest.url);
328+
// The envelope's requestId/sessionId are minted per request; compare the wire model only.
329+
const defaultModel = JSON.parse(defaultRequest.body).model as string;
330+
const optOutModel = JSON.parse(optOutRequest.body).model as string;
331+
expect(optOutModel).toBe(defaultModel);
332+
}
333+
});
334+
307335
test("directGeminiWireRenames does not affect Vertex requests", async () => {
308336
const vertexProvider = { ...provider, googleMode: "vertex" as const };
309337
for (const modelId of ["gemini-3.7-flash", "gemini-3.6-flash"]) {

0 commit comments

Comments
 (0)