Skip to content

Commit 44f7c20

Browse files
authored
Merge pull request #22 from zss823158062/main
feat: 实现自动下载更新功能
2 parents 43c33bf + 1b7da3c commit 44f7c20

35 files changed

Lines changed: 657 additions & 269 deletions

src-tauri/src/commands/config_cmd.rs

Lines changed: 462 additions & 96 deletions
Large diffs are not rendered by default.

src-tauri/src/commands/provider_pool_cmd.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ pub struct CredentialSyncServiceState(pub Option<Arc<CredentialSyncService>>);
2222

2323
/// 展开路径中的 ~ 为用户主目录
2424
fn expand_tilde(path: &str) -> String {
25-
if path.starts_with("~/") {
25+
if let Some(stripped) = path.strip_prefix("~/") {
2626
if let Some(home) = dirs::home_dir() {
27-
return home.join(&path[2..]).to_string_lossy().to_string();
27+
return home.join(stripped).to_string_lossy().to_string();
2828
}
2929
}
3030
path.to_string()
@@ -82,8 +82,7 @@ fn copy_and_rename_credential_file(
8282

8383
// 对于 Kiro 凭证,需要合并 clientIdHash 文件中的 client_id/client_secret
8484
if provider_type == "kiro" {
85-
let content =
86-
fs::read_to_string(&source).map_err(|e| format!("读取凭证文件失败: {}", e))?;
85+
let content = fs::read_to_string(source).map_err(|e| format!("读取凭证文件失败: {}", e))?;
8786
let mut creds: serde_json::Value =
8887
serde_json::from_str(&content).map_err(|e| format!("解析凭证文件失败: {}", e))?;
8988

@@ -200,9 +199,9 @@ fn copy_and_rename_credential_file(
200199
tracing::error!(
201200
"[KIRO] IdC 认证方式缺少 clientId/clientSecret,无法创建有效的凭证副本"
202201
);
203-
return Err(format!(
204-
"IdC 认证凭证不完整:缺少 clientId/clientSecret。\n\n💡 解决方案:\n1. 确保 ~/.aws/sso/cache/ 目录下有对应的 clientIdHash 文件\n2. 如果使用 AWS IAM Identity Center,请确保已完成完整的 SSO 登录流程\n3. 或者尝试使用 Social 认证方式的凭证"
205-
));
202+
return Err(
203+
"IdC 认证凭证不完整:缺少 clientId/clientSecret。\n\n💡 解决方案:\n1. 确保 ~/.aws/sso/cache/ 目录下有对应的 clientIdHash 文件\n2. 如果使用 AWS IAM Identity Center,请确保已完成完整的 SSO 登录流程\n3. 或者尝试使用 Social 认证方式的凭证".to_string()
204+
);
206205
} else {
207206
tracing::warn!("[KIRO] 未找到 client_id/client_secret,将使用 social 认证方式");
208207
}
@@ -214,7 +213,7 @@ fn copy_and_rename_credential_file(
214213
fs::write(&target_path, merged_content).map_err(|e| format!("写入凭证文件失败: {}", e))?;
215214
} else {
216215
// 其他类型直接复制
217-
fs::copy(&source, &target_path).map_err(|e| format!("复制凭证文件失败: {}", e))?;
216+
fs::copy(source, &target_path).map_err(|e| format!("复制凭证文件失败: {}", e))?;
218217
}
219218

220219
// 返回新的文件路径
@@ -1117,7 +1116,7 @@ pub async fn get_antigravity_auth_url_and_wait(
11171116
);
11181117

11191118
// 从凭证中获取 project_id
1120-
let project_id = result.credentials.projectId.clone();
1119+
let project_id = result.credentials.project_id.clone();
11211120

11221121
// 添加到凭证池
11231122
let credential = pool_service.0.add_credential(
@@ -1165,7 +1164,7 @@ pub async fn start_antigravity_oauth_login(
11651164
);
11661165

11671166
// 从凭证中获取 project_id
1168-
let project_id = result.credentials.projectId.clone();
1167+
let project_id = result.credentials.project_id.clone();
11691168

11701169
// 添加到凭证池
11711170
let credential = pool_service.0.add_credential(

src-tauri/src/commands/route_cmd.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,7 @@ pub async fn get_route_curl_examples(
6565
.map_err(|e| e.to_string())?;
6666

6767
// 查找匹配的路由
68-
let route = routes.iter().find(|r| r.selector == selector).or_else(|| {
69-
// 如果是默认路由
70-
if selector == "default" {
71-
None // 返回 None 让下面的代码生成默认示例
72-
} else {
73-
None
74-
}
75-
});
68+
let route = routes.iter().find(|r| r.selector == selector);
7669

7770
// P0 安全修复:curl 示例使用占位符,不暴露真实 API Key
7871
let api_key = "${PROXYCAST_API_KEY}";

src-tauri/src/commands/usage_cmd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ fn read_kiro_credential_info(creds_file_path: &str) -> Result<(String, Option<St
116116

117117
/// 展开路径中的 ~ 为用户主目录
118118
fn expand_tilde(path: &str) -> String {
119-
if path.starts_with("~/") {
119+
if let Some(stripped) = path.strip_prefix("~/") {
120120
if let Some(home) = dirs::home_dir() {
121-
return home.join(&path[2..]).to_string_lossy().to_string();
121+
return home.join(stripped).to_string_lossy().to_string();
122122
}
123123
}
124124
path.to_string()

src-tauri/src/config/export.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,8 @@ mod base64 {
500500
}
501501
}
502502

503-
pub use self::base64::{decode as base64_decode, encode as base64_encode};
503+
pub use self::base64::decode as base64_decode;
504+
pub use self::base64::encode as base64_encode;
504505

505506
#[cfg(test)]
506507
mod unit_tests {

src-tauri/src/config/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ pub use hot_reload::{
1717
pub use import::{ImportOptions, ImportService, ValidationResult};
1818
pub use path_utils::{collapse_tilde, contains_tilde, expand_tilde};
1919
pub use types::{
20-
generate_secure_api_key, is_default_api_key, AmpConfig, AmpModelMapping, ApiKeyEntry, Config,
21-
CredentialEntry, CredentialPoolConfig, CustomProviderConfig, GeminiApiKeyEntry,
22-
IFlowCredentialEntry, InjectionRuleConfig, InjectionSettings, LoggingConfig, ProviderConfig,
23-
ProvidersConfig, QuotaExceededConfig, RemoteManagementConfig, RetrySettings, RoutingConfig,
24-
RoutingRuleConfig, ServerConfig, TlsConfig, VertexApiKeyEntry, VertexModelAlias,
25-
DEFAULT_API_KEY,
20+
AmpConfig, AmpModelMapping, ApiKeyEntry, Config, CredentialEntry, CredentialPoolConfig,
21+
CustomProviderConfig, GeminiApiKeyEntry, IFlowCredentialEntry, InjectionRuleConfig,
22+
InjectionSettings, LoggingConfig, ProviderConfig, ProvidersConfig, QuotaExceededConfig,
23+
RemoteManagementConfig, RetrySettings, RoutingConfig, ServerConfig, TlsConfig,
24+
VertexApiKeyEntry, VertexModelAlias,
2625
};
2726
pub use yaml::{load_config, save_config, ConfigError, ConfigManager, YamlService};
2827

src-tauri/src/config/path_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ pub fn expand_tilde<P: AsRef<Path>>(path: P) -> PathBuf {
4444
if path_str == "~" {
4545
// 仅 ~
4646
home_dir
47-
} else if path_str.starts_with("~/") {
47+
} else if let Some(rest) = path_str.strip_prefix("~/") {
4848
// ~/path 格式
49-
let rest = &path_str[2..]; // 跳过 "~/"
49+
// 跳过 "~/"
5050
home_dir.join(rest)
5151
} else {
5252
// ~user/path 格式,不支持,返回原路径

src-tauri/src/converter/openai_to_antigravity.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ fn find_function_name(contents: &[GeminiContent], tool_id: &str) -> String {
331331

332332
/// 清理参数中不需要的字段
333333
fn clean_parameters(params: Option<serde_json::Value>) -> Option<serde_json::Value> {
334-
params.map(|v| clean_value(v))
334+
params.map(clean_value)
335335
}
336336

337337
fn clean_value(value: serde_json::Value) -> serde_json::Value {
@@ -489,8 +489,7 @@ pub fn convert_antigravity_to_openai_response(
489489
content.push_str(text);
490490
}
491491
if let Some(fc) = part.get("functionCall") {
492-
let call_id =
493-
format!("call_{}", uuid::Uuid::new_v4().to_string()[..8].to_string());
492+
let call_id = format!("call_{}", &uuid::Uuid::new_v4().to_string()[..8]);
494493
tool_calls.push(serde_json::json!({
495494
"id": call_id,
496495
"type": "function",

src-tauri/src/converter/protocol_selector.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,11 @@ impl ProtocolSelector {
149149
/// 获取推荐的中间协议(用于不支持直接转换的情况)
150150
pub fn intermediate_protocol(source: Protocol, target: Protocol) -> Option<Protocol> {
151151
// 大多数情况下,OpenAI 是最好的中间协议
152-
if !Self::supports_direct_conversion(source, target) {
153-
if source != Protocol::OpenAI && target != Protocol::OpenAI {
154-
return Some(Protocol::OpenAI);
155-
}
152+
if !Self::supports_direct_conversion(source, target)
153+
&& source != Protocol::OpenAI
154+
&& target != Protocol::OpenAI
155+
{
156+
return Some(Protocol::OpenAI);
156157
}
157158
None
158159
}
@@ -172,11 +173,11 @@ impl ProtocolSelector {
172173
) -> bool {
173174
// 工具调用在某些转换中需要特殊处理
174175
if has_tools {
175-
match (source, target_provider) {
176-
(Protocol::OpenAI, PoolProviderType::Kiro) => true,
177-
(Protocol::Anthropic, PoolProviderType::Kiro) => true,
178-
_ => false,
179-
}
176+
matches!(
177+
(source, target_provider),
178+
(Protocol::OpenAI, PoolProviderType::Kiro)
179+
| (Protocol::Anthropic, PoolProviderType::Kiro)
180+
)
180181
} else if has_images {
181182
// 图片在某些 Provider 中需要特殊处理
182183
match target_provider {

src-tauri/src/credential/health.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@ impl HealthChecker {
225225
let mut recovered = Vec::new();
226226

227227
for cred in pool.all() {
228-
if matches!(cred.status, CredentialStatus::Unhealthy { .. }) {
229-
if pool.mark_active(&cred.id).is_ok() {
230-
recovered.push(cred.id.clone());
231-
}
228+
if matches!(cred.status, CredentialStatus::Unhealthy { .. })
229+
&& pool.mark_active(&cred.id).is_ok()
230+
{
231+
recovered.push(cred.id.clone());
232232
}
233233
}
234234

0 commit comments

Comments
 (0)