Skip to main content

composio_sdk/models/
enums.rs

1//! Enums for Composio API
2
3use serde::{Deserialize, Serialize};
4
5/// Meta tool slugs for the 5 core Composio meta tools
6#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
7#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
8pub enum MetaToolSlug {
9    /// Search for relevant tools across 1000+ apps
10    ComposioSearchTools,
11    /// Execute up to 20 tools in parallel
12    ComposioMultiExecuteTool,
13    /// Handle OAuth and API key authentication
14    ComposioManageConnections,
15    /// Run Python code in persistent sandbox
16    ComposioRemoteWorkbench,
17    /// Execute bash commands for file/data processing
18    ComposioRemoteBashTool,
19}
20
21/// Tag types for tool filtering by behavior hints
22#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
23#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
24pub enum TagType {
25    /// Tool only reads data, doesn't modify anything
26    ReadOnlyHint,
27    /// Tool modifies or deletes data
28    DestructiveHint,
29    /// Tool can be safely retried (same result)
30    IdempotentHint,
31    /// Tool requires open world context
32    OpenWorldHint,
33}
34
35/// Authentication schemes supported by toolkits
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
38pub enum AuthScheme {
39    /// OAuth 1.0 authentication
40    Oauth1,
41    /// OAuth 2.0 authentication
42    Oauth2,
43    /// API key authentication
44    ApiKey,
45    /// Bearer token authentication
46    BearerToken,
47    /// HTTP Basic authentication
48    Basic,
49    /// No authentication required
50    NoAuth,
51    /// Snowflake authentication
52    Snowflake,
53    /// Cal.com authentication
54    CalcomAuth,
55    /// Bill.com authentication
56    BillcomAuth,
57    /// Composio Link authentication
58    ComposioLink,
59    /// Basic authentication with JWT
60    BasicWithJwt,
61    /// Google Service Account authentication
62    GoogleServiceAccount,
63}
64
65#[cfg(test)]
66mod tests {
67    use super::*;
68    use serde_json;
69
70    #[test]
71    fn test_meta_tool_slug_serialization() {
72        let slug = MetaToolSlug::ComposioSearchTools;
73        let json = serde_json::to_string(&slug).unwrap();
74        assert_eq!(json, "\"COMPOSIO_SEARCH_TOOLS\"");
75
76        let slug = MetaToolSlug::ComposioMultiExecuteTool;
77        let json = serde_json::to_string(&slug).unwrap();
78        assert_eq!(json, "\"COMPOSIO_MULTI_EXECUTE_TOOL\"");
79
80        let slug = MetaToolSlug::ComposioManageConnections;
81        let json = serde_json::to_string(&slug).unwrap();
82        assert_eq!(json, "\"COMPOSIO_MANAGE_CONNECTIONS\"");
83
84        let slug = MetaToolSlug::ComposioRemoteWorkbench;
85        let json = serde_json::to_string(&slug).unwrap();
86        assert_eq!(json, "\"COMPOSIO_REMOTE_WORKBENCH\"");
87
88        let slug = MetaToolSlug::ComposioRemoteBashTool;
89        let json = serde_json::to_string(&slug).unwrap();
90        assert_eq!(json, "\"COMPOSIO_REMOTE_BASH_TOOL\"");
91    }
92
93    #[test]
94    fn test_meta_tool_slug_deserialization() {
95        let json = "\"COMPOSIO_SEARCH_TOOLS\"";
96        let slug: MetaToolSlug = serde_json::from_str(json).unwrap();
97        assert!(matches!(slug, MetaToolSlug::ComposioSearchTools));
98
99        let json = "\"COMPOSIO_MULTI_EXECUTE_TOOL\"";
100        let slug: MetaToolSlug = serde_json::from_str(json).unwrap();
101        assert!(matches!(slug, MetaToolSlug::ComposioMultiExecuteTool));
102
103        let json = "\"COMPOSIO_MANAGE_CONNECTIONS\"";
104        let slug: MetaToolSlug = serde_json::from_str(json).unwrap();
105        assert!(matches!(slug, MetaToolSlug::ComposioManageConnections));
106
107        let json = "\"COMPOSIO_REMOTE_WORKBENCH\"";
108        let slug: MetaToolSlug = serde_json::from_str(json).unwrap();
109        assert!(matches!(slug, MetaToolSlug::ComposioRemoteWorkbench));
110
111        let json = "\"COMPOSIO_REMOTE_BASH_TOOL\"";
112        let slug: MetaToolSlug = serde_json::from_str(json).unwrap();
113        assert!(matches!(slug, MetaToolSlug::ComposioRemoteBashTool));
114    }
115
116    #[test]
117    fn test_tag_type_serialization() {
118        let tag = TagType::ReadOnlyHint;
119        let json = serde_json::to_string(&tag).unwrap();
120        assert_eq!(json, "\"READ_ONLY_HINT\"");
121
122        let tag = TagType::DestructiveHint;
123        let json = serde_json::to_string(&tag).unwrap();
124        assert_eq!(json, "\"DESTRUCTIVE_HINT\"");
125
126        let tag = TagType::IdempotentHint;
127        let json = serde_json::to_string(&tag).unwrap();
128        assert_eq!(json, "\"IDEMPOTENT_HINT\"");
129
130        let tag = TagType::OpenWorldHint;
131        let json = serde_json::to_string(&tag).unwrap();
132        assert_eq!(json, "\"OPEN_WORLD_HINT\"");
133    }
134
135    #[test]
136    fn test_tag_type_deserialization() {
137        let json = "\"READ_ONLY_HINT\"";
138        let tag: TagType = serde_json::from_str(json).unwrap();
139        assert!(matches!(tag, TagType::ReadOnlyHint));
140
141        let json = "\"DESTRUCTIVE_HINT\"";
142        let tag: TagType = serde_json::from_str(json).unwrap();
143        assert!(matches!(tag, TagType::DestructiveHint));
144
145        let json = "\"IDEMPOTENT_HINT\"";
146        let tag: TagType = serde_json::from_str(json).unwrap();
147        assert!(matches!(tag, TagType::IdempotentHint));
148
149        let json = "\"OPEN_WORLD_HINT\"";
150        let tag: TagType = serde_json::from_str(json).unwrap();
151        assert!(matches!(tag, TagType::OpenWorldHint));
152    }
153
154    #[test]
155    fn test_auth_scheme_serialization() {
156        let scheme = AuthScheme::Oauth2;
157        let json = serde_json::to_string(&scheme).unwrap();
158        assert_eq!(json, "\"OAUTH2\"");
159
160        let scheme = AuthScheme::Oauth1;
161        let json = serde_json::to_string(&scheme).unwrap();
162        assert_eq!(json, "\"OAUTH1\"");
163
164        let scheme = AuthScheme::ApiKey;
165        let json = serde_json::to_string(&scheme).unwrap();
166        assert_eq!(json, "\"API_KEY\"");
167
168        let scheme = AuthScheme::BearerToken;
169        let json = serde_json::to_string(&scheme).unwrap();
170        assert_eq!(json, "\"BEARER_TOKEN\"");
171
172        let scheme = AuthScheme::Basic;
173        let json = serde_json::to_string(&scheme).unwrap();
174        assert_eq!(json, "\"BASIC\"");
175
176        let scheme = AuthScheme::NoAuth;
177        let json = serde_json::to_string(&scheme).unwrap();
178        assert_eq!(json, "\"NO_AUTH\"");
179
180        let scheme = AuthScheme::Snowflake;
181        let json = serde_json::to_string(&scheme).unwrap();
182        assert_eq!(json, "\"SNOWFLAKE\"");
183
184        let scheme = AuthScheme::CalcomAuth;
185        let json = serde_json::to_string(&scheme).unwrap();
186        assert_eq!(json, "\"CALCOM_AUTH\"");
187
188        let scheme = AuthScheme::BillcomAuth;
189        let json = serde_json::to_string(&scheme).unwrap();
190        assert_eq!(json, "\"BILLCOM_AUTH\"");
191
192        let scheme = AuthScheme::ComposioLink;
193        let json = serde_json::to_string(&scheme).unwrap();
194        assert_eq!(json, "\"COMPOSIO_LINK\"");
195
196        let scheme = AuthScheme::BasicWithJwt;
197        let json = serde_json::to_string(&scheme).unwrap();
198        assert_eq!(json, "\"BASIC_WITH_JWT\"");
199
200        let scheme = AuthScheme::GoogleServiceAccount;
201        let json = serde_json::to_string(&scheme).unwrap();
202        assert_eq!(json, "\"GOOGLE_SERVICE_ACCOUNT\"");
203    }
204
205    #[test]
206    fn test_auth_scheme_deserialization() {
207        let json = "\"OAUTH2\"";
208        let scheme: AuthScheme = serde_json::from_str(json).unwrap();
209        assert!(matches!(scheme, AuthScheme::Oauth2));
210
211        let json = "\"OAUTH1\"";
212        let scheme: AuthScheme = serde_json::from_str(json).unwrap();
213        assert!(matches!(scheme, AuthScheme::Oauth1));
214
215        let json = "\"API_KEY\"";
216        let scheme: AuthScheme = serde_json::from_str(json).unwrap();
217        assert!(matches!(scheme, AuthScheme::ApiKey));
218
219        let json = "\"BEARER_TOKEN\"";
220        let scheme: AuthScheme = serde_json::from_str(json).unwrap();
221        assert!(matches!(scheme, AuthScheme::BearerToken));
222
223        let json = "\"BASIC\"";
224        let scheme: AuthScheme = serde_json::from_str(json).unwrap();
225        assert!(matches!(scheme, AuthScheme::Basic));
226
227        let json = "\"NO_AUTH\"";
228        let scheme: AuthScheme = serde_json::from_str(json).unwrap();
229        assert!(matches!(scheme, AuthScheme::NoAuth));
230
231        let json = "\"SNOWFLAKE\"";
232        let scheme: AuthScheme = serde_json::from_str(json).unwrap();
233        assert!(matches!(scheme, AuthScheme::Snowflake));
234
235        let json = "\"CALCOM_AUTH\"";
236        let scheme: AuthScheme = serde_json::from_str(json).unwrap();
237        assert!(matches!(scheme, AuthScheme::CalcomAuth));
238
239        let json = "\"BILLCOM_AUTH\"";
240        let scheme: AuthScheme = serde_json::from_str(json).unwrap();
241        assert!(matches!(scheme, AuthScheme::BillcomAuth));
242
243        let json = "\"COMPOSIO_LINK\"";
244        let scheme: AuthScheme = serde_json::from_str(json).unwrap();
245        assert!(matches!(scheme, AuthScheme::ComposioLink));
246
247        let json = "\"BASIC_WITH_JWT\"";
248        let scheme: AuthScheme = serde_json::from_str(json).unwrap();
249        assert!(matches!(scheme, AuthScheme::BasicWithJwt));
250
251        let json = "\"GOOGLE_SERVICE_ACCOUNT\"";
252        let scheme: AuthScheme = serde_json::from_str(json).unwrap();
253        assert!(matches!(scheme, AuthScheme::GoogleServiceAccount));
254    }
255
256    #[test]
257    fn test_enum_copy_trait() {
258        // Test that Copy trait works for MetaToolSlug and TagType
259        let slug1 = MetaToolSlug::ComposioSearchTools;
260        let slug2 = slug1; // Copy
261        let _slug3 = slug1; // Can still use slug1 after copy
262        assert!(matches!(slug2, MetaToolSlug::ComposioSearchTools));
263
264        let tag1 = TagType::ReadOnlyHint;
265        let tag2 = tag1; // Copy
266        let _tag3 = tag1; // Can still use tag1 after copy
267        assert!(matches!(tag2, TagType::ReadOnlyHint));
268    }
269
270    #[test]
271    fn test_enum_clone_trait() {
272        // Test that Clone trait works for all enums
273        let slug = MetaToolSlug::ComposioSearchTools;
274        let slug_clone = slug.clone();
275        assert!(matches!(slug_clone, MetaToolSlug::ComposioSearchTools));
276
277        let tag = TagType::ReadOnlyHint;
278        let tag_clone = tag.clone();
279        assert!(matches!(tag_clone, TagType::ReadOnlyHint));
280
281        let scheme = AuthScheme::Oauth2;
282        let scheme_clone = scheme.clone();
283        assert!(matches!(scheme_clone, AuthScheme::Oauth2));
284    }
285
286    #[test]
287    fn test_enum_debug_trait() {
288        // Test that Debug trait works for all enums
289        let slug = MetaToolSlug::ComposioSearchTools;
290        let debug_str = format!("{:?}", slug);
291        assert!(debug_str.contains("ComposioSearchTools"));
292
293        let tag = TagType::ReadOnlyHint;
294        let debug_str = format!("{:?}", tag);
295        assert!(debug_str.contains("ReadOnlyHint"));
296
297        let scheme = AuthScheme::Oauth2;
298        let debug_str = format!("{:?}", scheme);
299        assert!(debug_str.contains("Oauth2"));
300    }
301}