Skip to main content

context69_sdk/client/
settings.rs

1use context69_contracts::{
2    DoclingSettingsResponse, ProviderAccountResponse, RuntimeSettingsResponse,
3    SearchSettingsResponse, UpdateDoclingSettingsRequest, UpdateRuntimeSettingsRequest,
4    UpdateSearchSettingsRequest, UpsertProviderAccountRequest,
5};
6use reqwest::Method;
7
8use crate::{Context69Client, Error};
9
10impl Context69Client {
11    pub async fn get_runtime_settings(&self) -> Result<RuntimeSettingsResponse, Error> {
12        self.execute_json(
13            self.authorized_request(Method::GET, "/v1/settings/runtime")
14                .await?,
15        )
16        .await
17    }
18
19    pub async fn update_runtime_settings(
20        &self,
21        request: &UpdateRuntimeSettingsRequest,
22    ) -> Result<RuntimeSettingsResponse, Error> {
23        self.execute_json(
24            self.authorized_request(Method::PUT, "/v1/settings/runtime")
25                .await?
26                .json(request),
27        )
28        .await
29    }
30
31    pub async fn list_provider_accounts(&self) -> Result<Vec<ProviderAccountResponse>, Error> {
32        self.execute_json(
33            self.authorized_request(Method::GET, "/v1/settings/provider-accounts")
34                .await?,
35        )
36        .await
37    }
38
39    pub async fn create_provider_account(
40        &self,
41        request: &UpsertProviderAccountRequest,
42    ) -> Result<ProviderAccountResponse, Error> {
43        self.execute_json(
44            self.authorized_request(Method::POST, "/v1/settings/provider-accounts")
45                .await?
46                .json(request),
47        )
48        .await
49    }
50
51    pub async fn update_provider_account(
52        &self,
53        request: &UpsertProviderAccountRequest,
54    ) -> Result<ProviderAccountResponse, Error> {
55        self.execute_json(
56            self.authorized_request(Method::PUT, "/v1/settings/provider-accounts")
57                .await?
58                .json(request),
59        )
60        .await
61    }
62
63    pub async fn delete_provider_account(&self, account_key: &str) -> Result<(), Error> {
64        let path = format!("/v1/settings/provider-accounts/{account_key}");
65        self.execute_empty(self.authorized_request(Method::DELETE, &path).await?)
66            .await
67    }
68
69    pub async fn get_docling_settings(&self) -> Result<DoclingSettingsResponse, Error> {
70        self.execute_json(
71            self.authorized_request(Method::GET, "/v1/settings/docling")
72                .await?,
73        )
74        .await
75    }
76
77    pub async fn update_docling_settings(
78        &self,
79        request: &UpdateDoclingSettingsRequest,
80    ) -> Result<DoclingSettingsResponse, Error> {
81        self.execute_json(
82            self.authorized_request(Method::PUT, "/v1/settings/docling")
83                .await?
84                .json(request),
85        )
86        .await
87    }
88
89    pub async fn get_search_settings(&self) -> Result<SearchSettingsResponse, Error> {
90        self.execute_json(
91            self.authorized_request(Method::GET, "/v1/settings/search")
92                .await?,
93        )
94        .await
95    }
96
97    pub async fn update_search_settings(
98        &self,
99        request: &UpdateSearchSettingsRequest,
100    ) -> Result<SearchSettingsResponse, Error> {
101        self.execute_json(
102            self.authorized_request(Method::PUT, "/v1/settings/search")
103                .await?
104                .json(request),
105        )
106        .await
107    }
108}