Skip to main content

opencode_sdk/http/
permissions.rs

1//! Permissions API for OpenCode.
2//!
3//! Endpoints for managing permission requests.
4
5use crate::error::Result;
6use crate::http::HttpClient;
7use crate::types::api::PermissionReplyResponse;
8use crate::types::permission::{PermissionReplyRequest, PermissionRequest};
9use reqwest::Method;
10
11/// Permissions API client.
12#[derive(Clone)]
13pub struct PermissionsApi {
14    http: HttpClient,
15}
16
17impl PermissionsApi {
18    /// Create a new Permissions API client.
19    pub fn new(http: HttpClient) -> Self {
20        Self { http }
21    }
22
23    /// List pending permission requests.
24    ///
25    /// # Errors
26    ///
27    /// Returns an error if the request fails.
28    pub async fn list(&self) -> Result<Vec<PermissionRequest>> {
29        self.http
30            .request_json(Method::GET, "/permission", None)
31            .await
32    }
33
34    /// Reply to a permission request.
35    ///
36    /// # Errors
37    ///
38    /// Returns an error if the request fails.
39    pub async fn reply(
40        &self,
41        request_id: &str,
42        reply: &PermissionReplyRequest,
43    ) -> Result<PermissionReplyResponse> {
44        let body = serde_json::to_value(reply)?;
45        self.http
46            .request_json(
47                Method::POST,
48                &format!("/permission/{}/reply", request_id),
49                Some(body),
50            )
51            .await
52    }
53}