diff --git a/plugins/data-plugin/index.ts b/plugins/data-plugin/index.ts index 4dbd95d35c..f9716291a2 100644 --- a/plugins/data-plugin/index.ts +++ b/plugins/data-plugin/index.ts @@ -1,5 +1,5 @@ import { - core, + invokePluginFunc, store, RegisterExtensionPoint, StoreService, @@ -22,7 +22,7 @@ function createCollection({ name: string; schema?: { [key: string]: any }; }): Promise { - return core.invokePluginFunc(MODULE_PATH, "createCollection", name, schema); + return invokePluginFunc(MODULE_PATH, "createCollection", name, schema); } /** @@ -33,7 +33,7 @@ function createCollection({ * */ function deleteCollection(name: string): Promise { - return core.invokePluginFunc(MODULE_PATH, "deleteCollection", name); + return invokePluginFunc(MODULE_PATH, "deleteCollection", name); } /** @@ -51,7 +51,7 @@ function insertOne({ collectionName: string; value: any; }): Promise { - return core.invokePluginFunc(MODULE_PATH, "insertOne", collectionName, value); + return invokePluginFunc(MODULE_PATH, "insertOne", collectionName, value); } /** @@ -72,13 +72,7 @@ function updateOne({ key: string; value: any; }): Promise { - return core.invokePluginFunc( - MODULE_PATH, - "updateOne", - collectionName, - key, - value - ); + return invokePluginFunc(MODULE_PATH, "updateOne", collectionName, key, value); } /** @@ -97,7 +91,7 @@ function updateMany({ value: any; selector?: { [key: string]: any }; }): Promise { - return core.invokePluginFunc( + return invokePluginFunc( MODULE_PATH, "updateMany", collectionName, @@ -121,7 +115,7 @@ function deleteOne({ collectionName: string; key: string; }): Promise { - return core.invokePluginFunc(MODULE_PATH, "deleteOne", collectionName, key); + return invokePluginFunc(MODULE_PATH, "deleteOne", collectionName, key); } /** @@ -139,12 +133,7 @@ function deleteMany({ collectionName: string; selector?: { [key: string]: any }; }): Promise { - return core.invokePluginFunc( - MODULE_PATH, - "deleteMany", - collectionName, - selector - ); + return invokePluginFunc(MODULE_PATH, "deleteMany", collectionName, selector); } /** @@ -160,7 +149,7 @@ function findOne({ collectionName: string; key: string; }): Promise { - return core.invokePluginFunc(MODULE_PATH, "findOne", collectionName, key); + return invokePluginFunc(MODULE_PATH, "findOne", collectionName, key); } /** @@ -179,7 +168,7 @@ function findMany({ selector: { [key: string]: any }; sort?: [{ [key: string]: any }]; }): Promise { - return core.invokePluginFunc( + return invokePluginFunc( MODULE_PATH, "findMany", collectionName, @@ -195,18 +184,12 @@ function onStart() { } // Register all the above functions and objects with the relevant extension points +// prettier-ignore export function init({ register }: { register: RegisterExtensionPoint }) { register(PluginService.OnStart, PLUGIN_NAME, onStart); - register( - StoreService.CreateCollection, - createCollection.name, - createCollection - ); - register( - StoreService.DeleteCollection, - deleteCollection.name, - deleteCollection - ); + register(StoreService.CreateCollection, createCollection.name, createCollection); + register(StoreService.DeleteCollection, deleteCollection.name, deleteCollection); + register(StoreService.InsertOne, insertOne.name, insertOne); register(StoreService.UpdateOne, updateOne.name, updateOne); register(StoreService.UpdateMany, updateMany.name, updateMany); @@ -215,44 +198,24 @@ export function init({ register }: { register: RegisterExtensionPoint }) { register(StoreService.FindOne, findOne.name, findOne); register(StoreService.FindMany, findMany.name, findMany); - register( - DataService.GetConversations, - getConversations.name, - getConversations - ); - register( - DataService.CreateConversation, - createConversation.name, - createConversation - ); - register( - DataService.UpdateConversation, - updateConversation.name, - updateConversation - ); + // for conversations management + register(DataService.GetConversations, getConversations.name, getConversations); + register(DataService.GetConversationById,getConversationById.name,getConversationById); + register(DataService.CreateConversation, createConversation.name, createConversation); + register(DataService.UpdateConversation, updateConversation.name, updateConversation); + register(DataService.DeleteConversation, deleteConversation.name, deleteConversation); + + // for messages management register(DataService.UpdateMessage, updateMessage.name, updateMessage); - register( - DataService.DeleteConversation, - deleteConversation.name, - deleteConversation - ); register(DataService.CreateMessage, createMessage.name, createMessage); - register( - DataService.GetConversationMessages, - getConversationMessages.name, - getConversationMessages - ); + register(DataService.GetConversationMessages, getConversationMessages.name, getConversationMessages); - register( - "getConversationById", - getConversationById.name, - getConversationById - ); - register("createBot", createBot.name, createBot); - register("getBots", getBots.name, getBots); - register("getBotById", getBotById.name, getBotById); - register("deleteBot", deleteBot.name, deleteBot); - register("updateBot", updateBot.name, updateBot); + // for bots management + register(DataService.CreateBot, createBot.name, createBot); + register(DataService.GetBots, getBots.name, getBots); + register(DataService.GetBotById, getBotById.name, getBotById); + register(DataService.DeleteBot, deleteBot.name, deleteBot); + register(DataService.UpdateBot, updateBot.name, updateBot); } function getConversations(): Promise { @@ -308,7 +271,7 @@ function createBot(bot: any): Promise { function getBots(): Promise { console.debug("Getting bots"); return store - .findMany("bots", {name: { $gt: null }}) + .findMany("bots", { name: { $gt: null } }) .then((bots) => { console.debug("Bots retrieved", JSON.stringify(bots, null, 2)); return Promise.resolve(bots); diff --git a/plugins/data-plugin/package.json b/plugins/data-plugin/package.json index b4b9dd9348..96bc774235 100644 --- a/plugins/data-plugin/package.json +++ b/plugins/data-plugin/package.json @@ -40,7 +40,7 @@ "node_modules" ], "dependencies": { - "@janhq/core": "file:../../core", + "@janhq/core": "^0.1.6", "pouchdb-find": "^8.0.1", "pouchdb-node": "^8.0.1" }, diff --git a/plugins/inference-plugin/package.json b/plugins/inference-plugin/package.json index 5f8d5cc7e0..4193bf38c4 100644 --- a/plugins/inference-plugin/package.json +++ b/plugins/inference-plugin/package.json @@ -26,7 +26,7 @@ "webpack-cli": "^5.1.4" }, "dependencies": { - "@janhq/core": "^0.1.3", + "@janhq/core": "^0.1.6", "kill-port-process": "^3.2.0", "rxjs": "^7.8.1", "tcp-port-used": "^1.0.2", diff --git a/plugins/model-management-plugin/package.json b/plugins/model-management-plugin/package.json index 45fb14f7c9..4222634308 100644 --- a/plugins/model-management-plugin/package.json +++ b/plugins/model-management-plugin/package.json @@ -27,7 +27,7 @@ "README.md" ], "dependencies": { - "@janhq/core": "^0.1.3", + "@janhq/core": "^0.1.6", "ts-loader": "^9.5.0" } } diff --git a/plugins/monitoring-plugin/package.json b/plugins/monitoring-plugin/package.json index f56a7e07de..45efb846b1 100644 --- a/plugins/monitoring-plugin/package.json +++ b/plugins/monitoring-plugin/package.json @@ -21,7 +21,7 @@ "webpack-cli": "^5.1.4" }, "dependencies": { - "@janhq/core": "^0.1.3", + "@janhq/core": "^0.1.6", "systeminformation": "^5.21.8", "ts-loader": "^9.5.0" }, diff --git a/plugins/openai-plugin/package.json b/plugins/openai-plugin/package.json index 3e562704c6..a0bbc188a9 100644 --- a/plugins/openai-plugin/package.json +++ b/plugins/openai-plugin/package.json @@ -26,7 +26,7 @@ "webpack-cli": "^5.1.4" }, "dependencies": { - "@janhq/core": "^0.1.3", + "@janhq/core": "^0.1.6", "azure-openai": "^0.9.4", "kill-port-process": "^3.2.0", "tcp-port-used": "^1.0.2", diff --git a/web/app/_hooks/useCreateBot.ts b/web/app/_hooks/useCreateBot.ts index 1267b00b10..4afc3cd3a9 100644 --- a/web/app/_hooks/useCreateBot.ts +++ b/web/app/_hooks/useCreateBot.ts @@ -1,10 +1,11 @@ import { Bot } from "@/_models/Bot"; import { executeSerial } from "../../../electron/core/plugin-manager/execution/extension-manager"; +import { DataService } from "@janhq/core"; export default function useCreateBot() { const createBot = async (bot: Bot) => { try { - await executeSerial("createBot", bot); + await executeSerial(DataService.CreateBot, bot); } catch (err) { alert(err); console.error(err); diff --git a/web/app/_hooks/useDeleteBot.ts b/web/app/_hooks/useDeleteBot.ts index 18b2bf941e..079bfd941e 100644 --- a/web/app/_hooks/useDeleteBot.ts +++ b/web/app/_hooks/useDeleteBot.ts @@ -2,6 +2,7 @@ import { useSetAtom } from "jotai"; import { executeSerial } from "../../../electron/core/plugin-manager/execution/extension-manager"; import { activeBotAtom } from "@/_helpers/atoms/Bot.atom"; import { rightSideBarExpandStateAtom } from "@/_helpers/atoms/LeftSideBarExpand.atom"; +import { DataService } from "@janhq/core"; export default function useDeleteBot() { const setActiveBot = useSetAtom(activeBotAtom); @@ -9,7 +10,7 @@ export default function useDeleteBot() { const deleteBot = async (botId: string): Promise<"success" | "failed"> => { try { - await executeSerial("deleteBot", botId); + await executeSerial(DataService.DeleteBot, botId); setRightPanelVisibility(false); setActiveBot(undefined); return "success"; diff --git a/web/app/_hooks/useGetBots.ts b/web/app/_hooks/useGetBots.ts index 8c3c9403bd..94a17c6413 100644 --- a/web/app/_hooks/useGetBots.ts +++ b/web/app/_hooks/useGetBots.ts @@ -1,10 +1,11 @@ import { Bot } from "@/_models/Bot"; import { executeSerial } from "../../../electron/core/plugin-manager/execution/extension-manager"; +import { DataService } from "@janhq/core"; export default function useGetBots() { const getAllBots = async (): Promise => { try { - const bots = await executeSerial("getBots"); + const bots = await executeSerial(DataService.GetBots); return bots; } catch (err) { alert(`Failed to get bots: ${err}`); @@ -15,7 +16,7 @@ export default function useGetBots() { const getBotById = async (botId: string): Promise => { try { - const bot: Bot = await executeSerial("getBotById", botId); + const bot: Bot = await executeSerial(DataService.GetBotById, botId); return bot; } catch (err) { alert(`Failed to get bot ${botId}: ${err}`); diff --git a/web/app/_hooks/useUpdateBot.ts b/web/app/_hooks/useUpdateBot.ts index b4c541d3f0..988b619818 100644 --- a/web/app/_hooks/useUpdateBot.ts +++ b/web/app/_hooks/useUpdateBot.ts @@ -1,5 +1,6 @@ import { Bot } from "@/_models/Bot"; import { executeSerial } from "../../../electron/core/plugin-manager/execution/extension-manager"; +import { DataService } from "@janhq/core"; export default function useUpdateBot() { const updateBot = async ( @@ -16,7 +17,7 @@ export default function useUpdateBot() { } } - await executeSerial("updateBot", bot); + await executeSerial(DataService.UpdateBot, bot); console.debug("Bot updated", JSON.stringify(bot, null, 2)); } catch (err) { alert(`Update bot error: ${err}`); diff --git a/web/package.json b/web/package.json index 508f66ba5f..f097109a9b 100644 --- a/web/package.json +++ b/web/package.json @@ -14,7 +14,7 @@ "dependencies": { "@headlessui/react": "^1.7.15", "@heroicons/react": "^2.0.18", - "@janhq/core": "^0.1.2", + "@janhq/core": "^0.1.6", "@tailwindcss/typography": "^0.5.9", "@types/react": "18.2.15", "@types/react-dom": "18.2.7",