Skip to content

Commit

Permalink
chore: rebase main
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-menlo committed Nov 28, 2023
1 parent 771679f commit eeb2690
Show file tree
Hide file tree
Showing 22 changed files with 117 additions and 122 deletions.
52 changes: 12 additions & 40 deletions core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@ const executeOnMain: (
window.coreAPI?.invokePluginFunc(plugin, method, ...args) ??
window.electronAPI?.invokePluginFunc(plugin, method, ...args);

/**
* @deprecated This object is deprecated and should not be used.
* Use individual functions instead.
*/
const invokePluginFunc: (
plugin: string,
method: string,
...args: any[]
) => Promise<any> = (plugin, method, ...args) =>
window.coreAPI?.invokePluginFunc(plugin, method, ...args) ??
window.electronAPI?.invokePluginFunc(plugin, method, ...args);

/**
* Downloads a file from a URL and saves it to the local file system.
* @param {string} url - The URL of the file to download.
Expand All @@ -36,16 +24,7 @@ const invokePluginFunc: (
const downloadFile: (url: string, fileName: string) => Promise<any> = (
url,
fileName
) =>
window.coreAPI?.downloadFile(url, fileName) ??
window.electronAPI?.downloadFile(url, fileName);

/**
* @deprecated This object is deprecated and should not be used.
* Use fs module instead.
*/
const deleteFile: (path: string) => Promise<any> = (path) =>
window.coreAPI?.deleteFile(path) ?? window.electronAPI?.deleteFile(path);
) => window.coreAPI?.downloadFile(url, fileName);

/**
* Aborts the download of a specific file.
Expand All @@ -69,8 +48,16 @@ const appDataPath: () => Promise<any> = () => window.coreAPI?.appDataPath();
const getUserSpace = (): Promise<string> =>
window.coreAPI?.getUserSpace() ?? window.electronAPI?.getUserSpace();

/** Register extension point function type definition
*
/**
* Opens the file explorer at a specific path.
* @param {string} path - The path to open in the file explorer.
* @returns {Promise<any>} A promise that resolves when the file explorer is opened.
*/
const openFileExplorer: (path: string) => Promise<any> = (path) =>
window.coreAPI?.openFileExplorer(path);

/**
* Register extension point function type definition
*/
export type RegisterExtensionPoint = (
extensionName: string,
Expand All @@ -79,29 +66,14 @@ export type RegisterExtensionPoint = (
priority?: number
) => void;

/**
* @deprecated This object is deprecated and should not be used.
* Use individual functions instead.
*/
export const core = {
invokePluginFunc,
executeOnMain,
downloadFile,
abortDownload,
deleteFile,
appDataPath,
getUserSpace,
};

/**
* Functions exports
*/
export {
invokePluginFunc,
executeOnMain,
downloadFile,
abortDownload,
deleteFile,
appDataPath,
getUserSpace,
openFileExplorer,
};
13 changes: 6 additions & 7 deletions core/src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ const appendFile: (path: string, data: string) => Promise<any> = (path, data) =>
window.coreAPI?.appendFile(path, data) ??
window.electronAPI?.appendFile(path, data);

/**
* Reads a file line by line.
* @param {string} path - The path of the file to read.
* @returns {Promise<any>} A promise that resolves to the lines of the file.
*/
const readLineByLine: (path: string) => Promise<any> = (path) =>
window.coreAPI?.readLineByLine(path) ??
window.electronAPI?.readLineByLine(path);

const openFileExplorer: (path: string) => Promise<any> = (path) =>
window.coreAPI?.openFileExplorer(path) ??
window.electronAPI?.openFileExplorer(path);
window.coreAPI?.readLineByLine(path);

export const fs = {
isDirectory,
Expand All @@ -82,5 +82,4 @@ export const fs = {
deleteFile,
appendFile,
readLineByLine,
openFileExplorer,
};
22 changes: 4 additions & 18 deletions core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,26 @@
/**
* @deprecated This object is deprecated and should not be used.
* Use individual functions instead.
*/
export { core, deleteFile, invokePluginFunc } from "./core";

/**
* Core module exports.
* @module
*/
export {
downloadFile,
executeOnMain,
appDataPath,
getUserSpace,
abortDownload,
} from "./core";
export * from "./core";

/**
* Events module exports.
* Events events exports.
* @module
*/
export { events } from "./events";
export * from "./events";

/**
* Events types exports.
* @module
*/
export * from "./events";

export * from "./types/index";

/**
* Filesystem module exports.
* @module
*/
export { fs } from "./fs";
export * from "./fs";

/**
* Plugin base module export.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"build:web": "yarn workspace jan-web build && cpx \"web/out/**\" \"electron/renderer/\"",
"build:electron": "yarn workspace jan build",
"build:electron:test": "yarn workspace jan build:test",
"build:plugins": "rimraf ./electron/core/pre-install/*.tgz && concurrently --kill-others-on-fail \"cd ./plugins/conversational-json && npm install && npm run build:publish\" \"cd ./plugins/inference-plugin && npm install && npm run build:publish\" \"cd ./plugins/model-plugin && npm install && npm run build:publish\" \"cd ./plugins/monitoring-plugin && npm install && npm run build:publish\"",
"build:plugins": "rimraf ./electron/core/pre-install/*.tgz && concurrently --kill-others-on-fail \"cd ./plugins/conversational-json && npm install && npm run build:publish\" \"cd ./plugins/inference-plugin && npm install && npm run build:publish\" \"cd ./plugins/model-plugin && npm install && npm run build:publish\" \"cd ./plugins/monitoring-plugin && npm install && npm run build:publish\" \"cd ./plugins/assistant-plugin && npm install && npm run build:publish\"",
"build:test": "yarn build:web && yarn workspace jan build:test",
"build": "yarn build:web && yarn workspace jan build",
"build:publish": "yarn build:web && yarn workspace jan build:publish"
Expand Down
11 changes: 4 additions & 7 deletions web/containers/CardSidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import { ReactNode, useState } from 'react'
import { Fragment } from 'react'

import { Menu, Transition } from '@headlessui/react'
import {
ChevronDownIcon,
EllipsisVerticalIcon,
} from '@heroicons/react/20/solid'
import { twMerge } from 'tailwind-merge'

interface Props {
children: ReactNode
title: string
onRevealInFinderClick: (type: string) => void
onViewJsonClick: (type: string) => void
}

function classNames(...classes: any) {
return classes.filter(Boolean).join(' ')
}

export default function CardSidebar({
children,
title,
Expand Down Expand Up @@ -58,7 +55,7 @@ export default function CardSidebar({
{({ active }) => (
<a
onClick={() => onRevealInFinderClick(title)}
className={classNames(
className={twMerge(
active ? 'bg-gray-50' : '',
'block cursor-pointer px-3 py-1 text-xs leading-6 text-gray-900'
)}
Expand All @@ -71,7 +68,7 @@ export default function CardSidebar({
{({ active }) => (
<a
onClick={() => onViewJsonClick(title)}
className={classNames(
className={twMerge(
active ? 'bg-gray-50' : '',
'block cursor-pointer px-3 py-1 text-xs leading-6 text-gray-900'
)}
Expand Down
14 changes: 7 additions & 7 deletions web/containers/DropdownListSidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Fragment, useEffect, useState } from 'react'

import { Listbox, Transition } from '@headlessui/react'
import { CheckIcon, ChevronUpDownIcon } from '@heroicons/react/20/solid'
import { getDownloadedModels } from '@/hooks/useGetDownloadedModels'

import { Model } from '@janhq/core/lib/types'
import { atom, useSetAtom } from 'jotai'
import { twMerge } from 'tailwind-merge'

function classNames(...classes: any) {
return classes.filter(Boolean).join(' ')
}
import { getDownloadedModels } from '@/hooks/useGetDownloadedModels'

export const selectedModelAtom = atom<Model | undefined>(undefined)

Expand Down Expand Up @@ -62,7 +62,7 @@ export default function DropdownListSidebar() {
<Listbox.Option
key={model.id}
className={({ active }) =>
classNames(
twMerge(
active ? 'bg-indigo-600 text-white' : 'text-gray-900',
'relative cursor-default select-none py-2 pl-3 pr-9'
)
Expand All @@ -72,7 +72,7 @@ export default function DropdownListSidebar() {
{({ selected, active }) => (
<>
<span
className={classNames(
className={twMerge(
selected ? 'font-semibold' : 'font-normal',
'block truncate'
)}
Expand All @@ -82,7 +82,7 @@ export default function DropdownListSidebar() {

{selected ? (
<span
className={classNames(
className={twMerge(
active ? 'text-white' : 'text-indigo-600',
'absolute inset-y-0 right-0 flex items-center pr-4'
)}
Expand Down
2 changes: 1 addition & 1 deletion web/containers/ItemCardSidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function ItemCardSidebar({ description, title }: Props) {
<div className="flex flex-col gap-2">
<div className="flex items-center gap-2">
<span>{title}</span>
</div>
</div>
<input
value={description}
type="text"
Expand Down
3 changes: 2 additions & 1 deletion web/containers/Layout/TopBar/CommandSearch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
CommandList,
} from '@janhq/uikit'

import { useSetAtom } from 'jotai'
import {
MessageCircleIcon,
SettingsIcon,
Expand All @@ -26,7 +27,7 @@ import { FeatureToggleContext } from '@/context/FeatureToggle'
import { MainViewState } from '@/constants/screens'

import { useMainViewState } from '@/hooks/useMainViewState'
import { useSetAtom } from 'jotai'

import { showRightSideBarAtom } from '@/screens/Chat/Sidebar'

export default function CommandSearch() {
Expand Down
3 changes: 3 additions & 0 deletions web/hooks/useActiveModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import { PluginType } from '@janhq/core'
import { InferencePlugin } from '@janhq/core/lib/plugins'
import { Model, ModelSettingParams } from '@janhq/core/lib/types'
import { atom, useAtom } from 'jotai'

import { toaster } from '@/containers/Toast'

import { useGetDownloadedModels } from './useGetDownloadedModels'

import { pluginManager } from '@/plugin'

const activeModelAtom = atom<Model | undefined>(undefined)
Expand Down
2 changes: 2 additions & 0 deletions web/hooks/useCreateNewThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
ThreadState,
} from '@janhq/core/lib/types'
import { atom, useAtom, useAtomValue, useSetAtom } from 'jotai'

import { generateThreadId } from '@/utils/conversation'

import {
threadsAtom,
setActiveThreadIdAtom,
Expand Down
3 changes: 3 additions & 0 deletions web/hooks/useDeleteModel.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { PluginType } from '@janhq/core'
import { ModelPlugin } from '@janhq/core/lib/plugins'
import { Model } from '@janhq/core/lib/types'

import { toaster } from '@/containers/Toast'

import { useGetDownloadedModels } from '@/hooks/useGetDownloadedModels'

import { pluginManager } from '@/plugin/PluginManager'

export default function useDeleteModel() {
Expand Down
3 changes: 2 additions & 1 deletion web/hooks/useGetAllThreads.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PluginType, ThreadState } from '@janhq/core'
import { ConversationalPlugin } from '@janhq/core/lib/plugins'
import { useSetAtom } from 'jotai'

import {
threadStatesAtom,
threadsAtom,
Expand All @@ -19,7 +20,7 @@ const useGetAllThreads = () => {
const threadStates: Record<string, ThreadState> = {}
threads?.forEach((thread) => {
if (thread.id != null) {
const lastMessage = thread.metadata?.lastMessage ?? ''
const lastMessage = (thread.metadata?.lastMessage as string) ?? ''
threadStates[thread.id] = {
hasMore: true,
waitingForResponse: false,
Expand Down
7 changes: 5 additions & 2 deletions web/hooks/useGetAssistants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { pluginManager } from '@/plugin/PluginManager'
import { useEffect, useState } from 'react'

import { Assistant, PluginType } from '@janhq/core'

import { AssistantPlugin } from '@janhq/core/lib/plugins'
import { useEffect, useState } from 'react'

import { pluginManager } from '@/plugin/PluginManager'

const getAssistants = async (): Promise<Assistant[]> => {
return (
Expand Down
2 changes: 2 additions & 0 deletions web/hooks/useGetDownloadedModels.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useEffect, useState } from 'react'

import { PluginType } from '@janhq/core'
import { ModelPlugin } from '@janhq/core/lib/plugins'
import { Model } from '@janhq/core/lib/types'

import { pluginManager } from '@/plugin/PluginManager'

export function useGetDownloadedModels() {
Expand Down
10 changes: 8 additions & 2 deletions web/hooks/useSendChatMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useAtom, useAtomValue, useSetAtom } from 'jotai'

import { ulid } from 'ulid'

import { selectedModelAtom } from '@/containers/DropdownListSidebar'
import { currentPromptAtom } from '@/containers/Providers/Jotai'

import { useActiveModel } from './useActiveModel'
Expand All @@ -29,7 +30,6 @@ import {
updateConversationWaitingForResponseAtom,
} from '@/helpers/atoms/Conversation.atom'
import { pluginManager } from '@/plugin/PluginManager'
import { selectedModelAtom } from '@/containers/DropdownListSidebar'

export default function useSendChatMessage() {
const activeThread = useAtomValue(activeThreadAtom)
Expand All @@ -41,6 +41,7 @@ export default function useSendChatMessage() {
const currentMessages = useAtomValue(getCurrentChatMessagesAtom)
const { activeModel } = useActiveModel()
const selectedModel = useAtomValue(selectedModelAtom)
const { startModel } = useActiveModel()

function updateThreadTitle(newMessage: MessageRequest) {
if (
Expand Down Expand Up @@ -169,12 +170,17 @@ export default function useSendChatMessage() {
}

addNewMessage(threadMessage)
updateThreadTitle(messageRequest)

await pluginManager
.get<ConversationalPlugin>(PluginType.Conversational)
?.addNewMessage(threadMessage)

const modelId = selectedModel?.id ?? activeThread.assistants[0].model.id
if (activeModel?.id !== modelId) {
await startModel(modelId)
}
events.emit(EventName.OnNewMessageRequest, messageRequest)
updateThreadTitle(messageRequest)
}

return {
Expand Down
Loading

0 comments on commit eeb2690

Please sign in to comment.