assistant_tool.rs

 1mod tool_registry;
 2mod tool_working_set;
 3
 4use std::sync::Arc;
 5
 6use anyhow::Result;
 7use gpui::{App, Entity, SharedString, Task};
 8use project::Project;
 9
10pub use crate::tool_registry::*;
11pub use crate::tool_working_set::*;
12
13pub fn init(cx: &mut App) {
14    ToolRegistry::default_global(cx);
15}
16
17#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
18pub enum ToolSource {
19    /// A native tool built-in to Zed.
20    Native,
21    /// A tool provided by a context server.
22    ContextServer { id: SharedString },
23}
24
25/// A tool that can be used by a language model.
26pub trait Tool: 'static + Send + Sync {
27    /// Returns the name of the tool.
28    fn name(&self) -> String;
29
30    /// Returns the description of the tool.
31    fn description(&self) -> String;
32
33    /// Returns the source of the tool.
34    fn source(&self) -> ToolSource {
35        ToolSource::Native
36    }
37
38    /// Returns the JSON schema that describes the tool's input.
39    fn input_schema(&self) -> serde_json::Value {
40        serde_json::Value::Object(serde_json::Map::default())
41    }
42
43    /// Runs the tool with the provided input.
44    fn run(
45        self: Arc<Self>,
46        input: serde_json::Value,
47        project: Entity<Project>,
48        cx: &mut App,
49    ) -> Task<Result<String>>;
50}