@expiren/opencode-antigravity-auth 1.6.4 → 1.6.6

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
@@ -671,6 +671,40 @@ async function loadAccounts() {
671
671
  return null;
672
672
  }
673
673
  }
674
+ async function atomicWriteFile(targetPath, content) {
675
+ const tempPath = `${targetPath}.${randomBytes(6).toString("hex")}.tmp`;
676
+ await fs.writeFile(tempPath, content, { encoding: "utf-8", mode: 384 });
677
+ const RETRY_DELAYS = [50, 100, 200];
678
+ let lastError;
679
+ for (let attempt = 0; attempt <= RETRY_DELAYS.length; attempt++) {
680
+ try {
681
+ await fs.rename(tempPath, targetPath);
682
+ return;
683
+ } catch (error) {
684
+ lastError = error;
685
+ const code = error.code;
686
+ if (code !== "EPERM" && code !== "EACCES") {
687
+ break;
688
+ }
689
+ if (attempt < RETRY_DELAYS.length) {
690
+ await new Promise((r) => setTimeout(r, RETRY_DELAYS[attempt]));
691
+ }
692
+ }
693
+ }
694
+ try {
695
+ await fs.copyFile(tempPath, targetPath);
696
+ try {
697
+ await fs.unlink(tempPath);
698
+ } catch {
699
+ }
700
+ } catch {
701
+ try {
702
+ await fs.unlink(tempPath);
703
+ } catch {
704
+ }
705
+ throw lastError;
706
+ }
707
+ }
674
708
  async function saveAccounts(storage) {
675
709
  const path5 = getStoragePath();
676
710
  const configDir = dirname(path5);
@@ -679,18 +713,8 @@ async function saveAccounts(storage) {
679
713
  await withFileLock(path5, async () => {
680
714
  const existing = await loadAccountsUnsafe();
681
715
  const merged = existing ? mergeAccountStorage(existing, storage) : storage;
682
- const tempPath = `${path5}.${randomBytes(6).toString("hex")}.tmp`;
683
716
  const content = JSON.stringify(merged, null, 2);
684
- try {
685
- await fs.writeFile(tempPath, content, { encoding: "utf-8", mode: 384 });
686
- await fs.rename(tempPath, path5);
687
- } catch (error) {
688
- try {
689
- await fs.unlink(tempPath);
690
- } catch {
691
- }
692
- throw error;
693
- }
717
+ await atomicWriteFile(path5, content);
694
718
  });
695
719
  }
696
720
  async function saveAccountsReplace(storage) {
@@ -699,18 +723,8 @@ async function saveAccountsReplace(storage) {
699
723
  await fs.mkdir(configDir, { recursive: true });
700
724
  await ensureGitignore(configDir);
701
725
  await withFileLock(path5, async () => {
702
- const tempPath = `${path5}.${randomBytes(6).toString("hex")}.tmp`;
703
726
  const content = JSON.stringify(storage, null, 2);
704
- try {
705
- await fs.writeFile(tempPath, content, { encoding: "utf-8", mode: 384 });
706
- await fs.rename(tempPath, path5);
707
- } catch (error) {
708
- try {
709
- await fs.unlink(tempPath);
710
- } catch {
711
- }
712
- throw error;
713
- }
727
+ await atomicWriteFile(path5, content);
714
728
  });
715
729
  }
716
730
  async function loadAccountsUnsafe() {
@@ -5289,6 +5303,7 @@ function needsThinkingRecovery(state) {
5289
5303
 
5290
5304
  // src/plugin/transform/claude.ts
5291
5305
  var CLAUDE_THINKING_MAX_OUTPUT_TOKENS = 64e3;
5306
+ 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.";
5292
5307
  function isClaudeModel(model) {
5293
5308
  return model.toLowerCase().includes("claude");
5294
5309
  }
@@ -5296,6 +5311,23 @@ function isClaudeThinkingModel(model) {
5296
5311
  const lower = model.toLowerCase();
5297
5312
  return lower.includes("claude") && lower.includes("thinking");
5298
5313
  }
5314
+ function appendClaudeThinkingHint(payload, hint = CLAUDE_INTERLEAVED_THINKING_HINT) {
5315
+ const existing = payload.systemInstruction;
5316
+ if (typeof existing === "string") {
5317
+ payload.systemInstruction = existing.trim().length > 0 ? { role: "user", parts: [{ text: existing }, { text: hint }] } : hint;
5318
+ } else if (existing && typeof existing === "object") {
5319
+ const sys = existing;
5320
+ const partsValue = sys.parts;
5321
+ if (Array.isArray(partsValue)) {
5322
+ sys.parts = [...partsValue, { text: hint }];
5323
+ } else {
5324
+ sys.parts = [{ text: hint }];
5325
+ }
5326
+ payload.systemInstruction = sys;
5327
+ } else if (Array.isArray(payload.contents)) {
5328
+ payload.systemInstruction = { parts: [{ text: hint }] };
5329
+ }
5330
+ }
5299
5331
 
5300
5332
  // src/plugin/transform/gemini.ts
5301
5333
  var UNSUPPORTED_SCHEMA_FIELDS = /* @__PURE__ */ new Set([
@@ -7209,22 +7241,7 @@ function prepareAntigravityRequest(input2, init, accessToken, projectId, endpoin
7209
7241
  delete requestPayload.system_instruction;
7210
7242
  }
7211
7243
  if (isClaudeThinking && Array.isArray(requestPayload.tools) && requestPayload.tools.length > 0) {
7212
- const 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.";
7213
- const existing = requestPayload.systemInstruction;
7214
- if (typeof existing === "string") {
7215
- requestPayload.systemInstruction = { parts: [{ text: existing }, { text: hint }] };
7216
- } else if (existing && typeof existing === "object") {
7217
- const sys = existing;
7218
- const partsValue = sys.parts;
7219
- if (Array.isArray(partsValue)) {
7220
- sys.parts = [...partsValue, { text: hint }];
7221
- } else {
7222
- sys.parts = [{ text: hint }];
7223
- }
7224
- requestPayload.systemInstruction = sys;
7225
- } else if (Array.isArray(requestPayload.contents)) {
7226
- requestPayload.systemInstruction = { parts: [{ text: hint }] };
7227
- }
7244
+ appendClaudeThinkingHint(requestPayload);
7228
7245
  }
7229
7246
  const cachedContentFromExtra = typeof requestPayload.extra_body === "object" && requestPayload.extra_body ? requestPayload.extra_body.cached_content ?? requestPayload.extra_body.cachedContent : void 0;
7230
7247
  const cachedContent = requestPayload.cached_content ?? requestPayload.cachedContent ?? cachedContentFromExtra;