@cortexkit/opencode-antigravity-auth 3.0.28 → 3.0.29

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.
@@ -171,7 +171,7 @@
171
171
  "format": "esm"
172
172
  },
173
173
  "../core/dist/account-selector.js": {
174
- "bytes": 61373,
174
+ "bytes": 62829,
175
175
  "imports": [
176
176
  {
177
177
  "path": "../core/dist/fingerprint.js",
@@ -5952,8 +5952,13 @@
5952
5952
  "format": "esm"
5953
5953
  },
5954
5954
  "src/plugin/shared/request-services.ts": {
5955
- "bytes": 122076,
5955
+ "bytes": 127038,
5956
5956
  "imports": [
5957
+ {
5958
+ "path": "node:crypto",
5959
+ "kind": "import-statement",
5960
+ "external": true
5961
+ },
5957
5962
  {
5958
5963
  "path": "../core/dist/index.js",
5959
5964
  "kind": "import-statement",
@@ -6487,7 +6492,7 @@
6487
6492
  "imports": [],
6488
6493
  "exports": [],
6489
6494
  "inputs": {},
6490
- "bytes": 4781051
6495
+ "bytes": 4791055
6491
6496
  },
6492
6497
  "dist/index.js": {
6493
6498
  "imports": [
@@ -7636,6 +7641,11 @@
7636
7641
  "kind": "import-statement",
7637
7642
  "external": true
7638
7643
  },
7644
+ {
7645
+ "path": "node:crypto",
7646
+ "kind": "import-statement",
7647
+ "external": true
7648
+ },
7639
7649
  {
7640
7650
  "path": "node:path",
7641
7651
  "kind": "import-statement",
@@ -7694,7 +7704,7 @@
7694
7704
  "bytesInOutput": 11075
7695
7705
  },
7696
7706
  "../core/dist/account-selector.js": {
7697
- "bytesInOutput": 53453
7707
+ "bytesInOutput": 54555
7698
7708
  },
7699
7709
  "../core/dist/atomic-write.js": {
7700
7710
  "bytesInOutput": 905
@@ -8426,7 +8436,7 @@
8426
8436
  "bytesInOutput": 7661
8427
8437
  },
8428
8438
  "src/plugin/shared/request-services.ts": {
8429
- "bytesInOutput": 82069
8439
+ "bytesInOutput": 85584
8430
8440
  },
8431
8441
  "src/common-auth-embedded/routing-accessor/index.js": {
8432
8442
  "bytesInOutput": 3335
@@ -8480,7 +8490,7 @@
8480
8490
  "bytesInOutput": 0
8481
8491
  }
8482
8492
  },
8483
- "bytes": 2164052
8493
+ "bytes": 2168669
8484
8494
  }
8485
8495
  }
8486
8496
  }
package/dist/server.js CHANGED
@@ -6632,6 +6632,15 @@ function resolveQuotaGroup(family, model, cachedQuota) {
6632
6632
  }
6633
6633
  return family === "claude" ? "non-gemini" : "gemini";
6634
6634
  }
6635
+ function reportsArgon(account) {
6636
+ return account.cachedQuotaUpdatedAt !== void 0 && account.cachedQuota?.["gemini-argon"] !== void 0;
6637
+ }
6638
+ function preferArgonAccounts(accounts, model) {
6639
+ if (!model || getQuotaGroupForModel(model, true) !== "gemini-argon")
6640
+ return accounts;
6641
+ const reporting = accounts.filter(reportsArgon);
6642
+ return reporting.length > 0 ? reporting : accounts;
6643
+ }
6635
6644
  function isOverSoftQuotaThreshold(account, family, thresholdPercent, cacheTtlMs, now, model) {
6636
6645
  if (thresholdPercent >= 100)
6637
6646
  return false;
@@ -7106,7 +7115,10 @@ var init_account_selector = __esm({
7106
7115
  };
7107
7116
  });
7108
7117
  const currentIndex = this.getActiveIndex(family, identity3);
7109
- const selectedIndex = selectHybridAccount(accountsWithMetrics, tokenTracker, currentIndex, 50, this.now);
7118
+ const preferred2 = preferArgonAccounts(eligibleAccounts, model);
7119
+ const preferredIndexes = new Set(preferred2.map((row) => row.index));
7120
+ const select4 = (candidates) => selectHybridAccount(candidates, tokenTracker, currentIndex, 50, this.now);
7121
+ const selectedIndex = select4(accountsWithMetrics.filter((row) => preferredIndexes.has(row.index))) ?? select4(accountsWithMetrics);
7110
7122
  if (selectedIndex !== null) {
7111
7123
  const selected = this.accounts[selectedIndex];
7112
7124
  if (selected) {
@@ -7134,7 +7146,8 @@ var init_account_selector = __esm({
7134
7146
  offsetApplied[family] = true;
7135
7147
  }
7136
7148
  const current = this.getCurrentAccountForFamily(family, identity3);
7137
- if (current && !excludeIndexes?.has(current.index)) {
7149
+ const preferred = preferArgonAccounts(this.accounts.filter((row) => row.enabled !== false && !row.accountIneligible && !row.verificationRequired && !excludeIndexes?.has(row.index) && !isRateLimitedForFamily(row, family, this.now, model) && !this.isAccountCoolingDown(row) && !isOverSoftQuotaThreshold(row, family, effectiveSoftQuotaThreshold, softQuotaCacheTtlMs, this.now, model)), model);
7150
+ if (current && preferred.includes(current)) {
7138
7151
  clearExpiredRateLimits(current, this.now);
7139
7152
  const isLimitedForRequestedStyle = isRateLimitedForFamily(current, family, this.now, model);
7140
7153
  const isOverThreshold = isOverSoftQuotaThreshold(current, family, effectiveSoftQuotaThreshold, softQuotaCacheTtlMs, this.now, model);
@@ -7156,7 +7169,7 @@ var init_account_selector = __esm({
7156
7169
  clearExpiredRateLimits(account2, this.now);
7157
7170
  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);
7158
7171
  });
7159
- const available = this.preferAccountOutsideParent(allAvailable, family, identity3);
7172
+ const available = this.preferAccountOutsideParent(preferArgonAccounts(allAvailable, model), family, identity3);
7160
7173
  if (available.length === 0) {
7161
7174
  return null;
7162
7175
  }
@@ -44666,6 +44679,7 @@ async function retainResponseLifetime(response, cancellation) {
44666
44679
 
44667
44680
  // src/plugin/shared/request-services.ts
44668
44681
  init_dist();
44682
+ import { createHash as createHash17 } from "node:crypto";
44669
44683
 
44670
44684
  // src/common-auth-embedded/routing-accessor/index.js
44671
44685
  function isObject2(value) {
@@ -45492,6 +45506,7 @@ function isPrimaryVaultRequest(kind, headers) {
45492
45506
 
45493
45507
  // src/plugin/shared/request-services.ts
45494
45508
  var FIRST_RETRY_DELAY_MS = 1e3;
45509
+ var MODEL_UNAVAILABLE_TTL_MS = 60 * 60 * 1e3;
45495
45510
  function prepareAgyWireRequest(wire, request) {
45496
45511
  return wire.prepare(
45497
45512
  request.input,
@@ -45651,6 +45666,84 @@ function createRequestExecutor(deps) {
45651
45666
  } = deps;
45652
45667
  const retryState = createRetryState();
45653
45668
  const warmupState = createWarmupState();
45669
+ const modelAvailabilityNow = deps.modelAvailabilityNow ?? Date.now;
45670
+ const unavailableModels = /* @__PURE__ */ new Map();
45671
+ const accountKey = (account) => {
45672
+ if (credentials.domain === "vault") {
45673
+ const route = account.route;
45674
+ return route ? JSON.stringify([
45675
+ "vault",
45676
+ route.routeId,
45677
+ route.credentialId,
45678
+ route.accountIdentity
45679
+ ]) : account;
45680
+ }
45681
+ if (account.ref) {
45682
+ const ref = account.ref;
45683
+ return JSON.stringify([
45684
+ "local",
45685
+ ref.id,
45686
+ ref.credentialEpoch,
45687
+ ref.identity
45688
+ ]);
45689
+ }
45690
+ const refresh = credentials.toAuthDetails(account).refresh;
45691
+ return JSON.stringify([
45692
+ "pool-file",
45693
+ account.email?.toLowerCase(),
45694
+ createHash17("sha256").update(parseRefreshParts(refresh).refreshToken).digest("hex")
45695
+ ]);
45696
+ };
45697
+ const tierOf2 = (account) => JSON.stringify([account.capturedTierId, account.capturedPaidTierId]);
45698
+ const dropModel = (key, model, cause) => {
45699
+ const entries = unavailableModels.get(key);
45700
+ const entry = entries?.get(model);
45701
+ if (!entries || !entry) return;
45702
+ log17.debug("model-unavailable-memory-drop", {
45703
+ account: entry.label,
45704
+ model,
45705
+ cause
45706
+ });
45707
+ entries.delete(model);
45708
+ if (entries.size === 0) unavailableModels.delete(key);
45709
+ };
45710
+ const rememberedIndexes = (model) => {
45711
+ const rows = accountManager.getAccounts();
45712
+ const live = new Map(rows.map((row) => [accountKey(row), row]));
45713
+ const indexes = /* @__PURE__ */ new Set();
45714
+ for (const [key, entries] of unavailableModels) {
45715
+ const row = live.get(key);
45716
+ for (const [exactModel, entry] of entries) {
45717
+ const cause = !row ? "identity-replaced" : modelAvailabilityNow() - entry.recordedAt >= MODEL_UNAVAILABLE_TTL_MS ? "expired" : row.cachedQuotaUpdatedAt !== void 0 && row.cachedQuota?.["gemini-argon"] !== void 0 && (!entry.argonPool || row.cachedQuotaUpdatedAt !== entry.quotaUpdatedAt) ? "argon-pool" : row.cachedQuotaUpdatedAt !== void 0 && row.cachedQuotaUpdatedAt !== entry.quotaUpdatedAt ? "quota-reading" : tierOf2(row) !== entry.tier ? "tier-changed" : void 0;
45718
+ if (cause) dropModel(key, exactModel, cause);
45719
+ else if (row && exactModel === model) indexes.add(row.index);
45720
+ }
45721
+ }
45722
+ return indexes;
45723
+ };
45724
+ const captureAvailability = (account) => ({
45725
+ key: accountKey(account),
45726
+ quotaUpdatedAt: account.cachedQuotaUpdatedAt,
45727
+ tier: tierOf2(account),
45728
+ argonPool: account.cachedQuota?.["gemini-argon"] !== void 0,
45729
+ label: `Account ${account.index + 1}`
45730
+ });
45731
+ const rememberUnavailable = (snapshot2, model) => {
45732
+ const { key, ...entry } = snapshot2;
45733
+ let entries = unavailableModels.get(key);
45734
+ if (!entries) {
45735
+ entries = /* @__PURE__ */ new Map();
45736
+ unavailableModels.set(key, entries);
45737
+ }
45738
+ entries.set(model, {
45739
+ ...entry,
45740
+ recordedAt: modelAvailabilityNow()
45741
+ });
45742
+ log17.debug("model-unavailable-memory-record", {
45743
+ account: entry.label,
45744
+ model
45745
+ });
45746
+ };
45654
45747
  const shutdown = new AbortController();
45655
45748
  const inFlight = /* @__PURE__ */ new Set();
45656
45749
  const advisoryWork = /* @__PURE__ */ new Set();
@@ -45900,11 +45993,15 @@ function createRequestExecutor(deps) {
45900
45993
  const killedIndexes = eligibleIndexes === null ? void 0 : new Set(
45901
45994
  accountManager.getAccounts().map((entry) => entry.index).filter((index) => !eligibleIndexes.has(index))
45902
45995
  );
45903
- if (modelUnavailableIndexes.size > 0) {
45996
+ const unavailableIndexes = /* @__PURE__ */ new Set([
45997
+ ...modelUnavailableIndexes,
45998
+ ...rememberedIndexes(model)
45999
+ ]);
46000
+ if (unavailableIndexes.size > 0) {
45904
46001
  const candidates = accountManager.getAccounts().filter(
45905
46002
  (entry) => entry.enabled !== false && !entry.accountIneligible && !entry.verificationRequired && (eligibleIndexes === null || eligibleIndexes.has(entry.index))
45906
46003
  );
45907
- if (candidates.length > 0 && candidates.every((entry) => modelUnavailableIndexes.has(entry.index))) {
46004
+ if (candidates.length > 0 && candidates.every((entry) => unavailableIndexes.has(entry.index))) {
45908
46005
  pushDebug(
45909
46006
  `model-unavailable: all ${candidates.length} eligible account(s) skipped`
45910
46007
  );
@@ -45919,7 +46016,7 @@ function createRequestExecutor(deps) {
45919
46016
  });
45920
46017
  }
45921
46018
  }
45922
- const excludedIndexes = modelUnavailableIndexes.size === 0 ? killedIndexes : /* @__PURE__ */ new Set([...killedIndexes ?? [], ...modelUnavailableIndexes]);
46019
+ const excludedIndexes = unavailableIndexes.size === 0 ? killedIndexes : /* @__PURE__ */ new Set([...killedIndexes ?? [], ...unavailableIndexes]);
45923
46020
  const routingPresent = credentials.domain === "vault" && hasVaultRoutingAccessor();
45924
46021
  const firstPlacement = routingPresent && !routingPlacementConsidered && accountSessionIdentity && !accountManager.getCurrentAccountForFamily(
45925
46022
  family,
@@ -46510,6 +46607,7 @@ function createRequestExecutor(deps) {
46510
46607
  let tokenConsumed = false;
46511
46608
  let physicalAttemptStarted = false;
46512
46609
  try {
46610
+ const availabilitySnapshot = captureAvailability(account);
46513
46611
  let sendAdmission;
46514
46612
  let sendAccessToken;
46515
46613
  let sendProjectId;
@@ -46911,6 +47009,7 @@ function createRequestExecutor(deps) {
46911
47009
  void response.body?.cancel().catch(() => {
46912
47010
  });
46913
47011
  modelUnavailableIndexes.add(account.index);
47012
+ if (model) rememberUnavailable(availabilitySnapshot, model);
46914
47013
  skippedForModelUnavailable = true;
46915
47014
  shouldSwitchAccount = true;
46916
47015
  break;
@@ -47323,6 +47422,9 @@ function createRequestExecutor(deps) {
47323
47422
  while (advisoryWork.size > 0) await Promise.allSettled([...advisoryWork]);
47324
47423
  retryState.dispose();
47325
47424
  warmupState.dispose();
47425
+ for (const [key, entries] of unavailableModels) {
47426
+ for (const model of entries.keys()) dropModel(key, model, "disposed");
47427
+ }
47326
47428
  })();
47327
47429
  return drainPromise;
47328
47430
  }
@@ -47521,9 +47623,9 @@ init_dist();
47521
47623
 
47522
47624
  // src/plugin/background-quota-refresh.ts
47523
47625
  init_file_lock();
47524
- import { createHash as createHash17 } from "node:crypto";
47626
+ import { createHash as createHash18 } from "node:crypto";
47525
47627
  function quotaAccountIdentity2(refreshToken) {
47526
- return createHash17("sha256").update(refreshToken).digest("hex").slice(0, 16);
47628
+ return createHash18("sha256").update(refreshToken).digest("hex").slice(0, 16);
47527
47629
  }
47528
47630
  var MIN_INTERVAL_MS = 6e4;
47529
47631
  var STARTUP_JITTER_MS = 3e4;
@@ -52810,7 +52912,7 @@ function createGaAntigravityPlugin(overrides = {}) {
52810
52912
 
52811
52913
  // src/plugin/index.ts
52812
52914
  init_dist();
52813
- import { createHash as createHash23, randomUUID as randomUUID22 } from "node:crypto";
52915
+ import { createHash as createHash24, randomUUID as randomUUID22 } from "node:crypto";
52814
52916
  import { join as join39, resolve as resolve27 } from "node:path";
52815
52917
 
52816
52918
  // src/cli.ts
@@ -53113,7 +53215,7 @@ async function select2(terminal, items, options) {
53113
53215
  }
53114
53216
 
53115
53217
  // src/common-auth-embedded/claustrum/enrollment.js
53116
- import { createHash as createHash18, randomBytes as randomBytes6, randomUUID as randomUUID19 } from "node:crypto";
53218
+ import { createHash as createHash19, randomBytes as randomBytes6, randomUUID as randomUUID19 } from "node:crypto";
53117
53219
  import { constants as fsConstants2 } from "node:fs";
53118
53220
  import { chmod as chmod6, mkdir as mkdir15, open as open10, readFile as readFile14, realpath as realpath4, rename as rename12, stat as stat12, unlink as unlink11 } from "node:fs/promises";
53119
53221
  import { basename as basename6, dirname as dirname22, extname as extname2, isAbsolute as isAbsolute4, join as join26, resolve as resolve22 } from "node:path";
@@ -54437,7 +54539,7 @@ var ClaustrumEnrollmentManager2 = class {
54437
54539
  }
54438
54540
  if (!state.requestId) {
54439
54541
  try {
54440
- const requestSecretHash = createHash18("sha256").update(Buffer.from(state.requestSecret, "hex")).digest("hex");
54542
+ const requestSecretHash = createHash19("sha256").update(Buffer.from(state.requestSecret, "hex")).digest("hex");
54441
54543
  const proposed = await this.#client.enrollPropose({
54442
54544
  name: state.proposedName,
54443
54545
  requestSecretHash
@@ -57512,7 +57614,7 @@ function isTuiConnected(sessionId) {
57512
57614
  }
57513
57615
 
57514
57616
  // src/rpc/rpc-dir.ts
57515
- import { createHash as createHash19 } from "node:crypto";
57617
+ import { createHash as createHash20 } from "node:crypto";
57516
57618
  import { homedir as homedir13, tmpdir as tmpdir6 } from "node:os";
57517
57619
  import { isAbsolute as isAbsolute5, join as join34, resolve as resolve25 } from "node:path";
57518
57620
  var RPC_DIR_ENV = "ANTIGRAVITY_AUTH_RPC_DIR";
@@ -57521,7 +57623,7 @@ function getRpcDir(projectDirectory) {
57521
57623
  if (override) {
57522
57624
  return isAbsolute5(override) ? override : resolve25(projectDirectory, override);
57523
57625
  }
57524
- const projectHash = createHash19("sha256").update(resolve25(projectDirectory)).digest("hex").slice(0, 16);
57626
+ const projectHash = createHash20("sha256").update(resolve25(projectDirectory)).digest("hex").slice(0, 16);
57525
57627
  const stateHome = process.env.XDG_STATE_HOME ?? join34(homedir13(), ".local", "state");
57526
57628
  return join34(stateHome, "cortexkit", "antigravity-auth", "rpc", projectHash);
57527
57629
  }
@@ -57533,7 +57635,7 @@ function isSessionId(value) {
57533
57635
 
57534
57636
  // src/common-auth-embedded/rpc/port-file.js
57535
57637
  init_private_files2();
57536
- import { createHash as createHash20, randomUUID as randomUUID21 } from "node:crypto";
57638
+ import { createHash as createHash21, randomUUID as randomUUID21 } from "node:crypto";
57537
57639
  import { chmod as chmod7, mkdir as mkdir17, open as open12, readdir as readdir4, rename as rename14, rmdir as rmdir3, stat as stat15, unlink as unlink13 } from "node:fs/promises";
57538
57640
  import { join as join35, resolve as resolve26 } from "node:path";
57539
57641
  function isProbeablePid(pid) {
@@ -60755,13 +60857,13 @@ function createAccountCommandOAuthService(options) {
60755
60857
 
60756
60858
  // src/plugin/auth-loader.ts
60757
60859
  init_dist();
60758
- import { createHash as createHash21 } from "node:crypto";
60860
+ import { createHash as createHash22 } from "node:crypto";
60759
60861
  init_debug();
60760
60862
  init_logger4();
60761
60863
  init_storage();
60762
60864
  var log13 = createLogger4("auth-loader");
60763
60865
  function refreshTokenIdentity(refreshToken) {
60764
- return createHash21("sha256").update(refreshToken).digest("hex").slice(0, 16);
60866
+ return createHash22("sha256").update(refreshToken).digest("hex").slice(0, 16);
60765
60867
  }
60766
60868
  async function initializeDefaultFreshStore() {
60767
60869
  return initializeFreshAccountStoreFor(await loadCommonAuthStoreModules());
@@ -61503,7 +61605,7 @@ function registerAntigravityCommands(config) {
61503
61605
  }
61504
61606
 
61505
61607
  // src/plugin/command-data.ts
61506
- import { createHash as createHash22 } from "node:crypto";
61608
+ import { createHash as createHash23 } from "node:crypto";
61507
61609
  var QUOTA_GROUP_LABELS = {
61508
61610
  gemini: "Gemini",
61509
61611
  "non-gemini": "Non-Gemini",
@@ -61561,7 +61663,7 @@ function toCommandAccountRow(entry) {
61561
61663
  };
61562
61664
  }
61563
61665
  function quotaAccountIdentity3(refreshToken) {
61564
- return createHash22("sha256").update(refreshToken).digest("hex").slice(0, 16);
61666
+ return createHash23("sha256").update(refreshToken).digest("hex").slice(0, 16);
61565
61667
  }
61566
61668
  function projectCommandAccountRows(storage) {
61567
61669
  if (!storage) return [];
@@ -62433,7 +62535,7 @@ init_storage();
62433
62535
  init_vault_custody();
62434
62536
  var logger2 = createLogger4("plugin");
62435
62537
  function quotaAccountIdentity4(refreshToken) {
62436
- return createHash23("sha256").update(refreshToken).digest("hex").slice(0, 16);
62538
+ return createHash24("sha256").update(refreshToken).digest("hex").slice(0, 16);
62437
62539
  }
62438
62540
  function registerQuotaManagerProducer(lifecycle, quotaManager) {
62439
62541
  lifecycle.register({ dispose: () => quotaManager.dispose() }, "producer");