1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! Config API for OpenCode.
//!
//! Endpoints for configuration management.
use crate::error::Result;
use crate::http::HttpClient;
use crate::types::config::{Config, ConfigProviders, UpdateConfigRequest};
use reqwest::Method;
/// Config API client.
#[derive(Clone)]
pub struct ConfigApi {
http: HttpClient,
}
impl ConfigApi {
/// Create a new Config API client.
pub fn new(http: HttpClient) -> Self {
Self { http }
}
/// Get current configuration.
///
/// # Errors
///
/// Returns an error if the request fails.
pub async fn get(&self) -> Result<Config> {
self.http.request_json(Method::GET, "/config", None).await
}
/// Update configuration.
///
/// # Errors
///
/// Returns an error if the request fails.
pub async fn update(&self, req: &UpdateConfigRequest) -> Result<Config> {
let body = serde_json::to_value(req)?;
self.http
.request_json(Method::PATCH, "/config", Some(body))
.await
}
/// Get provider configuration.
///
/// # Errors
///
/// Returns an error if the request fails.
pub async fn providers(&self) -> Result<ConfigProviders> {
self.http
.request_json(Method::GET, "/config/providers", None)
.await
}
}