Skip to main content

steer_tools/tools/
replace.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use thiserror::Error;
4
5use crate::ToolSpec;
6use crate::error::{ToolExecutionError, WorkspaceOpError};
7use crate::result::ReplaceResult;
8
9pub const REPLACE_TOOL_NAME: &str = "write_file";
10
11pub struct ReplaceToolSpec;
12
13impl ToolSpec for ReplaceToolSpec {
14    type Params = ReplaceParams;
15    type Result = ReplaceResult;
16    type Error = ReplaceError;
17
18    const NAME: &'static str = REPLACE_TOOL_NAME;
19    const DISPLAY_NAME: &'static str = "Replace File";
20
21    fn execution_error(error: Self::Error) -> ToolExecutionError {
22        ToolExecutionError::Replace(error)
23    }
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, Error)]
27#[serde(tag = "code", content = "details", rename_all = "snake_case")]
28pub enum ReplaceError {
29    #[error("{0}")]
30    Workspace(WorkspaceOpError),
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
34pub struct ReplaceParams {
35    /// The absolute path to the file to write (must be absolute, not relative)
36    pub file_path: String,
37    /// The content to write to the file
38    pub content: String,
39}