misardev 1.1.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::transport::Transport;
use crate::transport::body_or_empty;
use crate::transport::build_query;
use crate::transport::encode_path;
use reqwest::Method;
use serde_json::Value;

/// The `dm` resource — 10 operation(s).
///
/// Direct messages: threads and requests, messages, read state, unread counts.
///
/// Reached through [`crate::MisarDev::dm`].
#[derive(Debug, Clone, Copy)]
pub struct DmResource<'a> {
    pub(crate) t: &'a Transport,
}

impl DmResource<'_> {
    /// `POST /dm/threads/:id/accept`
    ///
    /// misardev:method dm.acceptThread
    pub async fn accept_thread(self, id: &str) -> Result<Value, MisarDevError> {
        self.t.request(Method::POST, &format!("/dm/threads/{}/accept", encode_path(id)), "", None).await
    }

    /// `POST /dm/threads`
    ///
    /// misardev:method dm.createThread
    pub async fn create_thread(self, body: Option<Value>) -> Result<Value, MisarDevError> {
        self.t.request(Method::POST, "/dm/threads", "", Some(body_or_empty(body))).await
    }

    /// `POST /dm/threads/:id/mute`
    ///
    /// misardev:method dm.createThreadsMute
    pub async fn create_threads_mute(self, id: &str) -> Result<Value, MisarDevError> {
        self.t.request(Method::POST, &format!("/dm/threads/{}/mute", encode_path(id)), "", None).await
    }

    /// `POST /dm/threads/:id/decline`
    ///
    /// misardev:method dm.declineThread
    pub async fn decline_thread(self, id: &str) -> Result<Value, MisarDevError> {
        self.t.request(Method::POST, &format!("/dm/threads/{}/decline", encode_path(id)), "", None).await
    }

    /// `DELETE /dm/threads/:id/mute`
    ///
    /// misardev:method dm.deleteThreadsMute
    pub async fn delete_threads_mute(self, id: &str) -> Result<Value, MisarDevError> {
        self.t.request(Method::DELETE, &format!("/dm/threads/{}/mute", encode_path(id)), "", None).await
    }

    /// `GET /dm/threads/:id/messages`
    ///
    /// Optional query: `cursor`, `limit`.
    ///
    /// misardev:method dm.listMessages
    pub async fn list_messages(self, id: &str, query: Option<Value>) -> Result<Value, MisarDevError> {
        self.t.request(Method::GET, &format!("/dm/threads/{}/messages", encode_path(id)), &build_query(query.as_ref(), &[]), None).await
    }

    /// `GET /dm/threads`
    ///
    /// Optional query: `box`, `cursor`, `limit`.
    ///
    /// misardev:method dm.listThreads
    pub async fn list_threads(self, query: Option<Value>) -> Result<Value, MisarDevError> {
        self.t.request(Method::GET, "/dm/threads", &build_query(query.as_ref(), &[]), None).await
    }

    /// `POST /dm/threads/:id/read`
    ///
    /// misardev:method dm.markThreadRead
    pub async fn mark_thread_read(self, id: &str) -> Result<Value, MisarDevError> {
        self.t.request(Method::POST, &format!("/dm/threads/{}/read", encode_path(id)), "", None).await
    }

    /// `POST /dm/threads/:id/messages`
    ///
    /// misardev:method dm.sendMessage
    pub async fn send_message(self, id: &str, body: Option<Value>) -> Result<Value, MisarDevError> {
        self.t.request(Method::POST, &format!("/dm/threads/{}/messages", encode_path(id)), "", Some(body_or_empty(body))).await
    }

    /// `GET /dm/unread`
    ///
    /// misardev:method dm.unreadCounts
    pub async fn unread_counts(self) -> Result<Value, MisarDevError> {
        self.t.request(Method::GET, "/dm/unread", "", None).await
    }
}