pub struct OpenCodeZenClient { /* private fields */ }Expand description
Concrete OpenCode Zen API client.
Implementations§
Source§impl OpenCodeZenClient
impl OpenCodeZenClient
Sourcepub fn from_env_or_dotenv(workspace_root: &Path) -> Result<Self>
pub fn from_env_or_dotenv(workspace_root: &Path) -> Result<Self>
Create a client from OPENCODE_ZEN_KEY, falling back to managed stores
and workspace .env.
Sourcepub fn new(base_url: &str, api_key: &str) -> Self
pub fn new(base_url: &str, api_key: &str) -> Self
Create a client with an explicit base URL and API key.
Sourcepub fn fetch_models(&self) -> Result<Vec<ModelInfo>>
pub fn fetch_models(&self) -> Result<Vec<ModelInfo>>
Fetch model metadata from GET /models.
Sourcepub fn build_chat_headers(&self) -> Vec<(String, String)>
pub fn build_chat_headers(&self) -> Vec<(String, String)>
Build the headers for a chat-completions request.
Sourcepub fn build_messages_headers(&self) -> Vec<(String, String)>
pub fn build_messages_headers(&self) -> Vec<(String, String)>
Build headers for an Anthropic-compatible Messages request.
Sourcepub fn build_chat_request_body(
model: &str,
messages: &[ProviderMessage],
max_tokens: u32,
stream: bool,
tools: Option<&Value>,
) -> Result<Value>
pub fn build_chat_request_body( model: &str, messages: &[ProviderMessage], max_tokens: u32, stream: bool, tools: Option<&Value>, ) -> Result<Value>
Build a request body for POST /chat/completions.
Sourcepub fn build_request_body(
model: &str,
messages: &[ProviderMessage],
max_tokens: u32,
tools: Option<&Value>,
effort: ReasoningEffort,
summary: ReasoningSummary,
continuation: &ProviderContinuation,
) -> Result<Value>
pub fn build_request_body( model: &str, messages: &[ProviderMessage], max_tokens: u32, tools: Option<&Value>, effort: ReasoningEffort, summary: ReasoningSummary, continuation: &ProviderContinuation, ) -> Result<Value>
Build the request body for the endpoint family selected by model.
Sourcepub fn send_streaming_request(
&self,
model: &str,
messages: &[ProviderMessage],
max_tokens: u32,
tools: Option<&Value>,
effort: ReasoningEffort,
summary: ReasoningSummary,
continuation: &ProviderContinuation,
) -> Result<Response<Body>>
pub fn send_streaming_request( &self, model: &str, messages: &[ProviderMessage], max_tokens: u32, tools: Option<&Value>, effort: ReasoningEffort, summary: ReasoningSummary, continuation: &ProviderContinuation, ) -> Result<Response<Body>>
Send a streaming request to the endpoint selected by model.
Trait Implementations§
Source§impl StreamingProvider for OpenCodeZenClient
impl StreamingProvider for OpenCodeZenClient
type Metadata = Vec<ModelInfo>
fn name(&self) -> &'static str
fn load_status(&self) -> String
fn request_status(&self, model: &str) -> String
fn from_env_or_dotenv(root: &Path) -> Result<Self>
fn load_metadata(&self) -> Result<Self::Metadata>
fn metadata_loaded_event(&self, metadata: &Self::Metadata) -> Option<AgentEvent>
fn metadata_status( &self, model: &str, metadata: &Self::Metadata, ) -> Option<String>
fn token_budget(&self, _model: &str, _metadata: Option<&Self::Metadata>) -> u32
Source§fn serialized_request_body(
&self,
model: &str,
messages: &[ProviderMessage],
request: &StreamingRequest<'_>,
) -> Result<Vec<u8>>
fn serialized_request_body( &self, model: &str, messages: &[ProviderMessage], request: &StreamingRequest<'_>, ) -> Result<Vec<u8>>
Serialize exactly the request body that the adapter sends.
fn send_streaming_request( &self, model: &str, messages: &[ProviderMessage], request: &StreamingRequest<'_>, ) -> Result<Response<Body>>
fn stream_format(&self, model: &str) -> Result<StreamFormat>
fn request_error_message(error: &ProviderError) -> String
fn is_retryable_request_error(error: &ProviderError) -> bool
Auto Trait Implementations§
impl !RefUnwindSafe for OpenCodeZenClient
impl !UnwindSafe for OpenCodeZenClient
impl Freeze for OpenCodeZenClient
impl Send for OpenCodeZenClient
impl Sync for OpenCodeZenClient
impl Unpin for OpenCodeZenClient
impl UnsafeUnpin for OpenCodeZenClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoMaybeUndefined<T> for T
impl<T> IntoMaybeUndefined<T> for T
Source§fn into_maybe_undefined(self) -> MaybeUndefined<T>
fn into_maybe_undefined(self) -> MaybeUndefined<T>
Converts this value into a three-state builder argument.
Source§impl<T> IntoOption<T> for T
impl<T> IntoOption<T> for T
Source§fn into_option(self) -> Option<T>
fn into_option(self) -> Option<T>
Converts this value into an optional builder argument.