bamboo_domain/storage.rs
1//! Storage port definitions — abstract interfaces for session persistence.
2//!
3//! These traits define the boundary between the domain layer and storage
4//! implementations. Concrete implementations live in infrastructure crates.
5
6use crate::session::types::Session;
7
8/// Trait for session storage backends.
9///
10/// Provides an abstract interface for persisting and retrieving session data.
11/// Implementations can use different storage backends
12/// (e.g., JSONL files, databases, cloud storage).
13#[async_trait::async_trait]
14pub trait Storage: Send + Sync {
15 /// Saves a session's metadata.
16 async fn save_session(&self, session: &Session) -> std::io::Result<()>;
17
18 /// Loads a session by ID, returns None if not found.
19 async fn load_session(&self, session_id: &str) -> std::io::Result<Option<Session>>;
20
21 /// Deletes a session, returns true if anything was deleted.
22 async fn delete_session(&self, session_id: &str) -> std::io::Result<bool>;
23}
24
25/// Attachment reader for `bamboo-attachment://<session_id>/<attachment_id>` references.
26///
27/// This is used to keep session storage free of base64 while still allowing the
28/// agent loop to send data URLs upstream (most providers expect either HTTP(S)
29/// URLs or `data:` URLs for images).
30#[async_trait::async_trait]
31pub trait AttachmentReader: Send + Sync {
32 async fn read_attachment(
33 &self,
34 session_id: &str,
35 attachment_id: &str,
36 ) -> std::io::Result<Option<(Vec<u8>, String)>>;
37}