tuxevil-rotator 4.4.8 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +3 -1
  3. package/package.json +1 -1
  4. package/plugins/opencode-discovery/index.mjs +50 -21
  5. package/src/access-probe.ts +1 -1
  6. package/src/account-store.ts +14 -2
  7. package/src/audio-transcription.ts +1 -0
  8. package/src/auto-model-access.ts +22 -0
  9. package/src/compat/model-specs.ts +7 -0
  10. package/src/compat/schema-sanitizer.ts +420 -287
  11. package/src/compat.ts +110 -66
  12. package/src/config-defaults.ts +7 -0
  13. package/src/fetch-with-retry.ts +294 -16
  14. package/src/idempotency.ts +3 -1
  15. package/src/model-access-api.ts +9 -1
  16. package/src/model-access.ts +2 -2
  17. package/src/notification-poller.ts +9 -1
  18. package/src/provider-catalog-evidence.ts +18 -1
  19. package/src/providers/adapter.ts +10 -0
  20. package/src/providers/credential-helpers.ts +34 -0
  21. package/src/providers/google-antigravity/aicode-eligibility.ts +256 -0
  22. package/src/providers/google-antigravity/aicode-forward.ts +381 -0
  23. package/src/providers/google-antigravity/aicode.ts +478 -0
  24. package/src/providers/google-antigravity/catalog.ts +6 -0
  25. package/src/providers/google-antigravity/code-assist.ts +53 -41
  26. package/src/providers/google-antigravity/dynamic-catalog.ts +72 -7
  27. package/src/providers/google-antigravity/forward.ts +309 -86
  28. package/src/providers/google-antigravity/index.ts +122 -4
  29. package/src/providers/google-antigravity/oauth.ts +22 -12
  30. package/src/providers/google-antigravity/quota.ts +781 -34
  31. package/src/providers/google-antigravity/translators.ts +55 -46
  32. package/src/providers/google-antigravity/twin-payload.ts +231 -0
  33. package/src/providers/ollama/quota.ts +6 -4
  34. package/src/providers/openai-codex/compat.ts +11 -2
  35. package/src/providers/openai-codex/quota.ts +2 -1
  36. package/src/providers/opencode-zen/catalog.ts +159 -13
  37. package/src/providers/opencode-zen/discovery.ts +50 -0
  38. package/src/providers/opencode-zen/index.ts +7 -2
  39. package/src/providers/opencode-zen/quota.ts +14 -1
  40. package/src/proxy.ts +570 -87
  41. package/src/quota-pools.ts +76 -1
  42. package/src/rate-limit-parser.ts +239 -19
  43. package/src/rotator.ts +848 -297
  44. package/src/stream-guards.ts +87 -1
  45. package/src/telemetry.ts +17 -3
  46. package/src/types.ts +184 -9
  47. package/src/validators.ts +3 -0
  48. package/src/web/lib/accounts.ts +2 -0
  49. package/src/web/lib/attention.ts +19 -0
  50. package/src/web/lib/models.ts +6 -1
  51. package/src/web/lib/status.ts +22 -4
  52. package/src/web/pages/AccountDetail.tsx +49 -2
  53. package/src/web/pages/Accounts.tsx +38 -3
  54. package/src/web/pages/ModelAccess.tsx +4 -0
  55. package/src/web/pages/Models.tsx +2 -1
  56. package/src/web/pages/Overview.tsx +15 -1
  57. package/src/web/styles/app.css +73 -3
  58. package/tools/telemetry-receiver/receiver.js +523 -266
package/CHANGELOG.md CHANGED
@@ -2,6 +2,46 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [4.5.0] - 2026-11-28
6
+
7
+ ### Added
8
+
9
+ - **AICode support (Phases 1–4)**: Adds the `https://www.googleapis.com/auth/aicode` OAuth scope, a `v1alpha` client (`fetchConfig`, `fetchLicenses`) and payload/SSE translation for `aicode.googleapis.com`, dual routing (AICode for eligible models in `availableExperiences`, CCPA fallback otherwise), `v1alpha:fetchQuotaStatus` polling merged with CCPA catalog discovery, and a `missing-aicode-scope` auth warning surfaced in `/api/status`, Overview, Accounts, and AccountDetail. Auto-warmup now defaults to off. See [`docs/aicode-support-plan.md`](docs/aicode-support-plan.md).
10
+ - **Dynamic Antigravity quota groups and windows**: Supports dynamically advertised quota groups/windows (`Argon`, `Gemini Models`, `Claude/GPT`, and custom pools) with per-window dashboard breakdowns, cooldown isolation, and self-healing resets.
11
+ - **SSE keepalive configuration**: New `sseKeepaliveIntervalMs` (default `15000`) writes a `: ping` comment on idle SSE streams so proxies do not drop slow reasoning responses. `0` disables it.
12
+ - **`USE_AICODE` toggle**: `auto` (default) follows Google's `enable-inference-traffic-migration` experiment, `false`/`off` never uses AICode, and `true`/`on` forces it for eligible personal accounts with the `aicode` scope. `TUXEVIL_ROTATOR_USE_AICODE` is accepted as an alias.
13
+
14
+ ### Changed
15
+
16
+ - **Google Antigravity parity**: Aligns wire `User-Agent`, ProtoJSON metadata, `SystemInstruction`/identity prompt composition, `sessionId`, `requestId`, single-account retry curves, and `onboardUser` payloads with the current Antigravity client; the default Antigravity version is now `2.35.2`.
17
+ - **`sticky-quota` draining**: Drains one account sequentially down to 0% before rotating, skipping `rotateOnQuotaDrop` and least-loaded scatter, queuing on concurrency saturation, and restoring the preferred account after cooldowns.
18
+ - **Quota polling**: Adds `0.85x–1.20x` jitter, idle backoff, and staggered per-account spacing to scheduled polls.
19
+ - **Kickstart selection**: Chooses an active eligible alternative when the default model is disabled, and uses `gemini-3.8-flash-tiered` as the default Gemini kickstart model.
20
+
21
+ ### Fixed
22
+
23
+ - Stops cascading HTTP 401/403 responses across endpoints and avoids sending `X-Goog-User-Project` unless explicitly enabled with `GOOG_USER_PROJECT`.
24
+ - Preserves dynamic account catalogs when a refresh fails and matches Carbon/Pro access rules for model discovery.
25
+ - Aligns the default upstream headers timeout with the stream idle limit, strips framing and hop-by-hop headers case-insensitively, flushes multibyte UTF-8 safely, bounds error-body reads, and keeps in-flight lease symmetry.
26
+ - Hardens compatibility schema sanitization, telemetry receiver streaming/auth/pricing, and telemetry URL normalization.
27
+ - Sanitizes non-string enums and `const` unions for Gemini schemas.
28
+
29
+ ### Security
30
+
31
+ - Resolves CodeQL URL-substring sanitization and clear-text logging alerts.
32
+
33
+ ### Contributors
34
+
35
+ - Thanks to [@javargasm](https://github.com/javargasm) (Jeisson Alexander Vargas Marroquin) for the consolidated Antigravity parity, AICode support, sticky-quota draining, and proxy/streaming hardening work in [PR #55](https://github.com/tuxevil/tuxevil-rotator/pull/55), which supersedes [PR #51](https://github.com/tuxevil/tuxevil-rotator/pull/51), [PR #52](https://github.com/tuxevil/tuxevil-rotator/pull/52), and [PR #53](https://github.com/tuxevil/tuxevil-rotator/pull/53), plus the Gemini schema sanitization fix in [PR #54](https://github.com/tuxevil/tuxevil-rotator/pull/54).
36
+
37
+ ## [4.4.9] - 2026-11-24
38
+
39
+ ### Fixed
40
+
41
+ - **Paid Claude kickstart fallback**: Select account-aware Claude kickstart models for paid Pro, Ultra, Plus, Max, and Team tiers, preferring advertised Sonnet 5.5 candidates while retaining the historical primary as a compatibility fallback. Retry model-specific 400/404/403 and 5xx failures with per-model backoff without counting them as consecutive account errors; quota-exhaustion 429s do not switch models, and an explicit Free tier takes precedence over legacy Pro metadata. Gemini keeps its existing primary model.
42
+ - **Telemetry receiver account and install aggregation**: Detect paid tiers in `proDetected`/`wasProAccount`, accept larger model catalogs and heartbeat payloads, preserve install state when processing flag events, and aggregate per-model token maxima consistently.
43
+ - **OpenCode discovery recovery**: Keep `ctx.provider.transform` registered and retry automatically (`retryMs`, default 5s) when the rotator is temporarily unreachable at startup; preserve the last known-good model catalog when refreshes return an empty list or transient error.
44
+
5
45
  ## [4.4.8] - 2026-11-23
6
46
 
7
47
  ### Fixed
package/README.md CHANGED
@@ -55,6 +55,8 @@ Originally built as a multi-account rotator for Google Antigravity. It now gener
55
55
 
56
56
  ## Current Model Update
57
57
 
58
+ - **v4.5.0: AICode support, Antigravity parity, and sticky-quota draining**: Adds Google AICode Phases 1–4 (OAuth `aicode` scope, `aicode.googleapis.com` client, payload/SSE translation, dual routing with CCPA fallback, and `v1alpha:fetchQuotaStatus` polling), dynamic Antigravity quota groups/windows with per-window dashboard breakdowns, `sticky-quota` sequential draining, SSE keepalive (`sseKeepaliveIntervalMs`), and a `USE_AICODE` toggle. Aligns wire headers, prompts, tracking, retries, and single-account retry curves with the current Antigravity client; stops cascading 401/403 responses, hardens proxy/streaming/compat/telemetry paths, and resolves CodeQL sanitization and logging alerts. Thanks to [@javargasm](https://github.com/javargasm) for [PR #55](https://github.com/tuxevil/tuxevil-rotator/pull/55). ([Release notes](https://github.com/tuxevil/tuxevil-rotator/releases/tag/v4.5.0))
59
+ - **v4.4.9: Claude paid-tier kickstart fallback, telemetry accuracy, and OpenCode recovery**: Use account-aware Claude Sonnet 5.5 kickstart candidates for paid tiers with safe model-specific fallbacks and backoff, without changing Gemini's primary or switching models on quota-exhaustion 429s. Correct paid-tier and install telemetry aggregation, and retry OpenCode model discovery after transient startup failures while retaining the last good catalog. ([Release notes](https://github.com/tuxevil/tuxevil-rotator/releases/tag/v4.4.9))
58
60
  - **v4.4.8: Invalid-provider flag loop fix & telemetry receiver overhaul**: Stop quota polling and auto-warmup kickstarts from looping every 5 minutes on already-invalidated or disabled providers (emitting flag telemetry only on transitions and clearing invalidation across all providers on re-auth). Overhaul the standalone telemetry receiver with a cyberpunk/retro-console UX across `/dashboard`, `/notifications`, and `/stats`, fix flag double-counting and request inflation, add 24h sliding-window flag-loop deduplication, and harden security (Stored XSS fix, prototype-safe pricing, constant-time auth + brute-force lockout, trusted-proxy rate limiting, CSP/SRI, scoped CORS, and HTTP timeouts). ([Release notes](https://github.com/tuxevil/tuxevil-rotator/releases/tag/v4.4.8))
59
61
  - **v4.4.7: Artificial Analysis scores, static specs, and dashboard colors**: Refresh the Artificial Analysis Intelligence Index routing-quality snapshot (`2026-11-23`) with exact per-effort scores for Gemini 4 (`neon`, `hydrogen`, `carbon`, `argon`), Gemini 3.8 Flash, Claude 5.5, and OpenAI `gpt-6.1`/`gpt-6.2`, and add static model specs, context windows, and distinct dashboard chart colors for Gemini 4, Claude 5.5, GPT-6.1/6.2, and newer Ollama Cloud models. ([Release notes](https://github.com/tuxevil/tuxevil-rotator/releases/tag/v4.4.7))
60
62
  - **v4.4.6: Model pricing refresh**: Add official November 2026 pricing and family fallbacks for Gemini 4 (`neon`, `hydrogen`, `carbon`, `argon`), Claude 5.5 (`opus`, `sonnet`), OpenAI `gpt-6.1`/`gpt-6.2`, and newly published Ollama Cloud models in both the rotator and standalone telemetry receiver. ([Release notes](https://github.com/tuxevil/tuxevil-rotator/releases/tag/v4.4.6))
@@ -409,7 +411,7 @@ Thanks to these amazing people who have contributed to the project:
409
411
  - **[@josenicomaia](https://github.com/josenicomaia)** (José Nicodemos Maia Neto) — Modularized the compatibility layer architecture, added multimodal tool response support, fixed streaming pass-through for tool executions, and added PostgreSQL storage and weighted pool quota forecasting. ([PR #8](https://github.com/tuxevil/tuxevil-rotator/pull/8), [PR #9](https://github.com/tuxevil/tuxevil-rotator/pull/9), [PR #11](https://github.com/tuxevil/tuxevil-rotator/pull/11), [PR #13](https://github.com/tuxevil/tuxevil-rotator/pull/13), [PR #14](https://github.com/tuxevil/tuxevil-rotator/pull/14))
410
412
  - **[@yashyadav711](https://github.com/yashyadav711)** (Yash) — Fixed Draft-2020-12 inline JSON-Schema union type mapping for Gemini tools support. ([PR #10](https://github.com/tuxevil/tuxevil-rotator/pull/10))
411
413
  - **[@toRolex](https://github.com/toRolex)** (Rolex) — Added cached prompt-token extraction from Google Antigravity/Cloud Code usage and mapped it to OpenAI and Anthropic compatibility responses, with focused regression tests, plus transport-error retry recovery for single-account and exhausted-account pools. ([PR #34](https://github.com/tuxevil/tuxevil-rotator/pull/34), [PR #35](https://github.com/tuxevil/tuxevil-rotator/pull/35))
412
- - **[@javargasm](https://github.com/javargasm)** (Jeisson Alexander Vargas Marroquin) — Queued multi-request Antigravity account pooling (5×5 concurrent streams), strict FIFO overflow queue, dashboard concurrency metrics, canonical project ID resolution, account-scoped dynamic Antigravity discovery and routing, dynamic catalog and quota-safety hardening, persistent dynamic model ownership and validated catalog snapshots across restarts, exact upstream variant preservation, snapshot-based request admission, 429 quota resilience with account-scoped retry, synchronous leasing, snapshot-based token refresh with generation validation, provider-scoped token publication, spend-logger memory leak fix, atomic PostgreSQL CTE daily spend aggregation with idempotent retries, virtual-key cache bounding, Anthropic tool-use compatibility layer (`tool_use`/`tool_result` content block conversion), JSON schema round-trip fixes, compat test suite expansion, model-scoped cooldowns, explicit Antigravity reset-duration parsing, idle pool normalization, RAW POLL deadline reconciliation, serialized per-account quota polling, Ollama kickstart routing for multi-provider accounts, and OpenAI-compatible audio transcription plus bidirectional live WebSocket streaming through the local Antigravity observer model, with PR #36 adding rotator-backed transcription, Language Server fallback, model-scope checks, and live timeout/control-frame hardening. ([PR #3](https://github.com/tuxevil/tuxevil-rotator/pull/3), [PR #7](https://github.com/tuxevil/tuxevil-rotator/pull/7), [PR #22](https://github.com/tuxevil/tuxevil-rotator/pull/22), [PR #23](https://github.com/tuxevil/tuxevil-rotator/pull/23), [PR #24](https://github.com/tuxevil/tuxevil-rotator/pull/24), [PR #26](https://github.com/tuxevil/tuxevil-rotator/pull/26), [PR #29](https://github.com/tuxevil/tuxevil-rotator/pull/29), [PR #30](https://github.com/tuxevil/tuxevil-rotator/pull/30), [PR #31](https://github.com/tuxevil/tuxevil-rotator/pull/31), [PR #33](https://github.com/tuxevil/tuxevil-rotator/pull/33), [PR #36](https://github.com/tuxevil/tuxevil-rotator/pull/36), [PR #42](https://github.com/tuxevil/tuxevil-rotator/pull/42))
414
+ - **[@javargasm](https://github.com/javargasm)** (Jeisson Alexander Vargas Marroquin) — Queued multi-request Antigravity account pooling (5×5 concurrent streams), strict FIFO overflow queue, dashboard concurrency metrics, canonical project ID resolution, account-scoped dynamic Antigravity discovery and routing, dynamic catalog and quota-safety hardening, persistent dynamic model ownership and validated catalog snapshots across restarts, exact upstream variant preservation, snapshot-based request admission, 429 quota resilience with account-scoped retry, synchronous leasing, snapshot-based token refresh with generation validation, provider-scoped token publication, spend-logger memory leak fix, atomic PostgreSQL CTE daily spend aggregation with idempotent retries, virtual-key cache bounding, Anthropic tool-use compatibility layer (`tool_use`/`tool_result` content block conversion), JSON schema round-trip fixes, compat test suite expansion, model-scoped cooldowns, explicit Antigravity reset-duration parsing, idle pool normalization, RAW POLL deadline reconciliation, serialized per-account quota polling, Ollama kickstart routing for multi-provider accounts, and OpenAI-compatible audio transcription plus bidirectional live WebSocket streaming through the local Antigravity observer model, with PR #36 adding rotator-backed transcription, Language Server fallback, model-scope checks, and live timeout/control-frame hardening, plus Google AICode support (Phases 1–4), full Antigravity parity, `sticky-quota` sequential draining, dynamic quota groups/windows, and proxy/streaming/telemetry hardening. ([PR #3](https://github.com/tuxevil/tuxevil-rotator/pull/3), [PR #7](https://github.com/tuxevil/tuxevil-rotator/pull/7), [PR #22](https://github.com/tuxevil/tuxevil-rotator/pull/22), [PR #23](https://github.com/tuxevil/tuxevil-rotator/pull/23), [PR #24](https://github.com/tuxevil/tuxevil-rotator/pull/24), [PR #26](https://github.com/tuxevil/tuxevil-rotator/pull/26), [PR #29](https://github.com/tuxevil/tuxevil-rotator/pull/29), [PR #30](https://github.com/tuxevil/tuxevil-rotator/pull/30), [PR #31](https://github.com/tuxevil/tuxevil-rotator/pull/31), [PR #33](https://github.com/tuxevil/tuxevil-rotator/pull/33), [PR #36](https://github.com/tuxevil/tuxevil-rotator/pull/36), [PR #42](https://github.com/tuxevil/tuxevil-rotator/pull/42), [PR #54](https://github.com/tuxevil/tuxevil-rotator/pull/54), [PR #55](https://github.com/tuxevil/tuxevil-rotator/pull/55))
413
415
 
414
416
  ## Development
415
417
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tuxevil-rotator",
3
- "version": "4.4.8",
3
+ "version": "4.5.0",
4
4
  "description": "Multi-provider, multi-account AI proxy rotator with per-model routing, real-time quota tracking, and infringement detection (Google Antigravity, Ollama Cloud)",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -15,6 +15,7 @@
15
15
  * - providerName display name (default "Antigravity (rotator)")
16
16
  * - timeoutMs fetch timeout (default 3500)
17
17
  * - refreshMs background re-discovery interval (default 600000; 0 disables)
18
+ * - retryMs retry interval while initial discovery has not succeeded yet (default 5000)
18
19
  */
19
20
 
20
21
  import { openCodeReasoning, openCodeVariants } from "./capabilities.mjs"
@@ -138,12 +139,19 @@ export function resolvePluginOptions(options = {}, providerEntries = []) {
138
139
  let end = baseURLText.length
139
140
  while (end > 0 && baseURLText.charCodeAt(end - 1) === 47) end--
140
141
 
142
+ const refreshMs = options.refreshMs === 0 ? 0 : Number(options.refreshMs) || 600_000
143
+ const retryMs =
144
+ refreshMs <= 0
145
+ ? 0
146
+ : Math.min(refreshMs, Math.max(1, Number(options.retryMs) || 5_000))
147
+
141
148
  return {
142
149
  baseURL: baseURLText.slice(0, end),
143
150
  providerID: providerID || "antigravity",
144
151
  providerName: providerName || "Antigravity (rotator)",
145
152
  timeoutMs: Number(options.timeoutMs) || 3500,
146
- refreshMs: options.refreshMs === 0 ? 0 : Number(options.refreshMs) || 600_000,
153
+ refreshMs,
154
+ retryMs,
147
155
  }
148
156
  }
149
157
 
@@ -274,20 +282,29 @@ export default {
274
282
  async function load() {
275
283
  try {
276
284
  const models = await fetchRotatorModels(resolved.baseURL, resolved.timeoutMs)
277
- const list = Array.isArray(models) ? models : []
278
- const changed = lastSignature !== null && modelSignature(list) !== lastSignature
285
+ const list = Array.isArray(models) ? models.filter((m) => typeof m?.id === "string" && m.id.length > 0) : []
286
+ if (list.length === 0) {
287
+ // Never wipe the last known good catalog on a transient empty response
288
+ console.warn("[opencode-discovery] model discovery returned an empty catalog; keeping previous inventory")
289
+ return { ok: false, changed: false, invalidUrl: false }
290
+ }
291
+ const sig = modelSignature(list)
292
+ const changed = lastSignature !== sig
279
293
  source.models = list
280
- lastSignature = modelSignature(list)
281
- return { ok: true, changed }
294
+ lastSignature = sig
295
+ return { ok: true, changed, invalidUrl: false }
282
296
  } catch (err) {
297
+ const msg = err?.message ?? String(err)
298
+ const invalidUrl = msg.includes("fetch() URL is invalid") || msg.includes("Unsupported URL protocol")
283
299
  // Safe degrade: never fail OpenCode startup when the rotator is unreachable
284
- console.warn(`[opencode-discovery] model discovery skipped: ${err?.message ?? err}`)
285
- return { ok: false, changed: false }
300
+ console.warn(`[opencode-discovery] model discovery skipped: ${msg}`)
301
+ return { ok: false, changed: false, invalidUrl }
286
302
  }
287
303
  }
288
304
 
289
305
  const first = await load()
290
- if (!first.ok || !source.models?.length) return undefined
306
+ if (first.invalidUrl) return undefined
307
+ if (!first.ok && resolved.refreshMs <= 0) return undefined
291
308
 
292
309
  const toModelInfo = (raw, existingModel) => {
293
310
  const { id, modelDef } = mapModelToOpenCode(raw)
@@ -324,20 +341,32 @@ export default {
324
341
 
325
342
  if (resolved.refreshMs <= 0) return undefined
326
343
 
327
- const timer = setInterval(() => {
328
- void (async () => {
329
- const result = await load()
330
- if (!result.changed) return
331
- try {
332
- await ctx.provider.reload()
333
- } catch {
334
- // Registry reload unavailable; keep the last known inventory
335
- }
336
- })()
337
- }, resolved.refreshMs)
338
- if (typeof timer.unref === "function") timer.unref()
344
+ let stopped = false
345
+ let timer = null
346
+ const scheduleNext = () => {
347
+ if (stopped) return
348
+ const delayMs = source.models?.length ? resolved.refreshMs : resolved.retryMs
349
+ timer = setTimeout(() => {
350
+ void (async () => {
351
+ const result = await load()
352
+ if (!stopped && result.ok && result.changed) {
353
+ try {
354
+ await ctx.provider.reload()
355
+ } catch {
356
+ // Registry reload unavailable; keep the last known inventory
357
+ }
358
+ }
359
+ scheduleNext()
360
+ })()
361
+ }, delayMs)
362
+ if (typeof timer.unref === "function") timer.unref()
363
+ }
364
+ scheduleNext()
339
365
 
340
- return () => clearInterval(timer)
366
+ return () => {
367
+ stopped = true
368
+ if (timer) clearTimeout(timer)
369
+ }
341
370
  },
342
371
  }
343
372
 
@@ -63,7 +63,7 @@ export async function serveAccessProbe(req: IncomingMessage, res: ServerResponse
63
63
  controller.signal.throwIfAborted();
64
64
  if (rotator.getConfig().modelAccessShadow === true) logAccessPolicyShadow(account.config, provider, model, {});
65
65
  rotator.recordUpstreamAttempt(account);
66
- const forwarded = await adapter.forwardRequest(account, body, {}, controller.signal);
66
+ const forwarded = await adapter.forwardRequest(account, body, {}, controller.signal, { apiRetry: false });
67
67
  status = forwarded.response.status;
68
68
  const reader = forwarded.response.body?.getReader();
69
69
  if (reader) {
@@ -92,6 +92,16 @@ function validateCredentialLengths(
92
92
 
93
93
  export { validateAccountConfigLengths };
94
94
 
95
+ function stripUndefinedFields<T extends object>(obj: T): Partial<T> {
96
+ const clean: Partial<T> = {};
97
+ for (const [key, value] of Object.entries(obj)) {
98
+ if (value !== undefined) {
99
+ (clean as Record<string, unknown>)[key] = value;
100
+ }
101
+ }
102
+ return clean;
103
+ }
104
+
95
105
  export function mergeCredentials(
96
106
  existing: AccountConfig["credentials"] | undefined,
97
107
  incoming: AccountConfig["credentials"] | undefined,
@@ -103,10 +113,12 @@ export function mergeCredentials(
103
113
  if (seen.has(cred.provider)) continue;
104
114
  seen.add(cred.provider);
105
115
  const incomingCredential = incomingByProvider.get(cred.provider);
106
- out.push(incomingCredential ? { ...cred, ...incomingCredential } : cred);
116
+ out.push(incomingCredential ? { ...cred, ...stripUndefinedFields(incomingCredential) } : cred);
107
117
  incomingByProvider.delete(cred.provider);
108
118
  }
109
- for (const cred of incomingByProvider.values()) out.push(cred);
119
+ for (const cred of incomingByProvider.values()) {
120
+ out.push(stripUndefinedFields(cred) as NonNullable<AccountConfig["credentials"]>[number]);
121
+ }
110
122
  return sortAccountCredentials(out);
111
123
  }
112
124
 
@@ -278,6 +278,7 @@ export async function transcribeAudioWithRotator(
278
278
  model: targetModel,
279
279
  catalogModel: options.catalogModel,
280
280
  project: "",
281
+ preservePrompt: true,
281
282
  request: {
282
283
  contents: [
283
284
  {
@@ -1,5 +1,6 @@
1
1
  import { accessEvidenceStore, type AccessEvidenceStore } from "./access-evidence.js";
2
2
  import { evaluateModelAccess, MODEL_ACCESS_RULES } from "./model-access.js";
3
+ import { antigravityCatalogEvidence, catalogModelState, type CatalogModelState } from "./provider-catalog-evidence.js";
3
4
  import type { AccountConfig } from "./types.js";
4
5
 
5
6
  export interface AutoModelAccessDecision {
@@ -11,6 +12,8 @@ export interface AutoModelAccessDecision {
11
12
  | "account-tier"
12
13
  | "unknown";
13
14
  reason: string;
15
+ /** Present when the account's live Antigravity catalog decided eligibility. */
16
+ catalog?: Exclude<CatalogModelState, "unknown">;
14
17
  }
15
18
 
16
19
  export interface AutoAccountScope {
@@ -58,6 +61,7 @@ export function evaluateAutoModelAccess(
58
61
  model: string,
59
62
  store: AccessEvidenceStore = accessEvidenceStore(),
60
63
  now = Date.now(),
64
+ catalogPollIntervalMs?: number,
61
65
  ): AutoModelAccessDecision {
62
66
  const evidence = store.forAccount(account, now);
63
67
  const declared = evidence.plans
@@ -114,6 +118,24 @@ export function evaluateAutoModelAccess(
114
118
  };
115
119
  }
116
120
 
121
+ // The account catalog is the provider's own entitlement statement and
122
+ // outranks the static plan table. When a refresh fails, the last catalog
123
+ // captured for this credential stays authoritative; only with no catalog
124
+ // for the current credential do the plan rules apply.
125
+ if (provider === "google-antigravity") {
126
+ const evidence = antigravityCatalogEvidence(account, catalogPollIntervalMs, now);
127
+ const catalog = catalogModelState(evidence, model, true);
128
+ if (catalog !== "unknown") {
129
+ const reason = (catalog === "advertised"
130
+ ? "model is advertised in this account's catalog"
131
+ : catalog === "disabled"
132
+ ? "model is disabled in this account's catalog"
133
+ : "model is not in this account's catalog") +
134
+ (evidence.freshness === "stale" ? " (last known catalog)" : "");
135
+ return { eligible: catalog === "advertised", plan, planSource, reason, catalog };
136
+ }
137
+ }
138
+
117
139
  if (plan === "unknown") {
118
140
  // A verified Free-plan model is also safe to try when the Codex plan is
119
141
  // unknown; paid-only and unlisted models still require a known plan.
@@ -20,10 +20,15 @@ export const DEFAULT_MODEL_SPECS: Record<string, ModelSpec> = {
20
20
  "gemini-3.1-pro-high": { maxOutputTokens: 65535, thinkingBudget: 10001, isThinking: true, contextWindow: 1_000_000 },
21
21
  "gemini-3.1-pro-low": { maxOutputTokens: 65535, thinkingBudget: 1001, isThinking: true, contextWindow: 1_000_000 },
22
22
  "gemini-3.1-pro-preview": { maxOutputTokens: 65535, thinkingBudget: 10001, isThinking: true, contextWindow: 1_000_000 },
23
+ "gemini-3.1-pro-preview-customtools": { maxOutputTokens: 65535, thinkingBudget: 10001, isThinking: true, contextWindow: 1_000_000 },
23
24
  "gemini-3.6-flash-high": { maxOutputTokens: 65536, thinkingBudget: 10000, isThinking: true, contextWindow: 1_000_000 },
24
25
  "gemini-3.6-flash-medium": { maxOutputTokens: 65536, thinkingBudget: 4000, isThinking: true, contextWindow: 1_000_000 },
25
26
  "gemini-3.6-flash-low": { maxOutputTokens: 65536, thinkingBudget: 1000, isThinking: true, contextWindow: 1_000_000 },
26
27
  "gemini-3.6-flash-tiered": { maxOutputTokens: 65536, thinkingBudget: -1, isThinking: true, contextWindow: 1_000_000 },
28
+ "gemini-3.7-flash": { maxOutputTokens: 65536, thinkingBudget: -1, isThinking: true, contextWindow: 1_000_000 },
29
+ "gemini-3.7-flash-high": { maxOutputTokens: 65536, thinkingBudget: 10000, isThinking: true, contextWindow: 1_000_000 },
30
+ "gemini-3.7-flash-medium": { maxOutputTokens: 65536, thinkingBudget: 4000, isThinking: true, contextWindow: 1_000_000 },
31
+ "gemini-3.7-flash-low": { maxOutputTokens: 65536, thinkingBudget: 1000, isThinking: true, contextWindow: 1_000_000 },
27
32
  "gemini-3.7-flash-tiered": { maxOutputTokens: 65536, thinkingBudget: -1, isThinking: true, contextWindow: 1_000_000 },
28
33
  "gemini-3.8-flash": { maxOutputTokens: 65536, thinkingBudget: -1, isThinking: true, contextWindow: 1_000_000 },
29
34
  "gemini-3.8-flash-tiered": { maxOutputTokens: 65536, thinkingBudget: -1, isThinking: true, contextWindow: 1_000_000 },
@@ -61,10 +66,12 @@ export const DEFAULT_MODEL_SPECS: Record<string, ModelSpec> = {
61
66
  "gemini-2.5-flash": { maxOutputTokens: 65535, thinkingBudget: 24576, isThinking: true, contextWindow: 1_000_000 },
62
67
  "gemini-2.5-pro": { maxOutputTokens: 65535, thinkingBudget: 1024, isThinking: true, contextWindow: 1_000_000 },
63
68
  "claude-opus-5-5": { maxOutputTokens: 128000, thinkingBudget: 32768, isThinking: true, contextWindow: 1_000_000 },
69
+ "claude-opus-5-5-max": { maxOutputTokens: 128000, thinkingBudget: 32768, isThinking: true, contextWindow: 1_000_000 },
64
70
  "claude-opus-5-5-high": { maxOutputTokens: 128000, thinkingBudget: 32768, isThinking: true, contextWindow: 1_000_000 },
65
71
  "claude-opus-5-5-medium": { maxOutputTokens: 128000, thinkingBudget: 32768, isThinking: true, contextWindow: 1_000_000 },
66
72
  "claude-opus-5-5-low": { maxOutputTokens: 128000, thinkingBudget: 32768, isThinking: true, contextWindow: 1_000_000 },
67
73
  "claude-sonnet-5-5": { maxOutputTokens: 128000, thinkingBudget: 32768, isThinking: true, contextWindow: 1_000_000 },
74
+ "claude-sonnet-5-5-max": { maxOutputTokens: 128000, thinkingBudget: 32768, isThinking: true, contextWindow: 1_000_000 },
68
75
  "claude-sonnet-5-5-high": { maxOutputTokens: 128000, thinkingBudget: 32768, isThinking: true, contextWindow: 1_000_000 },
69
76
  "claude-sonnet-5-5-medium": { maxOutputTokens: 128000, thinkingBudget: 32768, isThinking: true, contextWindow: 1_000_000 },
70
77
  "claude-sonnet-5-5-low": { maxOutputTokens: 128000, thinkingBudget: 32768, isThinking: true, contextWindow: 1_000_000 },