Skip to content

Commit 0be660a

Browse files
committed
fix(antigravity): match live agy model discovery
1 parent 06df9d5 commit 0be660a

6 files changed

Lines changed: 162 additions & 29 deletions

File tree

‎src/adapters/google.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ export function createGoogleAdapter(provider: OcxProviderConfig): ProviderAdapte
395395
? resolveAntigravityEffortWireModel(
396396
parsed.modelId,
397397
mapReasoningEffort(provider, parsed.modelId, parsed.options.reasoning),
398+
provider.baseUrl,
398399
).wireModelId
399400
: resolveDirectGeminiWireModelId(parsed.modelId);
400401
const { systemInstruction, contents } = messagesToGeminiFormat(parsed, routedModelId);
@@ -450,7 +451,11 @@ export function createGoogleAdapter(provider: OcxProviderConfig): ProviderAdapte
450451
if (!project) throw new Error("Antigravity requires a discovered Cloud Code Assist project id (re-run `ocx login google-antigravity`).");
451452
const sessionId = antigravitySessionId(parsed);
452453
const mappedEffort = mapReasoningEffort(provider, parsed.modelId, parsed.options.reasoning);
453-
const { wireModelId, thinkingLevel } = resolveAntigravityEffortWireModel(parsed.modelId, mappedEffort);
454+
const { wireModelId, thinkingLevel } = resolveAntigravityEffortWireModel(
455+
parsed.modelId,
456+
mappedEffort,
457+
provider.baseUrl,
458+
);
454459
antigravityModel = wireModelId;
455460
antigravitySession = sessionId;
456461
// Effort → thinkingConfig for CCA (CLIProxyAPI proven: request.generationConfig.thinkingConfig).

‎src/codex/catalog/provider-fetch.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {
3838
type CapturedServiceTierAdapterAuthority,
3939
} from "../../providers/service-tier";
4040
import { effectiveGoogleMode, getProviderRegistryEntry, providerMatchesRegistryTransport } from "../../providers/registry";
41-
import { parseAntigravityAvailableModels } from "../../providers/antigravity-models";
41+
import { parseAntigravityAvailableModels, registerAntigravityDiscoveredWireModels } from "../../providers/antigravity-models";
4242
import { applyProviderContextCap, providerContextCap } from "../../providers/context-cap";
4343
import { routedSlug, slugEquals, slugsEquivalent } from "../../providers/slug-codec";
4444
import { CODEX_GPT5_IDENTITY_LINE } from "../../adapters/identity";
@@ -1361,6 +1361,7 @@ async function fetchProviderModelsWithAuth(
13611361
return observed(models, "degraded");
13621362
}
13631363
if (antigravity) {
1364+
registerAntigravityDiscoveredWireModels(prov.baseUrl, antigravity);
13641365
const live = antigravity.map(model => applyProviderConfigHints(name, prov, {
13651366
id: model.id,
13661367
provider: name,

‎src/providers/antigravity-models.ts‎

Lines changed: 84 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,12 @@ const ANTIGRAVITY_DISCOVERY_EFFORTS = ["low", "medium", "high"] as const;
7474

7575
function pickerModelIdForDiscoveredWireId(
7676
wireId: string,
77+
info: Record<string, unknown>,
7778
available: ReadonlyMap<string, Record<string, unknown>>,
7879
): string {
80+
const displayModelId = antigravityDisplayModelId(info.displayName, wireId);
81+
if (displayModelId) return displayModelId;
82+
7983
const explicitPickerId = Object.hasOwn(ANTIGRAVITY_PICKER_MODEL_BY_WIRE_ID, wireId)
8084
? ANTIGRAVITY_PICKER_MODEL_BY_WIRE_ID[wireId]
8185
: undefined;
@@ -240,6 +244,8 @@ export const ANTIGRAVITY_MODEL_INPUT_MODALITIES: Record<string, string[]> = {
240244

241245
export interface AntigravityAvailableModel {
242246
id: string;
247+
/** CCA model id used by the agent envelope when `id` comes from display metadata. */
248+
wireModelId: string;
243249
contextWindow?: number;
244250
inputModalities?: string[];
245251
}
@@ -254,6 +260,69 @@ function antigravityPositiveInteger(value: unknown): number | undefined {
254260
return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : undefined;
255261
}
256262

263+
const discoveredWireModelsByBaseUrl = new Map<string, ReadonlyMap<string, string>>();
264+
265+
function antigravityBaseUrlKey(baseUrl: string | undefined): string | undefined {
266+
if (typeof baseUrl !== "string" || !baseUrl.trim()) return undefined;
267+
const trimmed = baseUrl.trim().replace(/\/+$/, "");
268+
try {
269+
const url = new URL(trimmed);
270+
url.hash = "";
271+
url.search = "";
272+
return url.toString().replace(/\/+$/, "").toLowerCase();
273+
} catch {
274+
return trimmed.toLowerCase();
275+
}
276+
}
277+
278+
/** Remember the wire ids returned by one live CCA discovery for request routing. */
279+
export function registerAntigravityDiscoveredWireModels(
280+
baseUrl: string | undefined,
281+
models: readonly AntigravityAvailableModel[],
282+
): void {
283+
const key = antigravityBaseUrlKey(baseUrl);
284+
if (!key) return;
285+
const wireModels = new Map<string, string>();
286+
for (const model of models) wireModels.set(model.id, model.wireModelId);
287+
discoveredWireModelsByBaseUrl.set(key, wireModels);
288+
}
289+
290+
function discoveredAntigravityWireModelId(
291+
modelId: string,
292+
baseUrl: string | undefined,
293+
): string | undefined {
294+
const key = antigravityBaseUrlKey(baseUrl);
295+
return key ? discoveredWireModelsByBaseUrl.get(key)?.get(modelId) : undefined;
296+
}
297+
298+
/**
299+
* Convert the CCA display label used by `agy` into its public model selector.
300+
*
301+
* The wire id is authoritative for requests, while the label is authoritative for the
302+
* user-facing selector when Google has renamed or re-tiered a model. Keep both instead
303+
* of maintaining a provider-specific list of known model names.
304+
*/
305+
function antigravityDisplayModelId(displayName: unknown, wireId: string): string | undefined {
306+
if (typeof displayName !== "string") return undefined;
307+
const label = displayName.trim();
308+
if (!label || label.length > 512) return undefined;
309+
const slug = (replaceDots: boolean): string => label
310+
.normalize("NFKC")
311+
.toLowerCase()
312+
.replace(replaceDots ? /\./g : /\s+/g, replaceDots ? "-" : " ")
313+
.replace(/[^a-z0-9.-]+/g, "-")
314+
.replace(/-+/g, "-")
315+
.replace(/^-|-$/g, "");
316+
const preserved = slug(false);
317+
const compact = slug(true);
318+
if (!isValidModelDiscoveryModelId(preserved) && !isValidModelDiscoveryModelId(compact)) return undefined;
319+
if (preserved === wireId || compact === wireId
320+
|| preserved === `${wireId}-thinking` || compact === `${wireId}-thinking`) {
321+
return wireId;
322+
}
323+
return isValidModelDiscoveryModelId(preserved) ? preserved : compact;
324+
}
325+
257326
/**
258327
* Extract the CCA models that are valid for agent requests. The endpoint also returns tab,
259328
* command, commit-message, transcription, and standalone image-generation models; those are not
@@ -288,13 +357,6 @@ export function parseAntigravityAvailableModels(
288357
}
289358
}
290359
}
291-
// This model is exposed by Antigravity's agent chat surface even though it is grouped under
292-
// image generation in the discovery response.
293-
if (Array.isArray(body.imageGenerationModelIds)
294-
&& body.imageGenerationModelIds.includes("gemini-3.1-flash-image")) {
295-
if (ids.length >= limit) return null;
296-
ids.push("gemini-3.1-flash-image");
297-
}
298360
// Newer CCA responses identify tiered Flash models through this index instead of
299361
// adding their synthetic wire ids to agentModelSorts.
300362
const tieredModelIds = antigravityRecord(body.tieredModelIds);
@@ -305,6 +367,8 @@ export function parseAntigravityAvailableModels(
305367
|| !Object.hasOwn(models, id)
306368
|| !antigravityRecord(models[id])
307369
|| ids.length >= limit) return null;
370+
const baseId = id.endsWith("-tiered") ? id.slice(0, -"-tiered".length) : id;
371+
if (ids.some(agentId => agentId === baseId || agentId.startsWith(`${baseId}-`))) continue;
308372
ids.push(id);
309373
}
310374
}
@@ -313,23 +377,18 @@ export function parseAntigravityAvailableModels(
313377
for (const wireId of ids) {
314378
const info = antigravityRecord(models[wireId]);
315379
if (!info || available.has(wireId)) continue;
316-
// Legacy compatibility aliases are deliberately routed to newer wire ids for saved
317-
// selections. They are not safe as independently discovered picker rows.
318-
const alias = Object.hasOwn(ANTIGRAVITY_MODEL_ALIASES, wireId)
319-
? ANTIGRAVITY_MODEL_ALIASES[wireId]
320-
: undefined;
321-
if (alias && alias !== wireId) continue;
322380
available.set(wireId, info);
323381
}
324382

325383
const out: AntigravityAvailableModel[] = [];
326384
const seen = new Set<string>();
327385
for (const [wireId, info] of available) {
328-
const id = pickerModelIdForDiscoveredWireId(wireId, available);
386+
const id = pickerModelIdForDiscoveredWireId(wireId, info, available);
329387
if (seen.has(id)) continue;
330388
seen.add(id);
331389
out.push({
332390
id,
391+
wireModelId: wireId,
333392
...(antigravityPositiveInteger(info.maxTokens) ? { contextWindow: antigravityPositiveInteger(info.maxTokens) } : {}),
334393
// Tri-state, deliberately not a ternary: `true` asserts image support,
335394
// `false` asserts against it, and ABSENT is unknown. Collapsing absent into
@@ -347,7 +406,9 @@ export function parseAntigravityAvailableModels(
347406
return out;
348407
}
349408

350-
export function resolveAntigravityWireModelId(modelId: string): string {
409+
export function resolveAntigravityWireModelId(modelId: string, baseUrl?: string): string {
410+
const discovered = discoveredAntigravityWireModelId(modelId, baseUrl);
411+
if (discovered) return discovered;
351412
return Object.hasOwn(ANTIGRAVITY_MODEL_ALIASES, modelId)
352413
? ANTIGRAVITY_MODEL_ALIASES[modelId]
353414
: modelId;
@@ -380,7 +441,13 @@ export function retiredAntigravityFlashTier(modelId: string): string | undefined
380441
export function resolveAntigravityEffortWireModel(
381442
modelId: string,
382443
effort?: string,
444+
baseUrl?: string,
383445
): { wireModelId: string; thinkingLevel?: string } {
446+
const discoveredWireModelId = discoveredAntigravityWireModelId(modelId, baseUrl);
447+
if (discoveredWireModelId && (discoveredWireModelId !== modelId || isAntigravitySuffixModelId(modelId))) {
448+
return { wireModelId: discoveredWireModelId };
449+
}
450+
384451
// Rule 0: retired Flash id — Google has taken the wire id offline, so route to the
385452
// current generation and carry the tier the retired id encoded. This runs BEFORE the
386453
// suffix check because those ids are aliases, and rule 1 would drop the tier.
@@ -394,7 +461,7 @@ export function resolveAntigravityEffortWireModel(
394461

395462
// Rule 1: suffix/compat alias — suffix IS the effort.
396463
if (isAntigravitySuffixModelId(modelId)) {
397-
return { wireModelId: resolveAntigravityWireModelId(modelId) };
464+
return { wireModelId: resolveAntigravityWireModelId(modelId, baseUrl) };
398465
}
399466

400467
// Rule 1b: single-wire-id Gemini model whose tiers ride on thinkingLevel. Without
@@ -424,7 +491,7 @@ export function resolveAntigravityEffortWireModel(
424491
}
425492

426493
// Rule 5: everything else.
427-
return { wireModelId: resolveAntigravityWireModelId(modelId) };
494+
return { wireModelId: resolveAntigravityWireModelId(modelId, baseUrl) };
428495
}
429496

430497

‎tests/gemini-37-flash-migration.test.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ describe("3.7 reasoning control", () => {
110110
});
111111
});
112112

113-
describe("stale discovery cannot republish a retired model", () => {
114-
test("a CCA payload still listing 3.6 tiers yields no retired picker row", () => {
113+
describe("live discovery follows the CCA agent catalog", () => {
114+
test("a CCA payload still listing 3.6 tiers preserves those live rows", () => {
115115
const payload = {
116116
models: Object.fromEntries(
117117
["gemini-3.6-flash-low", "gemini-3.6-flash-medium", "gemini-3.6-flash-high", "gemini-3.7-flash"]
@@ -124,10 +124,12 @@ describe("stale discovery cannot republish a retired model", () => {
124124
}],
125125
};
126126
const ids = parseAntigravityAvailableModels(payload)?.map(model => model.id) ?? [];
127-
expect(ids).toContain("gemini-3.7-flash");
128-
for (const retired of Object.keys(RETIRED_TIERS)) {
129-
expect(ids).not.toContain(retired);
130-
}
127+
expect(ids).toEqual([
128+
"gemini-3.6-flash-low",
129+
"gemini-3.6-flash-medium",
130+
"gemini-3.6-flash-high",
131+
"gemini-3.7-flash",
132+
]);
131133
});
132134
});
133135

‎tests/google-antigravity-wire.test.ts‎

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, expect, test } from "bun:test";
22
import { createGoogleAdapter as createGoogleAdapterProduction } from "../src/adapters/google";
33
import { antigravitySessionId, isLikelyRealThoughtSignature } from "../src/adapters/google-antigravity-wire";
4-
import { ANTIGRAVITY_MODELS, ANTIGRAVITY_MODEL_EFFORTS, canonicalAntigravityUsageModel, parseAntigravityAvailableModels, resolveAntigravityEffortWireModel, resolveAntigravityWireModelId } from "../src/providers/antigravity-models";
4+
import { ANTIGRAVITY_MODELS, ANTIGRAVITY_MODEL_EFFORTS, canonicalAntigravityUsageModel, parseAntigravityAvailableModels, registerAntigravityDiscoveredWireModels, resolveAntigravityEffortWireModel, resolveAntigravityWireModelId } from "../src/providers/antigravity-models";
55
import { MODEL_DISCOVERY_MAX_MODEL_ID_LENGTH, MODEL_DISCOVERY_MAX_MODELS } from "../src/providers/model-discovery";
66
import type { AdapterEvent, OcxParsedRequest, OcxProviderConfig } from "../src/types";
77
import { withTestTranslatorBudget } from "./helpers/translator-budget";
@@ -188,6 +188,66 @@ describe("antigravity CCA envelope", () => {
188188
]);
189189
});
190190

191+
test("uses live CCA display names while retaining their wire ids", async () => {
192+
const payload = {
193+
models: {
194+
"gemini-3.7-flash-high": { displayName: "Gemini 3.7 Flash (High)", maxTokens: 1_048_576 },
195+
"gemini-3.6-flash-high": { displayName: "Gemini 3.6 Flash (High)", maxTokens: 1_048_576 },
196+
"gemini-3-flash-agent": { displayName: "Gemini 3.5 Flash (High)", maxTokens: 1_048_576 },
197+
"gemini-3.5-flash-low": { displayName: "Gemini 3.5 Flash (Medium)", maxTokens: 1_048_576 },
198+
"gemini-3.5-flash-extra-low": { displayName: "Gemini 3.5 Flash (Low)", maxTokens: 1_048_576 },
199+
"gemini-pro-agent": { displayName: "Gemini 3.1 Pro (High)", maxTokens: 1_048_576 },
200+
"gemini-3.1-pro-low": { displayName: "Gemini 3.1 Pro (Low)", maxTokens: 1_048_576 },
201+
"claude-sonnet-4-6": { displayName: "Claude Sonnet 4.6 (Thinking)", maxTokens: 250_000 },
202+
},
203+
agentModelSorts: [{ groups: [{ modelIds: [
204+
"gemini-3.7-flash-high",
205+
"gemini-3.6-flash-high",
206+
"gemini-3-flash-agent",
207+
"gemini-3.5-flash-low",
208+
"gemini-3.5-flash-extra-low",
209+
"gemini-pro-agent",
210+
"gemini-3.1-pro-low",
211+
"claude-sonnet-4-6",
212+
] }] }],
213+
};
214+
const rows = parseAntigravityAvailableModels(payload)!;
215+
expect(rows.map(model => model.id)).toEqual([
216+
"gemini-3.7-flash-high",
217+
"gemini-3.6-flash-high",
218+
"gemini-3.5-flash-high",
219+
"gemini-3.5-flash-medium",
220+
"gemini-3.5-flash-low",
221+
"gemini-3.1-pro-high",
222+
"gemini-3.1-pro-low",
223+
"claude-sonnet-4-6",
224+
]);
225+
expect(rows.map(model => [model.id, model.wireModelId])).toEqual([
226+
["gemini-3.7-flash-high", "gemini-3.7-flash-high"],
227+
["gemini-3.6-flash-high", "gemini-3.6-flash-high"],
228+
["gemini-3.5-flash-high", "gemini-3-flash-agent"],
229+
["gemini-3.5-flash-medium", "gemini-3.5-flash-low"],
230+
["gemini-3.5-flash-low", "gemini-3.5-flash-extra-low"],
231+
["gemini-3.1-pro-high", "gemini-pro-agent"],
232+
["gemini-3.1-pro-low", "gemini-3.1-pro-low"],
233+
["claude-sonnet-4-6", "claude-sonnet-4-6"],
234+
]);
235+
236+
const baseUrl = "https://cca.example";
237+
registerAntigravityDiscoveredWireModels(baseUrl, rows);
238+
expect(resolveAntigravityEffortWireModel("gemini-3.5-flash-high", undefined, baseUrl))
239+
.toEqual({ wireModelId: "gemini-3-flash-agent" });
240+
expect(resolveAntigravityEffortWireModel("gemini-3.6-flash-high", undefined, baseUrl))
241+
.toEqual({ wireModelId: "gemini-3.6-flash-high" });
242+
expect(resolveAntigravityEffortWireModel("claude-sonnet-4-6", "high", baseUrl))
243+
.toEqual({ wireModelId: "claude-sonnet-4-6", thinkingLevel: "high" });
244+
245+
const req = await createGoogleAdapter({ ...effortProvider, baseUrl }).buildRequest(
246+
parsedWithEffort("gemini-3.5-flash-high"),
247+
);
248+
expect(JSON.parse(req.body).model).toBe("gemini-3-flash-agent");
249+
});
250+
191251
test("keeps unknown discovered tier IDs directly routable", async () => {
192252
for (const modelId of ["future-flash-tiered", "future-flash-low"]) {
193253
const req = await createGoogleAdapter(effortProvider).buildRequest(parsedWithEffort(modelId, "high"));
@@ -267,7 +327,7 @@ describe("antigravity CCA envelope", () => {
267327
models: { "agent-model": { maxTokens: 1_048_576 } },
268328
agentModelSorts: [{ groups: [{ modelIds: ["agent-model"] }] }],
269329
imageGenerationModelIds: ["gemini-3.1-flash-image"],
270-
}, 1)).toBeNull();
330+
}, 1)?.map(model => model.id)).toEqual(["agent-model"]);
271331
});
272332

273333
test("throws when no project id is available", async () => {

‎tests/google-models-listing.test.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,6 @@ describe("Antigravity live model discovery", () => {
129129
"future-flash-high",
130130
"future-flash-low",
131131
"future-flash-medium",
132-
"future-flash-tiered",
133-
"gemini-3.1-flash-image",
134132
"gemini-3.1-pro-low",
135133
"gemini-3.7-flash",
136134
]);

0 commit comments

Comments
 (0)