use anyhow::Result;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::sync::RwLock;
use crate::coordination::AgentMessage as CCSwarmMessage;
use crate::identity::AgentRole;
pub type AgentId = String;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UnifiedAgentInfo {
pub ccswarm_id: String,
pub role: AgentRole,
pub active: bool,
pub capabilities: Vec<String>,
pub metadata: serde_json::Value,
}
pub struct AgentMappingRegistry {
mappings: RwLock<HashMap<String, UnifiedAgentInfo>>,
}
impl AgentMappingRegistry {
pub fn new() -> Self {
Self {
mappings: RwLock::new(HashMap::new()),
}
}
pub async fn register(&self, info: UnifiedAgentInfo) -> Result<()> {
let mut mappings = self
.mappings
.write()
.map_err(|e| anyhow::anyhow!("Failed to acquire write lock: {}", e))?;
mappings.insert(info.ccswarm_id.clone(), info);
Ok(())
}
pub fn get_agent_info(&self, agent_id: &str) -> Option<UnifiedAgentInfo> {
let mappings = self
.mappings
.read()
.map_err(|e| {
log::error!("Failed to acquire read lock: {}", e);
e
})
.ok()?;
mappings.get(agent_id).cloned()
}
pub fn to_unified(&self, ccswarm_id: &str) -> String {
ccswarm_id.to_string()
}
pub fn from_unified(&self, unified_id: &str) -> String {
unified_id.to_string()
}
}
impl Default for AgentMappingRegistry {
fn default() -> Self {
Self::new()
}
}
pub async fn convert_to_ai_session(
_msg: CCSwarmMessage,
_registry: &AgentMappingRegistry,
) -> Result<serde_json::Value> {
Ok(serde_json::json!({}))
}
pub async fn convert_from_ai_session(
_msg: serde_json::Value,
_registry: &AgentMappingRegistry,
) -> Result<CCSwarmMessage> {
Ok(CCSwarmMessage::StatusUpdate {
agent_id: "system".to_string(),
status: crate::agent::AgentStatus::Available,
metrics: serde_json::json!({}),
})
}