@expiren/opencode-antigravity-auth 1.6.19 → 1.6.21

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 (35) hide show
  1. package/dist/index.js +93 -21
  2. package/dist/index.js.map +2 -2
  3. package/dist/src/constants.d.ts +4 -3
  4. package/dist/src/constants.d.ts.map +1 -1
  5. package/dist/src/constants.js +2 -3
  6. package/dist/src/constants.js.map +1 -1
  7. package/dist/src/plugin/config/schema.d.ts +3 -0
  8. package/dist/src/plugin/config/schema.d.ts.map +1 -1
  9. package/dist/src/plugin/config/schema.js +44 -11
  10. package/dist/src/plugin/config/schema.js.map +1 -1
  11. package/dist/src/plugin/model-registry.d.ts +1 -1
  12. package/dist/src/plugin/model-registry.d.ts.map +1 -1
  13. package/dist/src/plugin/model-registry.js +3 -0
  14. package/dist/src/plugin/model-registry.js.map +1 -1
  15. package/dist/src/plugin/quota.d.ts +1 -1
  16. package/dist/src/plugin/quota.d.ts.map +1 -1
  17. package/dist/src/plugin/quota.js +3 -3
  18. package/dist/src/plugin/quota.js.map +1 -1
  19. package/dist/src/plugin/request.d.ts.map +1 -1
  20. package/dist/src/plugin/request.js +4 -4
  21. package/dist/src/plugin/request.js.map +1 -1
  22. package/dist/src/plugin/transform/claude.d.ts +11 -0
  23. package/dist/src/plugin/transform/claude.d.ts.map +1 -1
  24. package/dist/src/plugin/transform/claude.js +17 -1
  25. package/dist/src/plugin/transform/claude.js.map +1 -1
  26. package/dist/src/plugin/transform/index.d.ts +1 -1
  27. package/dist/src/plugin/transform/index.d.ts.map +1 -1
  28. package/dist/src/plugin/transform/index.js +1 -1
  29. package/dist/src/plugin/transform/index.js.map +1 -1
  30. package/dist/src/plugin/transform/model-resolver.js +4 -3
  31. package/dist/src/plugin/transform/model-resolver.js.map +1 -1
  32. package/dist/src/plugin.d.ts.map +1 -1
  33. package/dist/src/plugin.js +24 -5
  34. package/dist/src/plugin.js.map +1 -1
  35. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -27,17 +27,14 @@ var ANTIGRAVITY_SCOPES = [
27
27
  ];
28
28
  var ANTIGRAVITY_REDIRECT_URI = "http://localhost:51121/oauth-callback";
29
29
  var ANTIGRAVITY_ENDPOINT_DAILY = "https://daily-cloudcode-pa.sandbox.googleapis.com";
30
- var ANTIGRAVITY_ENDPOINT_AUTOPUSH = "https://autopush-cloudcode-pa.sandbox.googleapis.com";
31
30
  var ANTIGRAVITY_ENDPOINT_PROD = "https://cloudcode-pa.googleapis.com";
32
31
  var ANTIGRAVITY_ENDPOINT_FALLBACKS = [
33
32
  ANTIGRAVITY_ENDPOINT_DAILY,
34
- ANTIGRAVITY_ENDPOINT_AUTOPUSH,
35
33
  ANTIGRAVITY_ENDPOINT_PROD
36
34
  ];
37
35
  var ANTIGRAVITY_LOAD_ENDPOINTS = [
38
36
  ANTIGRAVITY_ENDPOINT_PROD,
39
- ANTIGRAVITY_ENDPOINT_DAILY,
40
- ANTIGRAVITY_ENDPOINT_AUTOPUSH
37
+ ANTIGRAVITY_ENDPOINT_DAILY
41
38
  ];
42
39
  var ANTIGRAVITY_ENDPOINT = ANTIGRAVITY_ENDPOINT_DAILY;
43
40
  var GEMINI_CLI_ENDPOINT = ANTIGRAVITY_ENDPOINT_PROD;
@@ -2032,7 +2029,10 @@ var QUOTA_GROUP_BY_MODEL_ID = {
2032
2029
  "gemini-3.1-pro-high": "gemini-pro",
2033
2030
  "gemini-3-flash": "gemini-flash",
2034
2031
  "gemini-3-flash-agent": "gemini-flash",
2035
- "gemini-3.5-flash-low": "gemini-flash"
2032
+ "gemini-3.5-flash-low": "gemini-flash",
2033
+ "gemini-3.1-flash-image": "gemini-flash",
2034
+ "gpt-oss-120b": "gpt-oss",
2035
+ "gpt-oss-120b-medium": "gpt-oss"
2036
2036
  };
2037
2037
  var OPENCODE_MODEL_DEFINITIONS = PUBLIC_MODEL_DEFINITIONS;
2038
2038
  function getResolverAliasMap() {
@@ -3020,9 +3020,21 @@ var AntigravityConfigSchema = z2.object({
3020
3020
  * @default false
3021
3021
  */
3022
3022
  keep_thinking: z2.boolean().default(false),
3023
+ /**
3024
+ * Enable thinking warmup requests for Claude thinking models.
3025
+ * When enabled, sends a separate API call at session start to warm up
3026
+ * thinking signature validation. Costs 1 full API call per session.
3027
+ *
3028
+ * Disable to save quota — most users don't need this unless using
3029
+ * keep_thinking with signature caching.
3030
+ *
3031
+ * Env override: OPENCODE_ANTIGRAVITY_THINKING_WARMUP=1
3032
+ * @default false
3033
+ */
3034
+ thinking_warmup: z2.boolean().default(false),
3023
3035
  // =========================================================================
3024
3036
  // Session Recovery
3025
- // =========================================================================
3037
+ // =========================================================================
3026
3038
  /**
3027
3039
  * Enable automatic session recovery from tool_result_missing errors.
3028
3040
  * When enabled, shows a toast notification when recoverable errors occur.
@@ -3062,9 +3074,9 @@ var AntigravityConfigSchema = z2.object({
3062
3074
  * Maximum retry attempts when Antigravity returns an empty response.
3063
3075
  * Empty responses occur when no candidates/choices are returned.
3064
3076
  *
3065
- * @default 4
3077
+ * @default 2
3066
3078
  */
3067
- empty_response_max_attempts: z2.number().min(1).max(10).default(4),
3079
+ empty_response_max_attempts: z2.number().min(1).max(10).default(2),
3068
3080
  /**
3069
3081
  * Delay in milliseconds between empty response retries.
3070
3082
  *
@@ -3185,8 +3197,28 @@ var AntigravityConfigSchema = z2.object({
3185
3197
  */
3186
3198
  switch_on_first_rate_limit: z2.boolean().default(true),
3187
3199
  /**
3188
- * Scheduling mode for rate limit behavior.
3200
+ * Maximum number of account switches per request before giving up.
3201
+ * Each switch re-sends the full request payload, consuming quota on the new account.
3202
+ * Lower values reduce quota waste from cascading rate limits across accounts.
3203
+ *
3204
+ * Env override: OPENCODE_ANTIGRAVITY_MAX_ACCOUNT_SWITCHES
3205
+ * @default 2
3206
+ */
3207
+ max_account_switches: z2.number().min(0).max(50).default(2),
3208
+ /**
3209
+ * Allow falling back between quota pools (antigravity ↔ gemini-cli) when rate-limited.
3210
+ * When enabled, if one quota pool is exhausted the plugin re-sends the SAME request
3211
+ * using the alternate header style, consuming tokens from BOTH pools.
3212
+ * Disable to prevent double-spending quota across pools — the plugin will only
3213
+ * rotate accounts instead.
3214
+ * Only applies to Gemini models (Claude always uses antigravity).
3189
3215
  *
3216
+ * Env override: OPENCODE_ANTIGRAVITY_QUOTA_STYLE_FALLBACK
3217
+ * @default false
3218
+ */
3219
+ quota_style_fallback: z2.boolean().default(false),
3220
+ /**
3221
+ * Scheduling mode for rate limit behavior. *
3190
3222
  * - `cache_first`: Wait for same account to recover (preserves prompt cache). Default.
3191
3223
  * - `balance`: Switch account immediately on rate limit. Maximum availability.
3192
3224
  * - `performance_first`: Round-robin distribution for maximum throughput.
@@ -3250,7 +3282,7 @@ var AntigravityConfigSchema = z2.object({
3250
3282
  *
3251
3283
  * @default 15
3252
3284
  */
3253
- quota_refresh_interval_minutes: z2.number().min(0).max(60).default(15),
3285
+ quota_refresh_interval_minutes: z2.number().min(0).max(120).default(30),
3254
3286
  /**
3255
3287
  * How long quota cache is considered fresh for threshold checks (in minutes).
3256
3288
  * After this time, cache is stale and account is allowed (fail-open).
@@ -3298,10 +3330,11 @@ var DEFAULT_CONFIG = {
3298
3330
  debug: false,
3299
3331
  debug_tui: false,
3300
3332
  keep_thinking: false,
3333
+ thinking_warmup: false,
3301
3334
  session_recovery: true,
3302
3335
  auto_resume: true,
3303
3336
  resume_text: "continue",
3304
- empty_response_max_attempts: 4,
3337
+ empty_response_max_attempts: 2,
3305
3338
  empty_response_retry_delay_ms: 2e3,
3306
3339
  tool_id_recovery: true,
3307
3340
  claude_tool_hardening: true,
@@ -3315,6 +3348,8 @@ var DEFAULT_CONFIG = {
3315
3348
  account_selection_strategy: "hybrid",
3316
3349
  pid_offset_enabled: false,
3317
3350
  switch_on_first_rate_limit: true,
3351
+ max_account_switches: 2,
3352
+ quota_style_fallback: false,
3318
3353
  scheduling_mode: "cache_first",
3319
3354
  max_cache_first_wait_seconds: 60,
3320
3355
  failure_ttl_seconds: 3600,
@@ -3322,7 +3357,7 @@ var DEFAULT_CONFIG = {
3322
3357
  max_backoff_seconds: 60,
3323
3358
  request_jitter_max_ms: 0,
3324
3359
  soft_quota_threshold_percent: 90,
3325
- quota_refresh_interval_minutes: 15,
3360
+ quota_refresh_interval_minutes: 30,
3326
3361
  soft_quota_cache_ttl_minutes: "auto",
3327
3362
  auto_update: true,
3328
3363
  signature_cache: {
@@ -5603,6 +5638,12 @@ function needsThinkingRecovery(state) {
5603
5638
 
5604
5639
  // src/plugin/transform/claude.ts
5605
5640
  var CLAUDE_THINKING_MAX_OUTPUT_TOKENS = 64e3;
5641
+ function computeClaudeMaxOutputTokens(thinkingBudget) {
5642
+ if (typeof thinkingBudget !== "number" || thinkingBudget <= 0) {
5643
+ return CLAUDE_THINKING_MAX_OUTPUT_TOKENS;
5644
+ }
5645
+ return Math.min(Math.max(thinkingBudget * 2, 32e3), CLAUDE_THINKING_MAX_OUTPUT_TOKENS);
5646
+ }
5606
5647
  function isClaudeModel(model) {
5607
5648
  return model.toLowerCase().includes("claude");
5608
5649
  }
@@ -6135,7 +6176,7 @@ function resolveModelWithTier(requestedModel, options = {}) {
6135
6176
  if (isClaudeThinking) {
6136
6177
  return {
6137
6178
  actualModel: resolvedModel,
6138
- thinkingBudget: THINKING_TIER_BUDGETS.claude.high,
6179
+ thinkingBudget: THINKING_TIER_BUDGETS.claude.medium,
6139
6180
  isThinkingModel: true,
6140
6181
  quotaPreference,
6141
6182
  explicitQuota
@@ -7507,7 +7548,7 @@ function prepareAntigravityRequest(input2, init, accessToken, projectId, endpoin
7507
7548
  if (isClaudeThinking && typeof thinkingBudget === "number" && thinkingBudget > 0) {
7508
7549
  const currentMax = rawGenerationConfig.maxOutputTokens ?? rawGenerationConfig.max_output_tokens;
7509
7550
  if (!currentMax || currentMax <= thinkingBudget) {
7510
- rawGenerationConfig.maxOutputTokens = CLAUDE_THINKING_MAX_OUTPUT_TOKENS;
7551
+ rawGenerationConfig.maxOutputTokens = computeClaudeMaxOutputTokens(thinkingBudget);
7511
7552
  if (rawGenerationConfig.max_output_tokens !== void 0) {
7512
7553
  delete rawGenerationConfig.max_output_tokens;
7513
7554
  }
@@ -7517,7 +7558,7 @@ function prepareAntigravityRequest(input2, init, accessToken, projectId, endpoin
7517
7558
  } else {
7518
7559
  const generationConfig = { thinkingConfig };
7519
7560
  if (isClaudeThinking && typeof thinkingBudget === "number" && thinkingBudget > 0) {
7520
- generationConfig.maxOutputTokens = CLAUDE_THINKING_MAX_OUTPUT_TOKENS;
7561
+ generationConfig.maxOutputTokens = computeClaudeMaxOutputTokens(thinkingBudget);
7521
7562
  }
7522
7563
  requestPayload.generationConfig = generationConfig;
7523
7564
  }
@@ -7827,7 +7868,7 @@ function buildThinkingWarmupBody(bodyText, isClaudeThinking) {
7827
7868
  include_thoughts: true,
7828
7869
  thinking_budget: DEFAULT_THINKING_BUDGET
7829
7870
  };
7830
- generationConfig.maxOutputTokens = CLAUDE_THINKING_MAX_OUTPUT_TOKENS;
7871
+ generationConfig.maxOutputTokens = computeClaudeMaxOutputTokens(DEFAULT_THINKING_BUDGET);
7831
7872
  req.generationConfig = generationConfig;
7832
7873
  };
7833
7874
  if (parsed.request && typeof parsed.request === "object") {
@@ -10287,7 +10328,7 @@ function aggregateGeminiCliQuota(response) {
10287
10328
  continue;
10288
10329
  }
10289
10330
  const modelId = bucket.modelId;
10290
- const isRelevantModel = modelId.startsWith("gemini-3-") || modelId === "gemini-2.5-pro";
10331
+ const isRelevantModel = modelId.startsWith("gemini-3-") || modelId.startsWith("gemini-3.") || modelId.startsWith("gemini-2.5-");
10291
10332
  if (!isRelevantModel) {
10292
10333
  continue;
10293
10334
  }
@@ -11914,6 +11955,8 @@ var createAntigravityPlugin = (providerId) => async ({ client, directory }) => {
11914
11955
  if (family !== "gemini") return false;
11915
11956
  return accountManager.hasOtherAccountWithAntigravityAvailable(currentAccount.index, family, model);
11916
11957
  };
11958
+ let accountSwitchCount = 0;
11959
+ const maxAccountSwitches = config.max_account_switches ?? 2;
11917
11960
  while (true) {
11918
11961
  checkAborted();
11919
11962
  const accountCount = accountManager.getAccountCount();
@@ -12134,6 +12177,9 @@ var createAntigravityPlugin = (providerId) => async ({ client, directory }) => {
12134
12177
  }
12135
12178
  }
12136
12179
  const runThinkingWarmup = async (prepared, projectId) => {
12180
+ if (!config.thinking_warmup) {
12181
+ return;
12182
+ }
12137
12183
  if (!prepared.needsSignedThinkingWarmup || !prepared.sessionId) {
12138
12184
  return;
12139
12185
  }
@@ -12245,6 +12291,7 @@ var createAntigravityPlugin = (providerId) => async ({ client, directory }) => {
12245
12291
  let tokenConsumed = false;
12246
12292
  let capacityRetryCount = 0;
12247
12293
  let lastEndpointIndex = -1;
12294
+ let apiRequestCount = 0;
12248
12295
  for (let i = 0; i < ANTIGRAVITY_ENDPOINT_FALLBACKS.length; i++) {
12249
12296
  if (i !== lastEndpointIndex) {
12250
12297
  capacityRetryCount = 0;
@@ -12307,7 +12354,8 @@ var createAntigravityPlugin = (providerId) => async ({ client, directory }) => {
12307
12354
  tokenConsumed = getTokenTracker().consume(account.index);
12308
12355
  }
12309
12356
  const response = await fetch(prepared.request, prepared.init);
12310
- pushDebug(`status=${response.status} ${response.statusText}`);
12357
+ apiRequestCount++;
12358
+ pushDebug(`status=${response.status} ${response.statusText} (api_request #${apiRequestCount})`);
12311
12359
  if (response.status === 429 || response.status === 503 || response.status === 529) {
12312
12360
  if (tokenConsumed) {
12313
12361
  getTokenTracker().refund(account.index);
@@ -12332,12 +12380,12 @@ var createAntigravityPlugin = (providerId) => async ({ client, directory }) => {
12332
12380
  "warning"
12333
12381
  );
12334
12382
  await sleep(waitMs, abortSignal);
12335
- if (capacityRetryCount < 3) {
12383
+ if (capacityRetryCount < 1) {
12336
12384
  capacityRetryCount++;
12337
12385
  i -= 1;
12338
12386
  continue;
12339
12387
  } else {
12340
- pushDebug(`Max capacity retries (3) exhausted for endpoint ${currentEndpoint}, regenerating fingerprint...`);
12388
+ pushDebug(`Max capacity retries (1) exhausted for endpoint ${currentEndpoint}, regenerating fingerprint...`);
12341
12389
  const newFingerprint = accountManager.regenerateAccountFingerprint(account.index);
12342
12390
  if (newFingerprint) {
12343
12391
  pushDebug(`Fingerprint regenerated for account ${account.index}`);
@@ -12589,6 +12637,9 @@ Alternatively, you can:
12589
12637
  );
12590
12638
  }
12591
12639
  }
12640
+ if (apiRequestCount > 1) {
12641
+ pushDebug(`[Quota] Total API requests for this user message: ${apiRequestCount} (${apiRequestCount - 1} retries)`);
12642
+ }
12592
12643
  return transformedResponse;
12593
12644
  } catch (error) {
12594
12645
  if (tokenConsumed) {
@@ -12635,6 +12686,27 @@ Alternatively, you can:
12635
12686
  }
12636
12687
  }
12637
12688
  if (shouldSwitchAccount) {
12689
+ accountSwitchCount++;
12690
+ if (accountSwitchCount > maxAccountSwitches) {
12691
+ pushDebug(`account-switch-cap: exceeded max_account_switches=${maxAccountSwitches}, giving up`);
12692
+ if (lastFailure) {
12693
+ return transformAntigravityResponse(
12694
+ lastFailure.response,
12695
+ lastFailure.streaming,
12696
+ lastFailure.debugContext,
12697
+ lastFailure.requestedModel,
12698
+ lastFailure.projectId,
12699
+ lastFailure.endpoint,
12700
+ lastFailure.effectiveModel,
12701
+ lastFailure.sessionId,
12702
+ lastFailure.toolDebugMissing,
12703
+ lastFailure.toolDebugSummary,
12704
+ lastFailure.toolDebugPayload,
12705
+ debugLines
12706
+ );
12707
+ }
12708
+ throw lastError || new Error(`Exceeded max account switches (${maxAccountSwitches}). All accounts rate-limited.`);
12709
+ }
12638
12710
  if (accountCount <= 1) {
12639
12711
  if (lastFailure) {
12640
12712
  return transformAntigravityResponse(
@@ -13478,7 +13550,7 @@ function resolveHeaderRoutingDecision(urlString, family, config) {
13478
13550
  cliFirst,
13479
13551
  preferredHeaderStyle,
13480
13552
  explicitQuota,
13481
- allowQuotaFallback: family === "gemini"
13553
+ allowQuotaFallback: family === "gemini" && !!(config.quota_style_fallback ?? false)
13482
13554
  };
13483
13555
  }
13484
13556
  function getCliFirst(config) {