unai 0.0.1

Common AI abstractions
Documentation
use mime::Mime;
use url::Url;

#[derive(Debug, Clone)]
pub enum FileData {
    /// The raw bytes of the file
    Bytes(Vec<u8>),

    /// The file data encoded in Base64
    Base64(String),

    /// A URL pointing to the file location
    Url(Url),
}

#[derive(Debug, Clone)]
pub struct FileContent {
    /// The data of the file
    pub data: FileData,

    /// The name of the file
    pub file_name: Option<String>,

    /// The MIME type of the file
    pub mime: Option<Mime>,
}

#[derive(Debug, Clone)]
pub struct ToolCallContent {
    /// The id of the tool call
    pub id: String,

    /// The name of the tool that was called
    pub tool_name: String,

    /// The arguments for the tool call
    pub args: serde_json::Value,
}

#[derive(Debug, Clone)]
pub struct ToolCallResultContent {
    /// The id of the tool call
    pub id: String,

    /// The name of the tool that was called
    pub tool_name: String,

    /// The arguments for the tool call
    pub args: serde_json::Value,

    /// The output produced by the tool call
    pub output: serde_json::Value,

    /// Indicates whether the tool call was successful
    pub success: bool,
}

#[derive(Debug, Clone)]
pub enum Content {
    Text(String),

    File(FileContent),

    ToolCall(ToolCallContent),

    ToolCallResult(ToolCallResultContent),
}

impl From<String> for Content {
    fn from(content: String) -> Self {
        Self::Text(content)
    }
}

impl From<&str> for Content {
    fn from(content: &str) -> Self {
        Self::from(content.to_owned())
    }
}