steer_tools/tools/
fetch.rs1use 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("request failed: {message}")]
30 RequestFailed { message: String },
31
32 #[error("http error: {status} when fetching {url}")]
33 Http { status: u16, url: String },
34
35 #[error("failed to read response body from {url}: {message}")]
36 ReadFailed { url: String, message: String },
37
38 #[error("model call failed: {message}")]
39 ModelCallFailed { message: String },
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
43pub struct FetchParams {
44 pub url: String,
46 pub prompt: String,
48}