43 lines
1.4 KiB
Rust
43 lines
1.4 KiB
Rust
use crate::app::subagent::spawn::AgentDefinition;
|
|||
|
|
|
||
|
|
pub fn load_global_agents() -> Vec<AgentDefinition> {
|
||
|
|
let store = crate::model::store::Store::new();
|
||
|
|
let agents_dir = store.base_dir.join("agents");
|
||
|
|
if !agents_dir.exists() {
|
||
|
|
return Vec::new();
|
||
|
|
}
|
||
|
|
let mut agents = Vec::new();
|
||
|
|
if let Ok(entries) = std::fs::read_dir(&agents_dir) {
|
||
|
|
for entry in entries.flatten() {
|
||
|
|
let path = entry.path();
|
||
|
|
if path.extension().is_some_and(|e| e == "json") {
|
||
|
|
if let Ok(content) = std::fs::read_to_string(&path) {
|
||
|
|
if let Ok(def) = serde_json::from_str::<AgentDefinition>(&content) {
|
||
|
|
agents.push(def);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
agents
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn save_global_agent(def: &AgentDefinition) -> anyhow::Result<()> {
|
||
|
|
let store = crate::model::store::Store::new();
|
||
|
|
let agents_dir = store.base_dir.join("agents");
|
||
|
|
std::fs::create_dir_all(&agents_dir)?;
|
||
|
|
let path = agents_dir.join(format!("{}.json", def.name));
|
||
|
|
let content = serde_json::to_string_pretty(def)?;
|
||
|
|
std::fs::write(path, content)?;
|
||
|
|
Ok(())
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn remove_global_agent(name: &str) -> anyhow::Result<()> {
|
||
|
|
let store = crate::model::store::Store::new();
|
||
|
|
let path = store.base_dir.join("agents").join(format!("{}.json", name));
|
||
|
|
if path.exists() {
|
||
|
|
std::fs::remove_file(path)?;
|
||
|
|
}
|
||
|
|
Ok(())
|
||
|
|
}
|