pub mod adapter;
mod error;
pub mod index;
#[cfg(feature = "jsonl")]
pub mod jsonl;
#[cfg(feature = "memory")]
pub mod memory;
pub mod redb_store;
pub use adapter::StoreAdapter;
pub use error::StoreError;
pub use index::SessionIndex;
pub use redb_store::RedbSessionStore;
use async_trait::async_trait;
use meerkat_core::{Session, SessionId, SessionMeta};
use std::time::SystemTime;
#[derive(Debug, Clone, Default)]
pub struct SessionFilter {
pub created_after: Option<SystemTime>,
pub updated_after: Option<SystemTime>,
pub limit: Option<usize>,
pub offset: Option<usize>,
}
#[async_trait]
pub trait SessionStore: Send + Sync {
async fn save(&self, session: &Session) -> Result<(), StoreError>;
async fn load(&self, id: &SessionId) -> Result<Option<Session>, StoreError>;
async fn list(&self, filter: SessionFilter) -> Result<Vec<SessionMeta>, StoreError>;
async fn delete(&self, id: &SessionId) -> Result<(), StoreError>;
async fn exists(&self, id: &SessionId) -> Result<bool, StoreError> {
Ok(self.load(id).await?.is_some())
}
}
#[cfg(feature = "jsonl")]
pub use jsonl::JsonlStore;
#[cfg(feature = "memory")]
pub use memory::MemoryStore;
pub fn resolve_store_path(config: &meerkat_core::Config) -> std::path::PathBuf {
config
.store
.sessions_path
.clone()
.or_else(|| config.storage.directory.clone())
.unwrap_or_else(|| {
dirs::data_dir()
.unwrap_or_else(|| std::path::PathBuf::from("."))
.join("meerkat")
.join("sessions")
})
}