@expiren/opencode-antigravity-auth 1.6.41 → 1.6.43
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 +85 -2
- package/dist/index.js.map +2 -2
- package/dist/src/plugin/accounts.d.ts +5 -0
- package/dist/src/plugin/accounts.d.ts.map +1 -1
- package/dist/src/plugin/accounts.js +60 -2
- package/dist/src/plugin/accounts.js.map +1 -1
- package/dist/src/plugin/config/schema.d.ts +1 -0
- package/dist/src/plugin/config/schema.d.ts.map +1 -1
- package/dist/src/plugin/config/schema.js +15 -3
- package/dist/src/plugin/config/schema.js.map +1 -1
- package/dist/src/plugin.d.ts.map +1 -1
- package/dist/src/plugin.js +14 -1
- package/dist/src/plugin.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3500,9 +3500,21 @@ var AntigravityConfigSchema = z2.object({
|
|
|
3500
3500
|
z2.literal("auto"),
|
|
3501
3501
|
z2.number().min(1).max(120)
|
|
3502
3502
|
]).default("auto"),
|
|
3503
|
+
/**
|
|
3504
|
+
* Proactive rotation threshold percentage (0-100).
|
|
3505
|
+
* After a successful request, if the current account's remaining quota
|
|
3506
|
+
* drops below this percentage, proactively switch to a warm-cache account
|
|
3507
|
+
* before the next request — avoiding a forced 429 mid-conversation.
|
|
3508
|
+
*
|
|
3509
|
+
* Set to 0 to disable proactive rotation.
|
|
3510
|
+
*
|
|
3511
|
+
* @default 20
|
|
3512
|
+
* @env OPENCODE_ANTIGRAVITY_PROACTIVE_ROTATION_THRESHOLD
|
|
3513
|
+
*/
|
|
3514
|
+
proactive_rotation_threshold_percent: z2.number().min(0).max(100).default(20),
|
|
3503
3515
|
// =========================================================================
|
|
3504
3516
|
// Health Score (used by hybrid strategy)
|
|
3505
|
-
// =========================================================================
|
|
3517
|
+
// =========================================================================
|
|
3506
3518
|
health_score: z2.object({
|
|
3507
3519
|
initial: z2.number().min(0).max(100).default(70),
|
|
3508
3520
|
success_reward: z2.number().min(0).max(10).default(1),
|
|
@@ -3565,6 +3577,7 @@ var DEFAULT_CONFIG = {
|
|
|
3565
3577
|
soft_quota_threshold_percent: 90,
|
|
3566
3578
|
quota_refresh_interval_minutes: 30,
|
|
3567
3579
|
soft_quota_cache_ttl_minutes: "auto",
|
|
3580
|
+
proactive_rotation_threshold_percent: 20,
|
|
3568
3581
|
auto_update: true,
|
|
3569
3582
|
signature_cache: {
|
|
3570
3583
|
enabled: true,
|
|
@@ -9127,6 +9140,7 @@ var AccountManager = class _AccountManager {
|
|
|
9127
9140
|
savePromiseResolvers = [];
|
|
9128
9141
|
sessionStartTime = Date.now();
|
|
9129
9142
|
sessionRequestCounts = /* @__PURE__ */ new Map();
|
|
9143
|
+
sessionUsedAccounts = /* @__PURE__ */ new Set();
|
|
9130
9144
|
static async loadFromDisk(authFallback) {
|
|
9131
9145
|
const stored = await loadAccounts();
|
|
9132
9146
|
return new _AccountManager(authFallback, stored);
|
|
@@ -9352,7 +9366,9 @@ var AccountManager = class _AccountManager {
|
|
|
9352
9366
|
if (available.length === 0) {
|
|
9353
9367
|
return null;
|
|
9354
9368
|
}
|
|
9355
|
-
const
|
|
9369
|
+
const sessionUsed = available.filter((a) => this.sessionUsedAccounts.has(a.index));
|
|
9370
|
+
const candidates = sessionUsed.length > 0 ? sessionUsed : available;
|
|
9371
|
+
const account = candidates[this.cursor % candidates.length];
|
|
9356
9372
|
if (!account) {
|
|
9357
9373
|
return null;
|
|
9358
9374
|
}
|
|
@@ -9374,6 +9390,51 @@ var AccountManager = class _AccountManager {
|
|
|
9374
9390
|
account.lastUsed = nowMs();
|
|
9375
9391
|
}
|
|
9376
9392
|
}
|
|
9393
|
+
recordSessionUsage(accountIndex) {
|
|
9394
|
+
this.sessionUsedAccounts.add(accountIndex);
|
|
9395
|
+
}
|
|
9396
|
+
wasUsedInSession(accountIndex) {
|
|
9397
|
+
return this.sessionUsedAccounts.has(accountIndex);
|
|
9398
|
+
}
|
|
9399
|
+
shouldProactivelyRotate(family, model, thresholdPercent, cacheTtlMs) {
|
|
9400
|
+
if (thresholdPercent <= 0) return false;
|
|
9401
|
+
const current = this.getCurrentAccountForFamily(family);
|
|
9402
|
+
if (!current || !current.cachedQuota || current.cachedQuotaUpdatedAt == null) return false;
|
|
9403
|
+
const age = nowMs() - current.cachedQuotaUpdatedAt;
|
|
9404
|
+
if (age > cacheTtlMs) return false;
|
|
9405
|
+
const quotaGroup = resolveQuotaGroup(family, model);
|
|
9406
|
+
const groupData = current.cachedQuota[quotaGroup];
|
|
9407
|
+
if (groupData?.remainingFraction == null) return false;
|
|
9408
|
+
const remainingPercent = Math.max(0, Math.min(100, groupData.remainingFraction * 100));
|
|
9409
|
+
return remainingPercent < thresholdPercent;
|
|
9410
|
+
}
|
|
9411
|
+
proactivelyRotateForFamily(family, model, headerStyle, softQuotaThresholdPercent, softQuotaCacheTtlMs) {
|
|
9412
|
+
const currentIndex = this.currentAccountIndexByFamily[family];
|
|
9413
|
+
const candidates = this.accounts.filter((acc) => {
|
|
9414
|
+
if (acc.enabled === false) return false;
|
|
9415
|
+
if (acc.index === currentIndex) return false;
|
|
9416
|
+
clearExpiredRateLimits(acc);
|
|
9417
|
+
if (isRateLimitedForHeaderStyle(acc, family, headerStyle, model)) return false;
|
|
9418
|
+
if (isOverSoftQuotaThreshold(acc, family, softQuotaThresholdPercent, softQuotaCacheTtlMs, model)) return false;
|
|
9419
|
+
if (this.isAccountCoolingDown(acc)) return false;
|
|
9420
|
+
return true;
|
|
9421
|
+
});
|
|
9422
|
+
if (candidates.length === 0) return null;
|
|
9423
|
+
const warmCandidates = candidates.filter((a) => this.sessionUsedAccounts.has(a.index));
|
|
9424
|
+
const pool = warmCandidates.length > 0 ? warmCandidates : candidates;
|
|
9425
|
+
const quotaGroup = resolveQuotaGroup(family, model);
|
|
9426
|
+
pool.sort((a, b) => {
|
|
9427
|
+
const aRemaining = a.cachedQuota?.[quotaGroup]?.remainingFraction ?? 0;
|
|
9428
|
+
const bRemaining = b.cachedQuota?.[quotaGroup]?.remainingFraction ?? 0;
|
|
9429
|
+
return bRemaining - aRemaining;
|
|
9430
|
+
});
|
|
9431
|
+
const selected = pool[0];
|
|
9432
|
+
if (!selected) return null;
|
|
9433
|
+
const quotaKey = getQuotaKey(family, headerStyle, model);
|
|
9434
|
+
this.markTouchedForQuota(selected, quotaKey);
|
|
9435
|
+
this.currentAccountIndexByFamily[family] = selected.index;
|
|
9436
|
+
return selected;
|
|
9437
|
+
}
|
|
9377
9438
|
markRateLimitedWithReason(account, family, headerStyle, model, reason, retryAfterMs, failureTtlMs = 36e5) {
|
|
9378
9439
|
const now = nowMs();
|
|
9379
9440
|
if (account.lastFailureTime !== void 0 && now - account.lastFailureTime > failureTtlMs) {
|
|
@@ -12494,6 +12555,7 @@ var createAntigravityPlugin = (providerId) => async ({ client, directory }) => {
|
|
|
12494
12555
|
pushDebug(`account-switch: ${previousAccountIndex} \u2192 ${account.index}, warmup=${needsCacheWarmup}`);
|
|
12495
12556
|
}
|
|
12496
12557
|
previousAccountIndex = account.index;
|
|
12558
|
+
accountManager.recordSessionUsage(account.index);
|
|
12497
12559
|
if (isDebugEnabled()) {
|
|
12498
12560
|
logAccountContext("Selected", {
|
|
12499
12561
|
index: account.index,
|
|
@@ -13028,6 +13090,27 @@ var createAntigravityPlugin = (providerId) => async ({ client, directory }) => {
|
|
|
13028
13090
|
providerId,
|
|
13029
13091
|
config.quota_refresh_interval_minutes
|
|
13030
13092
|
);
|
|
13093
|
+
const proactiveThreshold = config.proactive_rotation_threshold_percent ?? 20;
|
|
13094
|
+
if (proactiveThreshold > 0 && accountManager.shouldProactivelyRotate(
|
|
13095
|
+
family,
|
|
13096
|
+
model,
|
|
13097
|
+
proactiveThreshold,
|
|
13098
|
+
softQuotaCacheTtlMs
|
|
13099
|
+
)) {
|
|
13100
|
+
const rotated = accountManager.proactivelyRotateForFamily(
|
|
13101
|
+
family,
|
|
13102
|
+
model,
|
|
13103
|
+
headerStyle,
|
|
13104
|
+
config.soft_quota_threshold_percent,
|
|
13105
|
+
softQuotaCacheTtlMs
|
|
13106
|
+
);
|
|
13107
|
+
if (rotated) {
|
|
13108
|
+
const remaining = account.cachedQuota?.[resolveQuotaGroup(family, model)]?.remainingFraction;
|
|
13109
|
+
const remainingPct = remaining != null ? `${(remaining * 100).toFixed(1)}%` : "?";
|
|
13110
|
+
pushDebug(`[ProactiveRotation] account ${account.index} quota ${remainingPct} < ${proactiveThreshold}%, pre-switched to account ${rotated.index} for next request`);
|
|
13111
|
+
pushDebug(`[ProactiveRotation] ${account.index} \u2192 ${rotated.index} (warm=${accountManager.wasUsedInSession(rotated.index)})`);
|
|
13112
|
+
}
|
|
13113
|
+
}
|
|
13031
13114
|
}
|
|
13032
13115
|
logAntigravityDebugResponse(debugContext, response, {
|
|
13033
13116
|
note: response.ok ? "Success" : `Error ${response.status}`
|