Skip to main content

prismer_sdk/
context.rs

1use crate::{PrismerClient, types::*};
2use serde_json::json;
3
4pub struct ContextClient<'a> {
5    pub(crate) client: &'a PrismerClient,
6}
7
8impl<'a> ContextClient<'a> {
9    /// Load context from URL, batch URLs, or search query.
10    pub async fn load(&self, input: &str) -> Result<ApiResponse<ContextLoadResult>, PrismerError> {
11        self.client.request(
12            reqwest::Method::POST,
13            "/api/context/load",
14            Some(json!({ "input": input })),
15        ).await
16    }
17
18    /// Save content to context cache.
19    pub async fn save(&self, content: &str, url: Option<&str>) -> Result<ApiResponse<serde_json::Value>, PrismerError> {
20        let mut body = json!({ "content": content });
21        if let Some(u) = url {
22            body["url"] = json!(u);
23        }
24        self.client.request(reqwest::Method::POST, "/api/context/save", Some(body)).await
25    }
26}