优化agent列表加载

This commit is contained in:
xintaofei
2026-03-26 22:37:52 +08:00
parent bf32cb71e7
commit 1b7c61e5af

View File

@@ -1256,11 +1256,9 @@ pub async fn acp_list_agents(
let meta = registry::get_agent_meta(agent_type); let meta = registry::get_agent_meta(agent_type);
let (available, dist_type, local_installed_version) = match &meta.distribution { let (available, dist_type, local_installed_version) = match &meta.distribution {
registry::AgentDistribution::Npx { .. } => { registry::AgentDistribution::Npx { .. } => {
// Detect NPX agent version dynamically, fall back to DB value // Use DB cached version for fast loading; updated during install/upgrade
let detected = detect_local_version(agent_type).await.or_else(|| { let cached = setting.and_then(|m| m.installed_version.clone());
setting.and_then(|m| m.installed_version.clone()) (true, "npx", cached)
});
(true, "npx", detected)
} }
registry::AgentDistribution::Binary { platforms, cmd, .. } => { registry::AgentDistribution::Binary { platforms, cmd, .. } => {
let detected = binary_cache::detect_installed_version(agent_type, cmd) let detected = binary_cache::detect_installed_version(agent_type, cmd)
@@ -1303,13 +1301,15 @@ pub async fn acp_list_agents(
} }
} }
let sort_order = setting.map(|m| m.sort_order).unwrap_or(idx as i32); let sort_order = setting.map(|m| m.sort_order).unwrap_or(idx as i32);
// Persist detected version to DB for both binary and npx agents // Persist detected version to DB for binary agents (npx written during install/upgrade)
let _ = agent_setting_service::set_installed_version( if dist_type == "binary" {
&db.conn, let _ = agent_setting_service::set_installed_version(
agent_type, &db.conn,
local_installed_version.clone(), agent_type,
) local_installed_version.clone(),
.await; )
.await;
}
let codex_auth_json = if agent_type == AgentType::Codex { let codex_auth_json = if agent_type == AgentType::Codex {
load_codex_auth_json_raw() load_codex_auth_json_raw()
} else { } else {