spring_ai_rs/ai_interface/callback/group/
command_info.rs1use std::{error::Error, ffi::CStr};
2
3use crate::get_callback;
4
5const MAX_PARAMETERS: usize = 32;
6
7#[derive(Debug, Copy, Clone)]
8pub struct GroupSupportedCommand {
9 pub ai_id: i32,
10 pub group_id: i32,
11 pub supported_command_index: i32,
12}
13
14#[derive(Debug, Clone)]
15pub struct GroupSupportedCommandAll {
16 id: i32,
17 name: String,
18 tooltip: String,
19 is_show_unique: bool,
20 is_disabled: bool,
21 parameters: String,
22}
23
24impl GroupSupportedCommand {
25 pub fn id(&self) -> Result<i32, Box<dyn Error>> {
26 let get_supported_command_id_func =
27 get_callback!(self.ai_id, Group_SupportedCommand_getId)?;
28
29 Ok(unsafe {
30 get_supported_command_id_func(self.ai_id, self.group_id, self.supported_command_index)
31 })
32 }
33
34 pub fn name(&self) -> Result<String, Box<dyn Error>> {
35 let get_supported_command_name_func =
36 get_callback!(self.ai_id, Group_SupportedCommand_getName)?;
37
38 Ok(String::from(
39 unsafe {
40 CStr::from_ptr(get_supported_command_name_func(
41 self.ai_id,
42 self.group_id,
43 self.supported_command_index,
44 ))
45 }
46 .to_str()?,
47 ))
48 }
49
50 pub fn tooltip(&self) -> Result<String, Box<dyn Error>> {
51 let get_supported_command_tooltip_func =
52 get_callback!(self.ai_id, Group_SupportedCommand_getToolTip)?;
53
54 Ok(String::from(
55 unsafe {
56 CStr::from_ptr(get_supported_command_tooltip_func(
57 self.ai_id,
58 self.group_id,
59 self.supported_command_index,
60 ))
61 }
62 .to_str()?,
63 ))
64 }
65
66 pub fn is_show_unique(&self) -> Result<bool, Box<dyn Error>> {
67 let get_suppored_command_is_show_unique_func =
68 get_callback!(self.ai_id, Group_SupportedCommand_isShowUnique)?;
69
70 Ok(unsafe {
71 get_suppored_command_is_show_unique_func(
72 self.ai_id,
73 self.group_id,
74 self.supported_command_index,
75 )
76 })
77 }
78
79 pub fn is_disabled(&self) -> Result<bool, Box<dyn Error>> {
80 let get_supported_command_is_disabled_func =
81 get_callback!(self.ai_id, Group_SupportedCommand_isDisabled)?;
82
83 Ok(unsafe {
84 get_supported_command_is_disabled_func(
85 self.ai_id,
86 self.group_id,
87 self.supported_command_index,
88 )
89 })
90 }
91
92 pub fn parameters(&self) -> Result<String, Box<dyn Error>> {
93 let get_supported_command_parameters_func =
94 get_callback!(self.ai_id, Group_SupportedCommand_getParams)?;
95
96 let s = String::with_capacity(MAX_PARAMETERS);
97 let ptr = &mut (s.as_ptr() as *const i8);
98 unsafe {
99 get_supported_command_parameters_func(
100 self.ai_id,
101 self.group_id,
102 self.supported_command_index,
103 ptr as *mut *const i8,
104 MAX_PARAMETERS as i32,
105 )
106 };
107
108 Ok(String::from(
109 unsafe { CStr::from_ptr(*ptr) }.to_str().unwrap_or(""),
110 ))
111 }
112
113 pub fn all(&self) -> Result<GroupSupportedCommandAll, Box<dyn Error>> {
114 Ok(GroupSupportedCommandAll {
115 id: self.id()?,
116 name: self.name()?,
117 tooltip: self.tooltip()?,
118 is_show_unique: self.is_show_unique()?,
119 is_disabled: self.is_disabled()?,
120 parameters: self.parameters()?,
121 })
122 }
123}