Skip to main content

steer_tools/tools/
fetch.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use thiserror::Error;
4
5use crate::ToolSpec;
6use crate::error::ToolExecutionError;
7use crate::result::FetchResult;
8
9pub const FETCH_TOOL_NAME: &str = "web_fetch";
10
11pub struct FetchToolSpec;
12
13impl ToolSpec for FetchToolSpec {
14    type Params = FetchParams;
15    type Result = FetchResult;
16    type Error = FetchError;
17
18    const NAME: &'static str = FETCH_TOOL_NAME;
19    const DISPLAY_NAME: &'static str = "Fetch URL";
20
21    fn execution_error(error: Self::Error) -> ToolExecutionError {
22        ToolExecutionError::Fetch(error)
23    }
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, Error)]
27#[serde(tag = "code", rename_all = "snake_case")]
28pub enum FetchError {
29    #[error("invalid url: {message}")]
30    InvalidUrl { message: String },
31
32    #[error("url scheme '{scheme}' is not supported")]
33    UnsupportedScheme { scheme: String },
34
35    #[error("request failed: {message}")]
36    RequestFailed { message: String },
37
38    #[error("http error: {status} when fetching {url}")]
39    Http { status: u16, url: String },
40
41    #[error("failed to read response body from {url}: {message}")]
42    ReadFailed { url: String, message: String },
43
44    #[error("model call failed: {message}")]
45    ModelCallFailed { message: String },
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
49pub struct FetchParams {
50    /// The URL to fetch content from
51    pub url: String,
52    /// The prompt to process the content with
53    pub prompt: String,
54}