Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
P0 KernelClient 功能断裂修复: - Skill CUD: registry.rs create/update/delete + serialize_skill_md + kernel proxy - Workflow CUD: pipeline_commands.rs create/update/delete + serde_yaml依赖 - Agent更新: registry update方法 + AgentConfigUpdated事件 + agent_update命令 - Hand流式事件: HandStart/HandEnd变体替换ToolStart/ToolEnd - 后端验证: hand_get/hand_run_status/hand_run_list确认实现完整 - Approval闭环: respond_to_approval后台spawn+5分钟超时轮询 P2/P3 质量改进: - Browser WebDriver: TCP探测ChromeDriver/GeckoDriver/Edge端口替换硬编码true - api-fallbacks: 移除假技能和16个捏造安全层,替换为真实能力映射 - dead_code清理: 移除5个模块级#![allow(dead_code)],删除3个真正死方法, 删除未注册的compactor_compact_llm命令,warnings从8降到3 - 所有变更通过cargo check + tsc --noEmit验证
107 lines
3.0 KiB
Rust
107 lines
3.0 KiB
Rust
//! Agent registry
|
|
|
|
use dashmap::DashMap;
|
|
use zclaw_types::{AgentConfig, AgentId, AgentInfo, AgentState};
|
|
use chrono::Utc;
|
|
|
|
/// In-memory registry of active agents
|
|
pub struct AgentRegistry {
|
|
agents: DashMap<AgentId, AgentConfig>,
|
|
states: DashMap<AgentId, AgentState>,
|
|
created_at: DashMap<AgentId, chrono::DateTime<Utc>>,
|
|
message_counts: DashMap<AgentId, u64>,
|
|
}
|
|
|
|
impl AgentRegistry {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
agents: DashMap::new(),
|
|
states: DashMap::new(),
|
|
created_at: DashMap::new(),
|
|
message_counts: DashMap::new(),
|
|
}
|
|
}
|
|
|
|
/// Register an agent
|
|
pub fn register(&self, config: AgentConfig) {
|
|
let id = config.id;
|
|
self.agents.insert(id, config);
|
|
self.states.insert(id, AgentState::Running);
|
|
self.created_at.insert(id, Utc::now());
|
|
}
|
|
|
|
/// Unregister an agent
|
|
pub fn unregister(&self, id: &AgentId) {
|
|
self.agents.remove(id);
|
|
self.states.remove(id);
|
|
self.created_at.remove(id);
|
|
self.message_counts.remove(id);
|
|
}
|
|
|
|
/// Update an agent's configuration (preserves state and message count)
|
|
pub fn update(&self, config: AgentConfig) {
|
|
let id = config.id;
|
|
self.agents.insert(id, config);
|
|
}
|
|
|
|
/// Get an agent by ID
|
|
pub fn get(&self, id: &AgentId) -> Option<AgentConfig> {
|
|
self.agents.get(id).map(|r| r.clone())
|
|
}
|
|
|
|
/// Get agent info
|
|
pub fn get_info(&self, id: &AgentId) -> Option<AgentInfo> {
|
|
let config = self.agents.get(id)?;
|
|
let state = self.states.get(id).map(|s| *s).unwrap_or(AgentState::Terminated);
|
|
let created_at = self.created_at.get(id).map(|t| *t).unwrap_or_else(Utc::now);
|
|
|
|
Some(AgentInfo {
|
|
id: *id,
|
|
name: config.name.clone(),
|
|
description: config.description.clone(),
|
|
model: config.model.model.clone(),
|
|
provider: config.model.provider.clone(),
|
|
state,
|
|
message_count: self.message_counts.get(id).map(|c| *c as usize).unwrap_or(0),
|
|
created_at,
|
|
updated_at: Utc::now(),
|
|
})
|
|
}
|
|
|
|
/// List all agents
|
|
pub fn list(&self) -> Vec<AgentInfo> {
|
|
self.agents.iter()
|
|
.filter_map(|entry| {
|
|
let id = entry.key();
|
|
self.get_info(id)
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
/// Update agent state
|
|
pub fn set_state(&self, id: &AgentId, state: AgentState) {
|
|
self.states.insert(*id, state);
|
|
}
|
|
|
|
/// Get agent state
|
|
pub fn get_state(&self, id: &AgentId) -> AgentState {
|
|
self.states.get(id).map(|s| *s).unwrap_or(AgentState::Terminated)
|
|
}
|
|
|
|
/// Count active agents
|
|
pub fn count(&self) -> usize {
|
|
self.agents.len()
|
|
}
|
|
|
|
/// Increment message count for an agent
|
|
pub fn increment_message_count(&self, id: &AgentId) {
|
|
self.message_counts.entry(*id).and_modify(|c| *c += 1).or_insert(1);
|
|
}
|
|
}
|
|
|
|
impl Default for AgentRegistry {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|