opencode_sdk/http/
misc.rs1use crate::error::Result;
6use crate::http::HttpClient;
7use crate::types::api::{FormatterInfo, LspServerStatus, OpenApiDoc};
8use reqwest::Method;
9use serde::{Deserialize, Serialize};
10
11#[derive(Clone)]
13pub struct MiscApi {
14 http: HttpClient,
15}
16
17impl MiscApi {
18 pub fn new(http: HttpClient) -> Self {
20 Self { http }
21 }
22
23 pub async fn path(&self) -> Result<PathInfo> {
29 self.http.request_json(Method::GET, "/path", None).await
30 }
31
32 pub async fn vcs(&self) -> Result<VcsInfo> {
38 self.http.request_json(Method::GET, "/vcs", None).await
39 }
40
41 pub async fn dispose(&self) -> Result<()> {
47 self.http
48 .request_empty(
49 Method::POST,
50 "/instance/dispose",
51 Some(serde_json::json!({})),
52 )
53 .await
54 }
55
56 pub async fn log(&self, entry: &LogEntry) -> Result<()> {
62 let body = serde_json::to_value(entry)?;
63 self.http
64 .request_empty(Method::POST, "/log", Some(body))
65 .await
66 }
67
68 pub async fn lsp(&self) -> Result<Vec<LspServerStatus>> {
74 self.http.request_json(Method::GET, "/lsp", None).await
75 }
76
77 pub async fn formatter(&self) -> Result<Vec<FormatterInfo>> {
83 self.http
84 .request_json(Method::GET, "/formatter", None)
85 .await
86 }
87
88 pub async fn health(&self) -> Result<HealthInfo> {
94 self.http
95 .request_json(Method::GET, "/global/health", None)
96 .await
97 }
98
99 pub async fn global_dispose(&self) -> Result<()> {
105 self.http
106 .request_empty(Method::POST, "/global/dispose", Some(serde_json::json!({})))
107 .await
108 }
109
110 pub async fn doc(&self) -> Result<OpenApiDoc> {
116 self.http.request_json(Method::GET, "/doc", None).await
117 }
118}
119
120#[derive(Debug, Clone, Serialize, Deserialize)]
122#[serde(rename_all = "camelCase")]
123pub struct PathInfo {
124 pub directory: String,
126 #[serde(default, skip_serializing_if = "Option::is_none")]
128 pub project_root: Option<String>,
129}
130
131#[derive(Debug, Clone, Serialize, Deserialize)]
133#[serde(rename_all = "camelCase")]
134pub struct VcsInfo {
135 #[serde(default, skip_serializing_if = "Option::is_none")]
137 pub r#type: Option<String>,
138 #[serde(default, skip_serializing_if = "Option::is_none")]
140 pub branch: Option<String>,
141 #[serde(default, skip_serializing_if = "Option::is_none")]
143 pub remote: Option<String>,
144}
145
146#[derive(Debug, Clone, Serialize, Deserialize)]
149#[serde(rename_all = "camelCase")]
150pub struct LogEntry {
151 pub level: String,
153 pub message: String,
155 #[serde(default, skip_serializing_if = "Option::is_none")]
157 pub data: Option<serde_json::Value>,
158}
159
160#[derive(Debug, Clone, Serialize, Deserialize)]
162#[serde(rename_all = "camelCase")]
163pub struct HealthInfo {
164 pub healthy: bool,
166 #[serde(default, skip_serializing_if = "Option::is_none")]
168 pub version: Option<String>,
169}