Helper method to save the agent config to file
(os: &mut Os, config: &Agent, agent_name: &str, is_global: bool)
| 3963 | |
| 3964 | // Helper method to save the agent config to file |
| 3965 | async fn save_agent_config(os: &mut Os, config: &Agent, agent_name: &str, is_global: bool) -> Result<(), ChatError> { |
| 3966 | let resolver = PathResolver::new(os); |
| 3967 | let config_dir = if is_global { |
| 3968 | resolver |
| 3969 | .global() |
| 3970 | .agents_dir() |
| 3971 | .map_err(|e| ChatError::Custom(format!("Could not find global agent directory: {}", e).into()))? |
| 3972 | } else { |
| 3973 | resolver |
| 3974 | .workspace() |
| 3975 | .agents_dir() |
| 3976 | .map_err(|e| ChatError::Custom(format!("Could not find local agent directory: {}", e).into()))? |
| 3977 | }; |
| 3978 | |
| 3979 | tokio::fs::create_dir_all(&config_dir) |
| 3980 | .await |
| 3981 | .map_err(|e| ChatError::Custom(format!("Failed to create config directory: {}", e).into()))?; |
| 3982 | |
| 3983 | let config_file = config_dir.join(format!("{}.json", agent_name)); |
| 3984 | let config_json = serde_json::to_string_pretty(config) |
| 3985 | .map_err(|e| ChatError::Custom(format!("Failed to serialize agent config: {}", e).into()))?; |
| 3986 | |
| 3987 | tokio::fs::write(&config_file, config_json) |
| 3988 | .await |
| 3989 | .map_err(|e| ChatError::Custom(format!("Failed to write agent config file: {}", e).into()))?; |
| 3990 | |
| 3991 | Ok(()) |
| 3992 | } |
| 3993 | |
| 3994 | #[cfg(test)] |
| 3995 | mod tests { |
no test coverage detected