infinity_daemon/
config.rs1use infinity_agent_core::tools::config::ToolsConfig;
2use std::path::PathBuf;
3
4type BoxError = Box<dyn std::error::Error + Send + Sync>;
5
6pub fn user_config_path() -> Result<PathBuf, BoxError> {
7 let home = dirs::home_dir().ok_or("could not determine home directory")?;
8 Ok(home.join(".infinity").join("rap.json"))
9}
10
11pub fn providers_config_path() -> Result<PathBuf, BoxError> {
13 let home = dirs::home_dir().ok_or("could not determine home directory")?;
14 Ok(home.join(".infinity").join("providers.json"))
15}
16
17pub fn load_config(path: &std::path::Path) -> Result<ToolsConfig, BoxError> {
18 ToolsConfig::from_file(path)
19}
20
21pub fn load_merged_rap_config(
29 cwd: &std::path::Path,
30 user_config_path: Option<&std::path::Path>,
31) -> Result<(String, Option<ToolsConfig>), BoxError> {
32 let cwd_rap = cwd.join(".infinity").join("rap.json");
33 let local_config = cwd_rap
34 .exists()
35 .then(|| load_config(&cwd_rap))
36 .transpose()?;
37 let user_config = user_config_path
38 .and_then(|p| p.exists().then(|| load_config(p)))
39 .transpose()?;
40
41 Ok(match (local_config, user_config) {
42 (None, None) => (
43 "Neither local nor user RAP configs exist, using empty config".into(),
44 None,
45 ),
46 (None, Some(c)) => ("Using user config".into(), Some(c)),
47 (Some(c), None) => ("Using local config".into(), Some(c)),
48 (Some(mut l), Some(u)) => {
49 l.merge(u);
50 (
51 "Both local and user RAP configs exist, merging".into(),
52 Some(l),
53 )
54 }
55 })
56}