@expiren/opencode-antigravity-auth 1.6.39 → 1.6.41

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",
@@ -7556,6 +7568,10 @@ function ensureThinkingBeforeToolUseInMessages(messages, signatureSessionKey) {
7556
7568
  }) };
7557
7569
  });
7558
7570
  }
7571
+ var _lastCacheStats = null;
7572
+ function getLastCacheStats() {
7573
+ return _lastCacheStats;
7574
+ }
7559
7575
  function generateSyntheticProjectId() {
7560
7576
  const adjectives = ["useful", "bright", "swift", "calm", "bold"];
7561
7577
  const nouns = ["fuze", "wave", "spark", "flow", "core"];
@@ -8157,6 +8173,7 @@ async function transformAntigravityResponse(response, streaming, debugContext, r
8157
8173
  const status = cacheRead > 0 ? "HIT" : "MISS";
8158
8174
  logCacheStats(effectiveModel, cacheRead, 0, totalInput);
8159
8175
  log6.debug(`[Cache] ${status} model=${effectiveModel} read=${cacheRead} total=${totalInput} hitRate=${hitRate}%`);
8176
+ _lastCacheStats = { model: effectiveModel, read: cacheRead, total: totalInput, hitRate };
8160
8177
  }
8161
8178
  },
8162
8179
  transformThinkingParts
@@ -12323,6 +12340,11 @@ var createAntigravityPlugin = (providerId) => async ({ client, directory }) => {
12323
12340
  debugLines.push(line);
12324
12341
  };
12325
12342
  pushDebug(`request=${urlString}`);
12343
+ const cachedStats = getLastCacheStats();
12344
+ if (cachedStats) {
12345
+ const label = cachedStats.hitRate > 0 ? "HIT" : "MISS";
12346
+ pushDebug(`[Cache] ${label} model=${cachedStats.model} read=${cachedStats.read} total=${cachedStats.total} hitRate=${cachedStats.hitRate}%`);
12347
+ }
12326
12348
  let lastFailure = null;
12327
12349
  let lastError = null;
12328
12350
  const abortSignal = init?.signal ?? void 0;
@@ -12359,6 +12381,8 @@ var createAntigravityPlugin = (providerId) => async ({ client, directory }) => {
12359
12381
  };
12360
12382
  let accountSwitchCount = 0;
12361
12383
  const maxAccountSwitches = config.max_account_switches ?? 2;
12384
+ let previousAccountIndex = -1;
12385
+ let needsCacheWarmup = false;
12362
12386
  while (true) {
12363
12387
  checkAborted();
12364
12388
  const accountCount = accountManager.getAccountCount();
@@ -12465,6 +12489,11 @@ var createAntigravityPlugin = (providerId) => async ({ client, directory }) => {
12465
12489
  pushDebug(
12466
12490
  `selected idx=${account.index} email=${account.email ?? ""} family=${family} accounts=${accountCount} strategy=${config.account_selection_strategy}`
12467
12491
  );
12492
+ if (previousAccountIndex >= 0 && previousAccountIndex !== account.index) {
12493
+ needsCacheWarmup = config.cache_warmup_on_switch;
12494
+ pushDebug(`account-switch: ${previousAccountIndex} \u2192 ${account.index}, warmup=${needsCacheWarmup}`);
12495
+ }
12496
+ previousAccountIndex = account.index;
12468
12497
  if (isDebugEnabled()) {
12469
12498
  logAccountContext("Selected", {
12470
12499
  index: account.index,
@@ -12636,6 +12665,45 @@ var createAntigravityPlugin = (providerId) => async ({ client, directory }) => {
12636
12665
  );
12637
12666
  }
12638
12667
  };
12668
+ const runCacheWarmupProbe = async (prepared) => {
12669
+ if (!needsCacheWarmup) return;
12670
+ needsCacheWarmup = false;
12671
+ const bodyStr = typeof prepared.init.body === "string" ? prepared.init.body : void 0;
12672
+ if (!bodyStr) return;
12673
+ try {
12674
+ const parsed = JSON.parse(bodyStr);
12675
+ parsed.generationConfig = {
12676
+ ...parsed.generationConfig ?? {},
12677
+ maxOutputTokens: 1,
12678
+ candidateCount: 1
12679
+ };
12680
+ if (parsed.generationConfig.thinkingConfig) {
12681
+ parsed.generationConfig.thinkingConfig = {
12682
+ thinkingBudget: 0
12683
+ };
12684
+ }
12685
+ const probeHeaders = new Headers(prepared.init.headers ?? {});
12686
+ probeHeaders.set("accept", "application/json");
12687
+ const probeUrl = toUrlString(prepared.request).replace(
12688
+ ":streamGenerateContent?alt=sse",
12689
+ ":generateContent"
12690
+ );
12691
+ pushDebug("cache-warmup-probe: start");
12692
+ const probeResponse = await fetch(probeUrl, {
12693
+ ...prepared.init,
12694
+ method: "POST",
12695
+ headers: probeHeaders,
12696
+ body: JSON.stringify(parsed)
12697
+ });
12698
+ await probeResponse.text();
12699
+ const status = probeResponse.status;
12700
+ pushDebug(`cache-warmup-probe: done status=${status}`);
12701
+ } catch (error) {
12702
+ pushDebug(
12703
+ `cache-warmup-probe: failed ${error instanceof Error ? error.message : String(error)}`
12704
+ );
12705
+ }
12706
+ };
12639
12707
  let apiRequestCount = 0;
12640
12708
  let shouldSwitchAccount = false;
12641
12709
  let headerStyle = preferredHeaderStyle;
@@ -12746,6 +12814,7 @@ var createAntigravityPlugin = (providerId) => async ({ client, directory }) => {
12746
12814
  toolDebugPayload: prepared.toolDebugPayload
12747
12815
  });
12748
12816
  await runThinkingWarmup(prepared, projectContext.effectiveProjectId);
12817
+ await runCacheWarmupProbe(prepared);
12749
12818
  if (config.request_jitter_max_ms > 0) {
12750
12819
  const jitterMs = Math.floor(Math.random() * config.request_jitter_max_ms);
12751
12820
  if (jitterMs > 0) {