refactor: adjusted assistant, datasource, mcp_server interface parameters (#746)

* chore: handle mcp interface parameters

* docs: update notes

* chore: remove code

* chore: assistant params

* fix: assistant params

* docs: update notes
This commit is contained in:
BiggerRain
2025-07-10 09:48:42 +08:00
committed by GitHub
parent c1c4e0db7b
commit 5b27488402
10 changed files with 153 additions and 111 deletions

View File

@@ -8,6 +8,8 @@
"clsx", "clsx",
"codegen", "codegen",
"dataurl", "dataurl",
"deeplink",
"deepthink",
"dtolnay", "dtolnay",
"dyld", "dyld",
"elif", "elif",
@@ -30,6 +32,7 @@
"localstorage", "localstorage",
"lucide", "lucide",
"maximizable", "maximizable",
"meval",
"Minimizable", "Minimizable",
"msvc", "msvc",
"nord", "nord",
@@ -42,6 +45,7 @@
"Raycast", "Raycast",
"rehype", "rehype",
"reqwest", "reqwest",
"rerank",
"rgba", "rgba",
"rustup", "rustup",
"screenshotable", "screenshotable",

View File

@@ -29,6 +29,7 @@ Information about release notes of Coco Server is provided here.
- refactor: create chat & send chat api #739 - refactor: create chat & send chat api #739
- chore: icon support for more file types #740 - chore: icon support for more file types #740
- chore: replace meval-rs with our fork to clear dep warning #745 - chore: replace meval-rs with our fork to clear dep warning #745
- refactor: adjusted assistant, datasource, mcp_server interface parameters #746
- refactor: adjust extension code hierarchy #747 - refactor: adjust extension code hierarchy #747
- chore: bump dep applications-rs #751 - chore: bump dep applications-rs #751

View File

@@ -43,7 +43,7 @@ export const AssistantFetcher = ({
query, query,
} = params; } = params;
const searchQuery: SearchQuery = { const queryParams = parseSearchQuery({
from: (current - 1) * pageSize, from: (current - 1) * pageSize,
size: pageSize, size: pageSize,
query: query ?? debounceKeyword, query: query ?? debounceKeyword,
@@ -52,33 +52,12 @@ export const AssistantFetcher = ({
enabled: true, enabled: true,
id: assistantIDs, id: assistantIDs,
}, },
}; });
const queryParams = parseSearchQuery(searchQuery); const response = await platformAdapter.fetchAssistant(
const body: Record<string, any> = {
serverId, serverId,
queryParams, queryParams
}; );
let response: any;
if (isTauri) {
if (!currentService?.id) {
throw new Error("currentService is undefined");
}
response = await platformAdapter.commands("assistant_search", body);
} else {
body.serverId = undefined;
const [error, res] = await Post(`/assistant/_search`, body);
if (error) {
throw new Error(error);
}
response = res;
}
let assistantList = response?.hits?.hits ?? []; let assistantList = response?.hits?.hits ?? [];

View File

@@ -111,10 +111,6 @@ const ChatAI = memo(
useEffect(() => { useEffect(() => {
activeChatProp && setActiveChat(activeChatProp); activeChatProp && setActiveChat(activeChatProp);
}, [activeChatProp]); }, [activeChatProp]);
useEffect(() => {
console.log("activeChat12121212121", activeChat);
}, [activeChat]);
useEffect(() => { useEffect(() => {
if (!isTauri) return; if (!isTauri) return;

View File

@@ -9,14 +9,13 @@ import ChatSwitch from "@/components/Common/ChatSwitch";
import Copyright from "@/components/Common/Copyright"; import Copyright from "@/components/Common/Copyright";
import type { DataSource } from "@/types/commands"; import type { DataSource } from "@/types/commands";
import platformAdapter from "@/utils/platformAdapter"; import platformAdapter from "@/utils/platformAdapter";
import { Post } from "@/api/axiosRequest";
import { useConnectStore } from "@/stores/connectStore"; import { useConnectStore } from "@/stores/connectStore";
import VisibleKey from "@/components/Common/VisibleKey"; import VisibleKey from "@/components/Common/VisibleKey";
import { useShortcutsStore } from "@/stores/shortcutsStore"; import { useShortcutsStore } from "@/stores/shortcutsStore";
import { useAppStore } from "@/stores/appStore"; import { useAppStore } from "@/stores/appStore";
import { useSearchStore } from "@/stores/searchStore"; import { useSearchStore } from "@/stores/searchStore";
import { useExtensionsStore } from "@/stores/extensionsStore"; import { useExtensionsStore } from "@/stores/extensionsStore";
import { parseSearchQuery, SearchQuery, unrequitable } from "@/utils"; import { parseSearchQuery, SearchQuery } from "@/utils";
// import InputExtra from "./InputExtra"; // import InputExtra from "./InputExtra";
// import AiSummaryIcon from "@/components/Common/Icons/AiSummaryIcon"; // import AiSummaryIcon from "@/components/Common/Icons/AiSummaryIcon";
@@ -76,45 +75,21 @@ const InputControls = ({
searchQuery.from ??= 0; searchQuery.from ??= 0;
searchQuery.size ??= 1000; searchQuery.size ??= 1000;
const body: Record<string, any> = { const queryParams = parseSearchQuery({
id: serverId, ...searchQuery,
queryParams: parseSearchQuery({ fuzziness: 5,
...searchQuery, filters: {
fuzziness: 5, enabled: true,
filters: { },
enabled: true, });
}, const response = await platformAdapter.searchDataSources(
}), serverId,
}; queryParams
);
let response: any;
if (isTauri) {
if (unrequitable()) {
return [];
}
response = await platformAdapter.invokeBackend(
"datasource_search",
body
);
} else {
body.id = undefined;
const [error, res]: any = await Post("/datasource/_search", body);
if (error) {
console.error("_search", error);
return [];
}
response = res?.hits?.hits?.map((item: any) => {
return {
...item,
id: item._source.id,
name: item._source.name,
};
});
}
let ids = assistantConfig.datasourceIds; let ids = assistantConfig.datasourceIds;
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)); return response?.filter((item: any) => ids.includes(item.id)) || [];
} }
return response || []; return response || [];
}, },
@@ -129,45 +104,22 @@ const InputControls = ({
searchQuery.from ??= 0; searchQuery.from ??= 0;
searchQuery.size ??= 1000; searchQuery.size ??= 1000;
const body: Record<string, any> = { const queryParams = parseSearchQuery({
id: serverId, ...searchQuery,
queryParams: parseSearchQuery({ fuzziness: 5,
...searchQuery, filters: {
fuzziness: 5, enabled: true,
filters: { },
enabled: true, });
},
}),
};
let response: any; const response = await platformAdapter.searchMCPServers(
if (isTauri) { serverId,
if (unrequitable()) { queryParams
return []; );
}
response = await platformAdapter.invokeBackend(
"mcp_server_search",
body
);
} else {
body.id = undefined;
const [error, res]: any = await Post("/mcp_server/_search", body);
if (error) {
console.error("_search", error);
return [];
}
response = res?.hits?.hits?.map((item: any) => {
return {
...item,
id: item._source.id,
name: item._source.name,
};
});
}
let ids = assistantConfig.mcpIds; let ids = assistantConfig.mcpIds;
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)); return response?.filter((item: any) => ids.includes(item.id)) || [];
} }
return response || []; return response || [];
}, },

View File

@@ -35,13 +35,9 @@ function WebApp({
width = 680, width = 680,
height = 590, height = 590,
headers = { headers = {
"X-API-TOKEN": "X-API-TOKEN": "",
"d1lmnn77271h79qdse0gbss0ev8usfin593h5qpa0zgismc8u1fxhg99ju0syeuy54j16ect58ybqzytp7v3", "APP-INTEGRATION-ID": "",
"APP-INTEGRATION-ID": "cvkm9hmhpcemufsg3vug",
}, },
// token = "cva1j5ehpcenic3ir7k0h8fb8qtv35iwtywze248oscrej8yoivhb5b1hyovp24xejjk27jy9ddt69ewfi3n", // https://coco.infini.cloud
// token = "cvqt6r02sdb2v3bkgip0x3ixv01f3r2lhnxoz1efbn160wm9og58wtv8t6wrv1ebvnvypuc23dx9pb33aemh", // http://localhost:9000
// token = "cv5djeb9om602jdvtnmg6kc1muyn2vcadr6te48j9t9pvt59ewrnwj7fwvxrw3va84j2a0lb5y8194fbr3jd", // http://43.153.113.88:9000
serverUrl = "", serverUrl = "",
hasModules = ["search", "chat"], hasModules = ["search", "chat"],
defaultModule = "search", defaultModule = "search",

View File

@@ -118,6 +118,9 @@ export interface SystemOperations {
isWindows10: () => Promise<boolean>; isWindows10: () => Promise<boolean>;
revealItemInDir: (path: string) => Promise<unknown>; revealItemInDir: (path: string) => Promise<unknown>;
openSearchItem: (data: SearchDocument) => Promise<unknown>; openSearchItem: (data: SearchDocument) => Promise<unknown>;
searchMCPServers: (serverId: string, queryParams: string[]) => Promise<any[]>;
searchDataSources: (serverId: string, queryParams: string[]) => Promise<any[]>;
fetchAssistant: (serverId: string, queryParams: string[]) => Promise<any>;
} }
// Base platform adapter interface // Base platform adapter interface

View File

@@ -15,6 +15,7 @@ import type { AppTheme } from "@/types/index";
import { useAppearanceStore } from "@/stores/appearanceStore"; import { useAppearanceStore } from "@/stores/appearanceStore";
import { copyToClipboard, OpenURLWithBrowser } from "."; import { copyToClipboard, OpenURLWithBrowser } from ".";
import { useAppStore } from "@/stores/appStore"; import { useAppStore } from "@/stores/appStore";
import { unrequitable } from "@/utils";
export interface TauriPlatformAdapter extends BasePlatformAdapter { export interface TauriPlatformAdapter extends BasePlatformAdapter {
openFileDialog: ( openFileDialog: (
@@ -300,5 +301,34 @@ export const createTauriAdapter = (): TauriPlatformAdapter => {
}, },
error, error,
async searchMCPServers(serverId, queryParams) {
if (unrequitable()) {
return [];
}
return await commandWrapper.commands("mcp_server_search", {
id: serverId,
queryParams,
});
},
async searchDataSources(serverId, queryParams) {
return await commandWrapper.commands("datasource_search", {
id: serverId,
queryParams,
});
},
async fetchAssistant(serverId, queryParams) {
if (!serverId) {
throw new Error("currentService is undefined");
}
return await commandWrapper.commands("assistant_search", {
serverId,
...queryParams,
});
},
}; };
}; };

View File

@@ -1,5 +1,6 @@
import type { BasePlatformAdapter } from "@/types/platform"; import type { BasePlatformAdapter } from "@/types/platform";
import { copyToClipboard, OpenURLWithBrowser } from "."; import { copyToClipboard, OpenURLWithBrowser } from ".";
import { Post } from "@/api/axiosRequest";
export interface WebPlatformAdapter extends BasePlatformAdapter { export interface WebPlatformAdapter extends BasePlatformAdapter {
// Add web-specific methods here // Add web-specific methods here
@@ -65,9 +66,9 @@ export const createWebAdapter = (): WebPlatformAdapter => {
async checkMicrophonePermission() { async checkMicrophonePermission() {
return false; return false;
}, },
async requestMicrophonePermission() { async requestMicrophonePermission() {
return false; return false;
}, },
requestScreenRecordingPermission() { requestScreenRecordingPermission() {
@@ -214,5 +215,80 @@ export const createWebAdapter = (): WebPlatformAdapter => {
}, },
error: console.error, error: console.error,
async searchMCPServers(_serverId, queryParams) {
const urlParams = new URLSearchParams();
queryParams.forEach((param) => {
const [key, value] = param.split("=");
urlParams.append(key, decodeURIComponent(value));
});
const [error, res]: any = await Post(
"/mcp_server/_search",
{},
Object.fromEntries(urlParams)
);
if (error) {
console.error("_search", error);
return [];
}
return (
res?.hits?.hits?.map((item: any) => ({
...item,
id: item._source.id,
name: item._source.name,
})) || []
);
},
async searchDataSources(_serverId, queryParams) {
const urlParams = new URLSearchParams();
queryParams.forEach((param) => {
const [key, value] = param.split("=");
urlParams.append(key, decodeURIComponent(value));
});
const [error, res]: any = await Post(
"/datasource/_search",
{},
Object.fromEntries(urlParams)
);
if (error) {
console.error("_search", error);
return [];
}
return (
res?.hits?.hits?.map((item: any) => ({
...item,
id: item._source.id,
name: item._source.name,
})) || []
);
},
async fetchAssistant(_serverId, queryParams) {
const urlParams = new URLSearchParams();
queryParams.forEach((param) => {
const [key, value] = param.split("=");
urlParams.append(key, decodeURIComponent(value));
});
const [error, res]: any = await Post(
"/assistant/_search",
{},
Object.fromEntries(urlParams)
);
if (error) {
console.error("_search", error);
return {};
}
return res;
},
}; };
}; };

View File

@@ -76,6 +76,11 @@ export default defineConfig(async () => ({
changeOrigin: true, changeOrigin: true,
secure: false, secure: false,
}, },
"/mcp_server": {
target: process.env.COCO_SERVER_URL,
changeOrigin: true,
secure: false,
},
}, },
}, },
build: { build: {