@expiren/opencode-antigravity-auth 1.6.31 → 1.6.32

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
@@ -1825,20 +1825,45 @@ function buildModelBreakdown(accounts) {
1825
1825
  let maxResetMs;
1826
1826
  for (const acc of accounts) {
1827
1827
  if (acc.enabled === false) continue;
1828
- const group = acc.cachedQuota?.[key];
1829
- if (!group || typeof group.remainingFraction !== "number") continue;
1830
- if (group.remainingFraction <= 0) {
1831
- const resetMs = parseResetTimeToMs2(group.resetTime);
1832
- if (resetMs !== null && resetMs > 0) {
1833
- exhaustedCount++;
1834
- if (maxResetMs === void 0 || resetMs > maxResetMs) {
1835
- maxResetMs = resetMs;
1828
+ if (acc.cachedPerModelQuota && acc.cachedPerModelQuota.length > 0) {
1829
+ const modelsInGroup = acc.cachedPerModelQuota.filter((m) => m.group === key);
1830
+ if (modelsInGroup.length === 0) continue;
1831
+ const allExhausted = modelsInGroup.every((m) => m.remainingFraction <= 0);
1832
+ if (allExhausted) {
1833
+ const freshExhausted = modelsInGroup.some((m) => {
1834
+ const resetMs = parseResetTimeToMs2(m.resetTime);
1835
+ return resetMs !== null && resetMs > 0;
1836
+ });
1837
+ if (freshExhausted) {
1838
+ exhaustedCount++;
1839
+ for (const m of modelsInGroup) {
1840
+ const resetMs = parseResetTimeToMs2(m.resetTime);
1841
+ if (resetMs !== null && resetMs > 0 && (maxResetMs === void 0 || resetMs > maxResetMs)) {
1842
+ maxResetMs = resetMs;
1843
+ }
1844
+ }
1845
+ } else {
1846
+ availableCount++;
1836
1847
  }
1837
1848
  } else {
1838
1849
  availableCount++;
1839
1850
  }
1840
1851
  } else {
1841
- availableCount++;
1852
+ const group = acc.cachedQuota?.[key];
1853
+ if (!group || typeof group.remainingFraction !== "number") continue;
1854
+ if (group.remainingFraction <= 0) {
1855
+ const resetMs = parseResetTimeToMs2(group.resetTime);
1856
+ if (resetMs !== null && resetMs > 0) {
1857
+ exhaustedCount++;
1858
+ if (maxResetMs === void 0 || resetMs > maxResetMs) {
1859
+ maxResetMs = resetMs;
1860
+ }
1861
+ } else {
1862
+ availableCount++;
1863
+ }
1864
+ } else {
1865
+ availableCount++;
1866
+ }
1842
1867
  }
1843
1868
  }
1844
1869
  if (exhaustedCount > 0 || availableCount > 0) {
@@ -2370,6 +2395,7 @@ async function promptLoginMode(existingAccounts) {
2370
2395
  cooldownMs: acc.cooldownMs,
2371
2396
  cooldownReason: acc.cooldownReason,
2372
2397
  cachedQuota: acc.cachedQuota,
2398
+ cachedPerModelQuota: acc.cachedPerModelQuota,
2373
2399
  fingerprintHistory: acc.fingerprintHistory
2374
2400
  }));
2375
2401
  console.log("");
@@ -10394,20 +10420,28 @@ function classifyQuotaGroup(modelName, displayName) {
10394
10420
  }
10395
10421
  function aggregateQuota(models) {
10396
10422
  const groups = {};
10423
+ const perModel = [];
10397
10424
  if (!models) {
10398
- return { groups, modelCount: 0 };
10425
+ return { groups, perModel, modelCount: 0 };
10399
10426
  }
10400
10427
  let totalCount = 0;
10401
10428
  for (const [modelName, entry] of Object.entries(models)) {
10402
10429
  const group = classifyQuotaGroup(modelName, entry.displayName ?? entry.modelName);
10403
- if (!group) {
10404
- continue;
10405
- }
10406
10430
  const quotaInfo = entry.quotaInfo;
10407
10431
  const remainingFraction = quotaInfo ? normalizeRemainingFraction(quotaInfo.remainingFraction) : void 0;
10408
10432
  const resetTime = quotaInfo?.resetTime;
10409
10433
  const resetTimestamp = parseResetTime(resetTime);
10410
10434
  totalCount += 1;
10435
+ perModel.push({
10436
+ modelId: modelName,
10437
+ displayName: entry.displayName ?? entry.modelName,
10438
+ group,
10439
+ remainingFraction: remainingFraction ?? 0,
10440
+ resetTime
10441
+ });
10442
+ if (!group) {
10443
+ continue;
10444
+ }
10411
10445
  const existing = groups[group];
10412
10446
  const nextCount = (existing?.modelCount ?? 0) + 1;
10413
10447
  const nextRemaining = remainingFraction === void 0 ? existing?.remainingFraction : existing?.remainingFraction === void 0 ? remainingFraction : Math.min(existing.remainingFraction, remainingFraction);
@@ -10428,7 +10462,8 @@ function aggregateQuota(models) {
10428
10462
  modelCount: nextCount
10429
10463
  };
10430
10464
  }
10431
- return { groups, modelCount: totalCount };
10465
+ perModel.sort((a, b) => a.modelId.localeCompare(b.modelId));
10466
+ return { groups, perModel, modelCount: totalCount };
10432
10467
  }
10433
10468
  async function fetchWithTimeout2(url, options, timeoutMs = FETCH_TIMEOUT_MS2) {
10434
10469
  const controller = new AbortController();
@@ -10440,51 +10475,85 @@ async function fetchWithTimeout2(url, options, timeoutMs = FETCH_TIMEOUT_MS2) {
10440
10475
  }
10441
10476
  }
10442
10477
  async function fetchAvailableModels(accessToken, projectId) {
10443
- const endpoint = ANTIGRAVITY_ENDPOINT_PROD;
10444
10478
  const quotaUserAgent = getAntigravityHeaders()["User-Agent"] || "antigravity/windows/amd64";
10445
10479
  const errors = [];
10446
- const body = projectId ? { project: projectId } : {};
10447
- const response = await fetchWithTimeout2(`${endpoint}/v1internal:fetchAvailableModels`, {
10448
- method: "POST",
10449
- headers: {
10450
- Authorization: `Bearer ${accessToken}`,
10451
- "Content-Type": "application/json",
10452
- "User-Agent": quotaUserAgent
10453
- },
10454
- body: JSON.stringify(body)
10455
- });
10456
- if (response.ok) {
10457
- return await response.json();
10480
+ for (const endpoint of ANTIGRAVITY_ENDPOINT_FALLBACKS) {
10481
+ const body = projectId ? { project: projectId } : {};
10482
+ try {
10483
+ const response = await fetchWithTimeout2(`${endpoint}/v1internal:fetchAvailableModels`, {
10484
+ method: "POST",
10485
+ headers: {
10486
+ Authorization: `Bearer ${accessToken}`,
10487
+ "Content-Type": "application/json",
10488
+ "User-Agent": quotaUserAgent
10489
+ },
10490
+ body: JSON.stringify(body)
10491
+ });
10492
+ if (response.ok) {
10493
+ return await response.json();
10494
+ }
10495
+ const status = response.status;
10496
+ if (status === 403 && projectId) {
10497
+ try {
10498
+ const retryResponse = await fetchWithTimeout2(`${endpoint}/v1internal:fetchAvailableModels`, {
10499
+ method: "POST",
10500
+ headers: {
10501
+ Authorization: `Bearer ${accessToken}`,
10502
+ "Content-Type": "application/json",
10503
+ "User-Agent": quotaUserAgent
10504
+ },
10505
+ body: JSON.stringify({})
10506
+ });
10507
+ if (retryResponse.ok) {
10508
+ return await retryResponse.json();
10509
+ }
10510
+ } catch {
10511
+ }
10512
+ }
10513
+ if (status === 429 || status >= 500) {
10514
+ const message2 = await response.text().catch(() => "");
10515
+ const snippet2 = message2.trim().slice(0, 200);
10516
+ errors.push(`fetchAvailableModels ${status} at ${endpoint}${snippet2 ? `: ${snippet2}` : ""}`);
10517
+ continue;
10518
+ }
10519
+ const message = await response.text().catch(() => "");
10520
+ const snippet = message.trim().slice(0, 200);
10521
+ errors.push(`fetchAvailableModels ${status} at ${endpoint}${snippet ? `: ${snippet}` : ""}`);
10522
+ break;
10523
+ } catch (error) {
10524
+ errors.push(`fetchAvailableModels network error at ${endpoint}: ${error instanceof Error ? error.message : String(error)}`);
10525
+ continue;
10526
+ }
10458
10527
  }
10459
- const message = await response.text().catch(() => "");
10460
- const snippet = message.trim().slice(0, 200);
10461
- errors.push(
10462
- `fetchAvailableModels ${response.status} at ${endpoint}${snippet ? `: ${snippet}` : ""}`
10463
- );
10464
10528
  throw new Error(errors.join("; ") || "fetchAvailableModels failed");
10465
10529
  }
10466
10530
  async function fetchGeminiCliQuota(accessToken, projectId) {
10467
- const endpoint = ANTIGRAVITY_ENDPOINT_PROD;
10468
10531
  const geminiCliUserAgent = buildGeminiCliUserAgent();
10469
- const body = projectId ? { project: projectId } : {};
10470
- try {
10471
- const response = await fetchWithTimeout2(`${endpoint}/v1internal:retrieveUserQuota`, {
10472
- method: "POST",
10473
- headers: {
10474
- Authorization: `Bearer ${accessToken}`,
10475
- "Content-Type": "application/json",
10476
- "User-Agent": geminiCliUserAgent
10477
- },
10478
- body: JSON.stringify(body)
10479
- });
10480
- if (response.ok) {
10481
- const data = await response.json();
10482
- return data;
10532
+ for (const endpoint of ANTIGRAVITY_ENDPOINT_FALLBACKS) {
10533
+ const body = projectId ? { project: projectId } : {};
10534
+ try {
10535
+ const response = await fetchWithTimeout2(`${endpoint}/v1internal:retrieveUserQuota`, {
10536
+ method: "POST",
10537
+ headers: {
10538
+ Authorization: `Bearer ${accessToken}`,
10539
+ "Content-Type": "application/json",
10540
+ "User-Agent": geminiCliUserAgent
10541
+ },
10542
+ body: JSON.stringify(body)
10543
+ });
10544
+ if (response.ok) {
10545
+ return await response.json();
10546
+ }
10547
+ const status = response.status;
10548
+ if (status === 429 || status >= 500) {
10549
+ continue;
10550
+ }
10551
+ return { buckets: [] };
10552
+ } catch {
10553
+ continue;
10483
10554
  }
10484
- return { buckets: [] };
10485
- } catch {
10486
- return { buckets: [] };
10487
10555
  }
10556
+ return { buckets: [] };
10488
10557
  }
10489
10558
  function aggregateGeminiCliQuota(response) {
10490
10559
  const models = [];
@@ -12969,6 +13038,7 @@ Alternatively, you can:
12969
13038
  cooldownMs,
12970
13039
  cooldownReason: cooldownMs ? acc.cooldownReason : void 0,
12971
13040
  cachedQuota: acc.cachedQuota,
13041
+ cachedPerModelQuota: acc.cachedPerModelQuota,
12972
13042
  fingerprintHistory: acc.fingerprintHistory
12973
13043
  };
12974
13044
  });
@@ -13075,6 +13145,7 @@ Alternatively, you can:
13075
13145
  const acc = existingStorage2.accounts[res.index];
13076
13146
  if (acc) {
13077
13147
  acc.cachedQuota = res.quota.groups;
13148
+ acc.cachedPerModelQuota = res.quota.perModel;
13078
13149
  acc.cachedQuotaUpdatedAt = Date.now();
13079
13150
  storageUpdated = true;
13080
13151
  }
@@ -13083,6 +13154,7 @@ Alternatively, you can:
13083
13154
  existingStorage2.accounts[res.index] = {
13084
13155
  ...res.updatedAccount,
13085
13156
  cachedQuota: res.quota?.groups,
13157
+ cachedPerModelQuota: res.quota?.perModel,
13086
13158
  cachedQuotaUpdatedAt: Date.now()
13087
13159
  };
13088
13160
  storageUpdated = true;