bingocode 1.1.200-beta.18 → 1.1.200-beta.19
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/package.json
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import * as fs from 'fs/promises'
|
|
10
10
|
import * as path from 'path'
|
|
11
11
|
import * as os from 'os'
|
|
12
|
+
import { parse as parseJsonc } from 'jsonc-parser/lib/esm/main.js'
|
|
12
13
|
import { getDirectFetchOptions } from '../../utils/proxy.ts'
|
|
13
14
|
import { ApiError } from '../middleware/errorHandler.js'
|
|
14
15
|
import { anthropicToOpenaiChat } from '../proxy/transform/anthropicToOpenaiChat.js'
|
|
@@ -620,7 +621,9 @@ export class ProviderService {
|
|
|
620
621
|
let originalContent: string | null = null
|
|
621
622
|
try {
|
|
622
623
|
originalContent = await fs.readFile(settingsPath, "utf-8")
|
|
623
|
-
settings
|
|
624
|
+
// VS Code settings.json uses JSONC (JSON with comments) —
|
|
625
|
+
// parseJsonc handles comments/trailing commas, unlike JSON.parse
|
|
626
|
+
settings = parseJsonc(originalContent) as Record<string, unknown>
|
|
624
627
|
} catch {
|
|
625
628
|
// File does not exist yet — start fresh
|
|
626
629
|
}
|
|
@@ -650,7 +653,9 @@ export class ProviderService {
|
|
|
650
653
|
|
|
651
654
|
try {
|
|
652
655
|
await fs.mkdir(path.dirname(settingsPath), { recursive: true })
|
|
653
|
-
|
|
656
|
+
const tmpPath = `${settingsPath}.tmp.${Date.now()}`
|
|
657
|
+
await fs.writeFile(tmpPath, JSON.stringify(settings, null, 4) + '\n')
|
|
658
|
+
await fs.rename(tmpPath, settingsPath)
|
|
654
659
|
writtenPaths.push(settingsPath)
|
|
655
660
|
} catch (err) {
|
|
656
661
|
failedPaths.push(settingsPath)
|
|
@@ -661,7 +666,9 @@ export class ProviderService {
|
|
|
661
666
|
// Fix #11: Attempt restore from backup on write failure
|
|
662
667
|
if (originalContent !== null) {
|
|
663
668
|
try {
|
|
664
|
-
|
|
669
|
+
const tmpPath2 = `${settingsPath}.tmp.${Date.now()}`
|
|
670
|
+
await fs.writeFile(tmpPath2, originalContent, "utf-8")
|
|
671
|
+
await fs.rename(tmpPath2, settingsPath)
|
|
665
672
|
console.error(`[ProviderService] Restored ${settingsPath} from in-memory copy after write failure`)
|
|
666
673
|
} catch {
|
|
667
674
|
// In-memory restore failed, try .bak file
|
|
@@ -694,7 +701,9 @@ export class ProviderService {
|
|
|
694
701
|
const original = originalContents.get(p)
|
|
695
702
|
try {
|
|
696
703
|
if (original !== null) {
|
|
697
|
-
|
|
704
|
+
const tmpPath = `${p}.tmp.${Date.now()}`
|
|
705
|
+
await fs.writeFile(tmpPath, original, "utf-8")
|
|
706
|
+
await fs.rename(tmpPath, p)
|
|
698
707
|
} else {
|
|
699
708
|
await fs.unlink(p).catch(() => {})
|
|
700
709
|
}
|
|
@@ -754,14 +763,16 @@ export class ProviderService {
|
|
|
754
763
|
for (const settingsPath of linkedPaths) {
|
|
755
764
|
try {
|
|
756
765
|
const raw = await fs.readFile(settingsPath, "utf-8")
|
|
757
|
-
const settings =
|
|
766
|
+
const settings = parseJsonc(raw) as Record<string, unknown>
|
|
758
767
|
settings.claudeCode = preLinkClaudeCode[settingsPath] ?? {
|
|
759
768
|
preferredLocation: "panel",
|
|
760
769
|
environmentVariables: [
|
|
761
770
|
{ name: "ANTHROPIC_BASE_URL", value: "https://api.anthropic.com" },
|
|
762
771
|
],
|
|
763
772
|
}
|
|
764
|
-
|
|
773
|
+
const tmpPath = `${settingsPath}.tmp.${Date.now()}`
|
|
774
|
+
await fs.writeFile(tmpPath, JSON.stringify(settings, null, 4) + '\n')
|
|
775
|
+
await fs.rename(tmpPath, settingsPath)
|
|
765
776
|
} catch {
|
|
766
777
|
// File may have been moved or deleted since linking — harmless
|
|
767
778
|
}
|