From 642d7aacc9bf876f79fa4d12933ba932077a6f98 Mon Sep 17 00:00:00 2001 From: NamH Date: Sat, 27 Jan 2024 12:56:45 +0700 Subject: [PATCH] fix: user can't view model setting in local api server (#1807) * fix: cannot change jan data folder Signed-off-by: James * fix: user can't view model setting in local api server Signed-off-by: James --------- Signed-off-by: James Co-authored-by: James --- web/hooks/usePath.ts | 38 ++++++++++++------- .../Settings/Advanced/DataFolder/index.tsx | 9 ++--- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/web/hooks/usePath.ts b/web/hooks/usePath.ts index db6284f93..70dbfa6bb 100644 --- a/web/hooks/usePath.ts +++ b/web/hooks/usePath.ts @@ -11,20 +11,23 @@ export const usePath = () => { const selectedModel = useAtomValue(selectedModelAtom) const onReviewInFinder = async (type: string) => { - if (!activeThread) return - const activeThreadState = threadStates[activeThread.id] - if (!activeThreadState.isFinishInit) { - alert('Thread is not started yet') - return + // TODO: this logic should be refactored. + if (type !== 'Model') { + if (!activeThread) return + const activeThreadState = threadStates[activeThread.id] + if (!activeThreadState.isFinishInit) { + alert('Thread is not started yet') + return + } } const userSpace = await getJanDataFolderPath() let filePath = undefined - const assistantId = activeThread.assistants[0]?.assistant_id + const assistantId = activeThread?.assistants[0]?.assistant_id switch (type) { case 'Engine': case 'Thread': - filePath = await joinPath(['threads', activeThread.id]) + filePath = await joinPath(['threads', activeThread?.id ?? '']) break case 'Model': if (!selectedModel) return @@ -44,20 +47,27 @@ export const usePath = () => { } const onViewJson = async (type: string) => { - if (!activeThread) return - const activeThreadState = threadStates[activeThread.id] - if (!activeThreadState.isFinishInit) { - alert('Thread is not started yet') - return + // TODO: this logic should be refactored. + if (type !== 'Model') { + if (!activeThread) return + const activeThreadState = threadStates[activeThread.id] + if (!activeThreadState.isFinishInit) { + alert('Thread is not started yet') + return + } } const userSpace = await getJanDataFolderPath() let filePath = undefined - const assistantId = activeThread.assistants[0]?.assistant_id + const assistantId = activeThread?.assistants[0]?.assistant_id switch (type) { case 'Engine': case 'Thread': - filePath = await joinPath(['threads', activeThread.id, 'thread.json']) + filePath = await joinPath([ + 'threads', + activeThread?.id ?? '', + 'thread.json', + ]) break case 'Model': if (!selectedModel) return diff --git a/web/screens/Settings/Advanced/DataFolder/index.tsx b/web/screens/Settings/Advanced/DataFolder/index.tsx index 90a0dd38b..9a1863fa2 100644 --- a/web/screens/Settings/Advanced/DataFolder/index.tsx +++ b/web/screens/Settings/Advanced/DataFolder/index.tsx @@ -44,18 +44,17 @@ const DataFolder = () => { }, [janDataFolderPath, setShowSameDirectory, setShowDirectoryConfirm]) const onUserConfirmed = useCallback(async () => { - const destination = destinationPath - if (!destination) return + if (!destinationPath) return try { const appConfiguration: AppConfiguration = await window.core?.api?.getAppConfigurations() const currentJanDataFolder = appConfiguration.data_folder - appConfiguration.data_folder = destination - await fs.syncFile(currentJanDataFolder, destination) + appConfiguration.data_folder = destinationPath + await fs.syncFile(currentJanDataFolder, destinationPath) await window.core?.api?.updateAppConfiguration(appConfiguration) console.debug( - `File sync finished from ${currentJanDataFolder} to ${destination}` + `File sync finished from ${currentJanDataFolder} to ${destinationPath}` ) localStorage.setItem(SUCCESS_SET_NEW_DESTINATION, 'true')