Merge branch 'dev' into docs-tensorrt-llm
This commit is contained in:
commit
8a7227f94c
@ -101,7 +101,7 @@ export class FSExt implements Processor {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
rmdir(path: string): Promise<void> {
|
rm(path: string): Promise<void> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fs.rm(path, { recursive: true }, (err) => {
|
fs.rm(path, { recursive: true }, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@ -20,9 +20,9 @@ export default class JSONConversationalExtension extends ConversationalExtension
|
|||||||
* Called when the extension is loaded.
|
* Called when the extension is loaded.
|
||||||
*/
|
*/
|
||||||
async onLoad() {
|
async onLoad() {
|
||||||
if (!(await fs.existsSync(JSONConversationalExtension._threadFolder)))
|
if (!(await fs.existsSync(JSONConversationalExtension._threadFolder))) {
|
||||||
await fs.mkdirSync(JSONConversationalExtension._threadFolder)
|
await fs.mkdirSync(JSONConversationalExtension._threadFolder)
|
||||||
console.debug('JSONConversationalExtension loaded')
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import { Fragment, ReactNode, useEffect } from 'react'
|
import { Fragment, ReactNode, useEffect } from 'react'
|
||||||
|
|
||||||
import { AppConfiguration } from '@janhq/core'
|
import { AppConfiguration, getUserHomePath, joinPath } from '@janhq/core'
|
||||||
import { useSetAtom } from 'jotai'
|
import { useSetAtom } from 'jotai'
|
||||||
|
|
||||||
import useAssistants from '@/hooks/useAssistants'
|
import useAssistants from '@/hooks/useAssistants'
|
||||||
@ -10,6 +10,7 @@ import useGetSystemResources from '@/hooks/useGetSystemResources'
|
|||||||
import useModels from '@/hooks/useModels'
|
import useModels from '@/hooks/useModels'
|
||||||
import useThreads from '@/hooks/useThreads'
|
import useThreads from '@/hooks/useThreads'
|
||||||
|
|
||||||
|
import { defaultJanDataFolderAtom } from '@/helpers/atoms/App.atom'
|
||||||
import {
|
import {
|
||||||
janDataFolderPathAtom,
|
janDataFolderPathAtom,
|
||||||
quickAskEnabledAtom,
|
quickAskEnabledAtom,
|
||||||
@ -22,6 +23,7 @@ type Props = {
|
|||||||
const DataLoader: React.FC<Props> = ({ children }) => {
|
const DataLoader: React.FC<Props> = ({ children }) => {
|
||||||
const setJanDataFolderPath = useSetAtom(janDataFolderPathAtom)
|
const setJanDataFolderPath = useSetAtom(janDataFolderPathAtom)
|
||||||
const setQuickAskEnabled = useSetAtom(quickAskEnabledAtom)
|
const setQuickAskEnabled = useSetAtom(quickAskEnabledAtom)
|
||||||
|
const setJanDefaultDataFolder = useSetAtom(defaultJanDataFolderAtom)
|
||||||
|
|
||||||
useModels()
|
useModels()
|
||||||
useThreads()
|
useThreads()
|
||||||
@ -37,6 +39,16 @@ const DataLoader: React.FC<Props> = ({ children }) => {
|
|||||||
})
|
})
|
||||||
}, [setJanDataFolderPath, setQuickAskEnabled])
|
}, [setJanDataFolderPath, setQuickAskEnabled])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function getDefaultJanDataFolder() {
|
||||||
|
const homePath = await getUserHomePath()
|
||||||
|
const defaultJanDataFolder = await joinPath([homePath, 'jan'])
|
||||||
|
|
||||||
|
setJanDefaultDataFolder(defaultJanDataFolder)
|
||||||
|
}
|
||||||
|
getDefaultJanDataFolder()
|
||||||
|
}, [setJanDefaultDataFolder])
|
||||||
|
|
||||||
console.debug('Load Data...')
|
console.debug('Load Data...')
|
||||||
|
|
||||||
return <Fragment>{children}</Fragment>
|
return <Fragment>{children}</Fragment>
|
||||||
|
|||||||
@ -3,3 +3,5 @@ import { atom } from 'jotai'
|
|||||||
import { MainViewState } from '@/constants/screens'
|
import { MainViewState } from '@/constants/screens'
|
||||||
|
|
||||||
export const mainViewStateAtom = atom<MainViewState>(MainViewState.Thread)
|
export const mainViewStateAtom = atom<MainViewState>(MainViewState.Thread)
|
||||||
|
|
||||||
|
export const defaultJanDataFolderAtom = atom<string>('')
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useRef } from 'react'
|
import { useCallback, useEffect, useRef } from 'react'
|
||||||
|
|
||||||
import { events, Model, ModelEvent } from '@janhq/core'
|
import { events, Model, ModelEvent } from '@janhq/core'
|
||||||
import { atom, useAtom, useAtomValue, useSetAtom } from 'jotai'
|
import { atom, useAtom, useAtomValue, useSetAtom } from 'jotai'
|
||||||
@ -86,13 +86,12 @@ export function useActiveModel() {
|
|||||||
events.emit(ModelEvent.OnModelInit, model)
|
events.emit(ModelEvent.OnModelInit, model)
|
||||||
}
|
}
|
||||||
|
|
||||||
const stopModel = async () => {
|
const stopModel = useCallback(async () => {
|
||||||
if (activeModel) {
|
if (activeModel) {
|
||||||
setActiveModel(undefined)
|
|
||||||
setStateModel({ state: 'stop', loading: true, model: activeModel.id })
|
setStateModel({ state: 'stop', loading: true, model: activeModel.id })
|
||||||
events.emit(ModelEvent.OnModelStop, activeModel)
|
events.emit(ModelEvent.OnModelStop, activeModel)
|
||||||
}
|
}
|
||||||
}
|
}, [activeModel, setStateModel])
|
||||||
|
|
||||||
return { activeModel, startModel, stopModel, stateModel }
|
return { activeModel, startModel, stopModel, stateModel }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,49 +1,68 @@
|
|||||||
import { useEffect, useState } from 'react'
|
import { useCallback } from 'react'
|
||||||
|
|
||||||
import { fs, AppConfiguration, joinPath, getUserHomePath } from '@janhq/core'
|
import { fs, AppConfiguration } from '@janhq/core'
|
||||||
|
import { atom, useAtomValue, useSetAtom } from 'jotai'
|
||||||
|
|
||||||
|
import { useActiveModel } from './useActiveModel'
|
||||||
|
|
||||||
|
import { defaultJanDataFolderAtom } from '@/helpers/atoms/App.atom'
|
||||||
|
|
||||||
|
export enum FactoryResetState {
|
||||||
|
Idle = 'idle',
|
||||||
|
Starting = 'starting',
|
||||||
|
StoppingModel = 'stopping_model',
|
||||||
|
DeletingData = 'deleting_data',
|
||||||
|
ClearLocalStorage = 'clear_local_storage',
|
||||||
|
}
|
||||||
|
|
||||||
|
export const factoryResetStateAtom = atom(FactoryResetState.Idle)
|
||||||
|
|
||||||
export default function useFactoryReset() {
|
export default function useFactoryReset() {
|
||||||
const [defaultJanDataFolder, setdefaultJanDataFolder] = useState('')
|
const defaultJanDataFolder = useAtomValue(defaultJanDataFolderAtom)
|
||||||
|
const { activeModel, stopModel } = useActiveModel()
|
||||||
|
const setFactoryResetState = useSetAtom(factoryResetStateAtom)
|
||||||
|
|
||||||
useEffect(() => {
|
const resetAll = useCallback(
|
||||||
async function getDefaultJanDataFolder() {
|
async (keepCurrentFolder?: boolean) => {
|
||||||
const homePath = await getUserHomePath()
|
setFactoryResetState(FactoryResetState.Starting)
|
||||||
const defaultJanDataFolder = await joinPath([homePath, 'jan'])
|
// read the place of jan data folder
|
||||||
setdefaultJanDataFolder(defaultJanDataFolder)
|
const appConfiguration: AppConfiguration | undefined =
|
||||||
}
|
await window.core?.api?.getAppConfigurations()
|
||||||
getDefaultJanDataFolder()
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
const resetAll = async (keepCurrentFolder?: boolean) => {
|
if (!appConfiguration) {
|
||||||
// read the place of jan data folder
|
console.debug('Failed to get app configuration')
|
||||||
const appConfiguration: AppConfiguration | undefined =
|
|
||||||
await window.core?.api?.getAppConfigurations()
|
|
||||||
|
|
||||||
if (!appConfiguration) {
|
|
||||||
console.debug('Failed to get app configuration')
|
|
||||||
}
|
|
||||||
|
|
||||||
console.debug('appConfiguration: ', appConfiguration)
|
|
||||||
const janDataFolderPath = appConfiguration!.data_folder
|
|
||||||
|
|
||||||
if (!keepCurrentFolder) {
|
|
||||||
// set the default jan data folder to user's home directory
|
|
||||||
const configuration: AppConfiguration = {
|
|
||||||
data_folder: defaultJanDataFolder,
|
|
||||||
quick_ask: appConfiguration?.quick_ask ?? false,
|
|
||||||
}
|
}
|
||||||
await window.core?.api?.updateAppConfiguration(configuration)
|
|
||||||
}
|
|
||||||
await fs.rmdirSync(janDataFolderPath, { recursive: true })
|
|
||||||
|
|
||||||
// reset the localStorage
|
const janDataFolderPath = appConfiguration!.data_folder
|
||||||
localStorage.clear()
|
|
||||||
|
|
||||||
await window.core?.api?.relaunch()
|
if (!keepCurrentFolder) {
|
||||||
}
|
// set the default jan data folder to user's home directory
|
||||||
|
const configuration: AppConfiguration = {
|
||||||
|
data_folder: defaultJanDataFolder,
|
||||||
|
quick_ask: appConfiguration?.quick_ask ?? false,
|
||||||
|
}
|
||||||
|
await window.core?.api?.updateAppConfiguration(configuration)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activeModel) {
|
||||||
|
setFactoryResetState(FactoryResetState.StoppingModel)
|
||||||
|
await stopModel()
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 4000))
|
||||||
|
}
|
||||||
|
|
||||||
|
setFactoryResetState(FactoryResetState.DeletingData)
|
||||||
|
await fs.rm(janDataFolderPath)
|
||||||
|
|
||||||
|
setFactoryResetState(FactoryResetState.ClearLocalStorage)
|
||||||
|
// reset the localStorage
|
||||||
|
localStorage.clear()
|
||||||
|
|
||||||
|
await window.core?.api?.relaunch()
|
||||||
|
},
|
||||||
|
[defaultJanDataFolder, activeModel, stopModel, setFactoryResetState]
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
defaultJanDataFolder,
|
|
||||||
resetAll,
|
resetAll,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,21 +11,25 @@ import {
|
|||||||
Checkbox,
|
Checkbox,
|
||||||
Input,
|
Input,
|
||||||
} from '@janhq/uikit'
|
} from '@janhq/uikit'
|
||||||
import { atom, useAtom } from 'jotai'
|
import { atom, useAtom, useAtomValue } from 'jotai'
|
||||||
|
|
||||||
import useFactoryReset from '@/hooks/useFactoryReset'
|
import useFactoryReset from '@/hooks/useFactoryReset'
|
||||||
|
|
||||||
|
import { defaultJanDataFolderAtom } from '@/helpers/atoms/App.atom'
|
||||||
|
|
||||||
export const modalValidationAtom = atom(false)
|
export const modalValidationAtom = atom(false)
|
||||||
|
|
||||||
const ModalConfirmReset = () => {
|
const ModalConfirmReset = () => {
|
||||||
const [modalValidation, setModalValidation] = useAtom(modalValidationAtom)
|
const [modalValidation, setModalValidation] = useAtom(modalValidationAtom)
|
||||||
const { resetAll, defaultJanDataFolder } = useFactoryReset()
|
const defaultJanDataFolder = useAtomValue(defaultJanDataFolderAtom)
|
||||||
|
const { resetAll } = useFactoryReset()
|
||||||
const [inputValue, setInputValue] = useState('')
|
const [inputValue, setInputValue] = useState('')
|
||||||
const [currentDirectoryChecked, setCurrentDirectoryChecked] = useState(true)
|
const [currentDirectoryChecked, setCurrentDirectoryChecked] = useState(true)
|
||||||
const onFactoryResetClick = useCallback(
|
|
||||||
() => resetAll(currentDirectoryChecked),
|
const onFactoryResetClick = useCallback(() => {
|
||||||
[currentDirectoryChecked, resetAll]
|
setModalValidation(false)
|
||||||
)
|
resetAll(currentDirectoryChecked)
|
||||||
|
}, [currentDirectoryChecked, resetAll, setModalValidation])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
@ -65,7 +69,6 @@ const ModalConfirmReset = () => {
|
|||||||
</label>
|
</label>
|
||||||
<p className="mt-2 leading-relaxed">
|
<p className="mt-2 leading-relaxed">
|
||||||
Otherwise it will reset back to its original location at:{' '}
|
Otherwise it will reset back to its original location at:{' '}
|
||||||
{/* TODO should be from system */}
|
|
||||||
<span className="font-medium">{defaultJanDataFolder}</span>
|
<span className="font-medium">{defaultJanDataFolder}</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -0,0 +1,29 @@
|
|||||||
|
import { Modal, ModalContent, ModalHeader, ModalTitle } from '@janhq/uikit'
|
||||||
|
import { atom, useAtomValue } from 'jotai'
|
||||||
|
|
||||||
|
import {
|
||||||
|
FactoryResetState,
|
||||||
|
factoryResetStateAtom,
|
||||||
|
} from '@/hooks/useFactoryReset'
|
||||||
|
|
||||||
|
const resetModalVisibilityAtom = atom((get) => {
|
||||||
|
const visible = get(factoryResetStateAtom) !== FactoryResetState.Idle
|
||||||
|
return visible
|
||||||
|
})
|
||||||
|
|
||||||
|
const ResettingModal: React.FC = () => {
|
||||||
|
const visibility = useAtomValue(resetModalVisibilityAtom)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal open={visibility}>
|
||||||
|
<ModalContent>
|
||||||
|
<ModalHeader>
|
||||||
|
<ModalTitle>Factory reset in progress..</ModalTitle>
|
||||||
|
</ModalHeader>
|
||||||
|
<p className="text-muted-foreground">Resetting..</p>
|
||||||
|
</ModalContent>
|
||||||
|
</Modal>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ResettingModal
|
||||||
@ -3,6 +3,7 @@ import { Button } from '@janhq/uikit'
|
|||||||
import { useSetAtom } from 'jotai'
|
import { useSetAtom } from 'jotai'
|
||||||
|
|
||||||
import ModalValidation, { modalValidationAtom } from './ModalConfirmReset'
|
import ModalValidation, { modalValidationAtom } from './ModalConfirmReset'
|
||||||
|
import ResettingModal from './ResettingModal'
|
||||||
|
|
||||||
const FactoryReset = () => {
|
const FactoryReset = () => {
|
||||||
const setModalValidation = useSetAtom(modalValidationAtom)
|
const setModalValidation = useSetAtom(modalValidationAtom)
|
||||||
@ -30,6 +31,7 @@ const FactoryReset = () => {
|
|||||||
Reset
|
Reset
|
||||||
</Button>
|
</Button>
|
||||||
<ModalValidation />
|
<ModalValidation />
|
||||||
|
<ResettingModal />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user