@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 +122 -50
- package/dist/index.js.map +3 -3
- package/dist/src/plugin/cli.d.ts +7 -0
- package/dist/src/plugin/cli.d.ts.map +1 -1
- package/dist/src/plugin/cli.js +1 -0
- package/dist/src/plugin/cli.js.map +1 -1
- package/dist/src/plugin/quota.d.ts +8 -0
- package/dist/src/plugin/quota.d.ts.map +1 -1
- package/dist/src/plugin/quota.js +99 -43
- package/dist/src/plugin/quota.js.map +1 -1
- package/dist/src/plugin/storage.d.ts +9 -1
- package/dist/src/plugin/storage.d.ts.map +1 -1
- package/dist/src/plugin/storage.js.map +1 -1
- package/dist/src/plugin/ui/auth-menu.d.ts +7 -0
- package/dist/src/plugin/ui/auth-menu.d.ts.map +1 -1
- package/dist/src/plugin/ui/auth-menu.js +45 -12
- package/dist/src/plugin/ui/auth-menu.js.map +1 -1
- package/dist/src/plugin.d.ts.map +1 -1
- package/dist/src/plugin.js +3 -0
- package/dist/src/plugin.js.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
const
|
|
1832
|
-
if (
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
10447
|
-
|
|
10448
|
-
|
|
10449
|
-
|
|
10450
|
-
|
|
10451
|
-
|
|
10452
|
-
|
|
10453
|
-
|
|
10454
|
-
|
|
10455
|
-
|
|
10456
|
-
|
|
10457
|
-
|
|
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
|
|
10470
|
-
|
|
10471
|
-
|
|
10472
|
-
|
|
10473
|
-
|
|
10474
|
-
|
|
10475
|
-
|
|
10476
|
-
|
|
10477
|
-
|
|
10478
|
-
|
|
10479
|
-
|
|
10480
|
-
|
|
10481
|
-
|
|
10482
|
-
|
|
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;
|