fix: improve VS Code config synchronization and code formatting
- Add automatic VS Code config sync when base_url changes in TOML - Improve error handling for VS Code configuration writes - Enhance state management with ref tracking to prevent duplicate API calls - Fix code formatting issues and improve readability across components - Optimize common configuration handling for both Claude and Codex providers
This commit is contained in:
@@ -22,7 +22,10 @@ const deepMerge = (
|
||||
return target;
|
||||
};
|
||||
|
||||
const deepRemove = (target: Record<string, any>, source: Record<string, any>) => {
|
||||
const deepRemove = (
|
||||
target: Record<string, any>,
|
||||
source: Record<string, any>,
|
||||
) => {
|
||||
Object.entries(source).forEach(([key, value]) => {
|
||||
if (!(key in target)) return;
|
||||
|
||||
@@ -59,7 +62,7 @@ const isSubset = (target: any, source: any): boolean => {
|
||||
const deepClone = <T>(obj: T): T => {
|
||||
if (obj === null || typeof obj !== "object") return obj;
|
||||
if (obj instanceof Date) return new Date(obj.getTime()) as T;
|
||||
if (obj instanceof Array) return obj.map(item => deepClone(item)) as T;
|
||||
if (obj instanceof Array) return obj.map((item) => deepClone(item)) as T;
|
||||
if (obj instanceof Object) {
|
||||
const clonedObj = {} as T;
|
||||
for (const key in obj) {
|
||||
@@ -78,7 +81,10 @@ export interface UpdateCommonConfigResult {
|
||||
}
|
||||
|
||||
// 验证JSON配置格式
|
||||
export const validateJsonConfig = (value: string, fieldName: string = "配置"): string => {
|
||||
export const validateJsonConfig = (
|
||||
value: string,
|
||||
fieldName: string = "配置",
|
||||
): string => {
|
||||
if (!value.trim()) {
|
||||
return "";
|
||||
}
|
||||
@@ -123,7 +129,7 @@ export const updateCommonConfigSnippet = (
|
||||
error: snippetError,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
const snippet = JSON.parse(snippetString) as Record<string, any>;
|
||||
|
||||
if (enabled) {
|
||||
@@ -247,23 +253,23 @@ export const updateTomlCommonConfigSnippet = (
|
||||
const removeTomlCommonConfig = (tomlString: string): string => {
|
||||
const startIdx = tomlString.indexOf(COMMON_CONFIG_MARKER_START);
|
||||
const endIdx = tomlString.indexOf(COMMON_CONFIG_MARKER_END);
|
||||
|
||||
|
||||
if (startIdx === -1 || endIdx === -1) {
|
||||
return tomlString;
|
||||
}
|
||||
|
||||
|
||||
// 找到标记前的换行符(如果有)
|
||||
let realStartIdx = startIdx;
|
||||
if (startIdx > 0 && tomlString[startIdx - 1] === '\n') {
|
||||
if (startIdx > 0 && tomlString[startIdx - 1] === "\n") {
|
||||
realStartIdx = startIdx - 1;
|
||||
}
|
||||
|
||||
|
||||
// 找到标记后的换行符(如果有)
|
||||
let realEndIdx = endIdx + COMMON_CONFIG_MARKER_END.length;
|
||||
if (realEndIdx < tomlString.length && tomlString[realEndIdx] === '\n') {
|
||||
if (realEndIdx < tomlString.length && tomlString[realEndIdx] === "\n") {
|
||||
realEndIdx = realEndIdx + 1;
|
||||
}
|
||||
|
||||
|
||||
return tomlString.slice(0, realStartIdx) + tomlString.slice(realEndIdx);
|
||||
};
|
||||
|
||||
@@ -273,19 +279,19 @@ export const hasTomlCommonConfigSnippet = (
|
||||
snippetString: string,
|
||||
): boolean => {
|
||||
if (!snippetString.trim()) return false;
|
||||
|
||||
|
||||
const startIdx = tomlString.indexOf(COMMON_CONFIG_MARKER_START);
|
||||
const endIdx = tomlString.indexOf(COMMON_CONFIG_MARKER_END);
|
||||
|
||||
|
||||
if (startIdx === -1 || endIdx === -1 || startIdx >= endIdx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// 提取标记之间的内容
|
||||
const existingSnippet = tomlString
|
||||
.slice(startIdx + COMMON_CONFIG_MARKER_START.length, endIdx)
|
||||
.trim();
|
||||
|
||||
|
||||
return existingSnippet === snippetString.trim();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user