pub trait ProviderAdapter: Send + Sync {
// Required methods
fn kind(&self) -> AiProviderKind;
fn build_request(
&self,
req: &ChatRequest,
provider_model: &str,
) -> Result<ProviderRequest, AiError>;
fn parse_response(&self, body: &Value) -> Result<ChatResponse, AiError>;
fn parse_error(&self, body: &Value) -> ProviderErrorBody;
fn parse_stream_event(
&self,
data: &Value,
) -> Result<Vec<StreamEvent>, AiError>;
// Provided method
fn stream_done_sentinel(&self) -> Option<&'static str> { ... }
}Expand description
The translation contract of one provider dialect (DW-075). Pure
functions over the canonical types; implementations are stateless
singletons (see adapter_for).
Required Methods§
Sourcefn kind(&self) -> AiProviderKind
fn kind(&self) -> AiProviderKind
The dialect this adapter speaks.
Sourcefn build_request(
&self,
req: &ChatRequest,
provider_model: &str,
) -> Result<ProviderRequest, AiError>
fn build_request( &self, req: &ChatRequest, provider_model: &str, ) -> Result<ProviderRequest, AiError>
Translate a canonical request into this provider’s HTTP shape.
provider_model is the mapped provider model identifier that
must REPLACE the client’s alias in the outbound body.
Sourcefn parse_response(&self, body: &Value) -> Result<ChatResponse, AiError>
fn parse_response(&self, body: &Value) -> Result<ChatResponse, AiError>
Translate a provider success body (HTTP 200) into the canonical
ChatResponse.
Sourcefn parse_error(&self, body: &Value) -> ProviderErrorBody
fn parse_error(&self, body: &Value) -> ProviderErrorBody
Extract the error message/type/code from a provider error body (any shape the provider uses). Never fails — a best-effort generic message is produced when the body is not understood.
Sourcefn parse_stream_event(&self, data: &Value) -> Result<Vec<StreamEvent>, AiError>
fn parse_stream_event(&self, data: &Value) -> Result<Vec<StreamEvent>, AiError>
Translate ONE provider SSE data payload into zero or more canonical stream events (DW-077 wires the gateway streaming path; verified per adapter in DW-075 tests).
Provided Methods§
Sourcefn stream_done_sentinel(&self) -> Option<&'static str>
fn stream_done_sentinel(&self) -> Option<&'static str>
The dialect’s end-of-stream data sentinel, if it has one
(OpenAI [DONE]; Anthropic/Gemini use typed events instead).