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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
//! # Composio Rust SDK
//!
//! A minimal, type-safe Rust SDK for the Composio Tool Router REST API.
//!
//! This SDK enables ZeroClaw and other Rust applications to interact with external services
//! through Composio's Tool Router API, providing session management, tool execution,
//! and authentication handling with a minimal memory footprint (~2 MB).
//!
//! ## Features
//!
//! - **Session Management**: Create and manage Tool Router sessions for users
//! - **Tool Execution**: Execute tools and meta tools with automatic retry logic
//! - **Type Safety**: Comprehensive type definitions for all API requests and responses
//! - **Error Handling**: Detailed error types with actionable error messages
//! - **Async/Await**: Built on tokio for efficient async operations
//! - **Memory Efficient**: Minimal memory footprint suitable for resource-constrained environments
//!
//! ## Quick Start
//!
//! ```no_run
//! use composio_sdk::{ComposioClient, MetaToolSlug};
//! use serde_json::json;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//!     // Initialize client with API key
//!     let client = ComposioClient::builder()
//!         .api_key(std::env::var("COMPOSIO_API_KEY")?)
//!         .build()?;
//!
//!     // Create a session for a user
//!     let session = client
//!         .create_session("user_123")
//!         .toolkits(vec!["github", "gmail"])
//!         .manage_connections(true)
//!         .send()
//!         .await?;
//!
//!     println!("Session ID: {}", session.session_id());
//!     println!("MCP URL: {}", session.mcp_url());
//!
//!     // Execute a tool
//!     let result = session
//!         .execute_tool(
//!             "GITHUB_CREATE_ISSUE",
//!             json!({
//!                 "owner": "composio",
//!                 "repo": "composio",
//!                 "title": "Test issue",
//!                 "body": "Created via Rust SDK"
//!             })
//!         )
//!         .await?;
//!
//!     println!("Result: {:?}", result.data);
//!
//!     // Execute a meta tool
//!     let search_result = session
//!         .execute_meta_tool(
//!             MetaToolSlug::ComposioSearchTools,
//!             json!({
//!                 "query": "create a GitHub issue"
//!             })
//!         )
//!         .await?;
//!
//!     println!("Search result: {:?}", search_result.data);
//!
//!     Ok(())
//! }
//! ```
//!
//! ## Session Configuration
//!
//! Sessions can be configured with various options:
//!
//! ```no_run
//! # use composio_sdk::ComposioClient;
//! # async fn example(client: ComposioClient) -> Result<(), Box<dyn std::error::Error>> {
//! let session = client
//!     .create_session("user_123")
//!     .toolkits(vec!["github", "gmail"])           // Enable specific toolkits
//!     .disable_toolkits(vec!["exa", "firecrawl"])  // Or disable specific toolkits
//!     .auth_config("github", "ac_custom_config")   // Use custom auth config
//!     .connected_account("gmail", "ca_work_email") // Select specific account
//!     .manage_connections(true)                     // Enable in-chat auth
//!     .send()
//!     .await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Error Handling
//!
//! The SDK provides comprehensive error handling:
//!
//! ```no_run
//! # use composio_sdk::{ComposioClient, ComposioError};
//! # use serde_json::json;
//! # async fn example(client: ComposioClient) -> Result<(), Box<dyn std::error::Error>> {
//! # let session = client.create_session("user_123").send().await?;
//! match session.execute_tool("INVALID_TOOL", json!({})).await {
//!     Ok(result) => println!("Success: {:?}", result),
//!     Err(ComposioError::ApiError { status, message, suggested_fix, .. }) => {
//!         eprintln!("API error ({}): {}", status, message);
//!         if let Some(fix) = suggested_fix {
//!             eprintln!("Suggested fix: {}", fix);
//!         }
//!     }
//!     Err(ComposioError::NetworkError(e)) => {
//!         eprintln!("Network error: {}", e);
//!     }
//!     Err(e) => {
//!         eprintln!("Other error: {}", e);
//!     }
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Configuration
//!
//! Customize SDK behavior with [`ComposioConfig`]:
//!
//! ```no_run
//! use composio_sdk::ComposioClient;
//! use std::time::Duration;
//!
//! let client = ComposioClient::builder()
//!     .api_key("your-api-key")
//!     .base_url("https://backend.composio.dev/api/v3")
//!     .timeout(Duration::from_secs(60))
//!     .max_retries(5)
//!     .build()?;
//! # Ok::<(), composio_sdk::ComposioError>(())
//! ```

// ============================================================================
// Module Declarations
// ============================================================================

/// Client implementation for the Composio API
pub mod client;

/// Configuration types for the SDK
pub mod config;

/// Error types and error handling utilities
pub mod error;

/// Data models for API requests and responses
pub mod models;

/// Retry logic and exponential backoff utilities
pub mod retry;

/// Session management and tool execution
pub mod session;

/// Wizard instruction generation from Composio Skills
pub mod wizard;

/// Skills integration for copying and managing Composio Skills
pub mod skills_integration;

/// Meta tools - Native Rust implementations
pub mod meta_tools;

/// Utility functions for the SDK
pub mod utils;

/// Provider system for framework-specific tool formatting
pub mod providers;

// ============================================================================
// SDK Metadata
// ============================================================================

/// SDK version from Cargo.toml
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

/// SDK name
pub const NAME: &str = env!("CARGO_PKG_NAME");

/// Get SDK version information
///
/// # Examples
///
/// ```rust
/// use composio_sdk;
///
/// println!("Using Composio SDK v{}", composio_sdk::VERSION);
/// ```
pub fn version() -> &'static str {
    VERSION
}

// ============================================================================
// Core Client and Configuration
// ============================================================================

/// Main client for interacting with the Composio API
pub use client::ComposioClient;

/// Builder for constructing a [`ComposioClient`] with custom configuration
pub use client::ComposioClientBuilder;

/// Configuration for the Composio SDK
pub use config::ComposioConfig;

// ============================================================================
// Provider System
// ============================================================================

/// Provider trait for framework-specific tool formatting
///
/// See the [`providers`] module documentation for detailed usage examples.
pub use providers::Provider;

/// OpenAI provider for Chat Completions API
pub use providers::OpenAIProvider;

/// Anthropic provider for Claude API
pub use providers::AnthropicProvider;

// ============================================================================
// Logging Utilities
// ============================================================================

/// Logging utilities for the SDK
///
/// This module provides logging configuration with verbosity control,
/// message truncation, and environment-based setup.
///
/// See the [`utils::logging`] module documentation for detailed usage examples.
pub use utils::logging::{
    setup as setup_logging, setup_from_env as setup_logging_from_env,
    get_verbosity, set_verbosity, truncate_message, LogLevel, Verbosity, WithLogger,
    ENV_COMPOSIO_LOGGING_LEVEL, ENV_COMPOSIO_LOG_VERBOSITY,
};

// ============================================================================
// Session Management
// ============================================================================

/// A Tool Router session for a specific user
pub use session::Session;

/// Builder for constructing a session with custom configuration
pub use session::SessionBuilder;

// ============================================================================
// Error Types
// ============================================================================

/// Main error type for the SDK
pub use error::ComposioError;

/// Detailed error information from API error responses
pub use error::ErrorDetail;

// ============================================================================
// Request Models
// ============================================================================

/// Configuration for creating a Tool Router session
pub use models::SessionConfig;

/// Toolkit filter for enabling or disabling specific toolkits
pub use models::ToolkitFilter;

/// Configuration for per-toolkit tool filtering
pub use models::ToolsConfig;

/// Tool filter for a specific toolkit
pub use models::ToolFilter;

/// Configuration for tag-based tool filtering
pub use models::TagsConfig;

/// Configuration for workbench execution
pub use models::WorkbenchConfig;

/// Request to execute a tool
pub use models::ToolExecutionRequest;

/// Request to execute a meta tool
pub use models::MetaToolExecutionRequest;

/// Request to create an authentication link
pub use models::LinkRequest;

/// Parameters for creating an authentication configuration
pub use models::AuthConfigCreateParams;

/// Authentication configuration data
pub use models::AuthConfigData;

/// Parameters for listing authentication configurations
pub use models::AuthConfigListParams;

/// Parameters for updating an authentication configuration
pub use models::AuthConfigUpdateParams;

/// Parameters for creating a connected account
pub use models::ConnectedAccountCreateParams;

/// Reference to an authentication configuration
pub use models::AuthConfigReference;

/// Connection data for creating a connected account
pub use models::ConnectionData;

/// Parameters for listing connected accounts
pub use models::ConnectedAccountListParams;

/// Parameters for executing a proxy request
pub use models::ToolProxyParams;

// ============================================================================
// Response Models
// ============================================================================

/// Response from session creation
pub use models::SessionResponse;

/// MCP server information
pub use models::McpInfo;

/// Tool schema information
pub use models::ToolSchema;

/// Response from tool execution
pub use models::ToolExecutionResponse;

/// Response from meta tool execution
pub use models::MetaToolExecutionResponse;

/// Response from listing toolkits
pub use models::ToolkitListResponse;

/// Information about a toolkit
pub use models::ToolkitInfo;

/// Metadata about a toolkit
pub use models::ToolkitMeta;

/// Information about a connected account
pub use models::ConnectedAccountInfo;

/// Response from creating an auth link
pub use models::LinkResponse;

/// Error response from API
pub use models::ErrorResponse;

/// Response from creating an authentication configuration
pub use models::AuthConfigCreateResponse;

/// Response from listing authentication configurations
pub use models::AuthConfigListResponse;

/// Response from retrieving a single authentication configuration
pub use models::AuthConfigRetrieveResponse;

/// Information about an authentication configuration
pub use models::AuthConfigInfo;

/// Response from creating a connected account
pub use models::ConnectedAccountCreateResponse;

/// Response from listing connected accounts
pub use models::ConnectedAccountListResponse;

/// Detailed information about a connected account
pub use models::ConnectedAccountDetail;

/// Response from retrieving a single connected account
pub use models::ConnectedAccountRetrieveResponse;

/// Response from updating connected account status
pub use models::ConnectedAccountUpdateStatusResponse;

/// Response from a proxy request
pub use models::ToolProxyResponse;

/// Response from creating or updating a trigger instance
pub use models::TriggerInstanceUpsertResponse;

// ============================================================================
// Enums
// ============================================================================

/// Meta tool slugs for the 5 core Composio meta tools
pub use models::MetaToolSlug;

/// Tag types for filtering tools by behavior hints
pub use models::TagType;

/// Authentication schemes supported by toolkits
pub use models::AuthScheme;

// ============================================================================
// Versioning Types
// ============================================================================

/// Toolkit version type
pub use models::ToolkitVersion;

/// Map of toolkit versions
pub use models::ToolkitVersions;

/// Toolkit version parameter for configuration
pub use models::ToolkitVersionParam;

/// Constant for "latest" version
pub use models::TOOLKIT_LATEST_VERSION;

// ============================================================================
// Webhook Events
// ============================================================================

/// Webhook event types and utilities
///
/// This module provides strongly-typed definitions for webhook events,
/// enabling type-safe handling of events like connection expiration.
///
/// See the [`models::webhook_events`] module documentation for detailed usage examples.
pub use models::webhook_events::{
    ConnectionExpiredEvent, ConnectionState, ConnectionStatus,
    SingleConnectedAccountDetailedResponse, WebhookConnectionMetadata, WebhookEvent,
    WebhookEventType, is_connection_expired_event,
};

// ============================================================================
// Tool Modifiers
// ============================================================================

/// Tool modifier traits and utilities
///
/// This module provides functionality to modify tool schemas, execution parameters,
/// and execution responses. Modifiers allow you to customize tool behavior without
/// changing the underlying tool definitions.
///
/// See the [`models::modifiers`] module documentation for detailed usage examples.
pub use models::modifiers::{
    AfterExecute, BeforeExecute, SchemaModifier, BeforeExecuteMeta, AfterExecuteMeta,
    Modifier, Modifiers, ToolExecuteParams, CustomAuthParams, CustomConnectionData,
};

// ============================================================================
// Custom Tools
// ============================================================================

/// Custom tools functionality
///
/// This module provides functionality for creating and managing custom tools.
/// Custom tools can be simple tools without authentication or toolkit-based
/// tools with authentication and proxy execution.
///
/// See the [`models::custom_tools`] module documentation for detailed usage examples.
pub use models::custom_tools::{
    CustomTool, CustomToolsRegistry, ExecuteRequestFn,
};

// ============================================================================
// Triggers
// ============================================================================

/// Trigger event types and utilities
///
/// This module provides functionality to manage triggers in Composio.
/// Triggers are event listeners that notify your application when specific
/// events occur in connected services.
///
/// See the [`models::triggers`] module documentation for detailed usage examples.
pub use models::triggers::{
    TriggerEvent, TriggerMetadata, TriggerConnectedAccount,
    TriggerType, TriggerInstance, WebhookVersion,
};

// ============================================================================
// Connected Accounts
// ============================================================================

/// Connected accounts management
///
/// This module provides functionality to manage connected accounts,
/// which represent user connections to external services through Composio.
///
/// See the [`models::connected_accounts`] module documentation for detailed usage examples.
pub use models::connected_accounts::{
    ConnectionRequest, ConnectionStatus as ConnectedAccountStatus,
    AuthScheme as ConnectedAccountAuthScheme, AUTH_SCHEME as auth_scheme,
};

// ============================================================================
// Wizard Module (Skills Integration)
// ============================================================================

/// Wizard instruction generation utilities
///
/// This module provides tools for extracting Composio Skills content and
/// generating wizard instructions for AI agents based on official best practices.
///
/// See the [`wizard`] module documentation for detailed usage examples.
pub use wizard::{
    Impact, InstructionValidator, Rule, SkillsExtractor, ValidationResult,
    WizardInstructionGenerator,
};

// ============================================================================
// Skills Integration Module
// ============================================================================

/// Skills integration error types and utilities
///
/// This module provides error handling for Skills integration operations,
/// including file I/O errors, YAML parsing errors, validation failures,
/// and security violations.
///
/// See the [`skills_integration`] module documentation for detailed usage examples.
pub use skills_integration::{SkillsCopyResult, SkillsError, SkillsValidation};