@expiren/opencode-antigravity-auth 1.6.30 → 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
@@ -1606,7 +1606,7 @@ function classifyGroupStatus(group) {
1606
1606
  if (waitMs !== null && waitMs > 0) {
1607
1607
  return { label: "EXHAUSTED", waitMs };
1608
1608
  }
1609
- return { label: "EXHAUSTED" };
1609
+ return { label: "READY" };
1610
1610
  }
1611
1611
  if (remaining < 0.2) {
1612
1612
  return { label: "LOW" };
@@ -1692,10 +1692,12 @@ function classifyOverallQuotaHealth(cachedQuota) {
1692
1692
  if (typeof value !== "number" || !Number.isFinite(value)) continue;
1693
1693
  groupsWithData++;
1694
1694
  if (value <= 0) {
1695
- exhaustedCount++;
1696
1695
  const resetMs = parseResetTimeToMs(cachedQuota[key]?.resetTime);
1697
- if (resetMs !== null && (maxResetMs === void 0 || resetMs > maxResetMs)) {
1698
- maxResetMs = resetMs;
1696
+ if (resetMs !== null && resetMs > 0) {
1697
+ exhaustedCount++;
1698
+ if (maxResetMs === void 0 || resetMs > maxResetMs) {
1699
+ maxResetMs = resetMs;
1700
+ }
1699
1701
  }
1700
1702
  }
1701
1703
  }
@@ -1823,16 +1825,45 @@ function buildModelBreakdown(accounts) {
1823
1825
  let maxResetMs;
1824
1826
  for (const acc of accounts) {
1825
1827
  if (acc.enabled === false) continue;
1826
- const group = acc.cachedQuota?.[key];
1827
- if (!group || typeof group.remainingFraction !== "number") continue;
1828
- if (group.remainingFraction <= 0) {
1829
- exhaustedCount++;
1830
- const resetMs = parseResetTimeToMs2(group.resetTime);
1831
- if (resetMs !== null && (maxResetMs === void 0 || resetMs > maxResetMs)) {
1832
- 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++;
1847
+ }
1848
+ } else {
1849
+ availableCount++;
1833
1850
  }
1834
1851
  } else {
1835
- 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
+ }
1836
1867
  }
1837
1868
  }
1838
1869
  if (exhaustedCount > 0 || availableCount > 0) {
@@ -2364,6 +2395,7 @@ async function promptLoginMode(existingAccounts) {
2364
2395
  cooldownMs: acc.cooldownMs,
2365
2396
  cooldownReason: acc.cooldownReason,
2366
2397
  cachedQuota: acc.cachedQuota,
2398
+ cachedPerModelQuota: acc.cachedPerModelQuota,
2367
2399
  fingerprintHistory: acc.fingerprintHistory
2368
2400
  }));
2369
2401
  console.log("");
@@ -10388,20 +10420,28 @@ function classifyQuotaGroup(modelName, displayName) {
10388
10420
  }
10389
10421
  function aggregateQuota(models) {
10390
10422
  const groups = {};
10423
+ const perModel = [];
10391
10424
  if (!models) {
10392
- return { groups, modelCount: 0 };
10425
+ return { groups, perModel, modelCount: 0 };
10393
10426
  }
10394
10427
  let totalCount = 0;
10395
10428
  for (const [modelName, entry] of Object.entries(models)) {
10396
10429
  const group = classifyQuotaGroup(modelName, entry.displayName ?? entry.modelName);
10397
- if (!group) {
10398
- continue;
10399
- }
10400
10430
  const quotaInfo = entry.quotaInfo;
10401
10431
  const remainingFraction = quotaInfo ? normalizeRemainingFraction(quotaInfo.remainingFraction) : void 0;
10402
10432
  const resetTime = quotaInfo?.resetTime;
10403
10433
  const resetTimestamp = parseResetTime(resetTime);
10404
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
+ }
10405
10445
  const existing = groups[group];
10406
10446
  const nextCount = (existing?.modelCount ?? 0) + 1;
10407
10447
  const nextRemaining = remainingFraction === void 0 ? existing?.remainingFraction : existing?.remainingFraction === void 0 ? remainingFraction : Math.min(existing.remainingFraction, remainingFraction);
@@ -10422,7 +10462,8 @@ function aggregateQuota(models) {
10422
10462
  modelCount: nextCount
10423
10463
  };
10424
10464
  }
10425
- return { groups, modelCount: totalCount };
10465
+ perModel.sort((a, b) => a.modelId.localeCompare(b.modelId));
10466
+ return { groups, perModel, modelCount: totalCount };
10426
10467
  }
10427
10468
  async function fetchWithTimeout2(url, options, timeoutMs = FETCH_TIMEOUT_MS2) {
10428
10469
  const controller = new AbortController();
@@ -10434,51 +10475,85 @@ async function fetchWithTimeout2(url, options, timeoutMs = FETCH_TIMEOUT_MS2) {
10434
10475
  }
10435
10476
  }
10436
10477
  async function fetchAvailableModels(accessToken, projectId) {
10437
- const endpoint = ANTIGRAVITY_ENDPOINT_PROD;
10438
10478
  const quotaUserAgent = getAntigravityHeaders()["User-Agent"] || "antigravity/windows/amd64";
10439
10479
  const errors = [];
10440
- const body = projectId ? { project: projectId } : {};
10441
- const response = await fetchWithTimeout2(`${endpoint}/v1internal:fetchAvailableModels`, {
10442
- method: "POST",
10443
- headers: {
10444
- Authorization: `Bearer ${accessToken}`,
10445
- "Content-Type": "application/json",
10446
- "User-Agent": quotaUserAgent
10447
- },
10448
- body: JSON.stringify(body)
10449
- });
10450
- if (response.ok) {
10451
- 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
+ }
10452
10527
  }
10453
- const message = await response.text().catch(() => "");
10454
- const snippet = message.trim().slice(0, 200);
10455
- errors.push(
10456
- `fetchAvailableModels ${response.status} at ${endpoint}${snippet ? `: ${snippet}` : ""}`
10457
- );
10458
10528
  throw new Error(errors.join("; ") || "fetchAvailableModels failed");
10459
10529
  }
10460
10530
  async function fetchGeminiCliQuota(accessToken, projectId) {
10461
- const endpoint = ANTIGRAVITY_ENDPOINT_PROD;
10462
10531
  const geminiCliUserAgent = buildGeminiCliUserAgent();
10463
- const body = projectId ? { project: projectId } : {};
10464
- try {
10465
- const response = await fetchWithTimeout2(`${endpoint}/v1internal:retrieveUserQuota`, {
10466
- method: "POST",
10467
- headers: {
10468
- Authorization: `Bearer ${accessToken}`,
10469
- "Content-Type": "application/json",
10470
- "User-Agent": geminiCliUserAgent
10471
- },
10472
- body: JSON.stringify(body)
10473
- });
10474
- if (response.ok) {
10475
- const data = await response.json();
10476
- 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;
10477
10554
  }
10478
- return { buckets: [] };
10479
- } catch {
10480
- return { buckets: [] };
10481
10555
  }
10556
+ return { buckets: [] };
10482
10557
  }
10483
10558
  function aggregateGeminiCliQuota(response) {
10484
10559
  const models = [];
@@ -12963,6 +13038,7 @@ Alternatively, you can:
12963
13038
  cooldownMs,
12964
13039
  cooldownReason: cooldownMs ? acc.cooldownReason : void 0,
12965
13040
  cachedQuota: acc.cachedQuota,
13041
+ cachedPerModelQuota: acc.cachedPerModelQuota,
12966
13042
  fingerprintHistory: acc.fingerprintHistory
12967
13043
  };
12968
13044
  });
@@ -13069,6 +13145,7 @@ Alternatively, you can:
13069
13145
  const acc = existingStorage2.accounts[res.index];
13070
13146
  if (acc) {
13071
13147
  acc.cachedQuota = res.quota.groups;
13148
+ acc.cachedPerModelQuota = res.quota.perModel;
13072
13149
  acc.cachedQuotaUpdatedAt = Date.now();
13073
13150
  storageUpdated = true;
13074
13151
  }
@@ -13077,6 +13154,7 @@ Alternatively, you can:
13077
13154
  existingStorage2.accounts[res.index] = {
13078
13155
  ...res.updatedAccount,
13079
13156
  cachedQuota: res.quota?.groups,
13157
+ cachedPerModelQuota: res.quota?.perModel,
13080
13158
  cachedQuotaUpdatedAt: Date.now()
13081
13159
  };
13082
13160
  storageUpdated = true;