openfunctions_rs/core/
checker.rs

1//! Environment and dependency checker for ensuring the system is correctly configured.
2
3use crate::core::Config;
4use anyhow::Result;
5use tracing::{info, warn};
6
7/// Checker for validating the environment and dependencies.
8///
9/// This struct provides methods to verify that necessary external tools are
10/// available and that the system configuration is valid.
11pub struct Checker {
12    #[allow(dead_code)]
13    config: Config,
14}
15
16impl Checker {
17    /// Creates a new `Checker` with the given configuration.
18    pub fn new(config: &Config) -> Self {
19        Self {
20            config: config.clone(),
21        }
22    }
23
24    /// Checks all tools and agents for required dependencies and a valid environment.
25    pub async fn check_all(&self) -> Result<()> {
26        info!("Checking all tools and agents...");
27        self.check_environment().await?;
28        self.check_dependencies().await?;
29        Ok(())
30    }
31
32    /// Checks a specific target (tool or agent).
33    pub async fn check_target(&self, target: &str) -> Result<()> {
34        info!("Checking target: {}", target);
35        // TODO: Implement more specific checks for a single target
36        Ok(())
37    }
38
39    /// Checks for the presence of required system executables.
40    async fn check_environment(&self) -> Result<()> {
41        info!("Checking for required system executables...");
42        // Check for required executables
43        let executables = ["bash", "node", "python"];
44        for exe in &executables {
45            if which::which(exe).is_err() {
46                warn!("{} not found in PATH. This may limit functionality.", exe);
47            } else {
48                info!("Found executable: {}", exe);
49            }
50        }
51        Ok(())
52    }
53
54    /// Checks for other dependencies.
55    /// This is a placeholder for future dependency checks, such as required libraries or packages.
56    async fn check_dependencies(&self) -> Result<()> {
57        info!("Dependencies check passed.");
58        Ok(())
59    }
60}