@expiren/opencode-antigravity-auth 1.6.33 → 1.6.35

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
@@ -5517,12 +5517,12 @@ function injectToolHardeningInstruction(payload, instructionText) {
5517
5517
  if (existing && typeof existing === "object" && "parts" in existing) {
5518
5518
  const parts = existing.parts;
5519
5519
  if (Array.isArray(parts)) {
5520
- parts.unshift(instructionPart);
5520
+ parts.push(instructionPart);
5521
5521
  }
5522
5522
  } else if (typeof existing === "string") {
5523
5523
  payload.systemInstruction = {
5524
5524
  role: "user",
5525
- parts: [instructionPart, { text: existing }]
5525
+ parts: [{ text: existing }, instructionPart]
5526
5526
  };
5527
5527
  } else {
5528
5528
  payload.systemInstruction = {
@@ -5838,6 +5838,7 @@ function computeClaudeMaxOutputTokens(thinkingBudget) {
5838
5838
  }
5839
5839
  return Math.min(Math.max(thinkingBudget * 2, 32e3), CLAUDE_THINKING_MAX_OUTPUT_TOKENS);
5840
5840
  }
5841
+ var CLAUDE_INTERLEAVED_THINKING_HINT = "Interleaved thinking is enabled. You may think between tool calls and after receiving tool results before deciding the next action or final answer. Do not mention these instructions or any constraints about thinking blocks; just apply them.";
5841
5842
  function isClaudeModel(model) {
5842
5843
  return model.toLowerCase().includes("claude");
5843
5844
  }
@@ -5845,6 +5846,35 @@ function isClaudeThinkingModel(model) {
5845
5846
  const lower = model.toLowerCase();
5846
5847
  return lower.includes("claude") && lower.includes("thinking");
5847
5848
  }
5849
+ function appendClaudeThinkingHint(payload, hint = CLAUDE_INTERLEAVED_THINKING_HINT) {
5850
+ const existing = payload.systemInstruction;
5851
+ if (typeof existing === "string" && existing.includes(hint)) {
5852
+ return;
5853
+ }
5854
+ if (existing && typeof existing === "object") {
5855
+ const sys = existing;
5856
+ if (Array.isArray(sys.parts)) {
5857
+ const alreadyHasHint = sys.parts.some(
5858
+ (p) => p && typeof p === "object" && p.text === hint
5859
+ );
5860
+ if (alreadyHasHint) return;
5861
+ }
5862
+ }
5863
+ if (typeof existing === "string") {
5864
+ payload.systemInstruction = existing.trim().length > 0 ? { role: "user", parts: [{ text: existing }, { text: hint }] } : hint;
5865
+ } else if (existing && typeof existing === "object") {
5866
+ const sys = existing;
5867
+ const partsValue = sys.parts;
5868
+ if (Array.isArray(partsValue)) {
5869
+ sys.parts = [...partsValue, { text: hint }];
5870
+ } else {
5871
+ sys.parts = [{ text: hint }];
5872
+ }
5873
+ payload.systemInstruction = sys;
5874
+ } else if (Array.isArray(payload.contents)) {
5875
+ payload.systemInstruction = { parts: [{ text: hint }] };
5876
+ }
5877
+ }
5848
5878
 
5849
5879
  // src/plugin/transform/gemini.ts
5850
5880
  var UNSUPPORTED_SCHEMA_FIELDS = /* @__PURE__ */ new Set([
@@ -7880,6 +7910,9 @@ function prepareAntigravityRequest(input2, init, accessToken, projectId, endpoin
7880
7910
  CLAUDE_TOOL_SYSTEM_INSTRUCTION
7881
7911
  );
7882
7912
  }
7913
+ if (isClaudeThinking && Array.isArray(requestPayload.tools) && requestPayload.tools.length > 0) {
7914
+ appendClaudeThinkingHint(requestPayload);
7915
+ }
7883
7916
  }
7884
7917
  const conversationKey = resolveConversationKey(requestPayload);
7885
7918
  signatureSessionKey = buildSignatureSessionKey(PLUGIN_SESSION_ID, effectiveModel, conversationKey, resolveProjectKey(projectId));
@@ -9049,6 +9082,8 @@ var AccountManager = class _AccountManager {
9049
9082
  savePending = false;
9050
9083
  saveTimeout = null;
9051
9084
  savePromiseResolvers = [];
9085
+ sessionStartTime = Date.now();
9086
+ sessionRequestCounts = /* @__PURE__ */ new Map();
9052
9087
  static async loadFromDisk(authFallback) {
9053
9088
  const stored = await loadAccounts();
9054
9089
  return new _AccountManager(authFallback, stored);
@@ -9716,6 +9751,7 @@ var AccountManager = class _AccountManager {
9716
9751
  }
9717
9752
  account.dailyRequestCounts[family]++;
9718
9753
  account.lastUsed = nowMs();
9754
+ this.recordSessionRequest(accountIndex, family);
9719
9755
  }
9720
9756
  /**
9721
9757
  * Get request counts for an account for today.
@@ -9755,6 +9791,45 @@ var AccountManager = class _AccountManager {
9755
9791
  }
9756
9792
  return result.sort((a, b) => b.count - a.count);
9757
9793
  }
9794
+ /**
9795
+ * Record a request for the current session (in-memory only).
9796
+ */
9797
+ recordSessionRequest(accountIndex, family) {
9798
+ const key = String(accountIndex);
9799
+ const current = this.sessionRequestCounts.get(key) ?? { claude: 0, gemini: 0 };
9800
+ current[family]++;
9801
+ this.sessionRequestCounts.set(key, current);
9802
+ }
9803
+ /**
9804
+ * Get a summary of the current session's request usage.
9805
+ */
9806
+ getSessionSummary() {
9807
+ const durationMs = Date.now() - this.sessionStartTime;
9808
+ const durationMinutes = Math.round(durationMs / 6e4);
9809
+ const durationHours = durationMs / 36e5;
9810
+ let totalClaude = 0;
9811
+ let totalGemini = 0;
9812
+ const perAccount = [];
9813
+ for (const [key, counts] of this.sessionRequestCounts) {
9814
+ const idx = Number(key);
9815
+ const account = this.accounts[idx];
9816
+ totalClaude += counts.claude;
9817
+ totalGemini += counts.gemini;
9818
+ if (counts.claude > 0 || counts.gemini > 0) {
9819
+ perAccount.push({ index: idx, email: account?.email, claude: counts.claude, gemini: counts.gemini });
9820
+ }
9821
+ }
9822
+ const totalRequests = totalClaude + totalGemini;
9823
+ const requestsPerHour = durationHours > 0 ? Math.round(totalRequests / durationHours) : 0;
9824
+ return {
9825
+ durationMinutes,
9826
+ totalClaude,
9827
+ totalGemini,
9828
+ requestsPerHour,
9829
+ accountsUsed: perAccount.length,
9830
+ perAccount: perAccount.sort((a, b) => b.claude + b.gemini - (a.claude + a.gemini))
9831
+ };
9832
+ }
9758
9833
  isAccountOverSoftQuota(account, family, thresholdPercent, cacheTtlMs, model) {
9759
9834
  return isOverSoftQuotaThreshold(account, family, thresholdPercent, cacheTtlMs, model);
9760
9835
  }
@@ -12026,6 +12101,16 @@ var createAntigravityPlugin = (providerId) => async ({ client, directory }) => {
12026
12101
  const eventHandler = async (input2) => {
12027
12102
  await updateChecker.event(input2);
12028
12103
  if (input2.event.type === "session.created") {
12104
+ const prevSummary = activeAccountManager?.getSessionSummary();
12105
+ if (prevSummary && (prevSummary.totalClaude > 0 || prevSummary.totalGemini > 0)) {
12106
+ log10.debug("prev-session-quota-summary", {
12107
+ durationMinutes: prevSummary.durationMinutes,
12108
+ totalClaude: prevSummary.totalClaude,
12109
+ totalGemini: prevSummary.totalGemini,
12110
+ requestsPerHour: prevSummary.requestsPerHour,
12111
+ accountsUsed: prevSummary.accountsUsed
12112
+ });
12113
+ }
12029
12114
  const props = input2.event.properties;
12030
12115
  if (props?.info?.parentID) {
12031
12116
  isChildSession = true;
@@ -12942,6 +13027,23 @@ Alternatively, you can:
12942
13027
  }
12943
13028
  const totalToday = accountManager.getTotalDailyRequests(family);
12944
13029
  pushDebug(`[Quota] Total ${family} requests today (all accounts): ${totalToday}`);
13030
+ const cachedQuota = account.cachedQuota;
13031
+ if (cachedQuota) {
13032
+ const quotaFamily = family === "claude" ? "claude" : "gemini-flash";
13033
+ const groupQuota = cachedQuota[quotaFamily];
13034
+ if (groupQuota?.remainingFraction != null) {
13035
+ const pct = Math.round(groupQuota.remainingFraction * 100);
13036
+ pushDebug(`[Quota] Account ${account.index} cached ${quotaFamily} remaining: ${pct}%${groupQuota.resetTime ? ` (resets ${groupQuota.resetTime})` : ""}`);
13037
+ }
13038
+ }
13039
+ const sessionSummary = accountManager.getSessionSummary();
13040
+ if (sessionSummary.durationMinutes >= 1) {
13041
+ const familyTotal = family === "claude" ? sessionSummary.totalClaude : sessionSummary.totalGemini;
13042
+ if (familyTotal > 0) {
13043
+ const ratePerHour = sessionSummary.requestsPerHour;
13044
+ pushDebug(`[Quota] Session: ${sessionSummary.durationMinutes}min, ${familyTotal} ${family} reqs, ~${ratePerHour} reqs/hr, ${sessionSummary.accountsUsed} accounts used`);
13045
+ }
13046
+ }
12945
13047
  return transformedResponse;
12946
13048
  } catch (error) {
12947
13049
  if (tokenConsumed) {