pub mod error;
pub mod filesystem;
pub mod kvstore;
pub mod tools;
#[cfg(feature = "rig-integration")]
pub mod rig_integration;
#[cfg(not(feature = "rig-integration"))]
pub mod rig_integration;
pub use error::{AgentFsError, Result};
pub use filesystem::{DbFileSystem, FileSystem, Stats};
pub use kvstore::{DbKvStore, KvStore};
pub use tools::{DbToolRecorder, ToolCall, ToolCallStats, ToolCallStatus, ToolRecorder};
use agentdb::AgentDB;
use std::path::PathBuf;
use std::sync::Arc;
pub struct AgentFS {
pub fs: DbFileSystem,
pub kv: DbKvStore,
pub tools: DbToolRecorder,
pub agent_id: String,
pub mount_path: PathBuf,
}
impl AgentFS {
pub async fn new(
db: Box<dyn AgentDB>,
agent_id: impl Into<String>,
mount_path: impl Into<PathBuf>,
) -> Result<Self> {
let agent_id = agent_id.into();
let mount_path = mount_path.into();
let db_arc = Arc::new(db);
Ok(Self {
fs: DbFileSystem::new(db_arc.clone(), mount_path.to_string_lossy().to_string()),
kv: DbKvStore::new(db_arc.clone(), agent_id.clone()),
tools: DbToolRecorder::new(db_arc),
agent_id,
mount_path,
})
}
#[cfg(feature = "sqlite")]
pub async fn sqlite(
path: impl AsRef<std::path::Path>,
agent_id: impl Into<String>,
) -> Result<Self> {
use agentsql::SqlBackend;
let backend = SqlBackend::sqlite(path.as_ref().to_string_lossy().to_string())
.await
.map_err(|e| AgentFsError::Database(agentdb::AgentDbError::Backend(e.to_string())))?;
Self::new(Box::new(backend), agent_id, "/agent").await
}
#[cfg(feature = "postgres")]
pub async fn postgres(url: impl Into<String>, agent_id: impl Into<String>) -> Result<Self> {
use agentsql::SqlBackend;
let backend = SqlBackend::postgres(url.into())
.await
.map_err(|e| AgentFsError::Database(agentdb::AgentDbError::Backend(e.to_string())))?;
Self::new(Box::new(backend), agent_id, "/agent").await
}
#[cfg(feature = "mysql")]
pub async fn mysql(url: impl Into<String>, agent_id: impl Into<String>) -> Result<Self> {
use agentsql::SqlBackend;
let backend = SqlBackend::mysql(url.into())
.await
.map_err(|e| AgentFsError::Database(agentdb::AgentDbError::Backend(e.to_string())))?;
Self::new(Box::new(backend), agent_id, "/agent").await
}
pub fn agent_id(&self) -> &str {
&self.agent_id
}
pub fn mount_path(&self) -> &PathBuf {
&self.mount_path
}
}