Skip to main content

swink_agent_adapters/
lib.rs

1#![forbid(unsafe_code)]
2//! LLM provider adapters for [`swink-agent`](https://docs.rs/swink-agent).
3//!
4//! Provides [`StreamFn`](swink_agent::StreamFn) implementations for nine LLM providers.
5//! No provider is enabled by default; enable only what you need:
6//!
7//! | Feature | Provider |
8//! |---|---|
9//! | `anthropic` | Anthropic Claude |
10//! | `openai` | `OpenAI` GPT |
11//! | `ollama` | `Ollama` (local) |
12//! | `gemini` | Google Gemini |
13//! | `azure` | Azure `OpenAI` / AI Foundry |
14//! | `bedrock` | AWS Bedrock |
15//! | `mistral` | Mistral AI |
16//! | `xai` | xAI Grok |
17//! | `proxy` | Custom SSE proxy |
18//!
19//! Use `full` or `all` to compile every provider adapter.
20//!
21//! # Quick Start
22//!
23//! ```no_run
24//! use swink_agent_adapters::build_remote_connection_for_model;
25//!
26//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
27//! let conn = build_remote_connection_for_model("claude-sonnet-4-6")?;
28//! # Ok(())
29//! # }
30//! ```
31
32// ── Shared infrastructure (always compiled) ───────────────────────────────
33#[cfg_attr(
34    not(any(
35        feature = "anthropic",
36        feature = "openai",
37        feature = "ollama",
38        feature = "gemini",
39        feature = "proxy",
40        feature = "azure",
41        feature = "bedrock",
42        feature = "mistral",
43        feature = "xai",
44    )),
45    allow(dead_code)
46)]
47mod base;
48#[cfg_attr(
49    not(any(
50        feature = "anthropic",
51        feature = "openai",
52        feature = "ollama",
53        feature = "gemini",
54        feature = "proxy",
55        feature = "azure",
56        feature = "bedrock",
57        feature = "mistral",
58        feature = "xai",
59    )),
60    allow(dead_code)
61)]
62mod block_accumulator;
63pub mod classify;
64pub mod convert;
65#[cfg_attr(
66    not(any(
67        feature = "anthropic",
68        feature = "openai",
69        feature = "ollama",
70        feature = "gemini",
71        feature = "proxy",
72        feature = "azure",
73        feature = "bedrock",
74        feature = "mistral",
75        feature = "xai",
76    )),
77    allow(dead_code)
78)]
79mod finalize;
80#[cfg_attr(
81    not(any(feature = "openai-compat", feature = "azure", feature = "mistral",)),
82    allow(dead_code)
83)]
84mod oai_transport;
85#[cfg_attr(
86    not(any(feature = "openai-compat", feature = "azure", feature = "mistral",)),
87    allow(dead_code)
88)]
89mod openai_compat;
90mod remote_presets;
91pub mod sse;
92
93pub use remote_presets::{
94    RemoteModelConnectionError, RemotePresetKey, all_remote_presets, build_connection_from_preset,
95    build_remote_connection, build_remote_connection_for_model,
96    build_remote_connection_with_credential, is_provider_compiled, preset, remote_presets,
97};
98
99// ── Provider adapters (feature-gated) ─────────────────────────────────────
100//
101// Each adapter is gated behind its own feature flag. Enable the corresponding
102// feature in Cargo.toml to compile and use a provider:
103//
104//   swink-agent-adapters = { features = ["anthropic", "openai"] }
105
106#[cfg(feature = "anthropic")]
107mod anthropic;
108#[cfg(feature = "anthropic")]
109pub use anthropic::AnthropicStreamFn;
110
111#[cfg(feature = "openai-compat")]
112#[allow(clippy::doc_markdown)]
113mod openai;
114#[cfg(feature = "openai")]
115pub use openai::OpenAiStreamFn;
116
117#[cfg(feature = "ollama")]
118mod ollama;
119#[cfg(feature = "ollama")]
120pub use ollama::OllamaStreamFn;
121
122#[cfg(feature = "gemini")]
123mod google;
124#[cfg(feature = "gemini")]
125pub use google::GeminiStreamFn;
126
127#[cfg(feature = "proxy")]
128mod proxy;
129#[cfg(feature = "proxy")]
130pub use proxy::ProxyStreamFn;
131
132#[cfg(feature = "azure")]
133mod azure;
134#[cfg(feature = "azure")]
135pub use azure::{AzureAuth, AzureStreamFn};
136
137#[cfg(feature = "bedrock")]
138mod bedrock;
139#[cfg(feature = "bedrock")]
140pub use bedrock::BedrockStreamFn;
141
142#[cfg(feature = "mistral")]
143mod mistral;
144#[cfg(feature = "mistral")]
145pub use mistral::MistralStreamFn;
146
147#[cfg(feature = "xai")]
148mod xai;
149#[cfg(feature = "xai")]
150pub use xai::XAiStreamFn;