Skip to main content

steer_core/tools/static_tools/
view.rs

1use async_trait::async_trait;
2
3use super::workspace_op_error;
4use crate::tools::capability::Capabilities;
5use crate::tools::static_tool::{StaticTool, StaticToolContext, StaticToolError};
6use steer_tools::result::FileContentResult;
7use steer_tools::tools::view::{ViewError, ViewParams, ViewToolSpec};
8use steer_workspace::{ReadFileRequest, WorkspaceOpContext};
9
10pub struct ViewTool;
11
12#[async_trait]
13impl StaticTool for ViewTool {
14    type Params = ViewParams;
15    type Output = FileContentResult;
16    type Spec = ViewToolSpec;
17
18    const DESCRIPTION: &'static str = concat!(
19        "Reads a file from the local filesystem. The file_path parameter must be an absolute path, not a relative path.\n",
20        "By default, it reads up to 2000 lines starting from the beginning of the file. You can optionally specify a line offset and limit\n",
21        "(especially handy for long files), but it's recommended to read the whole file by not providing these parameters.\n",
22        "Any lines longer than 2000 characters will be truncated."
23    );
24    const REQUIRES_APPROVAL: bool = false;
25    const REQUIRED_CAPABILITIES: Capabilities = Capabilities::WORKSPACE;
26
27    async fn execute(
28        &self,
29        params: Self::Params,
30        ctx: &StaticToolContext,
31    ) -> Result<Self::Output, StaticToolError<ViewError>> {
32        let request = ReadFileRequest {
33            file_path: params.file_path,
34            offset: params.offset,
35            limit: params.limit,
36        };
37        let op_ctx =
38            WorkspaceOpContext::new(ctx.tool_call_id.0.clone(), ctx.cancellation_token.clone());
39        ctx.services
40            .workspace
41            .read_file(request, &op_ctx)
42            .await
43            .map_err(|e| StaticToolError::execution(ViewError::Workspace(workspace_op_error(e))))
44    }
45}