From cd1a54fd9e62e87a6fd2f6561acc436643d24630 Mon Sep 17 00:00:00 2001 From: Jack Schedel Date: Sat, 10 Feb 2024 13:07:22 -0500 Subject: [PATCH 1/2] apiKey migration --- src/App.tsx | 11 +++++++++++ src/hooks/useSubmit.ts | 5 +---- src/store/auth-slice.ts | 7 +------ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index f73dfe57..3e079d55 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -22,6 +22,10 @@ function App() { const setHideSideMenu = useStore((state) => state.setHideSideMenu); const hideSideMenu = useStore((state) => state.hideSideMenu); const bottomMessageRef = useStore((state) => state.bottomMessageRef); + const setApiAuth = useStore((state) => state.setApiAuth); + const apiAuth = useStore((state) => state.apiAuth); + const apiKey = useStore((state) => state.apiKey); + const setApiKey = useStore((state) => state.setApiKey); const initialiseNewChat = useInitialiseNewChat(); const addChat = useAddChat(); @@ -30,6 +34,13 @@ function App() { const copyCodeBlock = useCopyCodeBlock(); const { handleSubmit } = useSubmit(); + if (apiKey && !apiAuth[0].apiKey) { + const old = apiAuth; + old[0].apiKey = apiKey; + setApiAuth(old); + setApiKey(''); + } + const handleGenerate = () => { if (useStore.getState().generating) return; const updatedChats: ChatInterface[] = JSON.parse( diff --git a/src/hooks/useSubmit.ts b/src/hooks/useSubmit.ts index 466ea9a6..5019d577 100644 --- a/src/hooks/useSubmit.ts +++ b/src/hooks/useSubmit.ts @@ -104,9 +104,7 @@ const useSubmit = () => { if (!apiKey || apiKey.length === 0) { // official endpoint if (apiEndpoint === officialAPIEndpoint) { - const error = new Error(t('noApiKeyWarning') as string); - setError(error.message); - throw error; + throw new Error(t('noApiKeyWarning') as string); } // other endpoints @@ -232,7 +230,6 @@ const useSubmit = () => { } } catch (e: unknown) { setError((e as Error).message); - throw e; } setGenerating(false); }; diff --git a/src/store/auth-slice.ts b/src/store/auth-slice.ts index 3eb95a2b..ae159bb7 100644 --- a/src/store/auth-slice.ts +++ b/src/store/auth-slice.ts @@ -4,6 +4,7 @@ import { ModelDefinition } from '@type/chat'; import { StoreSlice } from './store'; export interface AuthSlice { + apiKey?: string; firstVisit: boolean; apiAuth: EndpointAuth[]; modelDefs: ModelDefinition[]; @@ -44,12 +45,6 @@ export const createAuthSlice: StoreSlice = (set) => ({ apiKey: apiKey, })); }, - setApiEndpoint: (apiEndpoint: string) => { - set((prev: AuthSlice) => ({ - ...prev, - apiEndpoint: apiEndpoint, - })); - }, setFirstVisit: (firstVisit: boolean) => { set((prev: AuthSlice) => ({ ...prev, From b7ee9bca01db18bb0054d113ea6f2079b9a09811 Mon Sep 17 00:00:00 2001 From: Jack Schedel Date: Sat, 10 Feb 2024 13:14:51 -0500 Subject: [PATCH 2/2] 2.1.0 versioning --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e5a9abb8..cda5cfd2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "koala-client", "private": true, - "version": "2.0.8", + "version": "2.1.0", "type": "module", "homepage": "./", "main": "electron/index.cjs",