1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//! Rig.rs FileSystem trait integration for AgentFS
//!
//! This module provides integration with the Rig.rs agent framework by implementing
//! the `rig::agent::FileSystem` trait for `AgentFS`.
//!
//! # Enabling Rig Integration
//!
//! To enable this integration, add `rig` as a dependency to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! agentfs = { version = "0.1", features = ["rig-integration"] }
//! rig = "0.3"
//! ```
//!
//! # Usage with Rig
//!
//! ```rust,ignore
//! use rig::{agent::AgentBuilder, providers::openai};
//! use agentfs::AgentFS;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let openai = openai::Client::new(std::env::var("OPENAI_API_KEY")?);
//!
//! // Create AgentFS with SQLite backend
//! let fs = AgentFS::sqlite("agents/my-agent.db", "my-agent").await?;
//!
//! // Use with Rig agent
//! let agent = AgentBuilder::new(openai.gpt4())
//! .with_filesystem(fs)
//! .build();
//!
//! agent.say("Write a report to /output/report.txt").await?;
//! Ok(())
//! }
//! ```
//!
//! # Implementation Notes
//!
//! The integration maps AgentFS operations to Rig's FileSystem trait:
//! - `read_file` returns an error if the file doesn't exist (Rig expects Result<Vec<u8>>)
//! - `list_dir` returns an error if the directory doesn't exist
//! - All errors are converted to `rig::agent::FileSystemError::Io`
//! - Paths are automatically sandboxed within the mount point
// NOTE: This implementation is currently a placeholder/demonstration.
// To activate it:
// 1. Uncomment the `rig` dependency in Cargo.toml
// 2. Uncomment the `rig-integration` feature
// 3. Uncomment the impl below
/*
use crate::{AgentFS, FileSystem as AgentFileSystem};
use async_trait::async_trait;
use rig::agent::{FileSystem, FileSystemError};
#[async_trait]
impl FileSystem for AgentFS {
async fn read_file(&self, path: &str) -> Result<Vec<u8>, FileSystemError> {
self.fs
.read_file(path)
.await
.map_err(|e| FileSystemError::Io(e.to_string()))?
.ok_or_else(|| FileSystemError::Io(format!("File not found: {}", path)))
}
async fn write_file(&self, path: &str, content: &[u8]) -> Result<(), FileSystemError> {
self.fs
.write_file(path, content)
.await
.map_err(|e| FileSystemError::Io(e.to_string()))
}
async fn list_dir(&self, path: &str) -> Result<Vec<String>, FileSystemError> {
let entries = self
.fs
.readdir(path)
.await
.map_err(|e| FileSystemError::Io(e.to_string()))?
.ok_or_else(|| FileSystemError::Io(format!("Directory not found: {}", path)))?;
Ok(entries)
}
async fn file_exists(&self, path: &str) -> Result<bool, FileSystemError> {
self.fs
.exists(path)
.await
.map_err(|e| FileSystemError::Io(e.to_string()))
}
async fn remove_file(&self, path: &str) -> Result<(), FileSystemError> {
self.fs
.remove(path)
.await
.map_err(|e| FileSystemError::Io(e.to_string()))
}
async fn mkdir(&self, path: &str) -> Result<(), FileSystemError> {
self.fs
.mkdir(path)
.await
.map_err(|e| FileSystemError::Io(e.to_string()))
}
}
*/
// Placeholder documentation for the implementation above
/// When the `rig-integration` feature is enabled, `AgentFS` implements
/// the `rig::agent::FileSystem` trait, allowing it to be used directly
/// with Rig agents.
///
/// # Methods
///
/// - `read_file(path) -> Result<Vec<u8>, FileSystemError>`
/// - `write_file(path, content) -> Result<(), FileSystemError>`
/// - `list_dir(path) -> Result<Vec<String>, FileSystemError>`
/// - `file_exists(path) -> Result<bool, FileSystemError>`
/// - `remove_file(path) -> Result<(), FileSystemError>`
/// - `mkdir(path) -> Result<(), FileSystemError>`
///
/// # Error Handling
///
/// All AgentFS errors are converted to `rig::agent::FileSystemError::Io(_)`.
/// Operations that return `Option<T>` (like read_file) are converted to
/// errors when the result is `None`.
///
/// # Path Sandboxing
///
/// All paths are automatically sandboxed within the AgentFS mount point
/// (default `/agent`), preventing directory traversal attacks.
;