Skip to main content

ProviderDriver

Trait ProviderDriver 

Source
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§

Source

fn provider_id(&self) -> &str

Unique provider identifier (matches manifest id).

Source

fn api_style(&self) -> ApiStyle

API style this driver implements.

Source

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.

Source

fn parse_response(&self, body: &Value) -> Result<DriverResponse, Error>

Parse a non-streaming response into unified format.

Source

fn parse_stream_event( &self, data: &str, ) -> Result<Option<StreamingEvent>, Error>

Parse a single streaming event from raw SSE/NDJSON data.

Source

fn supported_capabilities(&self) -> &[Capability]

Get the list of capabilities this driver supports.

Source

fn is_stream_done(&self, data: &str) -> bool

Check if the done signal has been received in streaming.

Implementors§