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
//! # Provider-Agnostic LLM Interface
//!
//! Abstraction layer supporting multiple LLM providers (Claude, OpenAI, local models)
//! with unified API, automatic fallback, and provider-specific optimizations.
//!
//! ## Core Components
//!
//! - **[`LLMProvider`]**: Universal trait for all LLM provider implementations
//! - **`ClaudeProvider`**: Claude-specific implementation with Claude Code integration
//! - **`LLMProviderFactory`**: Factory for creating provider instances
//! - **Provider Types**: Request/response types and configuration structures
//!
//! ## Key Features
//!
//! ### π Multi-Provider Support
//! - **Claude**: Full integration with Claude Code interface
//! - **CLI Mode (default)**: Uses `claude` command, no API key required
//! - **API Mode**: Direct Anthropic API access, requires API key
//! - Configure via `CLAUDE_MODE` env var or `additional_config["mode"]`
//! - **OpenAI Codex CLI**: Local Codex command-line integration
//! - **Anthropic API**: Direct Anthropic API integration (via API mode)
//! - **Local Models**: Ollama, LocalAI, and other local inference (planned)
//! - **Custom Providers**: Extensible architecture for custom implementations
//!
//! ### π Unified Interface
//! - Consistent API across all providers
//! - Standardized request/response format
//! - Provider-agnostic error handling
//! - Common configuration patterns
//!
//! ### π‘οΈ Reliability Features
//! - Automatic fallback between providers
//! - Provider health monitoring and status checking
//! - Circuit breaker patterns for failed providers
//! - Graceful degradation on provider unavailability
//!
//! ### β‘ Performance Optimization
//! - Provider-specific rate limiting and cost optimization
//! - Capability detection (streaming, function calling, vision)
//! - Model selection based on task requirements
//! - Token estimation and cost prediction
//!
//! ### π§ Configuration Management
//! - Flexible provider configuration system
//! - Environment-based configuration loading
//! - Runtime provider switching and hot-swapping
//! - Provider-specific optimization settings
//!
//! ## Provider Architecture
//!
//! ```text
//! βββββββββββββββββββ ββββββββββββββββββββ
//! β Application βββββΆβ LLMProvider β (Trait)
//! β Logic β β Interface β
//! βββββββββββββββββββ ββββββββββββββββββββ
//! β
//! ββββββββββββββΌβββββββββββββ
//! β β β
//! βββββββββΌβββββββ ββββββββββββ βββββββΌββββββ
//! βClaudeProviderβ βOpenAICodexβ βLocalModel β
//! β (CLI/API) β β Provider β β Provider β
//! ββββββββββββββββ ββββββββββββ βββββββββββββ
//! ```
//!
//! ## Example Usage
//!
//! ### Using Claude Code CLI (default, no API key required)
//!
//! ```rust,no_run
//! use aca::llm::{
//! LLMProvider, LLMRequest, ProviderConfig, ProviderType, ClaudeProvider
//! };
//! use std::collections::HashMap;
//! use std::path::PathBuf;
//!
//! #[tokio::main]
//! async fn main() -> anyhow::Result<()> {
//! // Configure Claude provider in CLI mode (default)
//! // No API key needed - uses `claude` CLI command
//! let config = ProviderConfig {
//! provider_type: ProviderType::ClaudeCode,
//! model: Some("claude-sonnet".to_string()),
//! ..Default::default() // claude_mode defaults to CLI
//! };
//!
//! // Create provider instance
//! let provider = ClaudeProvider::new(config, PathBuf::from(".")).await?;
//!
//! // Create a request
//! let request = LLMRequest {
//! id: uuid::Uuid::new_v4(),
//! prompt: "Write a Hello World function in Rust".to_string(),
//! max_tokens: Some(1000),
//! temperature: Some(0.7),
//! context: HashMap::new(),
//! ..Default::default()
//! };
//!
//! // Execute request (works with any provider)
//! let response = provider.execute_request(request).await?;
//! println!("Response: {}", response.content);
//!
//! Ok(())
//! }
//! ```
//!
//! ### Using Anthropic API (requires API key)
//!
//! ```rust,no_run
//! use aca::llm::{
//! LLMProvider, LLMRequest, ProviderConfig, ProviderType, ClaudeProvider
//! };
//! use std::collections::HashMap;
//! use std::path::PathBuf;
//!
//! #[tokio::main]
//! async fn main() -> anyhow::Result<()> {
//! // Configure Claude provider in API mode
//! let mut additional_config = HashMap::new();
//! additional_config.insert("mode".to_string(), serde_json::json!("API"));
//!
//! let config = ProviderConfig {
//! provider_type: ProviderType::ClaudeCode,
//! api_key: Some("your-api-key".to_string()), // Required in API mode
//! model: Some("claude-3-sonnet".to_string()),
//! additional_config,
//! ..Default::default()
//! };
//!
//! let provider = ClaudeProvider::new(config, PathBuf::from(".")).await?;
//! // ... rest of the code is the same
//! Ok(())
//! }
//! ```
//!
//! Alternatively, set the `CLAUDE_MODE=API` environment variable.
//!
//! ## Adding New Providers
//!
//! To add a new provider, implement the [`LLMProvider`] trait:
//!
//! ```rust,ignore
//! use futures::future::BoxFuture;
//! use crate::llm::{LLMProvider, LLMRequest, LLMResponse, LLMError};
//!
//! pub struct CustomProvider {
//! config: ProviderConfig,
//! // ... provider-specific fields
//! }
//!
//! impl LLMProvider for CustomProvider {
//! fn execute_request(&self, request: LLMRequest) -> BoxFuture<'_, Result<LLMResponse, LLMError>> {
//! Box::pin(async move {
//! // Implement provider-specific logic
//! todo!("Implement request execution")
//! })
//! }
//!
//! // ... implement other required methods
//! }
//! ```
/// Claude-specific LLM provider implementation.
///
/// Integrates with the Claude Code interface to provide full Claude
/// functionality including context management, rate limiting, and error recovery.
/// OpenAI Codex LLM provider implementation.
///
/// Provides access to OpenAI's Codex-style completions with smart rate limiting.
/// Core LLM provider trait and factory.
///
/// Defines the universal [`LLMProvider`] trait that all provider implementations
/// must satisfy, plus the factory for creating provider instances.
/// Provider-agnostic types and configuration.
///
/// Common data types, request/response structures, error types,
/// and configuration options used across all LLM providers.
pub use ClaudeProvider;
pub use OpenAIProvider;
pub use LLMProvider;
pub use *;
// Re-export ClaudeProviderMode for convenience
pub use ClaudeProviderMode;