chore: format code and fix bundle identifier for v3.0.0 release

- Format all TypeScript/React code with Prettier
- Format all Rust code with cargo fmt
- Fix bundle identifier from .app to .desktop to avoid macOS conflicts
- Prepare codebase for v3.0.0 Tauri release
This commit is contained in:
Jason
2025-08-27 11:00:53 +08:00
parent 5e2e80b00d
commit 642e7a3817
23 changed files with 359 additions and 321 deletions

View File

@@ -1,91 +1,97 @@
// 供应商配置处理工具函数
// 处理includeCoAuthoredBy字段的添加/删除
export const updateCoAuthoredSetting = (jsonString: string, disable: boolean): string => {
export const updateCoAuthoredSetting = (
jsonString: string,
disable: boolean,
): string => {
try {
const config = JSON.parse(jsonString)
const config = JSON.parse(jsonString);
if (disable) {
// 添加或更新includeCoAuthoredBy字段
config.includeCoAuthoredBy = false
config.includeCoAuthoredBy = false;
} else {
// 删除includeCoAuthoredBy字段
delete config.includeCoAuthoredBy
delete config.includeCoAuthoredBy;
}
return JSON.stringify(config, null, 2)
return JSON.stringify(config, null, 2);
} catch (err) {
// 如果JSON解析失败返回原始字符串
return jsonString
return jsonString;
}
}
};
// 从JSON配置中检查是否包含includeCoAuthoredBy设置
export const checkCoAuthoredSetting = (jsonString: string): boolean => {
try {
const config = JSON.parse(jsonString)
return config.includeCoAuthoredBy === false
const config = JSON.parse(jsonString);
return config.includeCoAuthoredBy === false;
} catch (err) {
return false
return false;
}
}
};
// 从JSON配置中提取并处理官网地址
export const extractWebsiteUrl = (jsonString: string): string => {
try {
const config = JSON.parse(jsonString)
const baseUrl = config?.env?.ANTHROPIC_BASE_URL
if (baseUrl && typeof baseUrl === 'string') {
const config = JSON.parse(jsonString);
const baseUrl = config?.env?.ANTHROPIC_BASE_URL;
if (baseUrl && typeof baseUrl === "string") {
// 去掉 "api." 前缀
return baseUrl.replace(/^https?:\/\/api\./, 'https://')
return baseUrl.replace(/^https?:\/\/api\./, "https://");
}
} catch (err) {
// 忽略JSON解析错误
}
return ''
}
return "";
};
// 读取配置中的 API Keyenv.ANTHROPIC_AUTH_TOKEN
export const getApiKeyFromConfig = (jsonString: string): string => {
try {
const config = JSON.parse(jsonString)
const key = config?.env?.ANTHROPIC_AUTH_TOKEN
return typeof key === 'string' ? key : ''
const config = JSON.parse(jsonString);
const key = config?.env?.ANTHROPIC_AUTH_TOKEN;
return typeof key === "string" ? key : "";
} catch (err) {
return ''
return "";
}
}
};
// 判断配置中是否存在 API Key 字段
export const hasApiKeyField = (jsonString: string): boolean => {
try {
const config = JSON.parse(jsonString)
return Object.prototype.hasOwnProperty.call(config?.env ?? {}, 'ANTHROPIC_AUTH_TOKEN')
const config = JSON.parse(jsonString);
return Object.prototype.hasOwnProperty.call(
config?.env ?? {},
"ANTHROPIC_AUTH_TOKEN",
);
} catch (err) {
return false
return false;
}
}
};
// 写入/更新配置中的 API Key默认不新增缺失字段
export const setApiKeyInConfig = (
jsonString: string,
apiKey: string,
options: { createIfMissing?: boolean } = {}
options: { createIfMissing?: boolean } = {},
): string => {
const { createIfMissing = false } = options
const { createIfMissing = false } = options;
try {
const config = JSON.parse(jsonString)
const config = JSON.parse(jsonString);
if (!config.env) {
if (!createIfMissing) return jsonString
config.env = {}
if (!createIfMissing) return jsonString;
config.env = {};
}
if (!('ANTHROPIC_AUTH_TOKEN' in config.env) && !createIfMissing) {
return jsonString
if (!("ANTHROPIC_AUTH_TOKEN" in config.env) && !createIfMissing) {
return jsonString;
}
config.env.ANTHROPIC_AUTH_TOKEN = apiKey
return JSON.stringify(config, null, 2)
config.env.ANTHROPIC_AUTH_TOKEN = apiKey;
return JSON.stringify(config, null, 2);
} catch (err) {
return jsonString
return jsonString;
}
}
};