@cortexkit/opencode-antigravity-auth 3.0.23 → 3.0.25

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 (40) hide show
  1. package/dist/cli.js +32 -3
  2. package/dist/cli.js.map +3 -3
  3. package/dist/cli.meta.json +8 -8
  4. package/dist/index.js +247 -68
  5. package/dist/index.js.map +3 -3
  6. package/dist/index.meta.json +12 -12
  7. package/dist/server.js +380 -98
  8. package/dist/server.js.map +3 -3
  9. package/dist/server.meta.json +1 -1
  10. package/dist/src/auth-method-labels.d.ts +1 -0
  11. package/dist/src/auth-method-labels.d.ts.map +1 -1
  12. package/dist/src/auth-method-labels.js +1 -0
  13. package/dist/src/auth-method-labels.js.map +1 -1
  14. package/dist/src/ga/server/auth.d.ts.map +1 -1
  15. package/dist/src/ga/server/auth.js +63 -21
  16. package/dist/src/ga/server/auth.js.map +1 -1
  17. package/dist/src/ga/server/pool-login.d.ts +4 -0
  18. package/dist/src/ga/server/pool-login.d.ts.map +1 -1
  19. package/dist/src/ga/server/pool-login.js +22 -1
  20. package/dist/src/ga/server/pool-login.js.map +1 -1
  21. package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
  22. package/dist/src/plugin/ga-location-services.js +42 -4
  23. package/dist/src/plugin/ga-location-services.js.map +1 -1
  24. package/dist/src/plugin/shared/request-services.d.ts +4 -0
  25. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  26. package/dist/src/plugin/shared/request-services.js +71 -23
  27. package/dist/src/plugin/shared/request-services.js.map +1 -1
  28. package/dist/src/setup.d.ts.map +1 -1
  29. package/dist/src/setup.js +38 -4
  30. package/dist/src/setup.js.map +1 -1
  31. package/dist/types/src/auth-method-labels.d.ts +1 -0
  32. package/dist/types/src/auth-method-labels.d.ts.map +1 -1
  33. package/dist/types/src/ga/server/auth.d.ts.map +1 -1
  34. package/dist/types/src/ga/server/pool-login.d.ts +4 -0
  35. package/dist/types/src/ga/server/pool-login.d.ts.map +1 -1
  36. package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
  37. package/dist/types/src/plugin/shared/request-services.d.ts +4 -0
  38. package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
  39. package/dist/types/src/setup.d.ts.map +1 -1
  40. package/package.json +2 -2
@@ -171,7 +171,7 @@
171
171
  "format": "esm"
172
172
  },
173
173
  "../core/dist/account-selector.js": {
174
- "bytes": 55552,
174
+ "bytes": 61373,
175
175
  "imports": [
176
176
  {
177
177
  "path": "../core/dist/fingerprint.js",
@@ -285,7 +285,7 @@
285
285
  "format": "esm"
286
286
  },
287
287
  "../core/dist/account-manager.js": {
288
- "bytes": 66811,
288
+ "bytes": 68562,
289
289
  "imports": [
290
290
  {
291
291
  "path": "node:crypto",
@@ -3624,7 +3624,7 @@
3624
3624
  "format": "esm"
3625
3625
  },
3626
3626
  "src/auth-method-labels.ts": {
3627
- "bytes": 318,
3627
+ "bytes": 404,
3628
3628
  "imports": [],
3629
3629
  "format": "esm"
3630
3630
  },
@@ -4193,7 +4193,7 @@
4193
4193
  "format": "esm"
4194
4194
  },
4195
4195
  "src/setup.ts": {
4196
- "bytes": 18714,
4196
+ "bytes": 20353,
4197
4197
  "imports": [
4198
4198
  {
4199
4199
  "path": "node:fs/promises",
@@ -4355,7 +4355,7 @@
4355
4355
  "imports": [],
4356
4356
  "exports": [],
4357
4357
  "inputs": {},
4358
- "bytes": 3165800
4358
+ "bytes": 3176325
4359
4359
  },
4360
4360
  "dist/cli.js": {
4361
4361
  "imports": [
@@ -5599,10 +5599,10 @@
5599
5599
  "bytesInOutput": 8443
5600
5600
  },
5601
5601
  "src/setup.ts": {
5602
- "bytesInOutput": 14143
5602
+ "bytesInOutput": 15311
5603
5603
  },
5604
5604
  "src/auth-method-labels.ts": {
5605
- "bytesInOutput": 142
5605
+ "bytesInOutput": 218
5606
5606
  },
5607
5607
  "src/common-auth-embedded/auth-menu/ansi.js": {
5608
5608
  "bytesInOutput": 2389
@@ -5677,7 +5677,7 @@
5677
5677
  "bytesInOutput": 292
5678
5678
  }
5679
5679
  },
5680
- "bytes": 1188792
5680
+ "bytes": 1190036
5681
5681
  }
5682
5682
  }
5683
5683
  }
package/dist/index.js CHANGED
@@ -6870,8 +6870,11 @@ var init_account_selector = __esm({
6870
6870
  rateLimitResetTimes: { ...a.rateLimitResetTimes }
6871
6871
  }));
6872
6872
  }
6873
- getEffectiveSoftQuotaThreshold(thresholdPercent) {
6874
- return this.getEnabledAccounts().length > 1 ? thresholdPercent : 100;
6873
+ getEligibleAccounts(excludeIndexes) {
6874
+ return this.accounts.filter((a) => a.enabled !== false && a.accountIneligible !== true && a.verificationRequired !== true && !excludeIndexes?.has(a.index));
6875
+ }
6876
+ getEffectiveSoftQuotaThreshold(thresholdPercent, excludeIndexes) {
6877
+ return this.getEligibleAccounts(excludeIndexes).length > 1 ? thresholdPercent : 100;
6875
6878
  }
6876
6879
  getRequestSessionState(identity3) {
6877
6880
  const now = this.now();
@@ -6974,7 +6977,7 @@ var init_account_selector = __esm({
6974
6977
  const currentIndex = this.getActiveIndex(family, identity3);
6975
6978
  if (currentIndex >= 0 && currentIndex < this.accounts.length) {
6976
6979
  const account = this.accounts[currentIndex] ?? null;
6977
- if (account && account.enabled !== false) {
6980
+ if (account && account.enabled !== false && account.accountIneligible !== true && account.verificationRequired !== true) {
6978
6981
  return account;
6979
6982
  }
6980
6983
  }
@@ -7017,7 +7020,7 @@ var init_account_selector = __esm({
7017
7020
  }
7018
7021
  getCurrentOrNextForFamily(family, model, strategy = "sticky", pidOffsetEnabled = false, softQuotaThresholdPercent = 100, softQuotaCacheTtlMs = 10 * 60 * 1e3, identity3, excludeIndexes) {
7019
7022
  const quotaKey = getQuotaKey(family, model);
7020
- const effectiveSoftQuotaThreshold = this.getEffectiveSoftQuotaThreshold(softQuotaThresholdPercent);
7023
+ const effectiveSoftQuotaThreshold = this.getEffectiveSoftQuotaThreshold(softQuotaThresholdPercent, excludeIndexes);
7021
7024
  if (identity3) {
7022
7025
  const pinned = this.getCurrentAccountForFamily(family, identity3);
7023
7026
  if (pinned) {
@@ -7040,7 +7043,7 @@ var init_account_selector = __esm({
7040
7043
  if (strategy === "hybrid") {
7041
7044
  const healthTracker = this.healthTracker;
7042
7045
  const tokenTracker = this.tokenTracker;
7043
- const eligibleAccounts = this.preferAccountOutsideParent(this.accounts.filter((acc) => acc.enabled !== false && !excludeIndexes?.has(acc.index)), family, identity3);
7046
+ const eligibleAccounts = this.preferAccountOutsideParent(this.accounts.filter((acc) => acc.enabled !== false && acc.accountIneligible !== true && acc.verificationRequired !== true && !excludeIndexes?.has(acc.index)), family, identity3);
7044
7047
  const accountsWithMetrics = eligibleAccounts.map((acc) => {
7045
7048
  clearExpiredRateLimits(acc, this.now);
7046
7049
  return {
@@ -7097,10 +7100,10 @@ var init_account_selector = __esm({
7097
7100
  return next;
7098
7101
  }
7099
7102
  getNextForFamily(family, model, softQuotaThresholdPercent = 100, softQuotaCacheTtlMs = 10 * 60 * 1e3, identity3, excludeIndexes) {
7100
- const effectiveSoftQuotaThreshold = this.getEffectiveSoftQuotaThreshold(softQuotaThresholdPercent);
7103
+ const effectiveSoftQuotaThreshold = this.getEffectiveSoftQuotaThreshold(softQuotaThresholdPercent, excludeIndexes);
7101
7104
  const allAvailable = this.accounts.filter((account2) => {
7102
7105
  clearExpiredRateLimits(account2, this.now);
7103
- return account2.enabled !== false && !excludeIndexes?.has(account2.index) && !isRateLimitedForFamily(account2, family, this.now, model) && !isOverSoftQuotaThreshold(account2, family, effectiveSoftQuotaThreshold, softQuotaCacheTtlMs, this.now, model) && !this.isAccountCoolingDown(account2);
7106
+ return account2.enabled !== false && account2.accountIneligible !== true && account2.verificationRequired !== true && !excludeIndexes?.has(account2.index) && !isRateLimitedForFamily(account2, family, this.now, model) && !isOverSoftQuotaThreshold(account2, family, effectiveSoftQuotaThreshold, softQuotaCacheTtlMs, this.now, model) && !this.isAccountCoolingDown(account2);
7104
7107
  });
7105
7108
  const available = this.preferAccountOutsideParent(allAvailable, family, identity3);
7106
7109
  if (available.length === 0) {
@@ -7181,6 +7184,9 @@ var init_account_selector = __esm({
7181
7184
  const candidates = this.preferAccountOutsideParent(this.accounts.filter((acc) => {
7182
7185
  if (acc.enabled === false)
7183
7186
  return false;
7187
+ if (acc.accountIneligible === true || acc.verificationRequired === true) {
7188
+ return false;
7189
+ }
7184
7190
  if (acc.index === currentIndex)
7185
7191
  return false;
7186
7192
  clearExpiredRateLimits(acc, this.now);
@@ -7286,7 +7292,7 @@ var init_account_selector = __esm({
7286
7292
  getFreshAccountsForQuota(quotaKey, family, model) {
7287
7293
  return this.accounts.filter((acc) => {
7288
7294
  clearExpiredRateLimits(acc, this.now);
7289
- return acc.enabled !== false && this.isFreshForQuota(acc, quotaKey) && !isRateLimitedForFamily(acc, family, this.now, model) && !this.isAccountCoolingDown(acc);
7295
+ return acc.enabled !== false && acc.accountIneligible !== true && acc.verificationRequired !== true && this.isFreshForQuota(acc, quotaKey) && !isRateLimitedForFamily(acc, family, this.now, model) && !this.isAccountCoolingDown(acc);
7290
7296
  });
7291
7297
  }
7292
7298
  isRateLimited(account, family, model) {
@@ -7422,12 +7428,42 @@ var init_account_selector = __esm({
7422
7428
  }
7423
7429
  return true;
7424
7430
  }
7425
- getMinWaitTimeForFamily(family, model) {
7431
+ /**
7432
+ * Calculates the minimum wait time in milliseconds across eligible accounts
7433
+ * for a given model family (and optional model).
7434
+ *
7435
+ * Note: Returning `0` can mean either:
7436
+ * 1. No eligible candidates exist in the pool, OR
7437
+ * 2. At least one eligible candidate is hard/cooldown-ready without waiting
7438
+ * (this does not imply the candidate is fully selectable, as soft quota
7439
+ * or session-level policies may still apply).
7440
+ * Callers must distinguish "no eligible candidates" from "zero wait time"
7441
+ * by inspecting candidate pool availability / eligibility directly.
7442
+ *
7443
+ * @param family Model family (e.g., 'claude', 'gemini')
7444
+ * @param model Optional model name for per-model rate limits
7445
+ * @param eligibleIndexes Optional set of account indexes permitted for this request
7446
+ * @param includeCooldown Whether to factor in `coolingDownUntil` alongside quota rate limits
7447
+ * @returns Minimum wait duration in milliseconds, or 0 if hard/cooldown-ready or no candidates
7448
+ */
7449
+ getMinWaitTimeForFamily(family, model, eligibleIndexes, includeCooldown = false) {
7426
7450
  const now = this.now();
7427
- const waits = this.accounts.filter((a) => a.enabled !== false).map((a) => {
7451
+ const waits = this.accounts.filter((a) => {
7452
+ if (a.enabled === false)
7453
+ return false;
7454
+ if (a.accountIneligible === true || a.verificationRequired === true) {
7455
+ return false;
7456
+ }
7457
+ if (eligibleIndexes !== void 0 && eligibleIndexes !== null) {
7458
+ if (!eligibleIndexes.has(a.index))
7459
+ return false;
7460
+ }
7461
+ return true;
7462
+ }).map((a) => {
7428
7463
  clearExpiredRateLimits(a, this.now);
7429
7464
  const modelReset = model ? a.rateLimitResetTimes[getQuotaKey(family, model)] : void 0;
7430
- return Math.max(0, (a.rateLimitResetTimes[family] ?? now) - now, (modelReset ?? now) - now);
7465
+ const cooldownWait = includeCooldown && a.coolingDownUntil !== void 0 && a.coolingDownUntil > now ? a.coolingDownUntil - now : 0;
7466
+ return Math.max(0, (a.rateLimitResetTimes[family] ?? now) - now, (modelReset ?? now) - now, cooldownWait);
7431
7467
  });
7432
7468
  return waits.length > 0 ? Math.min(...waits) : 0;
7433
7469
  }
@@ -7606,8 +7642,51 @@ var init_account_selector = __esm({
7606
7642
  perAccount: perAccount.sort((a, b) => b.claude + b.gemini - (a.claude + a.gemini))
7607
7643
  };
7608
7644
  }
7609
- isAccountOverSoftQuota(account, family, thresholdPercent, cacheTtlMs, model) {
7610
- return isOverSoftQuotaThreshold(account, family, this.getEffectiveSoftQuotaThreshold(thresholdPercent), cacheTtlMs, this.now, model);
7645
+ isAccountOverSoftQuota(account, family, thresholdPercent, cacheTtlMs, model, excludeIndexes) {
7646
+ return isOverSoftQuotaThreshold(account, family, this.getEffectiveSoftQuotaThreshold(thresholdPercent, excludeIndexes), cacheTtlMs, this.now, model);
7647
+ }
7648
+ /**
7649
+ * Calculates the minimum wait duration across eligible accounts until at least
7650
+ * one candidate becomes selectable.
7651
+ *
7652
+ * For each eligible account:
7653
+ * accountWait = max(hardCooldownWait, applicableSoftResetDelay)
7654
+ * where hardCooldownWait uses getMinWaitTimeForFamily(..., includeCooldown=true).
7655
+ * Soft quota is applicable if and only if eligible.length > 1 and thresholdPercent < 100.
7656
+ * Unknown soft reset renders that account an unknown candidate.
7657
+ * Returns minimum known accountWait, or null if no eligible candidates or all unknown.
7658
+ */
7659
+ getMinSelectableWaitTimeForFamily(family, thresholdPercent, cacheTtlMs, model, eligibleIndexes) {
7660
+ const eligible = this.accounts.filter((a) => a.enabled !== false && a.accountIneligible !== true && a.verificationRequired !== true && (eligibleIndexes == null || eligibleIndexes.has(a.index)));
7661
+ if (eligible.length === 0)
7662
+ return null;
7663
+ const now = this.now();
7664
+ const applySoftQuota = eligible.length > 1 && thresholdPercent < 100;
7665
+ const knownWaits = [];
7666
+ for (const acc of eligible) {
7667
+ const hardCooldownWait = this.getMinWaitTimeForFamily(family, model, /* @__PURE__ */ new Set([acc.index]), true);
7668
+ if (applySoftQuota && isOverSoftQuotaThreshold(acc, family, thresholdPercent, cacheTtlMs, this.now, model)) {
7669
+ if (!model && family !== "claude") {
7670
+ continue;
7671
+ }
7672
+ const quotaGroup = resolveQuotaGroup(family, model, acc.cachedQuota);
7673
+ const groupData = acc.cachedQuota?.[quotaGroup];
7674
+ if (!groupData?.resetTime) {
7675
+ continue;
7676
+ }
7677
+ const resetTimestamp = Date.parse(groupData.resetTime);
7678
+ if (!Number.isFinite(resetTimestamp) || resetTimestamp <= now) {
7679
+ continue;
7680
+ }
7681
+ const softResetDelay = resetTimestamp - now;
7682
+ knownWaits.push(Math.max(hardCooldownWait, softResetDelay));
7683
+ } else {
7684
+ knownWaits.push(hardCooldownWait);
7685
+ }
7686
+ }
7687
+ if (knownWaits.length === 0)
7688
+ return null;
7689
+ return Math.min(...knownWaits);
7611
7690
  }
7612
7691
  getOldestQuotaCacheAge() {
7613
7692
  let oldest = null;
@@ -7622,36 +7701,42 @@ var init_account_selector = __esm({
7622
7701
  }
7623
7702
  return oldest;
7624
7703
  }
7625
- areAllAccountsOverSoftQuota(family, thresholdPercent, cacheTtlMs, model) {
7704
+ /**
7705
+ * Check whether all eligible accounts (more than 1) are currently over the soft-quota threshold.
7706
+ * Returns false if thresholdPercent >= 100 or if <= 1 eligible account remains.
7707
+ */
7708
+ areAllAccountsOverSoftQuota(family, thresholdPercent, cacheTtlMs, model, eligibleIndexes) {
7626
7709
  if (thresholdPercent >= 100)
7627
7710
  return false;
7628
- const enabled = this.accounts.filter((a) => a.enabled !== false);
7629
- if (enabled.length <= 1)
7711
+ const eligible = this.accounts.filter((a) => a.enabled !== false && a.accountIneligible !== true && a.verificationRequired !== true && (eligibleIndexes == null || eligibleIndexes.has(a.index)));
7712
+ if (eligible.length <= 1)
7630
7713
  return false;
7631
- return enabled.every((a) => isOverSoftQuotaThreshold(a, family, thresholdPercent, cacheTtlMs, this.now, model));
7714
+ return eligible.every((a) => isOverSoftQuotaThreshold(a, family, thresholdPercent, cacheTtlMs, this.now, model));
7632
7715
  }
7633
7716
  /**
7634
- * Get minimum wait time until any account's soft quota resets.
7635
- * Returns 0 if any account is available (not over threshold).
7636
- * Returns the minimum resetTime across all over-threshold accounts.
7637
- * Returns null if no resetTime data is available.
7717
+ * Get minimum wait time until any eligible account's soft quota resets.
7718
+ * Operates over the eligible subset (enabled, non-ineligible, non-verification-required,
7719
+ * and present in `eligibleIndexes` when provided).
7720
+ * Returns null if no eligible accounts remain or no resetTime data is available.
7721
+ * Returns 0 if only 1 eligible account exists or any eligible account is below threshold.
7722
+ * Returns the minimum resetTime across all over-threshold eligible accounts.
7638
7723
  */
7639
- getMinWaitTimeForSoftQuota(family, thresholdPercent, cacheTtlMs, model) {
7724
+ getMinWaitTimeForSoftQuota(family, thresholdPercent, cacheTtlMs, model, eligibleIndexes) {
7640
7725
  if (thresholdPercent >= 100)
7641
7726
  return 0;
7642
- const enabled = this.accounts.filter((a) => a.enabled !== false);
7643
- if (enabled.length === 0)
7727
+ const eligible = this.accounts.filter((a) => a.enabled !== false && a.accountIneligible !== true && a.verificationRequired !== true && (eligibleIndexes == null || eligibleIndexes.has(a.index)));
7728
+ if (eligible.length === 0)
7644
7729
  return null;
7645
- if (enabled.length === 1)
7730
+ if (eligible.length === 1)
7646
7731
  return 0;
7647
- const available = enabled.filter((a) => !isOverSoftQuotaThreshold(a, family, thresholdPercent, cacheTtlMs, this.now, model));
7732
+ const available = eligible.filter((a) => !isOverSoftQuotaThreshold(a, family, thresholdPercent, cacheTtlMs, this.now, model));
7648
7733
  if (available.length > 0)
7649
7734
  return 0;
7650
7735
  if (!model && family !== "claude")
7651
7736
  return null;
7652
7737
  const now = this.now();
7653
7738
  const waitTimes = [];
7654
- for (const acc of enabled) {
7739
+ for (const acc of eligible) {
7655
7740
  const quotaGroup = resolveQuotaGroup(family, model, acc.cachedQuota);
7656
7741
  const groupData = acc.cachedQuota?.[quotaGroup];
7657
7742
  if (groupData?.resetTime) {
@@ -9656,8 +9741,24 @@ var init_account_manager = __esm({
9656
9741
  expires: account.expires
9657
9742
  };
9658
9743
  }
9659
- getMinWaitTimeForFamily(family, model) {
9660
- return this.selection.getMinWaitTimeForFamily(family, model);
9744
+ /**
9745
+ * Calculates the minimum wait time in milliseconds across eligible accounts
9746
+ * for a given model family (and optional model).
9747
+ *
9748
+ * Note: Returning `0` can mean either:
9749
+ * 1. No eligible candidates exist in the pool, OR
9750
+ * 2. At least one eligible candidate is immediately usable without waiting.
9751
+ * Callers must distinguish "no eligible candidates" from "zero wait time"
9752
+ * by inspecting candidate pool availability / eligibility directly.
9753
+ *
9754
+ * @param family Model family (e.g., 'claude', 'gemini')
9755
+ * @param model Optional model name for per-model rate limits
9756
+ * @param eligibleIndexes Optional set of account indexes permitted for this request
9757
+ * @param includeCooldown Whether to factor in `coolingDownUntil` alongside quota rate limits
9758
+ * @returns Minimum wait duration in milliseconds, or 0 if immediately usable or no candidates
9759
+ */
9760
+ getMinWaitTimeForFamily(family, model, eligibleIndexes, includeCooldown = false) {
9761
+ return this.selection.getMinWaitTimeForFamily(family, model, eligibleIndexes, includeCooldown);
9661
9762
  }
9662
9763
  getAccounts() {
9663
9764
  return this.selection.getAccounts();
@@ -9967,8 +10068,8 @@ var init_account_manager = __esm({
9967
10068
  getSessionSummary() {
9968
10069
  return this.selection.getSessionSummary();
9969
10070
  }
9970
- isAccountOverSoftQuota(account, family, thresholdPercent, cacheTtlMs, model) {
9971
- return this.selection.isAccountOverSoftQuota(account, family, thresholdPercent, cacheTtlMs, model);
10071
+ isAccountOverSoftQuota(account, family, thresholdPercent, cacheTtlMs, model, excludeIndexes) {
10072
+ return this.selection.isAccountOverSoftQuota(account, family, thresholdPercent, cacheTtlMs, model, excludeIndexes);
9972
10073
  }
9973
10074
  /**
9974
10075
  * The accounts a quota check should cover. For a repository-backed
@@ -10000,17 +10101,26 @@ var init_account_manager = __esm({
10000
10101
  getOldestQuotaCacheAge() {
10001
10102
  return this.selection.getOldestQuotaCacheAge();
10002
10103
  }
10003
- areAllAccountsOverSoftQuota(family, thresholdPercent, cacheTtlMs, model) {
10004
- return this.selection.areAllAccountsOverSoftQuota(family, thresholdPercent, cacheTtlMs, model);
10104
+ /**
10105
+ * Check whether all eligible accounts (more than 1) are currently over the soft-quota threshold.
10106
+ * Returns false if thresholdPercent >= 100 or if <= 1 eligible account remains.
10107
+ */
10108
+ areAllAccountsOverSoftQuota(family, thresholdPercent, cacheTtlMs, model, eligibleIndexes) {
10109
+ return this.selection.areAllAccountsOverSoftQuota(family, thresholdPercent, cacheTtlMs, model, eligibleIndexes);
10005
10110
  }
10006
10111
  /**
10007
- * Get minimum wait time until any account's soft quota resets.
10008
- * Returns 0 if any account is available (not over threshold).
10009
- * Returns the minimum resetTime across all over-threshold accounts.
10010
- * Returns null if no resetTime data is available.
10112
+ * Get minimum wait time until any eligible account's soft quota resets.
10113
+ * Operates over the eligible subset (enabled, non-ineligible, non-verification-required,
10114
+ * and present in `eligibleIndexes` when provided).
10115
+ * Returns null if no eligible accounts remain or no resetTime data is available.
10116
+ * Returns 0 if only 1 eligible account exists or any eligible account is below threshold.
10117
+ * Returns the minimum resetTime across all over-threshold eligible accounts.
10011
10118
  */
10012
- getMinWaitTimeForSoftQuota(family, thresholdPercent, cacheTtlMs, model) {
10013
- return this.selection.getMinWaitTimeForSoftQuota(family, thresholdPercent, cacheTtlMs, model);
10119
+ getMinWaitTimeForSoftQuota(family, thresholdPercent, cacheTtlMs, model, eligibleIndexes) {
10120
+ return this.selection.getMinWaitTimeForSoftQuota(family, thresholdPercent, cacheTtlMs, model, eligibleIndexes);
10121
+ }
10122
+ getMinSelectableWaitTimeForFamily(family, thresholdPercent, cacheTtlMs, model, eligibleIndexes) {
10123
+ return this.selection.getMinSelectableWaitTimeForFamily(family, thresholdPercent, cacheTtlMs, model, eligibleIndexes);
10014
10124
  }
10015
10125
  };
10016
10126
  }
@@ -36193,6 +36303,7 @@ import { join as join24, resolve as resolve20 } from "node:path";
36193
36303
  // src/auth-method-labels.ts
36194
36304
  var OPENCODE2_POOL_AUTH_LABEL = "Google (antigravity-auth pool, browser)";
36195
36305
  var OPENCODE2_VAULT_AUTH_LABEL = "Use approved Antigravity vault";
36306
+ var OPENCODE2_POOL_RECONNECT_LABEL = "Use existing local Antigravity pool";
36196
36307
 
36197
36308
  // src/common-auth-embedded/auth-menu/ansi.js
36198
36309
  var ANSI2 = {
@@ -39467,6 +39578,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
39467
39578
  }
39468
39579
  };
39469
39580
  let openCodeLogin;
39581
+ let hasLocalPool = false;
39470
39582
  const manifest = JSON.parse(
39471
39583
  await readFile16(new URL("../package.json", import.meta.url), "utf8")
39472
39584
  );
@@ -39522,7 +39634,23 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
39522
39634
  },
39523
39635
  signInLocal: async (host, context) => {
39524
39636
  await assertLocal(host, context);
39525
- if (host === "opencode" && context.opencodeGeneration === "2") return;
39637
+ if (host === "opencode" && context.opencodeGeneration === "2") {
39638
+ if (!forceLogin) {
39639
+ try {
39640
+ const source2 = await deps.accountStore.read(
39641
+ deps.accountStore.legacyPath()
39642
+ );
39643
+ const candidateAccounts = source2.kind === "store" ? source2.accounts : source2.kind === "legacy" ? (await deps.loadAccounts())?.accounts ?? [] : [];
39644
+ if (candidateAccounts.some(
39645
+ (account) => account.enabled !== false && account.accountIneligible !== true && account.verificationRequired !== true && typeof account.refreshToken === "string" && account.refreshToken.length > 0
39646
+ )) {
39647
+ hasLocalPool = true;
39648
+ }
39649
+ } catch {
39650
+ }
39651
+ }
39652
+ return;
39653
+ }
39526
39654
  const slot = (await nativeAuth(host, context))[provider(host)];
39527
39655
  const source = host === "opencode" ? await deps.accountStore.read(deps.accountStore.legacyPath()) : void 0;
39528
39656
  if (source?.kind === "unavailable") throw new Error(source.reason);
@@ -39534,6 +39662,11 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
39534
39662
  `Using existing local Antigravity login for ${host}.
39535
39663
  `
39536
39664
  );
39665
+ if (host === "opencode" && accounts.some(
39666
+ (account) => account.enabled !== false && account.accountIneligible !== true && account.verificationRequired !== true && typeof account.refreshToken === "string" && account.refreshToken.length > 0
39667
+ )) {
39668
+ hasLocalPool = true;
39669
+ }
39537
39670
  if (host === "opencode" && claustrum.classifyHostSlot(slot, provider(host)) !== "login") {
39538
39671
  const account = accounts[0];
39539
39672
  await writeNativeSlot(
@@ -39564,7 +39697,10 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
39564
39697
  host,
39565
39698
  context
39566
39699
  );
39567
- if (host === "opencode") openCodeLogin = result;
39700
+ if (host === "opencode") {
39701
+ openCodeLogin = result;
39702
+ hasLocalPool = true;
39703
+ }
39568
39704
  },
39569
39705
  beforeRegister: async (host, mode, context) => {
39570
39706
  const needsOpenCode2 = host === "opencode" && context.opencodeGeneration !== "1";
@@ -39588,7 +39724,10 @@ Setup has not completed the OpenCode 2 native Google connection.
39588
39724
  },
39589
39725
  context
39590
39726
  );
39591
- if (needsOpenCode2) nativeNextStep(OPENCODE2_POOL_AUTH_LABEL);
39727
+ if (needsOpenCode2)
39728
+ nativeNextStep(
39729
+ hasLocalPool ? OPENCODE2_POOL_RECONNECT_LABEL : OPENCODE2_POOL_AUTH_LABEL
39730
+ );
39592
39731
  return;
39593
39732
  }
39594
39733
  if (await authority(host) !== "vault")
@@ -54278,8 +54417,8 @@ function createRequestExecutor(deps) {
54278
54417
  accountManager.getAccounts().map((entry) => entry.index).filter((index) => !eligibleIndexes.has(index))
54279
54418
  );
54280
54419
  if (modelUnavailableIndexes.size > 0) {
54281
- const candidates = accountManager.getEnabledAccounts().filter(
54282
- (entry) => eligibleIndexes === null || eligibleIndexes.has(entry.index)
54420
+ const candidates = accountManager.getAccounts().filter(
54421
+ (entry) => entry.enabled !== false && !entry.accountIneligible && !entry.verificationRequired && (eligibleIndexes === null || eligibleIndexes.has(entry.index))
54283
54422
  );
54284
54423
  if (candidates.length > 0 && candidates.every((entry) => modelUnavailableIndexes.has(entry.index))) {
54285
54424
  pushDebug(
@@ -54315,13 +54454,14 @@ function createRequestExecutor(deps) {
54315
54454
  if (account) {
54316
54455
  routingPlacementConsidered = true;
54317
54456
  if (firstPlacement && credentials.domain === "vault" && credentials.routingCandidate && model && isPrimaryVaultRequest(kind, init?.headers)) {
54318
- const candidates = accountManager.getEnabledAccounts().filter(
54319
- (row) => !excludedIndexes?.has(row.index) && !accountManager.isRateLimited(row, family, model) && !accountManager.isAccountCoolingDown(row) && !accountManager.isAccountOverSoftQuota(
54457
+ const candidates = accountManager.getAccounts().filter(
54458
+ (row) => row.enabled !== false && !row.accountIneligible && !row.verificationRequired && !excludedIndexes?.has(row.index) && !accountManager.isRateLimited(row, family, model) && !accountManager.isAccountCoolingDown(row) && !accountManager.isAccountOverSoftQuota(
54320
54459
  row,
54321
54460
  family,
54322
54461
  config.soft_quota_threshold_percent,
54323
54462
  softQuotaCacheTtlMs,
54324
- model
54463
+ model,
54464
+ excludedIndexes
54325
54465
  )
54326
54466
  ).map((row) => ({
54327
54467
  ...credentials.routingCandidate(row),
@@ -54367,26 +54507,68 @@ function createRequestExecutor(deps) {
54367
54507
  const blockedSince = allAccountsBlockedAt;
54368
54508
  const remainingWaitMs = () => maxWaitMs > 0 ? Math.max(0, maxWaitMs - (Date.now() - blockedSince)) : Number.POSITIVE_INFINITY;
54369
54509
  const quotaWins = remainingWaitMs() <= deadline.remainingMs();
54370
- if (accountManager.areAllAccountsOverSoftQuota(
54510
+ const eligibleCandidates = accountManager.getAccounts().filter(
54511
+ (entry) => entry.enabled !== false && !entry.accountIneligible && !entry.verificationRequired && !excludedIndexes?.has(entry.index)
54512
+ );
54513
+ const eligibleCandidateIndexes = new Set(
54514
+ eligibleCandidates.map((entry) => entry.index)
54515
+ );
54516
+ if (eligibleCandidateIndexes.size === 0) {
54517
+ waitPolicy.refusal = () => createNativeGoogleErrorResponse({
54518
+ status: 412,
54519
+ reason: "pool_unavailable"
54520
+ });
54521
+ return waitPolicy.refusal();
54522
+ }
54523
+ const threshold = config.soft_quota_threshold_percent;
54524
+ const combinedDelayMs = accountManager.getMinSelectableWaitTimeForFamily(
54371
54525
  family,
54372
- config.soft_quota_threshold_percent,
54526
+ threshold,
54373
54527
  softQuotaCacheTtlMs,
54374
- model
54375
- )) {
54376
- const threshold = config.soft_quota_threshold_percent;
54377
- const softQuotaWaitMs = accountManager.getMinWaitTimeForSoftQuota(
54528
+ model,
54529
+ eligibleCandidateIndexes
54530
+ );
54531
+ const waitMs = combinedDelayMs !== null && combinedDelayMs > 0 ? combinedDelayMs : 6e4;
54532
+ const allOverSoftQuota = accountManager.areAllAccountsOverSoftQuota(
54533
+ family,
54534
+ threshold,
54535
+ softQuotaCacheTtlMs,
54536
+ model,
54537
+ eligibleCandidateIndexes
54538
+ );
54539
+ const hasActiveCooldown = eligibleCandidates.some(
54540
+ (acc) => accountManager.isAccountCoolingDown(acc)
54541
+ );
54542
+ const applySoftQuota = eligibleCandidates.length > 1 && threshold < 100;
54543
+ const hasUnknownSoftReset = applySoftQuota && eligibleCandidates.some((acc) => {
54544
+ if (!accountManager.isAccountOverSoftQuota(
54545
+ acc,
54378
54546
  family,
54379
54547
  threshold,
54380
54548
  softQuotaCacheTtlMs,
54381
- model
54382
- );
54549
+ model,
54550
+ excludedIndexes
54551
+ )) {
54552
+ return false;
54553
+ }
54554
+ if (!model && family !== "claude") return true;
54555
+ const quotaGroup = resolveQuotaGroup(family, model, acc.cachedQuota);
54556
+ const groupData = acc.cachedQuota?.[quotaGroup];
54557
+ if (!groupData?.resetTime) return true;
54558
+ const ts = Date.parse(groupData.resetTime);
54559
+ return !Number.isFinite(ts) || ts <= Date.now();
54560
+ });
54561
+ const resetDeadline = !hasActiveCooldown && !hasUnknownSoftReset && combinedDelayMs !== null && combinedDelayMs > 0 ? Date.now() + combinedDelayMs : void 0;
54562
+ const remainingResetAfterMs = () => resetDeadline ? Math.max(0, resetDeadline - Date.now()) : void 0;
54563
+ if (allOverSoftQuota) {
54383
54564
  waitPolicy.refusal = quotaWins ? () => createNativeGoogleErrorResponse({
54384
54565
  status: 412,
54385
54566
  reason: "soft_quota",
54386
- resetAfterMs: softQuotaWaitMs
54567
+ resetAfterMs: remainingResetAfterMs()
54387
54568
  }) : void 0;
54388
- if (softQuotaWaitMs === null || remainingWaitMs() <= 0 || maxWaitMs > 0 && softQuotaWaitMs > maxWaitMs) {
54389
- const waitTimeFormatted = softQuotaWaitMs ? formatWaitTime(softQuotaWaitMs) : "unknown";
54569
+ if (combinedDelayMs === null || remainingWaitMs() <= 0 || maxWaitMs > 0 && waitMs > maxWaitMs) {
54570
+ const resetAfterMs = remainingResetAfterMs();
54571
+ const waitTimeFormatted = resetAfterMs !== void 0 && resetAfterMs > 0 ? formatWaitTime(resetAfterMs) : "unknown";
54390
54572
  await showToast(
54391
54573
  `All accounts over ${threshold}% quota threshold. Resets in ${waitTimeFormatted}.`,
54392
54574
  "error"
@@ -54394,28 +54576,26 @@ function createRequestExecutor(deps) {
54394
54576
  return createNativeGoogleErrorResponse({
54395
54577
  status: 412,
54396
54578
  reason: "soft_quota",
54397
- resetAfterMs: softQuotaWaitMs
54579
+ resetAfterMs: remainingResetAfterMs()
54398
54580
  });
54399
54581
  }
54400
54582
  pushDebug(
54401
- `all-over-soft-quota family=${family} accounts=${accountCount} waitMs=${softQuotaWaitMs}`
54583
+ `all-over-soft-quota family=${family} accounts=${accountCount} waitMs=${waitMs}`
54402
54584
  );
54403
54585
  if (!retryState.softQuotaToastShown()) {
54404
54586
  await showToast(
54405
- `All ${accountCount} account(s) over ${threshold}% quota. Waiting ${formatWaitTime(softQuotaWaitMs)}...`,
54587
+ `All ${accountCount} account(s) over ${threshold}% quota. Waiting ${formatWaitTime(waitMs)}...`,
54406
54588
  "warning"
54407
54589
  );
54408
54590
  retryState.markSoftQuotaToastShown();
54409
54591
  }
54410
- await sleep4(Math.min(softQuotaWaitMs, remainingWaitMs()), abortSignal);
54592
+ await sleep4(Math.min(waitMs, remainingWaitMs()), abortSignal);
54411
54593
  continue;
54412
54594
  }
54413
- const minWaitMs = accountManager.getMinWaitTimeForFamily(family, model);
54414
- const waitMs = minWaitMs || 6e4;
54415
54595
  waitPolicy.refusal = quotaWins ? () => createNativeGoogleErrorResponse({
54416
54596
  status: 412,
54417
54597
  reason: "pool_unavailable",
54418
- resetAfterMs: minWaitMs > 0 ? minWaitMs : void 0
54598
+ resetAfterMs: remainingResetAfterMs()
54419
54599
  }) : void 0;
54420
54600
  pushDebug(
54421
54601
  `all-rate-limited family=${family} accounts=${accountCount} waitMs=${waitMs}`
@@ -54440,9 +54620,8 @@ function createRequestExecutor(deps) {
54440
54620
  return createNativeGoogleErrorResponse({
54441
54621
  status: 412,
54442
54622
  reason: "pool_unavailable",
54443
- // Zero means the account manager has no future reset to report.
54444
- // The fallback sleep duration above is not a quota reset estimate.
54445
- resetAfterMs: minWaitMs > 0 ? minWaitMs : void 0
54623
+ // Fallback sleep duration gets NO reset metadata.
54624
+ resetAfterMs: remainingResetAfterMs()
54446
54625
  });
54447
54626
  }
54448
54627
  if (!retryState.rateLimitToastShown()) {