@expiren/opencode-antigravity-auth 1.6.40 → 1.6.42

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
@@ -3226,6 +3226,17 @@ var AntigravityConfigSchema = z2.object({
3226
3226
  * @default false
3227
3227
  */
3228
3228
  thinking_warmup: z2.boolean().default(false),
3229
+ /**
3230
+ * Send a lightweight cache-seeding probe when switching to a different account.
3231
+ * The probe reuses the same request prefix with maxOutputTokens=1 so the
3232
+ * server-side implicit cache warms up before the real request fires.
3233
+ * Costs ~1 quota unit per account switch but eliminates the 0% cold-cache
3234
+ * MISS that otherwise occurs on every rotation.
3235
+ *
3236
+ * Env override: OPENCODE_ANTIGRAVITY_CACHE_WARMUP_ON_SWITCH=1
3237
+ * @default true
3238
+ */
3239
+ cache_warmup_on_switch: z2.boolean().default(true),
3229
3240
  // =========================================================================
3230
3241
  // Session Recovery
3231
3242
  // =========================================================================
@@ -3525,6 +3536,7 @@ var DEFAULT_CONFIG = {
3525
3536
  debug_tui: false,
3526
3537
  keep_thinking: false,
3527
3538
  thinking_warmup: false,
3539
+ cache_warmup_on_switch: true,
3528
3540
  session_recovery: true,
3529
3541
  auto_resume: true,
3530
3542
  resume_text: "continue",
@@ -9115,6 +9127,7 @@ var AccountManager = class _AccountManager {
9115
9127
  savePromiseResolvers = [];
9116
9128
  sessionStartTime = Date.now();
9117
9129
  sessionRequestCounts = /* @__PURE__ */ new Map();
9130
+ sessionUsedAccounts = /* @__PURE__ */ new Set();
9118
9131
  static async loadFromDisk(authFallback) {
9119
9132
  const stored = await loadAccounts();
9120
9133
  return new _AccountManager(authFallback, stored);
@@ -9340,7 +9353,9 @@ var AccountManager = class _AccountManager {
9340
9353
  if (available.length === 0) {
9341
9354
  return null;
9342
9355
  }
9343
- const account = available[this.cursor % available.length];
9356
+ const sessionUsed = available.filter((a) => this.sessionUsedAccounts.has(a.index));
9357
+ const candidates = sessionUsed.length > 0 ? sessionUsed : available;
9358
+ const account = candidates[this.cursor % candidates.length];
9344
9359
  if (!account) {
9345
9360
  return null;
9346
9361
  }
@@ -9362,6 +9377,12 @@ var AccountManager = class _AccountManager {
9362
9377
  account.lastUsed = nowMs();
9363
9378
  }
9364
9379
  }
9380
+ recordSessionUsage(accountIndex) {
9381
+ this.sessionUsedAccounts.add(accountIndex);
9382
+ }
9383
+ wasUsedInSession(accountIndex) {
9384
+ return this.sessionUsedAccounts.has(accountIndex);
9385
+ }
9365
9386
  markRateLimitedWithReason(account, family, headerStyle, model, reason, retryAfterMs, failureTtlMs = 36e5) {
9366
9387
  const now = nowMs();
9367
9388
  if (account.lastFailureTime !== void 0 && now - account.lastFailureTime > failureTtlMs) {
@@ -12369,6 +12390,8 @@ var createAntigravityPlugin = (providerId) => async ({ client, directory }) => {
12369
12390
  };
12370
12391
  let accountSwitchCount = 0;
12371
12392
  const maxAccountSwitches = config.max_account_switches ?? 2;
12393
+ let previousAccountIndex = -1;
12394
+ let needsCacheWarmup = false;
12372
12395
  while (true) {
12373
12396
  checkAborted();
12374
12397
  const accountCount = accountManager.getAccountCount();
@@ -12475,6 +12498,12 @@ var createAntigravityPlugin = (providerId) => async ({ client, directory }) => {
12475
12498
  pushDebug(
12476
12499
  `selected idx=${account.index} email=${account.email ?? ""} family=${family} accounts=${accountCount} strategy=${config.account_selection_strategy}`
12477
12500
  );
12501
+ if (previousAccountIndex >= 0 && previousAccountIndex !== account.index) {
12502
+ needsCacheWarmup = config.cache_warmup_on_switch;
12503
+ pushDebug(`account-switch: ${previousAccountIndex} \u2192 ${account.index}, warmup=${needsCacheWarmup}`);
12504
+ }
12505
+ previousAccountIndex = account.index;
12506
+ accountManager.recordSessionUsage(account.index);
12478
12507
  if (isDebugEnabled()) {
12479
12508
  logAccountContext("Selected", {
12480
12509
  index: account.index,
@@ -12646,6 +12675,45 @@ var createAntigravityPlugin = (providerId) => async ({ client, directory }) => {
12646
12675
  );
12647
12676
  }
12648
12677
  };
12678
+ const runCacheWarmupProbe = async (prepared) => {
12679
+ if (!needsCacheWarmup) return;
12680
+ needsCacheWarmup = false;
12681
+ const bodyStr = typeof prepared.init.body === "string" ? prepared.init.body : void 0;
12682
+ if (!bodyStr) return;
12683
+ try {
12684
+ const parsed = JSON.parse(bodyStr);
12685
+ parsed.generationConfig = {
12686
+ ...parsed.generationConfig ?? {},
12687
+ maxOutputTokens: 1,
12688
+ candidateCount: 1
12689
+ };
12690
+ if (parsed.generationConfig.thinkingConfig) {
12691
+ parsed.generationConfig.thinkingConfig = {
12692
+ thinkingBudget: 0
12693
+ };
12694
+ }
12695
+ const probeHeaders = new Headers(prepared.init.headers ?? {});
12696
+ probeHeaders.set("accept", "application/json");
12697
+ const probeUrl = toUrlString(prepared.request).replace(
12698
+ ":streamGenerateContent?alt=sse",
12699
+ ":generateContent"
12700
+ );
12701
+ pushDebug("cache-warmup-probe: start");
12702
+ const probeResponse = await fetch(probeUrl, {
12703
+ ...prepared.init,
12704
+ method: "POST",
12705
+ headers: probeHeaders,
12706
+ body: JSON.stringify(parsed)
12707
+ });
12708
+ await probeResponse.text();
12709
+ const status = probeResponse.status;
12710
+ pushDebug(`cache-warmup-probe: done status=${status}`);
12711
+ } catch (error) {
12712
+ pushDebug(
12713
+ `cache-warmup-probe: failed ${error instanceof Error ? error.message : String(error)}`
12714
+ );
12715
+ }
12716
+ };
12649
12717
  let apiRequestCount = 0;
12650
12718
  let shouldSwitchAccount = false;
12651
12719
  let headerStyle = preferredHeaderStyle;
@@ -12756,6 +12824,7 @@ var createAntigravityPlugin = (providerId) => async ({ client, directory }) => {
12756
12824
  toolDebugPayload: prepared.toolDebugPayload
12757
12825
  });
12758
12826
  await runThinkingWarmup(prepared, projectContext.effectiveProjectId);
12827
+ await runCacheWarmupProbe(prepared);
12759
12828
  if (config.request_jitter_max_ms > 0) {
12760
12829
  const jitterMs = Math.floor(Math.random() * config.request_jitter_max_ms);
12761
12830
  if (jitterMs > 0) {