Skip to main content

llm_optimizer_integrations/
lib.rs

1//! # LLM Auto Optimizer - Integrations
2//!
3//! Production-ready integrations with external services for the LLM Auto Optimizer.
4//!
5//! ## Features
6//!
7//! ### Jira Integration
8//!
9//! - Full CRUD operations for issues
10//! - Project and board management
11//! - JQL query support
12//! - Webhook event handling
13//! - OAuth 2.0 and Basic authentication
14//! - Rate limiting and retry logic
15//!
16//! ### Anthropic Claude Integration
17//!
18//! - Message/completion endpoints
19//! - Streaming support via Server-Sent Events
20//! - Token counting and validation
21//! - Cost tracking and estimation
22//! - Rate limiting
23//! - Multiple Claude model support
24//!
25//! ## Examples
26//!
27//! ### Jira Client
28//!
29//! ```no_run
30//! use integrations::jira::{JiraClient, JiraConfig, JiraAuth};
31//!
32//! # async fn example() -> anyhow::Result<()> {
33//! let config = JiraConfig {
34//!     base_url: "https://your-domain.atlassian.net".to_string(),
35//!     auth: JiraAuth::Basic {
36//!         email: "your-email@example.com".to_string(),
37//!         api_token: "your-api-token".to_string(),
38//!     },
39//!     timeout_secs: 30,
40//!     max_retries: 3,
41//!     rate_limit_per_minute: 100,
42//! };
43//!
44//! let client = JiraClient::new(config).await?;
45//! let projects = client.get_projects().await?;
46//!
47//! for project in projects {
48//!     println!("{}: {}", project.key, project.name);
49//! }
50//! # Ok(())
51//! # }
52//! ```
53//!
54//! ### Anthropic Client
55//!
56//! ```no_run
57//! use integrations::anthropic::{AnthropicClient, AnthropicConfig, ClaudeModel};
58//!
59//! # async fn example() -> anyhow::Result<()> {
60//! let config = AnthropicConfig {
61//!     api_key: "your-api-key".to_string(),
62//!     base_url: "https://api.anthropic.com".to_string(),
63//!     timeout_secs: 60,
64//!     max_retries: 3,
65//!     rate_limit_per_minute: 50,
66//!     api_version: "2023-06-01".to_string(),
67//! };
68//!
69//! let client = AnthropicClient::new(config).await?;
70//!
71//! let response = client.complete(
72//!     ClaudeModel::Claude3Haiku,
73//!     "What is the capital of France?",
74//!     100,
75//! ).await?;
76//!
77//! println!("Response: {}", response);
78//!
79//! // Get cost statistics
80//! let stats = client.get_cost_stats().await;
81//! println!("Total cost: ${:.4}", stats.total_cost);
82//! # Ok(())
83//! # }
84//! ```
85//!
86//! ## Architecture
87//!
88//! The integrations are designed with:
89//!
90//! - **Modularity**: Each integration is independent and self-contained
91//! - **Type Safety**: Comprehensive type definitions with Serde support
92//! - **Error Handling**: Detailed error types and context
93//! - **Observability**: Built-in logging and tracing
94//! - **Resilience**: Automatic retries, rate limiting, and circuit breakers
95//! - **Testing**: Comprehensive unit and integration tests
96//!
97//! ## Production Readiness
98//!
99//! All integrations include:
100//!
101//! - Authentication and authorization
102//! - Rate limiting and backoff strategies
103//! - Comprehensive error handling
104//! - Request/response logging
105//! - Input validation
106//! - Cost tracking (where applicable)
107//! - Full test coverage
108
109#![warn(missing_docs)]
110#![warn(
111    clippy::all,
112    clippy::pedantic,
113    clippy::nursery,
114    clippy::cargo
115)]
116#![allow(
117    clippy::missing_errors_doc,
118    clippy::module_name_repetitions,
119    clippy::must_use_candidate
120)]
121
122/// Jira REST API integration
123#[cfg(feature = "jira")]
124pub mod jira;
125
126/// Anthropic Claude API integration
127#[cfg(feature = "anthropic")]
128pub mod anthropic;
129
130// Re-export commonly used types
131#[cfg(feature = "jira")]
132pub use jira::{JiraAuth, JiraClient, JiraConfig};
133
134#[cfg(feature = "anthropic")]
135pub use anthropic::{AnthropicClient, AnthropicConfig, ClaudeModel};
136
137/// Library version
138pub const VERSION: &str = env!("CARGO_PKG_VERSION");
139
140/// Get the library version
141pub fn version() -> &'static str {
142    VERSION
143}
144
145#[cfg(test)]
146mod tests {
147    use super::*;
148
149    #[test]
150    fn test_version() {
151        let version = version();
152        assert!(!version.is_empty());
153    }
154
155    #[cfg(feature = "jira")]
156    #[test]
157    fn test_jira_module_exists() {
158        // Just verify the module compiles and is accessible
159        let _ = std::any::TypeId::of::<JiraConfig>();
160    }
161
162    #[cfg(feature = "anthropic")]
163    #[test]
164    fn test_anthropic_module_exists() {
165        // Just verify the module compiles and is accessible
166        let _ = std::any::TypeId::of::<AnthropicConfig>();
167    }
168}