Skip to main content

edgequake_sdk/resources/
workspaces.rs

1//! Workspaces resource.
2
3use crate::client::EdgeQuakeClient;
4use crate::error::Result;
5use crate::types::workspaces::*;
6
7pub struct WorkspacesResource<'a> {
8    pub(crate) client: &'a EdgeQuakeClient,
9}
10
11impl<'a> WorkspacesResource<'a> {
12    /// `GET /api/v1/tenants/{tenant_id}/workspaces`
13    pub async fn list(&self, tenant_id: &str) -> Result<Vec<WorkspaceInfo>> {
14        self.client
15            .get(&format!("/api/v1/tenants/{tenant_id}/workspaces"))
16            .await
17    }
18
19    /// `POST /api/v1/tenants/{tenant_id}/workspaces`
20    pub async fn create(
21        &self,
22        tenant_id: &str,
23        req: &CreateWorkspaceRequest,
24    ) -> Result<WorkspaceInfo> {
25        self.client
26            .post(
27                &format!("/api/v1/tenants/{tenant_id}/workspaces"),
28                Some(req),
29            )
30            .await
31    }
32
33    /// `GET /api/v1/workspaces/{id}/stats`
34    pub async fn stats(&self, workspace_id: &str) -> Result<WorkspaceStats> {
35        self.client
36            .get(&format!("/api/v1/workspaces/{workspace_id}/stats"))
37            .await
38    }
39
40    /// `POST /api/v1/workspaces/{id}/rebuild`
41    pub async fn rebuild(&self, workspace_id: &str) -> Result<RebuildResponse> {
42        self.client
43            .post::<(), RebuildResponse>(
44                &format!("/api/v1/workspaces/{workspace_id}/rebuild"),
45                None,
46            )
47            .await
48    }
49
50    /// `GET /api/v1/workspaces/{id}` — Get workspace by ID.
51    pub async fn get(&self, workspace_id: &str) -> Result<WorkspaceInfo> {
52        self.client
53            .get(&format!("/api/v1/workspaces/{workspace_id}"))
54            .await
55    }
56
57    /// `PUT /api/v1/workspaces/{id}` — Update workspace.
58    pub async fn update(
59        &self,
60        workspace_id: &str,
61        body: &serde_json::Value,
62    ) -> Result<WorkspaceInfo> {
63        self.client
64            .put(
65                &format!("/api/v1/workspaces/{workspace_id}"),
66                Some(body),
67            )
68            .await
69    }
70
71    /// `DELETE /api/v1/workspaces/{id}` — Delete workspace.
72    pub async fn delete(&self, workspace_id: &str) -> Result<()> {
73        self.client
74            .delete_no_content(&format!("/api/v1/workspaces/{workspace_id}"))
75            .await
76    }
77
78    /// `GET /api/v1/workspaces/{id}/metrics-history`
79    pub async fn metrics_history(&self, workspace_id: &str) -> Result<Vec<serde_json::Value>> {
80        self.client
81            .get(&format!("/api/v1/workspaces/{workspace_id}/metrics-history"))
82            .await
83    }
84
85    /// `POST /api/v1/workspaces/{id}/rebuild-embeddings`
86    pub async fn rebuild_embeddings(&self, workspace_id: &str) -> Result<serde_json::Value> {
87        self.client
88            .post::<(), serde_json::Value>(
89                &format!("/api/v1/workspaces/{workspace_id}/rebuild-embeddings"),
90                None,
91            )
92            .await
93    }
94
95    /// `POST /api/v1/workspaces/{id}/rebuild-knowledge-graph`
96    pub async fn rebuild_knowledge_graph(&self, workspace_id: &str) -> Result<serde_json::Value> {
97        self.client
98            .post::<(), serde_json::Value>(
99                &format!("/api/v1/workspaces/{workspace_id}/rebuild-knowledge-graph"),
100                None,
101            )
102            .await
103    }
104
105    /// `POST /api/v1/workspaces/{id}/reprocess-documents`
106    pub async fn reprocess_documents(&self, workspace_id: &str) -> Result<serde_json::Value> {
107        self.client
108            .post::<(), serde_json::Value>(
109                &format!("/api/v1/workspaces/{workspace_id}/reprocess-documents"),
110                None,
111            )
112            .await
113    }
114}