use async_trait::async_trait;
use crate::error::Result;
use crate::message::Message;
#[async_trait]
#[diagnostic::on_unimplemented(
message = "`{Self}` does not implement the `Session` trait",
label = "this type cannot be used as a conversation session",
note = "implement `Session` to provide conversation memory for agents"
)]
pub trait Session: Send + Sync {
fn id(&self) -> &str;
async fn get_messages(&self, limit: Option<usize>) -> Result<Vec<Message>>;
async fn add_messages(&self, messages: &[Message]) -> Result<()>;
async fn pop_message(&self) -> Result<Option<Message>>;
async fn clear(&self) -> Result<()>;
async fn len(&self) -> Result<usize>;
async fn is_empty(&self) -> Result<bool> {
Ok(self.len().await? == 0)
}
}
pub type BoxedSession = Box<dyn Session>;
pub type SharedSession = std::sync::Arc<dyn Session>;