cliai 0.2.0

A small Rust library for invoking AI tools through CLI backends like Ollama and GitHub Copilot CLI.
Documentation
use std::error::Error;
use std::fmt::{Display, Formatter};

/// Error returned by AI backends.
#[derive(Debug)]
pub enum AiError {
    /// Failed to start or communicate with the external process.
    Io(std::io::Error),
    /// Backend output was not valid UTF-8.
    Utf8(std::string::FromUtf8Error),
    /// Backend process exited unsuccessfully.
    CommandFailed(String),
}

impl Display for AiError {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Io(err) => write!(f, "io error: {}", err),
            Self::Utf8(err) => write!(f, "utf8 error: {}", err),
            Self::CommandFailed(msg) => write!(f, "command failed: {}", msg),
        }
    }
}

impl Error for AiError {}

impl From<std::io::Error> for AiError {
    fn from(value: std::io::Error) -> Self {
        Self::Io(value)
    }
}

impl From<std::string::FromUtf8Error> for AiError {
    fn from(value: std::string::FromUtf8Error) -> Self {
        Self::Utf8(value)
    }
}