use crate::message::Message;
#[derive(Debug, Clone)]
pub enum StoreError {
Open(String),
Io(String),
Serde(String),
}
impl std::fmt::Display for StoreError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Open(e) => write!(f, "store open: {}", e),
Self::Io(e) => write!(f, "store io: {}", e),
Self::Serde(e) => write!(f, "store serde: {}", e),
}
}
}
impl std::error::Error for StoreError {}
#[derive(Debug, Clone)]
pub struct ToolLog<'a> {
pub name: &'a str,
pub args: &'a str,
pub result: &'a str,
pub duration_us: u64,
}
pub trait MessageStore: Send + Sync {
fn load(&self, session: &str) -> Result<Vec<Message>, StoreError>;
fn append(&self, session: &str, message: &Message) -> Result<(), StoreError>;
fn log_tool(&self, session: &str, log: &ToolLog<'_>) -> Result<(), StoreError>;
fn clear(&self, session: &str) -> Result<(), StoreError>;
}