1use super::*;
2
3/// A tool that echoes its input
4#[derive(JsonSchema, Serialize, Deserialize)]
5pub struct EchoToolInput {
6 /// The text to echo.
7 text: String,
8}
9
10pub struct EchoTool;
11
12impl AgentTool for EchoTool {
13 type Input = EchoToolInput;
14
15 fn name(&self) -> SharedString {
16 "echo".into()
17 }
18
19 fn run(self: Arc<Self>, input: Self::Input, _cx: &mut App) -> Task<Result<String>> {
20 Task::ready(Ok(input.text))
21 }
22}
23
24/// A tool that waits for a specified delay
25#[derive(JsonSchema, Serialize, Deserialize)]
26pub struct DelayToolInput {
27 /// The delay in milliseconds.
28 ms: u64,
29}
30
31pub struct DelayTool;
32
33impl AgentTool for DelayTool {
34 type Input = DelayToolInput;
35
36 fn name(&self) -> SharedString {
37 "delay".into()
38 }
39
40 fn run(self: Arc<Self>, input: Self::Input, cx: &mut App) -> Task<Result<String>>
41 where
42 Self: Sized,
43 {
44 cx.foreground_executor().spawn(async move {
45 smol::Timer::after(Duration::from_millis(input.ms)).await;
46 Ok("Ding".to_string())
47 })
48 }
49}
50
51/// A tool that takes an object with map from letters to random words starting with that letter.
52/// All fiealds are required! Pass a word for every letter!
53#[derive(JsonSchema, Serialize, Deserialize)]
54pub struct WordListInput {
55 /// Provide a random word that starts with A.
56 a: Option<String>,
57 /// Provide a random word that starts with B.
58 b: Option<String>,
59 /// Provide a random word that starts with C.
60 c: Option<String>,
61 /// Provide a random word that starts with D.
62 d: Option<String>,
63 /// Provide a random word that starts with E.
64 e: Option<String>,
65 /// Provide a random word that starts with F.
66 f: Option<String>,
67 /// Provide a random word that starts with G.
68 g: Option<String>,
69}
70
71pub struct WordListTool;
72
73impl AgentTool for WordListTool {
74 type Input = WordListInput;
75
76 fn name(&self) -> SharedString {
77 "word_list".into()
78 }
79
80 fn run(self: Arc<Self>, _input: Self::Input, _cx: &mut App) -> Task<Result<String>> {
81 Task::ready(Ok("ok".to_string()))
82 }
83}