@expiren/opencode-antigravity-auth 1.6.32 → 1.6.34

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.
package/dist/index.js CHANGED
@@ -9049,6 +9049,8 @@ var AccountManager = class _AccountManager {
9049
9049
  savePending = false;
9050
9050
  saveTimeout = null;
9051
9051
  savePromiseResolvers = [];
9052
+ sessionStartTime = Date.now();
9053
+ sessionRequestCounts = /* @__PURE__ */ new Map();
9052
9054
  static async loadFromDisk(authFallback) {
9053
9055
  const stored = await loadAccounts();
9054
9056
  return new _AccountManager(authFallback, stored);
@@ -9089,6 +9091,7 @@ var AccountManager = class _AccountManager {
9089
9091
  fingerprintHistory: acc.fingerprintHistory ?? [],
9090
9092
  cachedQuota: acc.cachedQuota,
9091
9093
  cachedQuotaUpdatedAt: acc.cachedQuotaUpdatedAt,
9094
+ dailyRequestCounts: acc.dailyRequestCounts,
9092
9095
  verificationRequired: acc.verificationRequired,
9093
9096
  verificationRequiredAt: acc.verificationRequiredAt,
9094
9097
  verificationRequiredReason: acc.verificationRequiredReason,
@@ -9579,6 +9582,7 @@ var AccountManager = class _AccountManager {
9579
9582
  fingerprintHistory: a.fingerprintHistory?.length ? a.fingerprintHistory : void 0,
9580
9583
  cachedQuota: a.cachedQuota && Object.keys(a.cachedQuota).length > 0 ? a.cachedQuota : void 0,
9581
9584
  cachedQuotaUpdatedAt: a.cachedQuotaUpdatedAt,
9585
+ dailyRequestCounts: a.dailyRequestCounts,
9582
9586
  verificationRequired: a.verificationRequired,
9583
9587
  verificationRequiredAt: a.verificationRequiredAt,
9584
9588
  verificationRequiredReason: a.verificationRequiredReason,
@@ -9701,6 +9705,98 @@ var AccountManager = class _AccountManager {
9701
9705
  account.cachedQuotaUpdatedAt = nowMs();
9702
9706
  }
9703
9707
  }
9708
+ /**
9709
+ * Record a successful API request for an account.
9710
+ * Tracks per model family with daily reset.
9711
+ */
9712
+ recordRequest(accountIndex, family) {
9713
+ const account = this.accounts[accountIndex];
9714
+ if (!account) return;
9715
+ const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
9716
+ if (!account.dailyRequestCounts || account.dailyRequestCounts.date !== today) {
9717
+ account.dailyRequestCounts = { date: today, claude: 0, gemini: 0 };
9718
+ }
9719
+ account.dailyRequestCounts[family]++;
9720
+ account.lastUsed = nowMs();
9721
+ this.recordSessionRequest(accountIndex, family);
9722
+ }
9723
+ /**
9724
+ * Get request counts for an account for today.
9725
+ */
9726
+ getDailyRequestCounts(accountIndex) {
9727
+ const account = this.accounts[accountIndex];
9728
+ if (!account?.dailyRequestCounts) return null;
9729
+ const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
9730
+ if (account.dailyRequestCounts.date !== today) return null;
9731
+ return { ...account.dailyRequestCounts };
9732
+ }
9733
+ /**
9734
+ * Get total daily request counts across all accounts for a model family.
9735
+ */
9736
+ getTotalDailyRequests(family) {
9737
+ const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
9738
+ let total = 0;
9739
+ for (const account of this.accounts) {
9740
+ if (account.dailyRequestCounts?.date === today) {
9741
+ total += account.dailyRequestCounts[family];
9742
+ }
9743
+ }
9744
+ return total;
9745
+ }
9746
+ /**
9747
+ * Get a summary of daily request distribution across accounts.
9748
+ * Returns accounts sorted by request count (descending).
9749
+ */
9750
+ getDailyRequestSummary(family) {
9751
+ const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
9752
+ const result = [];
9753
+ for (const account of this.accounts) {
9754
+ const count = account.dailyRequestCounts?.date === today ? account.dailyRequestCounts[family] : 0;
9755
+ if (count > 0) {
9756
+ result.push({ index: account.index, email: account.email, count });
9757
+ }
9758
+ }
9759
+ return result.sort((a, b) => b.count - a.count);
9760
+ }
9761
+ /**
9762
+ * Record a request for the current session (in-memory only).
9763
+ */
9764
+ recordSessionRequest(accountIndex, family) {
9765
+ const key = String(accountIndex);
9766
+ const current = this.sessionRequestCounts.get(key) ?? { claude: 0, gemini: 0 };
9767
+ current[family]++;
9768
+ this.sessionRequestCounts.set(key, current);
9769
+ }
9770
+ /**
9771
+ * Get a summary of the current session's request usage.
9772
+ */
9773
+ getSessionSummary() {
9774
+ const durationMs = Date.now() - this.sessionStartTime;
9775
+ const durationMinutes = Math.round(durationMs / 6e4);
9776
+ const durationHours = durationMs / 36e5;
9777
+ let totalClaude = 0;
9778
+ let totalGemini = 0;
9779
+ const perAccount = [];
9780
+ for (const [key, counts] of this.sessionRequestCounts) {
9781
+ const idx = Number(key);
9782
+ const account = this.accounts[idx];
9783
+ totalClaude += counts.claude;
9784
+ totalGemini += counts.gemini;
9785
+ if (counts.claude > 0 || counts.gemini > 0) {
9786
+ perAccount.push({ index: idx, email: account?.email, claude: counts.claude, gemini: counts.gemini });
9787
+ }
9788
+ }
9789
+ const totalRequests = totalClaude + totalGemini;
9790
+ const requestsPerHour = durationHours > 0 ? Math.round(totalRequests / durationHours) : 0;
9791
+ return {
9792
+ durationMinutes,
9793
+ totalClaude,
9794
+ totalGemini,
9795
+ requestsPerHour,
9796
+ accountsUsed: perAccount.length,
9797
+ perAccount: perAccount.sort((a, b) => b.claude + b.gemini - (a.claude + a.gemini))
9798
+ };
9799
+ }
9704
9800
  isAccountOverSoftQuota(account, family, thresholdPercent, cacheTtlMs, model) {
9705
9801
  return isOverSoftQuotaThreshold(account, family, thresholdPercent, cacheTtlMs, model);
9706
9802
  }
@@ -11972,6 +12068,16 @@ var createAntigravityPlugin = (providerId) => async ({ client, directory }) => {
11972
12068
  const eventHandler = async (input2) => {
11973
12069
  await updateChecker.event(input2);
11974
12070
  if (input2.event.type === "session.created") {
12071
+ const prevSummary = activeAccountManager?.getSessionSummary();
12072
+ if (prevSummary && (prevSummary.totalClaude > 0 || prevSummary.totalGemini > 0)) {
12073
+ log10.debug("prev-session-quota-summary", {
12074
+ durationMinutes: prevSummary.durationMinutes,
12075
+ totalClaude: prevSummary.totalClaude,
12076
+ totalGemini: prevSummary.totalGemini,
12077
+ requestsPerHour: prevSummary.requestsPerHour,
12078
+ accountsUsed: prevSummary.accountsUsed
12079
+ });
12080
+ }
11975
12081
  const props = input2.event.properties;
11976
12082
  if (props?.info?.parentID) {
11977
12083
  isChildSession = true;
@@ -12592,6 +12698,11 @@ var createAntigravityPlugin = (providerId) => async ({ client, directory }) => {
12592
12698
  }
12593
12699
  const response = await fetch(prepared.request, prepared.init);
12594
12700
  apiRequestCount++;
12701
+ accountManager.recordRequest(account.index, family);
12702
+ const requestCounts = accountManager.getDailyRequestCounts(account.index);
12703
+ if (requestCounts) {
12704
+ pushDebug(`[Quota] account=${account.index} ${family}_today=${requestCounts[family]} total_${family}_today=${accountManager.getTotalDailyRequests(family)}`);
12705
+ }
12595
12706
  pushDebug(`status=${response.status} ${response.statusText} (api_request #${apiRequestCount})`);
12596
12707
  if (response.status === 429 || response.status === 503 || response.status === 529) {
12597
12708
  if (tokenConsumed) {
@@ -12877,6 +12988,29 @@ Alternatively, you can:
12877
12988
  if (apiRequestCount > 1) {
12878
12989
  pushDebug(`[Quota] Total API requests for this user message: ${apiRequestCount} (${apiRequestCount - 1} retries)`);
12879
12990
  }
12991
+ const dailyCounts = accountManager.getDailyRequestCounts(account.index);
12992
+ if (dailyCounts) {
12993
+ pushDebug(`[Quota] Account ${account.index} (${account.email ?? "unknown"}) today: claude=${dailyCounts.claude} gemini=${dailyCounts.gemini}`);
12994
+ }
12995
+ const totalToday = accountManager.getTotalDailyRequests(family);
12996
+ pushDebug(`[Quota] Total ${family} requests today (all accounts): ${totalToday}`);
12997
+ const cachedQuota = account.cachedQuota;
12998
+ if (cachedQuota) {
12999
+ const quotaFamily = family === "claude" ? "claude" : "gemini-flash";
13000
+ const groupQuota = cachedQuota[quotaFamily];
13001
+ if (groupQuota?.remainingFraction != null) {
13002
+ const pct = Math.round(groupQuota.remainingFraction * 100);
13003
+ pushDebug(`[Quota] Account ${account.index} cached ${quotaFamily} remaining: ${pct}%${groupQuota.resetTime ? ` (resets ${groupQuota.resetTime})` : ""}`);
13004
+ }
13005
+ }
13006
+ const sessionSummary = accountManager.getSessionSummary();
13007
+ if (sessionSummary.durationMinutes >= 1) {
13008
+ const familyTotal = family === "claude" ? sessionSummary.totalClaude : sessionSummary.totalGemini;
13009
+ if (familyTotal > 0) {
13010
+ const ratePerHour = sessionSummary.requestsPerHour;
13011
+ pushDebug(`[Quota] Session: ${sessionSummary.durationMinutes}min, ${familyTotal} ${family} reqs, ~${ratePerHour} reqs/hr, ${sessionSummary.accountsUsed} accounts used`);
13012
+ }
13013
+ }
12880
13014
  return transformedResponse;
12881
13015
  } catch (error) {
12882
13016
  if (tokenConsumed) {