Skip to content

Commit 929ef8b

Browse files
author
Xinwei Gao
committed
fix(google): discover Antigravity live models
1 parent 6d04574 commit 929ef8b

19 files changed

Lines changed: 383 additions & 108 deletions

‎docs-site/src/content/docs/contributing.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ sent to. A preset therefore needs primary-source evidence, not a working code pa
164164
that add or promote a provider must supply all of the following in the description:
165165

166166
- **The documented OpenAI-compatible endpoints.** Link the vendor's own API reference for the chat
167-
endpoint and, when the entry sets `liveModels: true`, for authenticated `GET /v1/models`. A
167+
endpoint and, when the entry sets `liveModels: true`, for its authenticated model-discovery
168+
endpoint (typically `GET /v1/models`). A
168169
passing fixture test is not a substitute: it proves our code shape, not the upstream contract.
169170
- **Terms of service and the operating legal entity.** An empty or placeholder legal page does not
170171
establish who runs the endpoint or under what terms user traffic is handled.

‎docs-site/src/content/docs/guides/providers.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ ocx logout <provider>
113113
| `anthropic` | `anthropic` | `https://api.anthropic.com` | Claude models; live model list fetched from `/v1/models`. |
114114
| `kimi` | `openai-chat` | `https://api.kimi.com/coding/v1` | Kimi K2.7/K2.6/K2.5 coding models. |
115115
| `kiro` | `kiro` | `https://runtime.us-east-1.kiro.dev` | Initial login imports the installed, signed-in `kiro-cli` session (on Unix, install with `curl -fsSL https://cli.kiro.dev/install | bash`; on Windows PowerShell, use `irm 'https://cli.kiro.dev/install.ps1' | iex`; then run `kiro-cli login`). **Add account** logs `kiro-cli` out, starts a fresh browser login that switches the account used by `kiro-cli`, and stores account-scoped profile metadata. Existing OpenCodex accounts are preserved, and cancellation or failure restores the previous `kiro-cli` session. |
116-
| `google-antigravity` | `google` | `https://daily-cloudcode-pa.googleapis.com` | Google OAuth over the Cloud Code Assist wire. Uses the maintained six-model static catalog because CCA does not expose the generic `/models` endpoint. |
116+
| `google-antigravity` | `google` | `https://daily-cloudcode-pa.googleapis.com` | Google OAuth over the Cloud Code Assist wire. Live discovery uses CCA's authenticated `v1internal:fetchAvailableModels` endpoint and publishes the agent models available to the signed-in account; the maintained catalog remains the fallback. |
117117
| `cursor` | `cursor` | `https://api2.cursor.sh` | Experimental PKCE login, live HTTP/2 transport, and account-filtered model discovery. |
118118
| `github-copilot` | `openai-chat` | `https://api.githubcopilot.com` | Experimental. GitHub device flow + `copilot_internal` exchange (VS Code OAuth client). Requires an active Copilot subscription; not an official third-party API. |
119119

‎docs-site/src/content/docs/ja/guides/providers.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ ocx logout <provider>
108108
| `anthropic` | `anthropic` | `https://api.anthropic.com` | Claude モデル; ライブモデル一覧は `/v1/models` から取得。 |
109109
| `kimi` | `openai-chat` | `https://api.kimi.com/coding/v1` | Kimi K2.7/K2.6/K2.5 コーディングモデル。 |
110110
| `kiro` | `kiro` | `https://runtime.us-east-1.kiro.dev` | 初回ログインは、インストール済みでサインインした `kiro-cli` セッションを取り込みます(Unix では `curl -fsSL https://cli.kiro.dev/install | bash`、Windows PowerShell では `irm 'https://cli.kiro.dev/install.ps1' | iex` でインストールしてから `kiro-cli login` を実行)。**アカウントを追加**は `kiro-cli` をログアウトして新しいブラウザログインを開始し、`kiro-cli` 自体のアカウントを切り替えてアカウント別プロファイルメタデータを保存します。既存の OpenCodex アカウントは保持され、キャンセルまたは失敗時には以前の `kiro-cli` セッションが復元されます。 |
111-
| `google-antigravity` | `google` | `https://daily-cloudcode-pa.googleapis.com` | Google OAuth を Cloud Code Assist wire で使用。CCA は汎用 `/models` エンドポイントを公開しないため、管理された 6 モデルの静的カタログを使用します。 |
111+
| `google-antigravity` | `google` | `https://daily-cloudcode-pa.googleapis.com` | Google OAuth を Cloud Code Assist wire で使用。ライブ探索は認証済みの CCA `v1internal:fetchAvailableModels` エンドポイントを使用し、ログイン中のアカウントで利用可能な agent モデルのみを公開します。管理されたカタログはフォールバックとして残ります。 |
112112
| `cursor` | `cursor` | `https://api2.cursor.sh` | 実験的 PKCE ログイン、HTTP/2 トランスポート、アカウント別モデル探索をサポート。 |
113113
| `github-copilot` | `openai-chat` | `https://api.githubcopilot.com` | 実験的。GitHub デバイスフロー + `copilot_internal` 交換(VS Code OAuth クライアント)。有効な Copilot サブスクリプションが必要で、公式のサードパーティ API ではありません。 |
114114

‎docs-site/src/content/docs/ko/guides/providers.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ ocx logout <provider>
107107
| `anthropic` | `anthropic` | `https://api.anthropic.com` | Claude 모델; 실시간 모델 목록은 `/v1/models`에서 가져옵니다. |
108108
| `kimi` | `openai-chat` | `https://api.kimi.com/coding/v1` | Kimi K2.7/K2.6/K2.5 코딩 모델. |
109109
| `kiro` | `kiro` | `https://runtime.us-east-1.kiro.dev` | 최초 로그인은 설치하고 로그인한 `kiro-cli` 세션을 가져옵니다(Unix에서는 `curl -fsSL https://cli.kiro.dev/install | bash`, Windows PowerShell에서는 `irm 'https://cli.kiro.dev/install.ps1' | iex`로 설치한 뒤 `kiro-cli login` 실행). **계정 추가**는 `kiro-cli`에서 로그아웃한 뒤 새 브라우저 로그인을 시작하여 `kiro-cli` 자체의 계정을 전환하고, 계정별 프로필 메타데이터를 저장합니다. 기존 OpenCodex 계정은 유지되며, 취소되거나 실패하면 이전 `kiro-cli` 세션을 복원합니다. |
110-
| `google-antigravity` | `google` | `https://daily-cloudcode-pa.googleapis.com` | Google OAuth를 Cloud Code Assist wire로 사용합니다. CCA가 범용 `/models` 엔드포인트를 제공하지 않으므로 유지 관리되는 6개 모델 정적 카탈로그를 사용합니다. |
110+
| `google-antigravity` | `google` | `https://daily-cloudcode-pa.googleapis.com` | Google OAuth를 Cloud Code Assist wire로 사용합니다. 실시간 탐색은 인증된 CCA `v1internal:fetchAvailableModels` 엔드포인트를 사용하며 로그인한 계정에서 사용할 수 있는 agent 모델만 게시합니다. 유지 관리되는 카탈로그는 폴백으로 남습니다. |
111111
| `cursor` | `cursor` | `https://api2.cursor.sh` | 실험적 PKCE 로그인, HTTP/2 전송, 계정별 모델 탐색을 지원합니다. |
112112
| `github-copilot` | `openai-chat` | `https://api.githubcopilot.com` | 실험적. GitHub 디바이스 플로우 + `copilot_internal` 교환(VS Code OAuth 클라이언트). 활성 Copilot 구독 필요; 공식 서드파티 API가 아닙니다. |
113113

‎docs-site/src/content/docs/ru/guides/providers.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ ocx logout <provider>
117117
| `anthropic` | `anthropic` | `https://api.anthropic.com` | Модели Claude; актуальный список моделей загружается из `/v1/models`. |
118118
| `kimi` | `openai-chat` | `https://api.kimi.com/coding/v1` | Модели Kimi K2.7/K2.6/K2.5 для кодинга. |
119119
| `kiro` | `kiro` | `https://runtime.us-east-1.kiro.dev` | Первый вход импортирует существующую сессию после установки Kiro CLI (в Unix: `curl -fsSL https://cli.kiro.dev/install | bash`; в Windows PowerShell: `irm 'https://cli.kiro.dev/install.ps1' | iex`; затем выполните `kiro-cli login`). **Добавить аккаунт** выполняет выход из `kiro-cli`, запускает новый вход через браузер, переключает аккаунт самого `kiro-cli` и сохраняет метаданные профиля отдельно для каждого аккаунта. Существующие аккаунты OpenCodex сохраняются; при отмене или сбое восстанавливается предыдущая сессия `kiro-cli`. |
120-
| `google-antigravity` | `google` | `https://daily-cloudcode-pa.googleapis.com` | Google OAuth поверх протокола Cloud Code Assist. Используется поддерживаемый статический каталог из шести моделей, поскольку CCA не предоставляет общий эндпоинт `/models`. |
120+
| `google-antigravity` | `google` | `https://daily-cloudcode-pa.googleapis.com` | Google OAuth поверх протокола Cloud Code Assist. Живое обнаружение использует аутентифицированный CCA-эндпоинт `v1internal:fetchAvailableModels` и публикует только agent-модели, доступные текущему аккаунту; поддерживаемый каталог остаётся резервным вариантом. |
121121
| `cursor` | `cursor` | `https://api2.cursor.sh` | Экспериментальный PKCE-вход, живой транспорт HTTP/2 и обнаружение моделей с фильтрацией по аккаунту. |
122122
| `github-copilot` | `openai-chat` | `https://api.githubcopilot.com` | Экспериментально. Device flow GitHub + обмен `copilot_internal` (OAuth-клиент VS Code). Требуется активная подписка Copilot; это не официальный сторонний API. |
123123

‎docs-site/src/content/docs/zh-cn/guides/providers.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ ocx logout <provider>
9898
| `anthropic` | `anthropic` | `https://api.anthropic.com` | Claude 模型;实时模型列表从 `/v1/models` 获取。 |
9999
| `kimi` | `openai-chat` | `https://api.kimi.com/coding/v1` | Kimi K2.7/K2.6/K2.5 编程模型。 |
100100
| `kiro` | `kiro` | `https://runtime.us-east-1.kiro.dev` | 首次登录会导入已安装并已登录的 Kiro CLI 会话(Unix 使用 `curl -fsSL https://cli.kiro.dev/install | bash`;Windows PowerShell 使用 `irm 'https://cli.kiro.dev/install.ps1' | iex`;然后运行 `kiro-cli login`)。**添加账户**会先退出 `kiro-cli`,再启动新的浏览器登录,从而切换 `kiro-cli` 自身使用的账户,并保存账户范围的配置文件元数据。现有 OpenCodex 账户会保留;如果取消或失败,则恢复之前的 `kiro-cli` 会话。 |
101-
| `google-antigravity` | `google` | `https://daily-cloudcode-pa.googleapis.com` | 通过 Cloud Code Assist 协议使用 Google OAuth。由于 CCA 不提供通用 `/models` 端点,因此使用维护中的六模型静态目录。 |
101+
| `google-antigravity` | `google` | `https://daily-cloudcode-pa.googleapis.com` | 通过 Cloud Code Assist 协议使用 Google OAuth。实时发现调用已认证的 CCA `v1internal:fetchAvailableModels` 端点,并仅发布当前登录账户可用的 agent 模型;维护中的目录仍作为回退。 |
102102
| `cursor` | `cursor` | `https://api2.cursor.sh` | 实验性 PKCE 登录、HTTP/2 传输和按账号筛选的模型发现。 |
103103
| `github-copilot` | `openai-chat` | `https://api.githubcopilot.com` | 实验性。GitHub 设备流 + `copilot_internal` 交换(VS Code OAuth 客户端)。需要有效的 Copilot 订阅;不是官方第三方 API。 |
104104

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

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from "../model-cache";
2121
import {
2222
buildModelsRequest,
23+
getValidAccessTokenSnapshot,
2324
observeActiveOAuthAccessToken,
2425
resolveModelsAuthToken,
2526
type OAuthActiveTokenObservation,
@@ -29,7 +30,8 @@ import { modelInList } from "../../types";
2930
import { CODEX_REASONING_LEVELS, codexEffortRank, configuredReasoningEfforts, modelRecordValue, sanitizeCodexReasoningEfforts } from "../../reasoning-effort";
3031
import { getJawcodeModelMetadata, getJawcodeModelMetadataCaseInsensitive, listJawcodeModelMetadata, resolveJawcodeProvider } from "../../generated/jawcode-model-metadata";
3132
import { enrichProviderFromRegistry, shouldCaseFoldMetadataModelId } from "../../providers/derive";
32-
import { getProviderRegistryEntry, providerMatchesRegistryTransport } from "../../providers/registry";
33+
import { effectiveGoogleMode, getProviderRegistryEntry, providerMatchesRegistryTransport } from "../../providers/registry";
34+
import { parseAntigravityAvailableModels } from "../../providers/antigravity-models";
3335
import { applyProviderContextCap, providerContextCap } from "../../providers/context-cap";
3436
import { routedSlug, slugEquals, slugsEquivalent } from "../../providers/slug-codec";
3537
import { CODEX_GPT5_IDENTITY_LINE } from "../../adapters/identity";
@@ -105,6 +107,7 @@ interface ModelsAuthResolution {
105107
readonly apiKey: string | undefined;
106108
readonly observed: boolean;
107109
readonly oauthApiBaseUrl?: string;
110+
readonly oauthProjectId?: string;
108111
}
109112

110113
type ModelsAuthResolver =
@@ -119,7 +122,7 @@ type ModelsAuthResolverFactory = (
119122
) => ModelsAuthResolver;
120123

121124
interface CapturedModelsRequest {
122-
readonly method: "GET";
125+
readonly method: "GET" | "POST";
123126
readonly url: string;
124127
readonly headersWithoutCredential: Readonly<Record<string, string>>;
125128
readonly headersWithCredential: Readonly<Record<string, string>>;
@@ -346,11 +349,12 @@ function captureModelsRequest(
346349
: undefined;
347350
const withoutCredential = buildModelsRequest(provider, undefined, name, observed);
348351
const withCredential = buildModelsRequest(provider, REQUEST_CREDENTIAL_SENTINEL, name, observed);
349-
if (withoutCredential.url !== withCredential.url) {
352+
const method = withoutCredential.method ?? "GET";
353+
if (withoutCredential.url !== withCredential.url || method !== (withCredential.method ?? "GET")) {
350354
throw new TypeError(`Provider model discovery URL for ${name} depends on credential bytes.`);
351355
}
352356
return detachedFrozen({
353-
method: "GET" as const,
357+
method,
354358
url: withoutCredential.url,
355359
headersWithoutCredential: withoutCredential.headers,
356360
headersWithCredential: withCredential.headers,
@@ -817,6 +821,7 @@ function observedModelsAuthResolver(
817821
apiKey: observation.snapshot.accessToken,
818822
observed: true,
819823
...(observation.snapshot.apiBaseUrl ? { oauthApiBaseUrl: observation.snapshot.apiBaseUrl } : {}),
824+
...(observation.snapshot.projectId ? { oauthProjectId: observation.snapshot.projectId } : {}),
820825
};
821826
},
822827
};
@@ -847,7 +852,15 @@ async function fetchProviderModelsWithAuth(
847852
return configured;
848853
}
849854
const auth: ModelsAuthResolution = captured.observedAuth ?? (resolveAuth.kind === "refreshing"
850-
? { apiKey: await resolveModelsAuthToken(name, prov), observed: false }
855+
? effectiveGoogleMode(name, prov) === "cloud-code-assist"
856+
? await getValidAccessTokenSnapshot(name)
857+
.then(snapshot => ({
858+
apiKey: snapshot.accessToken,
859+
observed: false,
860+
...(snapshot.projectId ? { oauthProjectId: snapshot.projectId } : {}),
861+
}))
862+
.catch(() => ({ apiKey: undefined, observed: false }))
863+
: { apiKey: await resolveModelsAuthToken(name, prov), observed: false }
851864
: resolveAuth.resolve(name, prov));
852865
const apiKey = auth.apiKey;
853866
// A configured default is a real callable selector and must remain discoverable when a
@@ -902,6 +915,7 @@ async function fetchProviderModelsWithAuth(
902915
// matching Cursor's !apiKey → configured degradation and fetch-failure fallback.
903916
return configured;
904917
}
918+
if (effectiveGoogleMode(name, prov) === "cloud-code-assist" && !auth.oauthProjectId) return configured;
905919
const fresh = getFreshCached(name, ttlMs);
906920
if (fresh) return withVertexDefaultSeed(applyConfigHintsToCachedModels(name, prov, fresh, contextCap)); // dedups Codex's frequent /v1/models polling within the TTL
907921
if (isModelsFetchCoolingDown(name)) {
@@ -934,10 +948,19 @@ async function fetchProviderModelsWithAuth(
934948
};
935949
};
936950
try {
937-
const res = await providerOutboundGet(name, prov, url, {
938-
headers,
939-
signal: AbortSignal.timeout(8000),
940-
});
951+
const providerFetch = (prov as OcxProviderConfig & { fetch?: typeof fetch }).fetch;
952+
const res = request.method === "POST"
953+
? await (providerFetch ?? globalThis.fetch)(url, {
954+
method: "POST",
955+
headers,
956+
body: JSON.stringify({ project: auth.oauthProjectId }),
957+
redirect: "manual",
958+
signal: AbortSignal.timeout(8000),
959+
})
960+
: await providerOutboundGet(name, prov, url, {
961+
headers,
962+
signal: AbortSignal.timeout(8000),
963+
});
941964
const redirectError = await providerRedirectError(res, url);
942965
if (redirectError) {
943966
const { models, fallback, shouldLog } = failedDiscoveryFallback({ reason: "http", httpStatus: res.status });
@@ -976,6 +999,32 @@ async function fetchProviderModelsWithAuth(
976999
}
9771000
return models;
9781001
}
1002+
const antigravity = effectiveGoogleMode(name, prov) === "cloud-code-assist"
1003+
? parseAntigravityAvailableModels(bounded.value)
1004+
: undefined;
1005+
if (effectiveGoogleMode(name, prov) === "cloud-code-assist" && !antigravity) {
1006+
const { models, fallback, shouldLog } = failedDiscoveryFallback({ reason: "invalid_response" });
1007+
if (shouldLog) {
1008+
console.warn(
1009+
`[opencodex] Provider model discovery for "${name}" returned malformed CCA model data [status=${res.status}, contentType=${contentType}, urlClass=${urlClass}, fallback=${fallback}].`,
1010+
);
1011+
}
1012+
return models;
1013+
}
1014+
if (antigravity) {
1015+
const live = antigravity.map(model => applyProviderConfigHints(name, prov, {
1016+
id: model.id,
1017+
provider: name,
1018+
// CCA only exposes a numeric thinking budget. Until the adapter owns an exact Codex
1019+
// effort-to-wire mapping for a newly discovered model, do not advertise a false ladder.
1020+
reasoningEfforts: [],
1021+
...(model.contextWindow ? { contextWindow: model.contextWindow } : {}),
1022+
...(model.inputModalities ? { inputModalities: model.inputModalities } : {}),
1023+
}, contextCap));
1024+
markProviderDiscoveryOk(name, live.length);
1025+
setCached(name, live);
1026+
return live;
1027+
}
9791028
const extracted = extractProviderModelItems(bounded.value, discovery);
9801029
if (!extracted.ok) {
9811030
const { models, fallback, shouldLog } = failedDiscoveryFallback({ reason: "invalid_response" });

‎src/codex/convergence-types.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ export interface CatalogProviderDiscoveryPolicySnapshot {
422422
readonly path: CatalogDiscoveryPolicyField<string | undefined>;
423423
readonly query: CatalogDiscoveryPolicyField<Readonly<Record<string, string>> | undefined>;
424424
}>;
425-
readonly finalMethod: "GET";
425+
readonly finalMethod: "GET" | "POST";
426426
readonly finalUrl: string;
427427
readonly filter: CatalogDiscoveryPolicyField<ProviderModelDiscoveryFilter | undefined>;
428428
readonly maxResponseBytes: number;

0 commit comments

Comments
 (0)