claude_agent/client/adapter/
mod.rs1mod anthropic;
4#[cfg(any(feature = "aws", feature = "gcp", feature = "azure"))]
5mod base;
6mod config;
7mod request;
8mod traits;
9
10#[cfg(any(feature = "aws", feature = "gcp", feature = "azure"))]
11mod token_cache;
12
13#[cfg(feature = "aws")]
14mod bedrock;
15#[cfg(feature = "azure")]
16mod foundry;
17#[cfg(feature = "gcp")]
18mod vertex;
19
20pub use anthropic::AnthropicAdapter;
21pub use config::{
22 BetaConfig, BetaFeature, DEFAULT_MODEL, DEFAULT_REASONING_MODEL, DEFAULT_SMALL_MODEL,
23 FRONTIER_MODEL, ModelConfig, ModelType, ProviderConfig,
24};
25pub use traits::ProviderAdapter;
26
27#[cfg(feature = "aws")]
28pub use bedrock::BedrockAdapter;
29#[cfg(feature = "azure")]
30pub use foundry::FoundryAdapter;
31#[cfg(feature = "gcp")]
32pub use vertex::VertexAdapter;
33
34use crate::Result;
35
36#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
37pub enum CloudProvider {
38 #[default]
39 Anthropic,
40 #[cfg(feature = "aws")]
41 Bedrock,
42 #[cfg(feature = "gcp")]
43 Vertex,
44 #[cfg(feature = "azure")]
45 Foundry,
46}
47
48impl CloudProvider {
49 pub fn from_env() -> Self {
50 #[cfg(feature = "aws")]
51 if std::env::var("CLAUDE_CODE_USE_BEDROCK").is_ok() {
52 return Self::Bedrock;
53 }
54 #[cfg(feature = "gcp")]
55 if std::env::var("CLAUDE_CODE_USE_VERTEX").is_ok() {
56 return Self::Vertex;
57 }
58 #[cfg(feature = "azure")]
59 if std::env::var("CLAUDE_CODE_USE_FOUNDRY").is_ok() {
60 return Self::Foundry;
61 }
62 Self::Anthropic
63 }
64
65 pub fn default_models(&self) -> ModelConfig {
66 match self {
67 Self::Anthropic => ModelConfig::anthropic(),
68 #[cfg(feature = "aws")]
69 Self::Bedrock => ModelConfig::bedrock(),
70 #[cfg(feature = "gcp")]
71 Self::Vertex => ModelConfig::vertex(),
72 #[cfg(feature = "azure")]
73 Self::Foundry => ModelConfig::foundry(),
74 }
75 }
76}
77
78pub async fn create_adapter(
79 provider: CloudProvider,
80 config: ProviderConfig,
81) -> Result<Box<dyn ProviderAdapter>> {
82 match provider {
83 CloudProvider::Anthropic => Ok(Box::new(AnthropicAdapter::new(config))),
84 #[cfg(feature = "aws")]
85 CloudProvider::Bedrock => Ok(Box::new(BedrockAdapter::from_env(config).await?)),
86 #[cfg(feature = "gcp")]
87 CloudProvider::Vertex => Ok(Box::new(VertexAdapter::from_env(config).await?)),
88 #[cfg(feature = "azure")]
89 CloudProvider::Foundry => Ok(Box::new(FoundryAdapter::from_env(config).await?)),
90 }
91}