Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apiKey migration #112

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koala-client",
"private": true,
"version": "2.0.8",
"version": "2.1.0",
"type": "module",
"homepage": "./",
"main": "electron/index.cjs",
Expand Down
11 changes: 11 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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(
Expand Down
5 changes: 1 addition & 4 deletions src/hooks/useSubmit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -232,7 +230,6 @@ const useSubmit = () => {
}
} catch (e: unknown) {
setError((e as Error).message);
throw e;
}
setGenerating(false);
};
Expand Down
7 changes: 1 addition & 6 deletions src/store/auth-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ModelDefinition } from '@type/chat';
import { StoreSlice } from './store';

export interface AuthSlice {
apiKey?: string;
firstVisit: boolean;
apiAuth: EndpointAuth[];
modelDefs: ModelDefinition[];
Expand Down Expand Up @@ -44,12 +45,6 @@ export const createAuthSlice: StoreSlice<AuthSlice> = (set) => ({
apiKey: apiKey,
}));
},
setApiEndpoint: (apiEndpoint: string) => {
set((prev: AuthSlice) => ({
...prev,
apiEndpoint: apiEndpoint,
}));
},
setFirstVisit: (firstVisit: boolean) => {
set((prev: AuthSlice) => ({
...prev,
Expand Down
Loading