pub trait ProviderDriver:
Send
+ Sync
+ Debug {
// Required methods
fn provider_id(&self) -> &str;
fn api_style(&self) -> ApiStyle;
fn build_request(
&self,
messages: &[Message],
model: &str,
temperature: Option<f64>,
max_tokens: Option<u32>,
stream: bool,
extra: Option<&Value>,
) -> Result<DriverRequest, Error>;
fn parse_response(&self, body: &Value) -> Result<DriverResponse, Error>;
fn parse_stream_event(
&self,
data: &str,
) -> Result<Option<StreamingEvent>, Error>;
fn supported_capabilities(&self) -> &[Capability];
fn is_stream_done(&self, data: &str) -> bool;
}Expand description
Core trait for provider-specific API adaptation.
Each provider API style (OpenAI, Anthropic, Gemini) has a concrete implementation.
The trait is object-safe and supports dynamic dispatch via Box<dyn ProviderDriver>.
§Design Notes
Inspired by sqlx::Database — the trait defines the contract, concrete types
implement the transformations. The runtime selects the correct driver based on
the manifest’s api_style or provider_contract.
Required Methods§
Sourcefn provider_id(&self) -> &str
fn provider_id(&self) -> &str
Unique provider identifier (matches manifest id).
Sourcefn build_request(
&self,
messages: &[Message],
model: &str,
temperature: Option<f64>,
max_tokens: Option<u32>,
stream: bool,
extra: Option<&Value>,
) -> Result<DriverRequest, Error>
fn build_request( &self, messages: &[Message], model: &str, temperature: Option<f64>, max_tokens: Option<u32>, stream: bool, extra: Option<&Value>, ) -> Result<DriverRequest, Error>
Build a provider-specific HTTP request from unified parameters.
Sourcefn parse_response(&self, body: &Value) -> Result<DriverResponse, Error>
fn parse_response(&self, body: &Value) -> Result<DriverResponse, Error>
Parse a non-streaming response into unified format.
Sourcefn parse_stream_event(
&self,
data: &str,
) -> Result<Option<StreamingEvent>, Error>
fn parse_stream_event( &self, data: &str, ) -> Result<Option<StreamingEvent>, Error>
Parse a single streaming event from raw SSE/NDJSON data.
Sourcefn supported_capabilities(&self) -> &[Capability]
fn supported_capabilities(&self) -> &[Capability]
Get the list of capabilities this driver supports.
Sourcefn is_stream_done(&self, data: &str) -> bool
fn is_stream_done(&self, data: &str) -> bool
Check if the done signal has been received in streaming.