composio-sdk 0.3.0

Minimal Rust SDK for Composio Tool Router REST API
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
//! Authentication configuration management
//!
//! This module provides functionality to manage authentication configurations
//! for toolkits in the Composio platform.
//!
//! Note: This is a translation of the Python SDK's auth_configs.py module.
//! Full HTTP client integration is pending.

use serde::{Deserialize, Serialize};

/// Auth config status used for update-status path operations
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "UPPERCASE")]
pub enum AuthConfigStatus {
    /// Enable auth config
    Enabled,
    /// Disable auth config
    Disabled,
}

impl AuthConfigStatus {
    /// Return wire-format path segment value.
    pub fn as_str(self) -> &'static str {
        match self {
            Self::Enabled => "ENABLED",
            Self::Disabled => "DISABLED",
        }
    }
}

/// Authentication configuration list parameters
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct AuthConfigListParams {
    /// Filter by whether the auth config is Composio-managed
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_composio_managed: Option<bool>,

    /// Filter by toolkit slug
    #[serde(skip_serializing_if = "Option::is_none")]
    pub toolkit_slug: Option<String>,

    /// Whether to show disabled auth configs
    #[serde(skip_serializing_if = "Option::is_none")]
    pub show_disabled: Option<bool>,

    /// Search query for filtering by name or ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub search: Option<String>,

    /// Maximum number of results to return
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,

    /// Cursor for pagination
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<String>,
}

/// Authentication configuration list response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuthConfigListResponse {
    /// List of auth configs
    pub items: Vec<AuthConfigInfo>,

    /// Next cursor for pagination
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_cursor: Option<String>,

    /// Total number of pages
    #[serde(skip_serializing_if = "Option::is_none")]
    pub total_pages: Option<u32>,

    /// Current page number
    #[serde(skip_serializing_if = "Option::is_none")]
    pub current_page: Option<u32>,

    /// Total number of items
    #[serde(skip_serializing_if = "Option::is_none")]
    pub total_items: Option<u32>,
}

/// Authentication configuration information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuthConfigInfo {
    /// Unique identifier (NanoID)
    pub id: String,

    /// UUID identifier (deprecated)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub uuid: Option<String>,

    /// Type of auth config
    #[serde(rename = "type")]
    pub config_type: String,

    /// Toolkit information
    pub toolkit: ToolkitInfo,

    /// Name of the auth config
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,

    /// Authentication scheme
    pub auth_scheme: String,

    /// Credentials (may be masked)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub credentials: Option<serde_json::Value>,

    /// Status (ENABLED/DISABLED)
    pub status: String,

    /// Creation timestamp
    pub created_at: String,

    /// Number of connections using this auth config
    #[serde(skip_serializing_if = "Option::is_none")]
    pub no_of_connections: Option<u32>,

    /// Tool access configuration
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tool_access_config: Option<serde_json::Value>,
}

/// Toolkit information in auth config
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolkitInfo {
    /// Toolkit slug
    pub slug: String,

    /// Toolkit name
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
}

/// Authentication configuration create parameters
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuthConfigCreateParams {
    /// Toolkit slug
    pub toolkit: String,

    /// Authentication configuration options
    pub options: AuthConfigOptions,
}

/// Authentication configuration options
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum AuthConfigOptions {
    /// Custom auth config with full credentials
    #[serde(rename = "custom")]
    Custom {
        /// Authentication scheme
        auth_scheme: String,

        /// Credentials for the auth config
        credentials: serde_json::Value,

        /// Tool access restrictions
        #[serde(skip_serializing_if = "Option::is_none")]
        restrict_to_following_tools: Option<Vec<String>>,
    },

    /// Default auth config with scopes only
    #[serde(rename = "default")]
    Default {
        /// OAuth scopes
        #[serde(skip_serializing_if = "Option::is_none")]
        scopes: Option<Vec<String>>,

        /// User-level scopes
        #[serde(skip_serializing_if = "Option::is_none")]
        user_scopes: Option<Vec<String>>,

        /// Tool access restrictions
        #[serde(skip_serializing_if = "Option::is_none")]
        restrict_to_following_tools: Option<Vec<String>>,
    },
}

/// Authentication configuration create response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuthConfigCreateResponse {
    /// Created auth config
    pub auth_config: AuthConfig,
}

/// Authentication configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuthConfig {
    /// Unique identifier
    pub id: String,

    /// Toolkit information
    pub toolkit: ToolkitInfo,

    /// Authentication scheme
    pub auth_scheme: String,

    /// Whether this is Composio-managed
    pub is_composio_managed: bool,

    /// Tool access restrictions
    #[serde(skip_serializing_if = "Option::is_none")]
    pub restrict_to_following_tools: Option<Vec<String>>,
}

/// Authentication configuration retrieve response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuthConfigRetrieveResponse {
    /// Auth config ID
    pub id: String,

    /// UUID (deprecated)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub uuid: Option<String>,

    /// Type of auth config
    #[serde(rename = "type")]
    pub config_type: String,

    /// Toolkit information
    pub toolkit: ToolkitInfo,

    /// Name
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,

    /// Authentication scheme
    pub auth_scheme: String,

    /// Credentials
    #[serde(skip_serializing_if = "Option::is_none")]
    pub credentials: Option<serde_json::Value>,

    /// Proxy configuration
    #[serde(skip_serializing_if = "Option::is_none")]
    pub proxy_config: Option<serde_json::Value>,

    /// Expected input fields
    #[serde(skip_serializing_if = "Option::is_none")]
    pub expected_input_fields: Option<Vec<String>>,

    /// Shared credentials
    #[serde(skip_serializing_if = "Option::is_none")]
    pub shared_credentials: Option<serde_json::Value>,
}

/// Authentication configuration update parameters
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum AuthConfigUpdateParams {
    /// Update custom auth config
    #[serde(rename = "custom")]
    Custom {
        /// Updated credentials
        #[serde(skip_serializing_if = "Option::is_none")]
        credentials: Option<serde_json::Value>,

        /// Updated proxy config
        #[serde(skip_serializing_if = "Option::is_none")]
        proxy_config: Option<serde_json::Value>,

        /// Updated tool access config
        #[serde(skip_serializing_if = "Option::is_none")]
        tool_access_config: Option<serde_json::Value>,

        /// Updated shared credentials
        #[serde(skip_serializing_if = "Option::is_none")]
        shared_credentials: Option<serde_json::Value>,

        /// Whether enabled for tool router
        #[serde(skip_serializing_if = "Option::is_none")]
        is_enabled_for_tool_router: Option<bool>,
    },

    /// Update default auth config
    #[serde(rename = "default")]
    Default {
        /// Updated credentials (scopes)
        #[serde(skip_serializing_if = "Option::is_none")]
        credentials: Option<DefaultCredentials>,

        /// Whether enabled for tool router
        #[serde(skip_serializing_if = "Option::is_none")]
        is_enabled_for_tool_router: Option<bool>,
    },
}

/// Default credentials (scopes)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DefaultCredentials {
    /// OAuth scopes
    #[serde(skip_serializing_if = "Option::is_none")]
    pub scopes: Option<Vec<String>>,

    /// User-level scopes
    #[serde(skip_serializing_if = "Option::is_none")]
    pub user_scopes: Option<Vec<String>>,
}

/// Authentication configuration update response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuthConfigUpdateResponse {
    /// Success status
    pub success: bool,

    /// Updated auth config
    #[serde(skip_serializing_if = "Option::is_none")]
    pub auth_config: Option<AuthConfigInfo>,
}

/// Authentication configuration delete response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuthConfigDeleteResponse {
    /// Success status
    pub success: bool,

    /// Message
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message: Option<String>,
}

/// Authentication configuration status update response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuthConfigStatusUpdateResponse {
    /// Success status
    pub success: bool,

    /// Updated status
    pub status: String,
}

// Note: The AuthConfigs resource implementation is pending full HTTP client integration.
// The data structures above are ready for use once the client supports generic HTTP methods.

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_auth_config_list_params_default() {
        let params = AuthConfigListParams::default();
        assert!(params.is_composio_managed.is_none());
        assert!(params.toolkit_slug.is_none());
    }

    #[test]
    fn test_auth_config_options_custom_serialization() {
        let options = AuthConfigOptions::Custom {
            auth_scheme: "OAUTH2".to_string(),
            credentials: serde_json::json!({"client_id": "test"}),
            restrict_to_following_tools: None,
        };

        let json = serde_json::to_string(&options).unwrap();
        assert!(json.contains("custom"));
        assert!(json.contains("OAUTH2"));
    }

    #[test]
    fn test_auth_config_status_serialization() {
        let enabled = AuthConfigStatus::Enabled;
        let json = serde_json::to_string(&enabled).unwrap();
        assert_eq!(json, "\"ENABLED\"");
        assert_eq!(enabled.as_str(), "ENABLED");
    }

    #[test]
    fn test_auth_config_update_response_deserialization() {
        let payload = r#"{"success":true}"#;
        let response: AuthConfigUpdateResponse = serde_json::from_str(payload).unwrap();
        assert!(response.success);
    }

    #[test]
    fn test_auth_config_delete_response_deserialization() {
        let payload = r#"{"success":true,"message":"deleted"}"#;
        let response: AuthConfigDeleteResponse = serde_json::from_str(payload).unwrap();
        assert!(response.success);
        assert_eq!(response.message.as_deref(), Some("deleted"));
    }

    #[test]
    fn test_auth_config_status_update_response_deserialization() {
        let payload = r#"{"success":true,"status":"DISABLED"}"#;
        let response: AuthConfigStatusUpdateResponse = serde_json::from_str(payload).unwrap();
        assert!(response.success);
        assert_eq!(response.status, "DISABLED");
    }

    #[test]
    fn test_auth_config_options_default_serialization() {
        let options = AuthConfigOptions::Default {
            scopes: Some(vec!["repo".to_string()]),
            user_scopes: None,
            restrict_to_following_tools: None,
        };

        let json = serde_json::to_string(&options).unwrap();
        assert!(json.contains("default"));
        assert!(json.contains("repo"));
    }
}