mirror of
https://github.com/infinilabs/coco-app.git
synced 2025-12-16 11:37:47 +01:00
refactor: optimized getting data sources and mcp lists (#460)
This commit is contained in:
@@ -184,7 +184,7 @@ function SearchChat({
|
|||||||
): Promise<DataSource[]> => {
|
): Promise<DataSource[]> => {
|
||||||
let response: any;
|
let response: any;
|
||||||
if (isTauri) {
|
if (isTauri) {
|
||||||
response = platformAdapter.invokeBackend("datasource_search", {
|
response = await platformAdapter.invokeBackend("datasource_search", {
|
||||||
id: serverId,
|
id: serverId,
|
||||||
options,
|
options,
|
||||||
});
|
});
|
||||||
@@ -222,7 +222,7 @@ function SearchChat({
|
|||||||
): Promise<DataSource[]> => {
|
): Promise<DataSource[]> => {
|
||||||
let response: any;
|
let response: any;
|
||||||
if (isTauri) {
|
if (isTauri) {
|
||||||
response = platformAdapter.invokeBackend("mcp_server_search", {
|
response = await platformAdapter.invokeBackend("mcp_server_search", {
|
||||||
id: serverId,
|
id: serverId,
|
||||||
options,
|
options,
|
||||||
});
|
});
|
||||||
@@ -240,7 +240,7 @@ function SearchChat({
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
let ids = currentAssistant?._source?.datasource?.ids;
|
let ids = currentAssistant?._source?.mcp_servers?.ids;
|
||||||
if (Array.isArray(ids) && ids.length > 0 && !ids.includes("*")) {
|
if (Array.isArray(ids) && ids.length > 0 && !ids.includes("*")) {
|
||||||
response = response?.filter((item: any) => ids.includes(item.id));
|
response = response?.filter((item: any) => ids.includes(item.id));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import {
|
|||||||
session_chat_history,
|
session_chat_history,
|
||||||
close_session_chat,
|
close_session_chat,
|
||||||
open_session_chat,
|
open_session_chat,
|
||||||
datasource_search,
|
|
||||||
delete_session_chat,
|
delete_session_chat,
|
||||||
update_session_chat,
|
update_session_chat,
|
||||||
} from "@/commands";
|
} from "@/commands";
|
||||||
@@ -168,13 +167,6 @@ export default function Chat({}: ChatProps) {
|
|||||||
return convertFileSrc(path);
|
return convertFileSrc(path);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const getDataSourcesByServer = useCallback(
|
|
||||||
async (serverId: string): Promise<DataSource[]> => {
|
|
||||||
return datasource_search(serverId);
|
|
||||||
},
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
||||||
const setupWindowFocusListener = useCallback(async (callback: () => void) => {
|
const setupWindowFocusListener = useCallback(async (callback: () => void) => {
|
||||||
return listen("tauri://focus", callback);
|
return listen("tauri://focus", callback);
|
||||||
}, []);
|
}, []);
|
||||||
@@ -264,6 +256,29 @@ export default function Chat({}: ChatProps) {
|
|||||||
await delete_session_chat(currentService.id, id);
|
await delete_session_chat(currentService.id, id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getDataSourcesByServer = useCallback(
|
||||||
|
async (
|
||||||
|
serverId: string,
|
||||||
|
options?: {
|
||||||
|
from?: number;
|
||||||
|
size?: number;
|
||||||
|
query?: string;
|
||||||
|
}
|
||||||
|
): Promise<DataSource[]> => {
|
||||||
|
let response: any;
|
||||||
|
response = await platformAdapter.invokeBackend("datasource_search", {
|
||||||
|
id: serverId,
|
||||||
|
options,
|
||||||
|
});
|
||||||
|
let ids = currentAssistant?._source?.datasource?.ids;
|
||||||
|
if (Array.isArray(ids) && ids.length > 0 && !ids.includes("*")) {
|
||||||
|
response = response?.filter((item: any) => ids.includes(item.id));
|
||||||
|
}
|
||||||
|
return response || [];
|
||||||
|
},
|
||||||
|
[JSON.stringify(currentAssistant)]
|
||||||
|
);
|
||||||
|
|
||||||
const getMCPByServer = useCallback(
|
const getMCPByServer = useCallback(
|
||||||
async (
|
async (
|
||||||
serverId: string,
|
serverId: string,
|
||||||
@@ -274,11 +289,11 @@ export default function Chat({}: ChatProps) {
|
|||||||
}
|
}
|
||||||
): Promise<DataSource[]> => {
|
): Promise<DataSource[]> => {
|
||||||
let response: any;
|
let response: any;
|
||||||
response = platformAdapter.invokeBackend("mcp_server_search", {
|
response = await platformAdapter.invokeBackend("mcp_server_search", {
|
||||||
id: serverId,
|
id: serverId,
|
||||||
options,
|
options,
|
||||||
});
|
});
|
||||||
let ids = currentAssistant?._source?.datasource?.ids;
|
let ids = currentAssistant?._source?.mcp_servers?.ids;
|
||||||
if (Array.isArray(ids) && ids.length > 0 && !ids.includes("*")) {
|
if (Array.isArray(ids) && ids.length > 0 && !ids.includes("*")) {
|
||||||
response = response?.filter((item: any) => ids.includes(item.id));
|
response = response?.filter((item: any) => ids.includes(item.id));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user