Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

cloud_api_client: Add update_system_settings (#56843)

Tom Houlé62c01be72eb7
diff --git a/crates/cloud_api_client/src/cloud_api_client.rs b/crates/cloud_api_client/src/cloud_api_client.rs
index 1121dc47572..dc00d001d3b 100644
--- a/crates/cloud_api_client/src/cloud_api_client.rs
+++ b/crates/cloud_api_client/src/cloud_api_client.rs
@@ -239,6 +239,56 @@ impl CloudApiClient {
serde_json::from_str(&body).map_err(|e| ClientApiError::InvalidResponse(e.into()))
}
+ pub async fn update_system_settings(
+ &self,
+ system_id: String,
+ body: UpdateSystemSettingsBody,
+ ) -> Result<SystemSettings, ClientApiError> {
+ let host = self.cloud_host();
+ let request_builder = Request::builder()
+ .method(Method::PATCH)
+ .uri(
+ self.http_client
+ .build_zed_cloud_url("/client/system_settings")
+ .map_err(ClientApiError::RequestBuildFailed)?
+ .as_ref(),
+ )
+ .header(ZED_SYSTEM_ID_HEADER_NAME, system_id);
+
+ let request = self.build_request(request_builder, Json(body))?;
+
+ let mut response = self.http_client.send(request).await.map_err(|source| {
+ ClientApiError::ConnectionFailed {
+ host: host.clone(),
+ source,
+ }
+ })?;
+
+ if !response.status().is_success() {
+ if response.status() == StatusCode::UNAUTHORIZED {
+ return Err(ClientApiError::Unauthorized);
+ }
+
+ let mut body = String::new();
+ response.body_mut().read_to_string(&mut body).await.ok();
+
+ return Err(ClientApiError::ServerError {
+ host,
+ status: response.status(),
+ body,
+ });
+ }
+
+ let mut body = String::new();
+ response
+ .body_mut()
+ .read_to_string(&mut body)
+ .await
+ .map_err(|e| ClientApiError::InvalidResponse(e.into()))?;
+
+ serde_json::from_str(&body).map_err(|e| ClientApiError::InvalidResponse(e.into()))
+ }
+
pub async fn validate_credentials(&self, user_id: u32, access_token: &str) -> Result<bool> {
let request = build_request(
Request::builder().method(Method::GET).uri(
diff --git a/crates/cloud_api_types/src/cloud_api_types.rs b/crates/cloud_api_types/src/cloud_api_types.rs
index 8966d02d0de..0422c4fa035 100644
--- a/crates/cloud_api_types/src/cloud_api_types.rs
+++ b/crates/cloud_api_types/src/cloud_api_types.rs
@@ -87,6 +87,16 @@ pub struct CreateLlmTokenResponse {
pub token: LlmToken,
}
+#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize)]
+pub struct UpdateSystemSettingsBody {
+ pub selected_organization_id: Option<OrganizationId>,
+}
+
+#[derive(Debug, Default, PartialEq, Clone, Serialize, Deserialize)]
+pub struct SystemSettings {
+ pub selected_organization_id: Option<OrganizationId>,
+}
+
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct SubmitAgentThreadFeedbackBody {
pub organization_id: Option<OrganizationId>,