mirror of
https://github.com/infinilabs/coco-app.git
synced 2025-12-16 11:37:47 +01:00
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:
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@@ -8,6 +8,8 @@
|
||||
"clsx",
|
||||
"codegen",
|
||||
"dataurl",
|
||||
"deeplink",
|
||||
"deepthink",
|
||||
"dtolnay",
|
||||
"dyld",
|
||||
"elif",
|
||||
@@ -30,6 +32,7 @@
|
||||
"localstorage",
|
||||
"lucide",
|
||||
"maximizable",
|
||||
"meval",
|
||||
"Minimizable",
|
||||
"msvc",
|
||||
"nord",
|
||||
@@ -42,6 +45,7 @@
|
||||
"Raycast",
|
||||
"rehype",
|
||||
"reqwest",
|
||||
"rerank",
|
||||
"rgba",
|
||||
"rustup",
|
||||
"screenshotable",
|
||||
|
||||
@@ -29,6 +29,7 @@ Information about release notes of Coco Server is provided here.
|
||||
- refactor: create chat & send chat api #739
|
||||
- chore: icon support for more file types #740
|
||||
- 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
|
||||
- chore: bump dep applications-rs #751
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ export const AssistantFetcher = ({
|
||||
query,
|
||||
} = params;
|
||||
|
||||
const searchQuery: SearchQuery = {
|
||||
const queryParams = parseSearchQuery({
|
||||
from: (current - 1) * pageSize,
|
||||
size: pageSize,
|
||||
query: query ?? debounceKeyword,
|
||||
@@ -52,33 +52,12 @@ export const AssistantFetcher = ({
|
||||
enabled: true,
|
||||
id: assistantIDs,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
const queryParams = parseSearchQuery(searchQuery);
|
||||
|
||||
const body: Record<string, any> = {
|
||||
const response = await platformAdapter.fetchAssistant(
|
||||
serverId,
|
||||
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;
|
||||
}
|
||||
queryParams
|
||||
);
|
||||
|
||||
let assistantList = response?.hits?.hits ?? [];
|
||||
|
||||
|
||||
@@ -111,10 +111,6 @@ const ChatAI = memo(
|
||||
useEffect(() => {
|
||||
activeChatProp && setActiveChat(activeChatProp);
|
||||
}, [activeChatProp]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log("activeChat12121212121", activeChat);
|
||||
}, [activeChat]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isTauri) return;
|
||||
|
||||
@@ -9,14 +9,13 @@ import ChatSwitch from "@/components/Common/ChatSwitch";
|
||||
import Copyright from "@/components/Common/Copyright";
|
||||
import type { DataSource } from "@/types/commands";
|
||||
import platformAdapter from "@/utils/platformAdapter";
|
||||
import { Post } from "@/api/axiosRequest";
|
||||
import { useConnectStore } from "@/stores/connectStore";
|
||||
import VisibleKey from "@/components/Common/VisibleKey";
|
||||
import { useShortcutsStore } from "@/stores/shortcutsStore";
|
||||
import { useAppStore } from "@/stores/appStore";
|
||||
import { useSearchStore } from "@/stores/searchStore";
|
||||
import { useExtensionsStore } from "@/stores/extensionsStore";
|
||||
import { parseSearchQuery, SearchQuery, unrequitable } from "@/utils";
|
||||
import { parseSearchQuery, SearchQuery } from "@/utils";
|
||||
// import InputExtra from "./InputExtra";
|
||||
// import AiSummaryIcon from "@/components/Common/Icons/AiSummaryIcon";
|
||||
|
||||
@@ -76,45 +75,21 @@ const InputControls = ({
|
||||
searchQuery.from ??= 0;
|
||||
searchQuery.size ??= 1000;
|
||||
|
||||
const body: Record<string, any> = {
|
||||
id: serverId,
|
||||
queryParams: parseSearchQuery({
|
||||
...searchQuery,
|
||||
fuzziness: 5,
|
||||
filters: {
|
||||
enabled: true,
|
||||
},
|
||||
}),
|
||||
};
|
||||
const queryParams = parseSearchQuery({
|
||||
...searchQuery,
|
||||
fuzziness: 5,
|
||||
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;
|
||||
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 || [];
|
||||
},
|
||||
@@ -129,45 +104,22 @@ const InputControls = ({
|
||||
searchQuery.from ??= 0;
|
||||
searchQuery.size ??= 1000;
|
||||
|
||||
const body: Record<string, any> = {
|
||||
id: serverId,
|
||||
queryParams: parseSearchQuery({
|
||||
...searchQuery,
|
||||
fuzziness: 5,
|
||||
filters: {
|
||||
enabled: true,
|
||||
},
|
||||
}),
|
||||
};
|
||||
const queryParams = parseSearchQuery({
|
||||
...searchQuery,
|
||||
fuzziness: 5,
|
||||
filters: {
|
||||
enabled: true,
|
||||
},
|
||||
});
|
||||
|
||||
let response: any;
|
||||
if (isTauri) {
|
||||
if (unrequitable()) {
|
||||
return [];
|
||||
}
|
||||
const response = await platformAdapter.searchMCPServers(
|
||||
serverId,
|
||||
queryParams
|
||||
);
|
||||
|
||||
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;
|
||||
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 || [];
|
||||
},
|
||||
|
||||
@@ -35,13 +35,9 @@ function WebApp({
|
||||
width = 680,
|
||||
height = 590,
|
||||
headers = {
|
||||
"X-API-TOKEN":
|
||||
"d1lmnn77271h79qdse0gbss0ev8usfin593h5qpa0zgismc8u1fxhg99ju0syeuy54j16ect58ybqzytp7v3",
|
||||
"APP-INTEGRATION-ID": "cvkm9hmhpcemufsg3vug",
|
||||
"X-API-TOKEN": "",
|
||||
"APP-INTEGRATION-ID": "",
|
||||
},
|
||||
// token = "cva1j5ehpcenic3ir7k0h8fb8qtv35iwtywze248oscrej8yoivhb5b1hyovp24xejjk27jy9ddt69ewfi3n", // https://coco.infini.cloud
|
||||
// token = "cvqt6r02sdb2v3bkgip0x3ixv01f3r2lhnxoz1efbn160wm9og58wtv8t6wrv1ebvnvypuc23dx9pb33aemh", // http://localhost:9000
|
||||
// token = "cv5djeb9om602jdvtnmg6kc1muyn2vcadr6te48j9t9pvt59ewrnwj7fwvxrw3va84j2a0lb5y8194fbr3jd", // http://43.153.113.88:9000
|
||||
serverUrl = "",
|
||||
hasModules = ["search", "chat"],
|
||||
defaultModule = "search",
|
||||
|
||||
@@ -118,6 +118,9 @@ export interface SystemOperations {
|
||||
isWindows10: () => Promise<boolean>;
|
||||
revealItemInDir: (path: string) => 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
|
||||
|
||||
@@ -15,6 +15,7 @@ import type { AppTheme } from "@/types/index";
|
||||
import { useAppearanceStore } from "@/stores/appearanceStore";
|
||||
import { copyToClipboard, OpenURLWithBrowser } from ".";
|
||||
import { useAppStore } from "@/stores/appStore";
|
||||
import { unrequitable } from "@/utils";
|
||||
|
||||
export interface TauriPlatformAdapter extends BasePlatformAdapter {
|
||||
openFileDialog: (
|
||||
@@ -300,5 +301,34 @@ export const createTauriAdapter = (): TauriPlatformAdapter => {
|
||||
},
|
||||
|
||||
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,
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { BasePlatformAdapter } from "@/types/platform";
|
||||
import { copyToClipboard, OpenURLWithBrowser } from ".";
|
||||
import { Post } from "@/api/axiosRequest";
|
||||
|
||||
export interface WebPlatformAdapter extends BasePlatformAdapter {
|
||||
// Add web-specific methods here
|
||||
@@ -65,9 +66,9 @@ export const createWebAdapter = (): WebPlatformAdapter => {
|
||||
async checkMicrophonePermission() {
|
||||
return false;
|
||||
},
|
||||
|
||||
|
||||
async requestMicrophonePermission() {
|
||||
return false;
|
||||
return false;
|
||||
},
|
||||
|
||||
requestScreenRecordingPermission() {
|
||||
@@ -214,5 +215,80 @@ export const createWebAdapter = (): WebPlatformAdapter => {
|
||||
},
|
||||
|
||||
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;
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -76,6 +76,11 @@ export default defineConfig(async () => ({
|
||||
changeOrigin: true,
|
||||
secure: false,
|
||||
},
|
||||
"/mcp_server": {
|
||||
target: process.env.COCO_SERVER_URL,
|
||||
changeOrigin: true,
|
||||
secure: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
build: {
|
||||
|
||||
Reference in New Issue
Block a user