@cortexkit/opencode-antigravity-auth 3.0.23 → 3.0.24

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 +148 -41
  5. package/dist/index.js.map +3 -3
  6. package/dist/index.meta.json +12 -12
  7. package/dist/server.js +281 -71
  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 +3 -0
  25. package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
  26. package/dist/src/plugin/shared/request-services.js +17 -3
  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 +3 -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": 58735,
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": 68295,
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": 3173161
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) {
@@ -7286,7 +7289,7 @@ var init_account_selector = __esm({
7286
7289
  getFreshAccountsForQuota(quotaKey, family, model) {
7287
7290
  return this.accounts.filter((acc) => {
7288
7291
  clearExpiredRateLimits(acc, this.now);
7289
- return acc.enabled !== false && this.isFreshForQuota(acc, quotaKey) && !isRateLimitedForFamily(acc, family, this.now, model) && !this.isAccountCoolingDown(acc);
7292
+ return acc.enabled !== false && acc.accountIneligible !== true && acc.verificationRequired !== true && this.isFreshForQuota(acc, quotaKey) && !isRateLimitedForFamily(acc, family, this.now, model) && !this.isAccountCoolingDown(acc);
7290
7293
  });
7291
7294
  }
7292
7295
  isRateLimited(account, family, model) {
@@ -7422,12 +7425,40 @@ var init_account_selector = __esm({
7422
7425
  }
7423
7426
  return true;
7424
7427
  }
7425
- getMinWaitTimeForFamily(family, model) {
7428
+ /**
7429
+ * Calculates the minimum wait time in milliseconds across eligible accounts
7430
+ * for a given model family (and optional model).
7431
+ *
7432
+ * Note: Returning `0` can mean either:
7433
+ * 1. No eligible candidates exist in the pool, OR
7434
+ * 2. At least one eligible candidate is immediately usable without waiting.
7435
+ * Callers must distinguish "no eligible candidates" from "zero wait time"
7436
+ * by inspecting candidate pool availability / eligibility directly.
7437
+ *
7438
+ * @param family Model family (e.g., 'claude', 'gemini')
7439
+ * @param model Optional model name for per-model rate limits
7440
+ * @param eligibleIndexes Optional set of account indexes permitted for this request
7441
+ * @param includeCooldown Whether to factor in `coolingDownUntil` alongside quota rate limits
7442
+ * @returns Minimum wait duration in milliseconds, or 0 if immediately usable or no candidates
7443
+ */
7444
+ getMinWaitTimeForFamily(family, model, eligibleIndexes, includeCooldown = false) {
7426
7445
  const now = this.now();
7427
- const waits = this.accounts.filter((a) => a.enabled !== false).map((a) => {
7446
+ const waits = this.accounts.filter((a) => {
7447
+ if (a.enabled === false)
7448
+ return false;
7449
+ if (a.accountIneligible === true || a.verificationRequired === true) {
7450
+ return false;
7451
+ }
7452
+ if (eligibleIndexes !== void 0 && eligibleIndexes !== null) {
7453
+ if (!eligibleIndexes.has(a.index))
7454
+ return false;
7455
+ }
7456
+ return true;
7457
+ }).map((a) => {
7428
7458
  clearExpiredRateLimits(a, this.now);
7429
7459
  const modelReset = model ? a.rateLimitResetTimes[getQuotaKey(family, model)] : void 0;
7430
- return Math.max(0, (a.rateLimitResetTimes[family] ?? now) - now, (modelReset ?? now) - now);
7460
+ const cooldownWait = includeCooldown && a.coolingDownUntil !== void 0 && a.coolingDownUntil > now ? a.coolingDownUntil - now : 0;
7461
+ return Math.max(0, (a.rateLimitResetTimes[family] ?? now) - now, (modelReset ?? now) - now, cooldownWait);
7431
7462
  });
7432
7463
  return waits.length > 0 ? Math.min(...waits) : 0;
7433
7464
  }
@@ -7622,36 +7653,42 @@ var init_account_selector = __esm({
7622
7653
  }
7623
7654
  return oldest;
7624
7655
  }
7625
- areAllAccountsOverSoftQuota(family, thresholdPercent, cacheTtlMs, model) {
7656
+ /**
7657
+ * Check whether all eligible accounts (more than 1) are currently over the soft-quota threshold.
7658
+ * Returns false if thresholdPercent >= 100 or if <= 1 eligible account remains.
7659
+ */
7660
+ areAllAccountsOverSoftQuota(family, thresholdPercent, cacheTtlMs, model, eligibleIndexes) {
7626
7661
  if (thresholdPercent >= 100)
7627
7662
  return false;
7628
- const enabled = this.accounts.filter((a) => a.enabled !== false);
7629
- if (enabled.length <= 1)
7663
+ const eligible = this.accounts.filter((a) => a.enabled !== false && a.accountIneligible !== true && a.verificationRequired !== true && (eligibleIndexes == null || eligibleIndexes.has(a.index)));
7664
+ if (eligible.length <= 1)
7630
7665
  return false;
7631
- return enabled.every((a) => isOverSoftQuotaThreshold(a, family, thresholdPercent, cacheTtlMs, this.now, model));
7666
+ return eligible.every((a) => isOverSoftQuotaThreshold(a, family, thresholdPercent, cacheTtlMs, this.now, model));
7632
7667
  }
7633
7668
  /**
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.
7669
+ * Get minimum wait time until any eligible account's soft quota resets.
7670
+ * Operates over the eligible subset (enabled, non-ineligible, non-verification-required,
7671
+ * and present in `eligibleIndexes` when provided).
7672
+ * Returns null if no eligible accounts remain or no resetTime data is available.
7673
+ * Returns 0 if only 1 eligible account exists or any eligible account is below threshold.
7674
+ * Returns the minimum resetTime across all over-threshold eligible accounts.
7638
7675
  */
7639
- getMinWaitTimeForSoftQuota(family, thresholdPercent, cacheTtlMs, model) {
7676
+ getMinWaitTimeForSoftQuota(family, thresholdPercent, cacheTtlMs, model, eligibleIndexes) {
7640
7677
  if (thresholdPercent >= 100)
7641
7678
  return 0;
7642
- const enabled = this.accounts.filter((a) => a.enabled !== false);
7643
- if (enabled.length === 0)
7679
+ const eligible = this.accounts.filter((a) => a.enabled !== false && a.accountIneligible !== true && a.verificationRequired !== true && (eligibleIndexes == null || eligibleIndexes.has(a.index)));
7680
+ if (eligible.length === 0)
7644
7681
  return null;
7645
- if (enabled.length === 1)
7682
+ if (eligible.length === 1)
7646
7683
  return 0;
7647
- const available = enabled.filter((a) => !isOverSoftQuotaThreshold(a, family, thresholdPercent, cacheTtlMs, this.now, model));
7684
+ const available = eligible.filter((a) => !isOverSoftQuotaThreshold(a, family, thresholdPercent, cacheTtlMs, this.now, model));
7648
7685
  if (available.length > 0)
7649
7686
  return 0;
7650
7687
  if (!model && family !== "claude")
7651
7688
  return null;
7652
7689
  const now = this.now();
7653
7690
  const waitTimes = [];
7654
- for (const acc of enabled) {
7691
+ for (const acc of eligible) {
7655
7692
  const quotaGroup = resolveQuotaGroup(family, model, acc.cachedQuota);
7656
7693
  const groupData = acc.cachedQuota?.[quotaGroup];
7657
7694
  if (groupData?.resetTime) {
@@ -9656,8 +9693,24 @@ var init_account_manager = __esm({
9656
9693
  expires: account.expires
9657
9694
  };
9658
9695
  }
9659
- getMinWaitTimeForFamily(family, model) {
9660
- return this.selection.getMinWaitTimeForFamily(family, model);
9696
+ /**
9697
+ * Calculates the minimum wait time in milliseconds across eligible accounts
9698
+ * for a given model family (and optional model).
9699
+ *
9700
+ * Note: Returning `0` can mean either:
9701
+ * 1. No eligible candidates exist in the pool, OR
9702
+ * 2. At least one eligible candidate is immediately usable without waiting.
9703
+ * Callers must distinguish "no eligible candidates" from "zero wait time"
9704
+ * by inspecting candidate pool availability / eligibility directly.
9705
+ *
9706
+ * @param family Model family (e.g., 'claude', 'gemini')
9707
+ * @param model Optional model name for per-model rate limits
9708
+ * @param eligibleIndexes Optional set of account indexes permitted for this request
9709
+ * @param includeCooldown Whether to factor in `coolingDownUntil` alongside quota rate limits
9710
+ * @returns Minimum wait duration in milliseconds, or 0 if immediately usable or no candidates
9711
+ */
9712
+ getMinWaitTimeForFamily(family, model, eligibleIndexes, includeCooldown = false) {
9713
+ return this.selection.getMinWaitTimeForFamily(family, model, eligibleIndexes, includeCooldown);
9661
9714
  }
9662
9715
  getAccounts() {
9663
9716
  return this.selection.getAccounts();
@@ -10000,17 +10053,23 @@ var init_account_manager = __esm({
10000
10053
  getOldestQuotaCacheAge() {
10001
10054
  return this.selection.getOldestQuotaCacheAge();
10002
10055
  }
10003
- areAllAccountsOverSoftQuota(family, thresholdPercent, cacheTtlMs, model) {
10004
- return this.selection.areAllAccountsOverSoftQuota(family, thresholdPercent, cacheTtlMs, model);
10056
+ /**
10057
+ * Check whether all eligible accounts (more than 1) are currently over the soft-quota threshold.
10058
+ * Returns false if thresholdPercent >= 100 or if <= 1 eligible account remains.
10059
+ */
10060
+ areAllAccountsOverSoftQuota(family, thresholdPercent, cacheTtlMs, model, eligibleIndexes) {
10061
+ return this.selection.areAllAccountsOverSoftQuota(family, thresholdPercent, cacheTtlMs, model, eligibleIndexes);
10005
10062
  }
10006
10063
  /**
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.
10064
+ * Get minimum wait time until any eligible account's soft quota resets.
10065
+ * Operates over the eligible subset (enabled, non-ineligible, non-verification-required,
10066
+ * and present in `eligibleIndexes` when provided).
10067
+ * Returns null if no eligible accounts remain or no resetTime data is available.
10068
+ * Returns 0 if only 1 eligible account exists or any eligible account is below threshold.
10069
+ * Returns the minimum resetTime across all over-threshold eligible accounts.
10011
10070
  */
10012
- getMinWaitTimeForSoftQuota(family, thresholdPercent, cacheTtlMs, model) {
10013
- return this.selection.getMinWaitTimeForSoftQuota(family, thresholdPercent, cacheTtlMs, model);
10071
+ getMinWaitTimeForSoftQuota(family, thresholdPercent, cacheTtlMs, model, eligibleIndexes) {
10072
+ return this.selection.getMinWaitTimeForSoftQuota(family, thresholdPercent, cacheTtlMs, model, eligibleIndexes);
10014
10073
  }
10015
10074
  };
10016
10075
  }
@@ -36193,6 +36252,7 @@ import { join as join24, resolve as resolve20 } from "node:path";
36193
36252
  // src/auth-method-labels.ts
36194
36253
  var OPENCODE2_POOL_AUTH_LABEL = "Google (antigravity-auth pool, browser)";
36195
36254
  var OPENCODE2_VAULT_AUTH_LABEL = "Use approved Antigravity vault";
36255
+ var OPENCODE2_POOL_RECONNECT_LABEL = "Use existing local Antigravity pool";
36196
36256
 
36197
36257
  // src/common-auth-embedded/auth-menu/ansi.js
36198
36258
  var ANSI2 = {
@@ -39467,6 +39527,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
39467
39527
  }
39468
39528
  };
39469
39529
  let openCodeLogin;
39530
+ let hasLocalPool = false;
39470
39531
  const manifest = JSON.parse(
39471
39532
  await readFile16(new URL("../package.json", import.meta.url), "utf8")
39472
39533
  );
@@ -39522,7 +39583,23 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
39522
39583
  },
39523
39584
  signInLocal: async (host, context) => {
39524
39585
  await assertLocal(host, context);
39525
- if (host === "opencode" && context.opencodeGeneration === "2") return;
39586
+ if (host === "opencode" && context.opencodeGeneration === "2") {
39587
+ if (!forceLogin) {
39588
+ try {
39589
+ const source2 = await deps.accountStore.read(
39590
+ deps.accountStore.legacyPath()
39591
+ );
39592
+ const candidateAccounts = source2.kind === "store" ? source2.accounts : source2.kind === "legacy" ? (await deps.loadAccounts())?.accounts ?? [] : [];
39593
+ if (candidateAccounts.some(
39594
+ (account) => account.enabled !== false && account.accountIneligible !== true && account.verificationRequired !== true && typeof account.refreshToken === "string" && account.refreshToken.length > 0
39595
+ )) {
39596
+ hasLocalPool = true;
39597
+ }
39598
+ } catch {
39599
+ }
39600
+ }
39601
+ return;
39602
+ }
39526
39603
  const slot = (await nativeAuth(host, context))[provider(host)];
39527
39604
  const source = host === "opencode" ? await deps.accountStore.read(deps.accountStore.legacyPath()) : void 0;
39528
39605
  if (source?.kind === "unavailable") throw new Error(source.reason);
@@ -39534,6 +39611,11 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
39534
39611
  `Using existing local Antigravity login for ${host}.
39535
39612
  `
39536
39613
  );
39614
+ if (host === "opencode" && accounts.some(
39615
+ (account) => account.enabled !== false && account.accountIneligible !== true && account.verificationRequired !== true && typeof account.refreshToken === "string" && account.refreshToken.length > 0
39616
+ )) {
39617
+ hasLocalPool = true;
39618
+ }
39537
39619
  if (host === "opencode" && claustrum.classifyHostSlot(slot, provider(host)) !== "login") {
39538
39620
  const account = accounts[0];
39539
39621
  await writeNativeSlot(
@@ -39564,7 +39646,10 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
39564
39646
  host,
39565
39647
  context
39566
39648
  );
39567
- if (host === "opencode") openCodeLogin = result;
39649
+ if (host === "opencode") {
39650
+ openCodeLogin = result;
39651
+ hasLocalPool = true;
39652
+ }
39568
39653
  },
39569
39654
  beforeRegister: async (host, mode, context) => {
39570
39655
  const needsOpenCode2 = host === "opencode" && context.opencodeGeneration !== "1";
@@ -39588,7 +39673,10 @@ Setup has not completed the OpenCode 2 native Google connection.
39588
39673
  },
39589
39674
  context
39590
39675
  );
39591
- if (needsOpenCode2) nativeNextStep(OPENCODE2_POOL_AUTH_LABEL);
39676
+ if (needsOpenCode2)
39677
+ nativeNextStep(
39678
+ hasLocalPool ? OPENCODE2_POOL_RECONNECT_LABEL : OPENCODE2_POOL_AUTH_LABEL
39679
+ );
39592
39680
  return;
39593
39681
  }
39594
39682
  if (await authority(host) !== "vault")
@@ -54367,18 +54455,32 @@ function createRequestExecutor(deps) {
54367
54455
  const blockedSince = allAccountsBlockedAt;
54368
54456
  const remainingWaitMs = () => maxWaitMs > 0 ? Math.max(0, maxWaitMs - (Date.now() - blockedSince)) : Number.POSITIVE_INFINITY;
54369
54457
  const quotaWins = remainingWaitMs() <= deadline.remainingMs();
54458
+ const eligibleCandidateIndexes = new Set(
54459
+ accountManager.getAccounts().filter(
54460
+ (entry) => entry.enabled !== false && !entry.accountIneligible && !entry.verificationRequired && !excludedIndexes?.has(entry.index)
54461
+ ).map((entry) => entry.index)
54462
+ );
54463
+ if (eligibleCandidateIndexes.size === 0) {
54464
+ waitPolicy.refusal = () => createNativeGoogleErrorResponse({
54465
+ status: 412,
54466
+ reason: "pool_unavailable"
54467
+ });
54468
+ return waitPolicy.refusal();
54469
+ }
54370
54470
  if (accountManager.areAllAccountsOverSoftQuota(
54371
54471
  family,
54372
54472
  config.soft_quota_threshold_percent,
54373
54473
  softQuotaCacheTtlMs,
54374
- model
54474
+ model,
54475
+ eligibleCandidateIndexes
54375
54476
  )) {
54376
54477
  const threshold = config.soft_quota_threshold_percent;
54377
54478
  const softQuotaWaitMs = accountManager.getMinWaitTimeForSoftQuota(
54378
54479
  family,
54379
54480
  threshold,
54380
54481
  softQuotaCacheTtlMs,
54381
- model
54482
+ model,
54483
+ eligibleCandidateIndexes
54382
54484
  );
54383
54485
  waitPolicy.refusal = quotaWins ? () => createNativeGoogleErrorResponse({
54384
54486
  status: 412,
@@ -54410,7 +54512,12 @@ function createRequestExecutor(deps) {
54410
54512
  await sleep4(Math.min(softQuotaWaitMs, remainingWaitMs()), abortSignal);
54411
54513
  continue;
54412
54514
  }
54413
- const minWaitMs = accountManager.getMinWaitTimeForFamily(family, model);
54515
+ const minWaitMs = accountManager.getMinWaitTimeForFamily(
54516
+ family,
54517
+ model,
54518
+ eligibleCandidateIndexes,
54519
+ true
54520
+ );
54414
54521
  const waitMs = minWaitMs || 6e4;
54415
54522
  waitPolicy.refusal = quotaWins ? () => createNativeGoogleErrorResponse({
54416
54523
  status: 412,