Skip to content

Commit 91c9cd5

Browse files
authored
fix: show only enabled datasource & MCP list (#523)
* fix: show only enabled datasource & MCP list * docs: update notes * fix: show only enabled datasource & MCP list
1 parent 7f3e602 commit 91c9cd5

8 files changed

Lines changed: 132 additions & 115 deletions

File tree

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"elif",
1414
"errmsg",
1515
"fullscreen",
16+
"fulltext",
1617
"headlessui",
1718
"Icdbb",
1819
"icns",

docs/content.en/docs/release-notes/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Information about release notes of Coco Server is provided here.
3232
- fix: fixed the newly created session has no title when it is deleted #511
3333
- fix: loading chat history for potential empty attachments
3434
- fix: datasource & MCP list synchronization update #521
35+
- fix: show only enabled datasource & MCP list
3536

3637
### ✈️ Improvements
3738

src-tauri/src/common/http.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub async fn get_response_body_text(response: Response) -> Result<String, String
2626
.await
2727
.map_err(|e| format!("Failed to read response body: {}, code: {}", e, status))?;
2828

29-
log::debug!("Response status: {}, body: {}", status, &body);
29+
//log::debug!("Response status: {}, body: {}", status, &body);
3030

3131
if status < 200 || status >= 400 {
3232
// Try to parse the error body
@@ -49,4 +49,4 @@ pub async fn get_response_body_text(response: Response) -> Result<String, String
4949
} else {
5050
Ok(body)
5151
}
52-
}
52+
}

src-tauri/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ pub fn run() {
210210
})
211211
.on_window_event(|window, event| match event {
212212
WindowEvent::CloseRequested { api, .. } => {
213-
dbg!("Close requested event received");
213+
//dbg!("Close requested event received");
214214
window.hide().unwrap();
215215
api.prevent_close();
216216
}
@@ -225,10 +225,10 @@ pub fn run() {
225225
has_visible_windows,
226226
..
227227
} => {
228-
dbg!(
229-
"Reopen event received: has_visible_windows = {}",
230-
has_visible_windows
231-
);
228+
// dbg!(
229+
// "Reopen event received: has_visible_windows = {}",
230+
// has_visible_windows
231+
// );
232232
if has_visible_windows {
233233
return;
234234
}
@@ -289,7 +289,7 @@ async fn hide_coco<R: Runtime>(app: AppHandle<R>) {
289289
}
290290

291291
fn move_window_to_active_monitor<R: Runtime>(window: &Window<R>) {
292-
dbg!("Moving window to active monitor");
292+
//dbg!("Moving window to active monitor");
293293
// Try to get the available monitors, handle failure gracefully
294294
let available_monitors = match window.available_monitors() {
295295
Ok(monitors) => monitors,

src-tauri/src/server/datasource.rs

Lines changed: 18 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::server::connector::get_connector_by_id;
44
use crate::server::http_client::HttpClient;
55
use crate::server::servers::get_all_servers;
66
use lazy_static::lazy_static;
7+
use serde_json::Value;
78
use std::collections::HashMap;
89
use std::sync::{Arc, RwLock};
910
use tauri::{AppHandle, Runtime};
@@ -12,7 +13,7 @@ use tauri::{AppHandle, Runtime};
1213
pub struct GetDatasourcesByServerOptions {
1314
pub from: Option<u32>,
1415
pub size: Option<u32>,
15-
pub query: Option<String>,
16+
pub query: Option<serde_json::Value>,
1617
}
1718

1819
lazy_static! {
@@ -32,7 +33,7 @@ pub fn save_datasource_to_cache(server_id: &str, datasources: Vec<DataSource>) {
3233
#[allow(dead_code)]
3334
pub fn get_datasources_from_cache(server_id: &str) -> Option<HashMap<String, DataSource>> {
3435
let cache = DATASOURCE_CACHE.read().unwrap(); // Acquire read lock
35-
// dbg!("cache: {:?}", &cache);
36+
// dbg!("cache: {:?}", &cache);
3637
let server_cache = cache.get(server_id)?; // Get the server's cache
3738
Some(server_cache.clone())
3839
}
@@ -100,31 +101,14 @@ pub async fn datasource_search(
100101
) -> Result<Vec<DataSource>, String> {
101102
let from = options.as_ref().and_then(|opt| opt.from).unwrap_or(0);
102103
let size = options.as_ref().and_then(|opt| opt.size).unwrap_or(10000);
103-
let query = options
104-
.and_then(|opt| opt.query)
105-
.unwrap_or(String::default());
106104

107105
let mut body = serde_json::json!({
108106
"from": from,
109107
"size": size,
110108
});
111109

112-
if !query.is_empty() {
113-
body["query"] = serde_json::json!({
114-
"bool": {
115-
"must": [{
116-
"query_string": {
117-
"fields": ["combined_fulltext"],
118-
"query": query,
119-
"fuzziness": "AUTO",
120-
"fuzzy_prefix_length": 2,
121-
"fuzzy_max_expansions": 10,
122-
"fuzzy_transpositions": true,
123-
"allow_leading_wildcard": false
124-
}
125-
}]
126-
}
127-
});
110+
if let Some(q) = options.unwrap().query {
111+
body["query"] = q;
128112
}
129113

130114
// Perform the async HTTP request outside the cache lock
@@ -134,12 +118,12 @@ pub async fn datasource_search(
134118
None,
135119
Some(reqwest::Body::from(body.to_string())),
136120
)
137-
.await
138-
.map_err(|e| format!("Error fetching datasource: {}", e))?;
121+
.await
122+
.map_err(|e| format!("Error fetching datasource: {}", e))?;
139123

140124
// Parse the search results from the response
141125
let datasources: Vec<DataSource> = parse_search_results(resp).await.map_err(|e| {
142-
dbg!("Error parsing search results: {}", &e);
126+
//dbg!("Error parsing search results: {}", &e);
143127
e.to_string()
144128
})?;
145129

@@ -152,35 +136,17 @@ pub async fn datasource_search(
152136
#[tauri::command]
153137
pub async fn mcp_server_search(
154138
id: &str,
155-
options: Option<GetDatasourcesByServerOptions>,
139+
from: u32,
140+
size: u32,
141+
query: Option<HashMap<String, Value>>,
156142
) -> Result<Vec<DataSource>, String> {
157-
let from = options.as_ref().and_then(|opt| opt.from).unwrap_or(0);
158-
let size = options.as_ref().and_then(|opt| opt.size).unwrap_or(10000);
159-
let query = options
160-
.and_then(|opt| opt.query)
161-
.unwrap_or(String::default());
162-
163143
let mut body = serde_json::json!({
164-
"from": from,
165-
"size": size,
144+
"from": from,
145+
"size": size,
166146
});
167147

168-
if !query.is_empty() {
169-
body["query"] = serde_json::json!({
170-
"bool": {
171-
"must": [{
172-
"query_string": {
173-
"fields": ["combined_fulltext"],
174-
"query": query,
175-
"fuzziness": "AUTO",
176-
"fuzzy_prefix_length": 2,
177-
"fuzzy_max_expansions": 10,
178-
"fuzzy_transpositions": true,
179-
"allow_leading_wildcard": false
180-
}
181-
}]
182-
}
183-
});
148+
if let Some(q) = query {
149+
body["query"] = serde_json::to_value(q).map_err(|e| e.to_string())?;
184150
}
185151

186152
// Perform the async HTTP request outside the cache lock
@@ -190,12 +156,12 @@ pub async fn mcp_server_search(
190156
None,
191157
Some(reqwest::Body::from(body.to_string())),
192158
)
193-
.await
194-
.map_err(|e| format!("Error fetching datasource: {}", e))?;
159+
.await
160+
.map_err(|e| format!("Error fetching datasource: {}", e))?;
195161

196162
// Parse the search results from the response
197163
let mcp_server: Vec<DataSource> = parse_search_results(resp).await.map_err(|e| {
198-
dbg!("Error parsing search results: {}", &e);
164+
//dbg!("Error parsing search results: {}", &e);
199165
e.to_string()
200166
})?;
201167

src-tauri/src/server/http_client.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,28 @@ impl HttpClient {
4444
headers: Option<HashMap<String, String>>,
4545
body: Option<reqwest::Body>,
4646
) -> Result<reqwest::Response, String> {
47-
log::debug!(
48-
"Sending Request: {}, query_params: {:?}, header: {:?}, body: {:?}",
49-
&url,
50-
&query_params,
51-
&headers,
52-
&body
53-
);
47+
// log::debug!(
48+
// "Sending Request: {}, query_params: {:?}, header: {:?}, body: {:?}",
49+
// &url,
50+
// &query_params,
51+
// &headers,
52+
// &body
53+
// );
5454

5555
let request_builder =
5656
Self::get_request_builder(method, url, headers, query_params, body).await;
5757

5858
let response = request_builder.send().await.map_err(|e| {
59-
dbg!("Failed to send request: {}", &e);
59+
//dbg!("Failed to send request: {}", &e);
6060
format!("Failed to send request: {}", e)
6161
})?;
6262

63-
log::debug!(
64-
"Request: {}, Response status: {:?}, header: {:?}",
65-
&url,
66-
&response.status(),
67-
&response.headers()
68-
);
63+
// log::debug!(
64+
// "Request: {}, Response status: {:?}, header: {:?}",
65+
// &url,
66+
// &response.status(),
67+
// &response.headers()
68+
// );
6969

7070
Ok(response)
7171
}
@@ -165,12 +165,12 @@ impl HttpClient {
165165
headers.insert("X-API-TOKEN".to_string(), t);
166166
}
167167

168-
log::debug!(
169-
"Sending request to server: {}, url: {}, headers: {:?}",
170-
&server_id,
171-
&url,
172-
&headers
173-
);
168+
// log::debug!(
169+
// "Sending request to server: {}, url: {}, headers: {:?}",
170+
// &server_id,
171+
// &url,
172+
// &headers
173+
// );
174174

175175
Self::send_raw_request(method, &url, query_params, Some(headers), body).await
176176
} else {

src/components/Assistant/AssistantList.tsx

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -82,34 +82,31 @@ export function AssistantList({ assistantIDs = [] }: AssistantListProps) {
8282
size,
8383
};
8484

85-
if (debounceKeyword || assistantIDs.length > 0) {
86-
body.query = {
87-
bool: {
88-
must: [
89-
{term: {"enabled": true}}
90-
],
85+
body.query = {
86+
bool: {
87+
must: [{ term: { enabled: true } }],
88+
},
89+
};
90+
91+
if (debounceKeyword) {
92+
body.query.bool.must.push({
93+
query_string: {
94+
fields: ["combined_fulltext"],
95+
query: debounceKeyword,
96+
fuzziness: "AUTO",
97+
fuzzy_prefix_length: 2,
98+
fuzzy_max_expansions: 10,
99+
fuzzy_transpositions: true,
100+
allow_leading_wildcard: false,
91101
},
92-
};
93-
if (debounceKeyword) {
94-
body.query.bool.must.push({
95-
query_string: {
96-
fields: ["combined_fulltext"],
97-
query: debounceKeyword,
98-
fuzziness: "AUTO",
99-
fuzzy_prefix_length: 2,
100-
fuzzy_max_expansions: 10,
101-
fuzzy_transpositions: true,
102-
allow_leading_wildcard: false,
103-
},
104-
});
105-
}
106-
if (assistantIDs.length > 0) {
107-
body.query.bool.must.push({
108-
terms: {
109-
id: assistantIDs.map((id) => id),
110-
},
111-
});
112-
}
102+
});
103+
}
104+
if (assistantIDs.length > 0) {
105+
body.query.bool.must.push({
106+
terms: {
107+
id: assistantIDs.map((id) => id),
108+
},
109+
});
113110
}
114111

115112
if (isTauri) {

0 commit comments

Comments
 (0)