Skip to content

Commit

Permalink
update core dependency
Browse files Browse the repository at this point in the history
Signed-off-by: James <[email protected]>
  • Loading branch information
James committed Oct 22, 2023
1 parent d8da3a9 commit 9c16132
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 104 deletions.
97 changes: 30 additions & 67 deletions plugins/data-plugin/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
core,
invokePluginFunc,
store,
RegisterExtensionPoint,
StoreService,
Expand All @@ -22,7 +22,7 @@ function createCollection({
name: string;
schema?: { [key: string]: any };
}): Promise<void> {
return core.invokePluginFunc(MODULE_PATH, "createCollection", name, schema);
return invokePluginFunc(MODULE_PATH, "createCollection", name, schema);
}

/**
Expand All @@ -33,7 +33,7 @@ function createCollection({
*
*/
function deleteCollection(name: string): Promise<void> {
return core.invokePluginFunc(MODULE_PATH, "deleteCollection", name);
return invokePluginFunc(MODULE_PATH, "deleteCollection", name);
}

/**
Expand All @@ -51,7 +51,7 @@ function insertOne({
collectionName: string;
value: any;
}): Promise<any> {
return core.invokePluginFunc(MODULE_PATH, "insertOne", collectionName, value);
return invokePluginFunc(MODULE_PATH, "insertOne", collectionName, value);
}

/**
Expand All @@ -72,13 +72,7 @@ function updateOne({
key: string;
value: any;
}): Promise<void> {
return core.invokePluginFunc(
MODULE_PATH,
"updateOne",
collectionName,
key,
value
);
return invokePluginFunc(MODULE_PATH, "updateOne", collectionName, key, value);
}

/**
Expand All @@ -97,7 +91,7 @@ function updateMany({
value: any;
selector?: { [key: string]: any };
}): Promise<void> {
return core.invokePluginFunc(
return invokePluginFunc(
MODULE_PATH,
"updateMany",
collectionName,
Expand All @@ -121,7 +115,7 @@ function deleteOne({
collectionName: string;
key: string;
}): Promise<void> {
return core.invokePluginFunc(MODULE_PATH, "deleteOne", collectionName, key);
return invokePluginFunc(MODULE_PATH, "deleteOne", collectionName, key);
}

/**
Expand All @@ -139,12 +133,7 @@ function deleteMany({
collectionName: string;
selector?: { [key: string]: any };
}): Promise<void> {
return core.invokePluginFunc(
MODULE_PATH,
"deleteMany",
collectionName,
selector
);
return invokePluginFunc(MODULE_PATH, "deleteMany", collectionName, selector);
}

/**
Expand All @@ -160,7 +149,7 @@ function findOne({
collectionName: string;
key: string;
}): Promise<any> {
return core.invokePluginFunc(MODULE_PATH, "findOne", collectionName, key);
return invokePluginFunc(MODULE_PATH, "findOne", collectionName, key);
}

/**
Expand All @@ -179,7 +168,7 @@ function findMany({
selector: { [key: string]: any };
sort?: [{ [key: string]: any }];
}): Promise<any> {
return core.invokePluginFunc(
return invokePluginFunc(
MODULE_PATH,
"findMany",
collectionName,
Expand All @@ -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);
Expand All @@ -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<any> {
Expand Down Expand Up @@ -308,7 +271,7 @@ function createBot(bot: any): Promise<void> {
function getBots(): Promise<any> {
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);
Expand Down
2 changes: 1 addition & 1 deletion plugins/data-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion plugins/inference-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion plugins/model-management-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"README.md"
],
"dependencies": {
"@janhq/core": "^0.1.3",
"@janhq/core": "^0.1.6",
"ts-loader": "^9.5.0"
}
}
2 changes: 1 addition & 1 deletion plugins/monitoring-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion plugins/openai-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion web/app/_components/CustomBotTemperature/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const CutomBotTemperature: React.FC<Props> = ({ control }) => (
control={control}
/>
<div className="text-gray-500 mt-1 text-[0.8em]">
Controls the creativity of the bot's responses. Higher values produce more
Controls the creativity of the bot&apos;s responses. Higher values produce more
varied but unpredictable replies, lower values generate more consistent
responses.
</div>
Expand Down
50 changes: 25 additions & 25 deletions web/app/_components/InputToolbar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
'use client'

import BasicPromptInput from "../BasicPromptInput"
import BasicPromptAccessories from "../BasicPromptAccessories"
import { useAtomValue, useSetAtom } from "jotai"
import { showingAdvancedPromptAtom } from "@/_helpers/atoms/Modal.atom"
import SecondaryButton from "../SecondaryButton"
import { Fragment, useEffect, useState } from "react"
import { PlusIcon } from "@heroicons/react/24/outline"
import useCreateConversation from "@/_hooks/useCreateConversation"
import { activeAssistantModelAtom } from "@/_helpers/atoms/Model.atom"
import BasicPromptInput from '../BasicPromptInput'
import BasicPromptAccessories from '../BasicPromptAccessories'
import { useAtomValue, useSetAtom } from 'jotai'
import { showingAdvancedPromptAtom } from '@/_helpers/atoms/Modal.atom'
import SecondaryButton from '../SecondaryButton'
import { Fragment, useEffect, useState } from 'react'
import { PlusIcon } from '@heroicons/react/24/outline'
import useCreateConversation from '@/_hooks/useCreateConversation'
import { activeAssistantModelAtom } from '@/_helpers/atoms/Model.atom'
import {
currentConversationAtom,
currentConvoStateAtom,
} from "@/_helpers/atoms/Conversation.atom"
import useGetBots from "@/_hooks/useGetBots"
import { activeBotAtom } from "@/_helpers/atoms/Bot.atom"
import { useGetDownloadedModels } from "@/_hooks/useGetDownloadedModels"
} from '@/_helpers/atoms/Conversation.atom'
import useGetBots from '@/_hooks/useGetBots'
import { activeBotAtom } from '@/_helpers/atoms/Bot.atom'
import { useGetDownloadedModels } from '@/_hooks/useGetDownloadedModels'

const InputToolbar: React.FC = () => {
const showingAdvancedPrompt = useAtomValue(showingAdvancedPromptAtom)
Expand All @@ -27,26 +27,22 @@ const InputToolbar: React.FC = () => {
const setActiveBot = useSetAtom(activeBotAtom)
const { getBotById } = useGetBots()
const [inputState, setInputState] = useState<
"available" | "disabled" | "loading"
'available' | 'disabled' | 'loading'
>()
const [error, setError] = useState<string | undefined>()
const { downloadedModels } = useGetDownloadedModels()

if (showingAdvancedPrompt) {
return <div />
}

useEffect(() => {
const getReplyState = async () => {
setInputState("loading")
setInputState('loading')
if (currentConvo && currentConvo.botId && currentConvo.botId.length > 0) {
// if botId is set, check if bot is available
const bot = await getBotById(currentConvo.botId)
console.debug("Found bot", JSON.stringify(bot, null, 2))
console.debug('Found bot', JSON.stringify(bot, null, 2))
if (bot) {
setActiveBot(bot)
}
setInputState(bot ? "available" : "disabled")
setInputState(bot ? 'available' : 'disabled')
setError(
bot
? undefined
Expand All @@ -57,7 +53,7 @@ const InputToolbar: React.FC = () => {
(model) => model._id === activeModel?._id
)

setInputState(model ? "available" : "disabled")
setInputState(model ? 'available' : 'disabled')
setError(
model
? undefined
Expand All @@ -74,15 +70,19 @@ const InputToolbar: React.FC = () => {
}
}

if (inputState === "loading") {
if (showingAdvancedPrompt) {
return <div />
}

if (inputState === 'loading') {
return <div>Loading..</div>
}

if (inputState === "disabled") {
if (inputState === 'disabled') {
// text italic

return (
<p className="mx-auto my-5 text-center text-ellipsis line-clamp-2 italic text-gray-600 text-sm">
<p className="mx-auto my-5 line-clamp-2 text-ellipsis text-center text-sm italic text-gray-600">
{error}
</p>
)
Expand Down
3 changes: 2 additions & 1 deletion web/app/_hooks/useCreateBot.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
3 changes: 2 additions & 1 deletion web/app/_hooks/useDeleteBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ 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);
const setRightPanelVisibility = useSetAtom(rightSideBarExpandStateAtom);

const deleteBot = async (botId: string): Promise<"success" | "failed"> => {
try {
await executeSerial("deleteBot", botId);
await executeSerial(DataService.DeleteBot, botId);
setRightPanelVisibility(false);
setActiveBot(undefined);
return "success";
Expand Down
5 changes: 3 additions & 2 deletions web/app/_hooks/useGetBots.ts
Original file line number Diff line number Diff line change
@@ -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<Bot[]> => {
try {
const bots = await executeSerial("getBots");
const bots = await executeSerial(DataService.GetBots);
return bots;
} catch (err) {
alert(`Failed to get bots: ${err}`);
Expand All @@ -15,7 +16,7 @@ export default function useGetBots() {

const getBotById = async (botId: string): Promise<Bot | undefined> => {
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}`);
Expand Down
Loading

0 comments on commit 9c16132

Please sign in to comment.