diff --git a/src/config/agent.rs b/src/config/agent.rs index 813df3a..2f44477 100644 --- a/src/config/agent.rs +++ b/src/config/agent.rs @@ -32,6 +32,9 @@ impl Agent { ) -> Result { let functions_dir = Config::agent_functions_dir(name)?; let definition_file_path = functions_dir.join("index.yaml"); + if !definition_file_path.exists() { + bail!("Unknown agent `{name}`"); + } let functions_file_path = functions_dir.join("functions.json"); let variables_path = Config::agent_variables_file(name)?; let rag_path = Config::agent_rag_file(name, "rag")?; diff --git a/src/config/mod.rs b/src/config/mod.rs index 8e3e2c3..33bde56 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -205,7 +205,7 @@ impl Default for Config { agent: None, model: Default::default(), functions: Default::default(), - working_mode: WorkingMode::Command, + working_mode: WorkingMode::Cmd, last_message: None, } } @@ -1199,6 +1199,9 @@ impl Config { Some(name) => { let rag_path = config.read().rag_file(name)?; if !rag_path.exists() { + if config.read().working_mode.is_cmd() { + bail!("Unknown RAG '{name}'") + } Rag::init(config, name, &rag_path, &[], abort_signal).await? } else { Rag::load(config, name, &rag_path)? @@ -1376,7 +1379,7 @@ impl Config { pub fn apply_prelude(&mut self) -> Result<()> { let prelude = match self.working_mode { - WorkingMode::Command => self.prelude.as_ref(), + WorkingMode::Cmd => self.prelude.as_ref(), WorkingMode::Repl => self.repl_prelude.as_ref().or(self.prelude.as_ref()), WorkingMode::Serve => return Ok(()), }; @@ -2043,12 +2046,15 @@ pub fn load_env_file() -> Result<()> { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum WorkingMode { - Command, + Cmd, Repl, Serve, } impl WorkingMode { + pub fn is_cmd(&self) -> bool { + *self == WorkingMode::Cmd + } pub fn is_repl(&self) -> bool { *self == WorkingMode::Repl } diff --git a/src/main.rs b/src/main.rs index 3c52f0d..299dc6b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,7 +50,7 @@ async fn main() -> Result<()> { } else if text.is_none() && cli.file.is_empty() { WorkingMode::Repl } else { - WorkingMode::Command + WorkingMode::Cmd }; setup_logger(working_mode.is_serve())?; let config = Arc::new(RwLock::new(Config::init(working_mode)?)); diff --git a/src/render/mod.rs b/src/render/mod.rs index 97161f8..b2ed55d 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -26,5 +26,5 @@ pub async fn render_stream( } pub fn render_error(err: anyhow::Error) { - eprintln!("{}", error_text(&pretty_error(&err))); + eprint!("{}", error_text(&pretty_error(&err))); }