优化Agent Connect时的agent状态获取
This commit is contained in:
@@ -244,6 +244,15 @@ pub struct AcpAgentInfo {
|
||||
pub codex_config_toml: Option<String>,
|
||||
}
|
||||
|
||||
/// Lightweight status info for a single agent, used by connect() pre-check.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct AcpAgentStatus {
|
||||
pub agent_type: crate::models::agent::AgentType,
|
||||
pub available: bool,
|
||||
pub enabled: bool,
|
||||
pub installed_version: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum AgentSkillScope {
|
||||
|
||||
@@ -1127,6 +1127,44 @@ pub async fn acp_list_connections(
|
||||
Ok(manager.list_connections().await)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn acp_get_agent_status(
|
||||
agent_type: AgentType,
|
||||
db: tauri::State<'_, AppDatabase>,
|
||||
) -> Result<crate::acp::types::AcpAgentStatus, AcpError> {
|
||||
let platform = registry::current_platform();
|
||||
let meta = registry::get_agent_meta(agent_type);
|
||||
let setting = agent_setting_service::get_by_agent_type(&db.conn, agent_type)
|
||||
.await
|
||||
.map_err(|e| AcpError::protocol(e.to_string()))?;
|
||||
|
||||
let (available, installed_version) = match &meta.distribution {
|
||||
registry::AgentDistribution::Npx { .. } => (
|
||||
true,
|
||||
setting.as_ref().and_then(|m| m.installed_version.clone()),
|
||||
),
|
||||
registry::AgentDistribution::Binary {
|
||||
platforms, cmd, ..
|
||||
} => {
|
||||
let detected =
|
||||
binary_cache::detect_installed_version(agent_type, cmd)
|
||||
.ok()
|
||||
.flatten();
|
||||
(
|
||||
platforms.iter().any(|p| p.platform == platform),
|
||||
detected,
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
Ok(crate::acp::types::AcpAgentStatus {
|
||||
agent_type,
|
||||
available,
|
||||
enabled: setting.map(|m| m.enabled).unwrap_or(true),
|
||||
installed_version,
|
||||
})
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn acp_list_agents(
|
||||
db: tauri::State<'_, AppDatabase>,
|
||||
|
||||
@@ -275,6 +275,7 @@ pub fn run() {
|
||||
acp_commands::acp_disconnect,
|
||||
acp_commands::acp_list_connections,
|
||||
acp_commands::acp_list_agents,
|
||||
acp_commands::acp_get_agent_status,
|
||||
acp_commands::acp_clear_binary_cache,
|
||||
acp_commands::acp_download_agent_binary,
|
||||
acp_commands::acp_detect_agent_local_version,
|
||||
|
||||
Reference in New Issue
Block a user