
This PR factors the tool definitions out of the `assistant` crate so that they can be shared between `assistant` and `assistant2`. `ToolWorkingSet` now lives in `assistant_tool`. The tool definitions themselves live in `assistant_tools`, with the exception of the `ContextServerTool`, which has been moved to the `context_server` crate. As part of this refactoring I needed to extract the `ContextServerSettings` to a separate `context_server_settings` crate so that the `extension_host`—which is referenced by the `remote_server`—can name the `ContextServerSettings` type without pulling in some undesired dependencies. Release Notes: - N/A
37 lines
959 B
Rust
37 lines
959 B
Rust
mod tool_registry;
|
|
mod tool_working_set;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use anyhow::Result;
|
|
use gpui::{AppContext, Task, WeakView, WindowContext};
|
|
use workspace::Workspace;
|
|
|
|
pub use crate::tool_registry::*;
|
|
pub use crate::tool_working_set::*;
|
|
|
|
pub fn init(cx: &mut AppContext) {
|
|
ToolRegistry::default_global(cx);
|
|
}
|
|
|
|
/// A tool that can be used by a language model.
|
|
pub trait Tool: 'static + Send + Sync {
|
|
/// Returns the name of the tool.
|
|
fn name(&self) -> String;
|
|
|
|
/// Returns the description of the tool.
|
|
fn description(&self) -> String;
|
|
|
|
/// Returns the JSON schema that describes the tool's input.
|
|
fn input_schema(&self) -> serde_json::Value {
|
|
serde_json::Value::Object(serde_json::Map::default())
|
|
}
|
|
|
|
/// Runs the tool with the provided input.
|
|
fn run(
|
|
self: Arc<Self>,
|
|
input: serde_json::Value,
|
|
workspace: WeakView<Workspace>,
|
|
cx: &mut WindowContext,
|
|
) -> Task<Result<String>>;
|
|
}
|