Skip to main content

tiny_loop/tool/
fs.rs

1use tiny_loop_macros::tool_internal;
2
3use super::utils::truncate_text;
4
5/// Read file contents with optional character range.
6#[tool_internal]
7pub async fn read(
8    /// File path
9    path: String,
10    /// Optional start character index (default: 0)
11    start: Option<usize>,
12    /// Optional length in characters (default: 5000)
13    len: Option<usize>,
14) -> String {
15    match tokio::fs::read_to_string(&path).await {
16        Ok(content) => truncate_text(content, start.unwrap_or(0), len.unwrap_or(5000)),
17        Err(e) => format!("Error reading file: {}", e),
18    }
19}