1use crate::{PrismerClient, types::*};
2use serde_json::json;
3
4pub struct MemoryClient<'a> {
5 pub(crate) client: &'a PrismerClient,
6}
7
8impl<'a> MemoryClient<'a> {
9 pub async fn create_file(&self, path: &str, content: &str, scope: Option<&str>) -> Result<ApiResponse<serde_json::Value>, PrismerError> {
11 let mut body = json!({ "path": path, "content": content });
12 if let Some(s) = scope { body["scope"] = json!(s); }
13 self.client.request(reqwest::Method::POST, "/api/im/memory/files", Some(body)).await
14 }
15
16 pub async fn list_files(&self, scope: Option<&str>, path: Option<&str>) -> Result<ApiResponse<Vec<serde_json::Value>>, PrismerError> {
18 let mut params = vec![];
19 if let Some(s) = scope { params.push(format!("scope={}", s)); }
20 if let Some(p) = path { params.push(format!("path={}", p)); }
21 let qs = if params.is_empty() { String::new() } else { format!("?{}", params.join("&")) };
22 self.client.request(reqwest::Method::GET, &format!("/api/im/memory/files{}", qs), None).await
23 }
24
25 pub async fn get_file(&self, file_id: &str) -> Result<ApiResponse<serde_json::Value>, PrismerError> {
27 self.client.request(reqwest::Method::GET, &format!("/api/im/memory/files/{}", file_id), None).await
28 }
29
30 pub async fn update_file(&self, file_id: &str, operation: &str, content: &str, section: Option<&str>, version: Option<i32>) -> Result<ApiResponse<serde_json::Value>, PrismerError> {
32 let mut body = json!({ "operation": operation, "content": content });
33 if let Some(s) = section { body["section"] = json!(s); }
34 if let Some(v) = version { body["version"] = json!(v); }
35 self.client.request(reqwest::Method::PATCH, &format!("/api/im/memory/files/{}", file_id), Some(body)).await
36 }
37
38 pub async fn delete_file(&self, file_id: &str) -> Result<ApiResponse<serde_json::Value>, PrismerError> {
40 self.client.request(reqwest::Method::DELETE, &format!("/api/im/memory/files/{}", file_id), None).await
41 }
42
43 pub async fn compact(&self, conversation_id: &str, summary: &str) -> Result<ApiResponse<serde_json::Value>, PrismerError> {
45 self.client.request(
46 reqwest::Method::POST,
47 "/api/im/memory/compact",
48 Some(json!({ "conversationId": conversation_id, "summary": summary })),
49 ).await
50 }
51
52 pub async fn load(&self, scope: Option<&str>) -> Result<ApiResponse<serde_json::Value>, PrismerError> {
54 let mut params = vec![];
55 if let Some(s) = scope { params.push(format!("scope={}", s)); }
56 let qs = if params.is_empty() { String::new() } else { format!("?{}", params.join("&")) };
57 self.client.request(reqwest::Method::GET, &format!("/api/im/memory/load{}", qs), None).await
58 }
59
60 pub async fn get_knowledge_links(&self) -> Result<ApiResponse<serde_json::Value>, PrismerError> {
62 self.client.request(reqwest::Method::GET, "/api/im/memory/links", None).await
63 }
64}