pub struct AdaptedClient { /* private fields */ }Expand description
HTTP client with provider-specific request/response adaptation.
Wraps HttpClient and an optional ProviderAdapter. When an adapter
is present, post_json will:
- Convert the payload via
adapter.convert_request() - Send via
HttpClient::post_json() - Convert the response body via
adapter.convert_response()
Implementations§
Source§impl AdaptedClient
impl AdaptedClient
Sourcepub fn new(client: HttpClient) -> Self
pub fn new(client: HttpClient) -> Self
Create an adapted client without any adapter (passthrough).
Sourcepub fn with_adapter(
client: HttpClient,
adapter: Box<dyn ProviderAdapter>,
) -> Self
pub fn with_adapter( client: HttpClient, adapter: Box<dyn ProviderAdapter>, ) -> Self
Create an adapted client with a provider adapter.
Sourcepub fn adapter_for_provider(provider: &str) -> Option<Box<dyn ProviderAdapter>>
pub fn adapter_for_provider(provider: &str) -> Option<Box<dyn ProviderAdapter>>
Create an adapter for a specific provider name.
Recognized providers:
"anthropic"→AnthropicAdapter"openai"→OpenAiAdapter"gemini"|"google"→GeminiAdapter
Returns None for providers that use the Chat Completions format natively
(groq, fireworks, mistral, etc.).
Sourcepub fn resolve_provider(provider: &str, api_key: &str) -> String
pub fn resolve_provider(provider: &str, api_key: &str) -> String
Resolve the provider name, falling back to auto-detection from the API key.
If provider is non-empty, returns it as-is. Otherwise, inspects the
API key prefix via detect_provider_from_key and returns the detected
provider or "openai" as the final fallback.
Sourcepub async fn post_json(
&self,
payload: &Value,
cancel: Option<&CancellationToken>,
) -> Result<HttpResult, HttpError>
pub async fn post_json( &self, payload: &Value, cancel: Option<&CancellationToken>, ) -> Result<HttpResult, HttpError>
POST JSON with optional request/response conversion.
Sourcepub fn supports_streaming(&self) -> bool
pub fn supports_streaming(&self) -> bool
Whether streaming is supported for this client’s adapter.
Sourcepub async fn post_json_streaming(
&self,
payload: &Value,
cancel: Option<&CancellationToken>,
callback: &dyn StreamCallback,
) -> Result<HttpResult, HttpError>
pub async fn post_json_streaming( &self, payload: &Value, cancel: Option<&CancellationToken>, callback: &dyn StreamCallback, ) -> Result<HttpResult, HttpError>
POST JSON with SSE streaming, calling the callback for each event.
Falls back to post_json if the adapter doesn’t support streaming.
Returns the final accumulated response as an HttpResult.