Skip to main content

potato_agent/agents/store/
mod.rs

1pub mod app_state_store;
2pub mod memory_store;
3pub mod persistent_memory;
4pub mod session_store;
5pub mod user_state_store;
6
7#[cfg(feature = "sqlite")]
8pub mod sqlite_app_state_store;
9#[cfg(feature = "sqlite")]
10pub mod sqlite_memory_store;
11#[cfg(feature = "sqlite")]
12pub mod sqlite_session_store;
13#[cfg(feature = "sqlite")]
14pub mod sqlite_user_state_store;
15
16pub use app_state_store::AppStateStore;
17pub use memory_store::{MemoryStore, StoredMemoryTurn};
18pub use persistent_memory::PersistentMemory;
19pub use session_store::SessionStore;
20pub use user_state_store::UserStateStore;
21
22#[cfg(feature = "sqlite")]
23pub use sqlite_app_state_store::SqliteAppStateStore;
24#[cfg(feature = "sqlite")]
25pub use sqlite_memory_store::SqliteMemoryStore;
26#[cfg(feature = "sqlite")]
27pub use sqlite_session_store::SqliteSessionStore;
28#[cfg(feature = "sqlite")]
29pub use sqlite_user_state_store::SqliteUserStateStore;
30
31use thiserror::Error;
32
33#[derive(Debug, Error)]
34pub enum StoreError {
35    #[error("storage backend error: {0}")]
36    Backend(String),
37
38    #[error("serialization error: {0}")]
39    Serialization(#[from] serde_json::Error),
40
41    #[error("session not found: {0}")]
42    NotFound(String),
43
44    #[error("connection error: {0}")]
45    Connection(String),
46
47    #[error("invalid database path: {0}")]
48    InvalidPath(String),
49}
50
51/// Validates a SQLite file path, rejecting path traversal and URL injection attempts.
52/// Returns the formatted connection URL on success.
53pub fn validate_db_path(path: &str) -> Result<String, StoreError> {
54    if path.contains('?') || path.contains('#') {
55        return Err(StoreError::InvalidPath(path.to_string()));
56    }
57    let p = std::path::Path::new(path);
58    if p.components().any(|c| c == std::path::Component::ParentDir) {
59        return Err(StoreError::InvalidPath(path.to_string()));
60    }
61    Ok(format!("sqlite:{}?mode=rwc", path))
62}