Skip to content

Commit c095ad4

Browse files
authored
feat: ai assistant supports search and paging (#431)
1 parent af63bab commit c095ad4

File tree

6 files changed

+342
-162
lines changed

6 files changed

+342
-162
lines changed

src-tauri/src/assistant/mod.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,30 @@ pub async fn update_session_chat(
232232
pub async fn assistant_search<R: Runtime>(
233233
_app_handle: AppHandle<R>,
234234
server_id: String,
235-
) -> Result<String, String> {
236-
let response = HttpClient::get(&server_id, "/assistant/_search", None)
237-
.await
238-
.map_err(|e| format!("Error searching assistants: {}", e))?;
235+
from: u32,
236+
size: u32,
237+
query: Option<HashMap<String, Value>>,
238+
) -> Result<Value, String> {
239+
let mut body = serde_json::json!({
240+
"from": from,
241+
"size": size,
242+
});
243+
244+
if let Some(q) = query {
245+
body["query"] = serde_json::to_value(q).map_err(|e| e.to_string())?;
246+
}
239247

240-
common::http::get_response_body_text(response).await
248+
let response = HttpClient::post(
249+
&server_id,
250+
"/assistant/_search",
251+
None,
252+
Some(reqwest::Body::from(body.to_string())),
253+
)
254+
.await
255+
.map_err(|e| format!("Error searching assistants: {}", e))?;
256+
257+
response
258+
.json::<Value>()
259+
.await
260+
.map_err(|err| err.to_string())
241261
}

src/api/axiosRequest.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ export const Get = <T>(
7272
const appStore = JSON.parse(localStorage.getItem("app-store") || "{}");
7373
// console.log("baseURL", appStore.state?.endpoint_http)
7474

75-
let baseURL = appStore.state?.endpoint_http;
75+
let baseURL = "";
76+
77+
if (import.meta.env.PROD) {
78+
baseURL = appStore.state?.endpoint_https;
79+
}
7680

7781
axios
7882
.get(baseURL + url, { params })
@@ -101,7 +105,11 @@ export const Post = <T>(
101105
const appStore = JSON.parse(localStorage.getItem("app-store") || "{}");
102106
// console.log("baseURL", appStore.state?.endpoint_http)
103107

104-
let baseURL = appStore.state?.endpoint_http;
108+
let baseURL = "";
109+
110+
if (import.meta.env.PROD) {
111+
baseURL = appStore.state?.endpoint_https;
112+
}
105113

106114
axios
107115
.post(baseURL + url, data, {

0 commit comments

Comments
 (0)