misardev 1.0.0

Async Rust client for the Misar.Dev API: create projects, write files, build and deploy, start from templates, run OpenAI-compatible chat completions, search code and read usage. Retries, typed plan-limit errors, SSE streaming.
Documentation
// GENERATED by scripts/generate-sdk-resources.mjs from sdks/manifest.json.
// Do not edit by hand — change the route, run `pnpm sdk:sync`, and regenerate.

use crate::error::MisarDevError;
use crate::sse::EventStream;
use crate::transport::Transport;
use crate::transport::body_or_empty;
use crate::transport::with_stream;
use reqwest::Method;
use serde_json::Value;

/// The `chat` resource — 3 operation(s).
///
/// OpenAI-compatible chat completions (plain and streamed) and the studio build conversation stream.
///
/// Reached through [`crate::MisarDev::chat`].
#[derive(Debug, Clone, Copy)]
pub struct ChatResource<'a> {
    pub(crate) t: &'a Transport,
}

impl ChatResource<'_> {
    /// `POST /v1/chat/completions`
    ///
    /// misardev:method chat.completions
    pub async fn completions(self, body: Option<Value>) -> Result<Value, MisarDevError> {
        self.t.request(Method::POST, "/v1/chat/completions", "", Some(body_or_empty(body))).await
    }

    /// `POST /chat`
    ///
    /// Yields each Server-Sent Event as it arrives, until the server closes the stream.
    ///
    /// misardev:stream chat.studioStream
    pub async fn studio_stream(self, body: Option<Value>) -> Result<EventStream, MisarDevError> {
        self.t.stream(Method::POST, "/chat", "", Some(body_or_empty(body)), None).await
    }

    /// `POST /v1/chat/completions`
    ///
    /// Sets `"stream": true` for you and yields each chunk until `[DONE]`.
    ///
    /// misardev:stream chat.completionsStream
    pub async fn completions_stream(self, body: Option<Value>) -> Result<EventStream, MisarDevError> {
        self.t.stream(Method::POST, "/v1/chat/completions", "", Some(with_stream(body)), Some("[DONE]")).await
    }
}