Skip to main content

Opencode

Struct Opencode 

Source
pub struct Opencode { /* private fields */ }
Expand description

The main OpenCode SDK client.

Holds connection settings and an inner HTTP client. Construct via Opencode::new, Opencode::with_options, or Opencode::builder.

Implementations§

Source§

impl Opencode

Source

pub fn new() -> Result<Self, OpencodeError>

Create a client with default configuration.

Reads OPENCODE_BASE_URL from the environment; all other settings use the JS SDK defaults (timeout = 60 s, max_retries = 2).

§Errors

Returns OpencodeError::Http if the underlying HTTP client cannot be built (e.g. TLS back-end init failure).

Source

pub fn with_options(opts: &ClientOptions) -> Result<Self, OpencodeError>

Create a client from explicit ClientOptions.

§Errors

Returns OpencodeError::Http if the underlying HTTP client cannot be built.

Source

pub fn builder() -> OpencodeBuilder

Return an OpencodeBuilder for fluent configuration.

Source

pub fn base_url(&self) -> &str

The resolved base URL.

Source

pub const fn timeout(&self) -> Duration

The per-request timeout.

Source

pub const fn max_retries(&self) -> u32

Maximum automatic retries.

Source

pub const fn default_headers(&self) -> &HeaderMap

Default headers sent with every request.

Source

pub const fn default_query(&self) -> &HashMap<String, String>

Default query parameters appended to every request.

Source

pub const fn app(&self) -> AppResource<'_>

Access the App resource.

Source

pub const fn config(&self) -> ConfigResource<'_>

Access the Config resource.

Source

pub const fn event(&self) -> EventResource<'_>

Access the Event resource.

Source

pub const fn file(&self) -> FileResource<'_>

Access the File resource.

Source

pub const fn find(&self) -> FindResource<'_>

Access the Find resource.

Source

pub const fn session(&self) -> SessionResource<'_>

Access the Session resource.

Source

pub const fn tui(&self) -> TuiResource<'_>

Access the Tui resource.

Source

pub async fn get<T: DeserializeOwned>( &self, path: &str, options: Option<&RequestOptions>, ) -> Result<T, OpencodeError>

Send a GET request and deserialise the JSON response.

Source

pub async fn get_with_query<T, Q>( &self, path: &str, query: Option<&Q>, options: Option<&RequestOptions>, ) -> Result<T, OpencodeError>

Send a GET request with query parameters.

Source

pub async fn post<T, B>( &self, path: &str, body: Option<&B>, options: Option<&RequestOptions>, ) -> Result<T, OpencodeError>

Send a POST request with an optional JSON body.

Source

pub async fn put<T, B>( &self, path: &str, body: Option<&B>, options: Option<&RequestOptions>, ) -> Result<T, OpencodeError>

Send a PUT request with an optional JSON body.

Source

pub async fn patch<T, B>( &self, path: &str, body: Option<&B>, options: Option<&RequestOptions>, ) -> Result<T, OpencodeError>

Send a PATCH request with an optional JSON body.

Source

pub async fn get_stream<T: DeserializeOwned + 'static>( &self, path: &str, ) -> Result<SseStream<T>, OpencodeError>

Send a GET request and return a streaming SSE response.

Unlike other HTTP methods, this does NOT parse the full response body. Instead it returns an crate::SseStream that lazily decodes each SSE event’s data field as JSON of type T.

Source

pub async fn delete<T, B>( &self, path: &str, body: Option<&B>, options: Option<&RequestOptions>, ) -> Result<T, OpencodeError>

Send a DELETE request with an optional JSON body.

Trait Implementations§

Source§

impl Clone for Opencode

Source§

fn clone(&self) -> Opencode

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Opencode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more