1use tiny_loop_macros::tool_internal;
2
3use super::utils::truncate_text;
4
5#[tool_internal]
7pub async fn fetch(
8 url: String,
10 start: Option<usize>,
12 end: Option<usize>,
14) -> String {
15 let response = match reqwest::get(&url).await {
16 Ok(r) => r,
17 Err(e) => return format!("Error fetching URL: {}", e),
18 };
19
20 let html = match response.text().await {
21 Ok(h) => h,
22 Err(e) => return format!("Error reading response: {}", e),
23 };
24
25 let markdown = html2md::parse_html(&html);
26 truncate_text(markdown, start.unwrap_or(0), end.unwrap_or(5000))
27}