pub mod filesystem;
pub mod sandbox;
pub mod state;
pub mod storage;
pub use self::filesystem::FilesystemBackend;
pub use self::sandbox::SandboxBackend;
pub use self::state::StateBackend;
pub use self::storage::{
BackendConfig, BackendFactory, BackendStats, CachedBackend, FilesystemStorageBackend,
InMemoryBackend, NamespacedBackend, StorageBackend,
};
use async_trait::async_trait;
use serde_json::Value;
use crate::agent::DeepAgentError;
pub type Result<T> = std::result::Result<T, DeepAgentError>;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct FileInfo {
pub path: String,
pub is_dir: bool,
pub size: u64,
}
#[async_trait]
pub trait Backend: Send + Sync {
async fn save_state(&self, session_id: &str, state: &Value) -> Result<()>;
async fn load_state(&self, session_id: &str) -> Result<Option<Value>>;
async fn list_sessions(&self) -> Result<Vec<String>>;
async fn read_file(&self, _path: &str) -> Result<String> {
Err(DeepAgentError::Other(
"read_file not supported by this backend".into(),
))
}
async fn write_file(&self, _path: &str, _content: &str) -> Result<()> {
Err(DeepAgentError::Other(
"write_file not supported by this backend".into(),
))
}
async fn edit_file(&self, _path: &str, _old: &str, _new: &str) -> Result<()> {
Err(DeepAgentError::Other(
"edit_file not supported by this backend".into(),
))
}
async fn list_dir(&self, _path: &str) -> Result<Vec<FileInfo>> {
Err(DeepAgentError::Other(
"list_dir not supported by this backend".into(),
))
}
}