Skip to content

Commit

Permalink
chore: rebase main
Browse files Browse the repository at this point in the history
chore: rebase main
  • Loading branch information
louis-jan committed Nov 29, 2023
1 parent 771679f commit 92be81e
Show file tree
Hide file tree
Showing 33 changed files with 203 additions and 261 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: 2 additions & 0 deletions core/src/plugins/conversational.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ export abstract class ConversationalPlugin extends JanPlugin {

abstract addNewMessage(message: ThreadMessage): Promise<void>;

abstract writeMessages(threadId: string, messages: ThreadMessage[]): Promise<void>;

abstract getAllMessages(threadId: string): Promise<ThreadMessage[]>;
}
3 changes: 1 addition & 2 deletions core/src/plugins/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ export abstract class ModelPlugin extends JanPlugin {

/**
* Cancels the download of a specific model.
* @param {string} name - The name of the model to cancel the download for.
* @param {string} modelId - The ID of the model to cancel the download for.
* @returns {Promise<void>} A promise that resolves when the download has been cancelled.
*/
abstract cancelModelDownload(name: string, modelId: string): Promise<void>;
abstract cancelModelDownload(modelId: string): Promise<void>;

/**
* Deletes a model.
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
21 changes: 21 additions & 0 deletions plugins/conversational-json/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,27 @@ export default class JSONConversationalPlugin implements ConversationalPlugin {
}
}

async writeMessages(
threadId: string,
messages: ThreadMessage[]
): Promise<void> {
try {
const threadDirPath = join(JSONConversationalPlugin._homeDir, threadId)
const threadMessagePath = join(
threadDirPath,
JSONConversationalPlugin._threadMessagesFileName
)
await fs.mkdir(threadDirPath)
await fs.writeFile(
threadMessagePath,
messages.map((msg) => JSON.stringify(msg)).join('\n')
)
Promise.resolve()
} catch (err) {
Promise.reject(err)
}
}

/**
* A promise builder for reading a thread from a file.
* @param threadDirName the thread dir we are reading from.
Expand Down
6 changes: 3 additions & 3 deletions plugins/model-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ export default class JanModelPlugin implements ModelPlugin {
* @param {string} modelId - The ID of the model whose download is to be cancelled.
* @returns {Promise<void>} A promise that resolves when the download has been cancelled.
*/
async cancelModelDownload(name: string, modelId: string): Promise<void> {
return abortDownload(join(JanModelPlugin._homeDir, name, modelId)).then(
async cancelModelDownload(modelId: string): Promise<void> {
return abortDownload(join(JanModelPlugin._homeDir, modelId, modelId)).then(
() => {
fs.deleteFile(join(JanModelPlugin._homeDir, name, modelId))
fs.rmdir(join(JanModelPlugin._homeDir, modelId))
}
)
}
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
2 changes: 1 addition & 1 deletion web/containers/Layout/BottomBar/DownloadingState/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default function DownloadingState() {
if (!model) return
pluginManager
.get<ModelPlugin>(PluginType.Model)
?.cancelModelDownload(model.name, item.fileName)
?.cancelModelDownload(item.modelId)
}
}}
>
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
4 changes: 2 additions & 2 deletions web/containers/ModalCancelDownload/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useMemo } from 'react'

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

import {
Modal,
Expand Down Expand Up @@ -79,7 +79,7 @@ export default function ModalCancelDownload({
if (!model) return
pluginManager
.get<ModelPlugin>(PluginType.Model)
?.cancelModelDownload(model.name, downloadState.fileName)
?.cancelModelDownload(downloadState.modelId)
}
}}
>
Expand Down
Loading

0 comments on commit 92be81e

Please sign in to comment.