1use std::sync::Arc;
2
3use crate::schema::json_schema_for;
4use action_log::ActionLog;
5use anyhow::{Result, anyhow};
6use assistant_tool::{Tool, ToolResult};
7use gpui::{AnyWindowHandle, App, Entity, Task};
8use language_model::{LanguageModel, LanguageModelRequest, LanguageModelToolSchemaFormat};
9use project::Project;
10use schemars::JsonSchema;
11use serde::{Deserialize, Serialize};
12use ui::IconName;
13
14#[derive(Debug, Serialize, Deserialize, JsonSchema)]
15pub struct ThinkingToolInput {
16 /// Content to think about. This should be a description of what to think about or
17 /// a problem to solve.
18 content: String,
19}
20
21pub struct ThinkingTool;
22
23impl Tool for ThinkingTool {
24 fn name(&self) -> String {
25 "thinking".to_string()
26 }
27
28 fn needs_confirmation(&self, _: &serde_json::Value, _: &Entity<Project>, _: &App) -> bool {
29 false
30 }
31
32 fn may_perform_edits(&self) -> bool {
33 false
34 }
35
36 fn description(&self) -> String {
37 include_str!("./thinking_tool/description.md").to_string()
38 }
39
40 fn icon(&self) -> IconName {
41 IconName::ToolThink
42 }
43
44 fn input_schema(&self, format: LanguageModelToolSchemaFormat) -> Result<serde_json::Value> {
45 json_schema_for::<ThinkingToolInput>(format)
46 }
47
48 fn ui_text(&self, _input: &serde_json::Value) -> String {
49 "Thinking".to_string()
50 }
51
52 fn run(
53 self: Arc<Self>,
54 input: serde_json::Value,
55 _request: Arc<LanguageModelRequest>,
56 _project: Entity<Project>,
57 _action_log: Entity<ActionLog>,
58 _model: Arc<dyn LanguageModel>,
59 _window: Option<AnyWindowHandle>,
60 _cx: &mut App,
61 ) -> ToolResult {
62 // This tool just "thinks out loud" and doesn't perform any actions.
63 Task::ready(match serde_json::from_value::<ThinkingToolInput>(input) {
64 Ok(_input) => Ok("Finished thinking.".to_string().into()),
65 Err(err) => Err(anyhow!(err)),
66 })
67 .into()
68 }
69}