From d612cfcb45f74da51ed4342264e35d42b77b7e8e Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Fri, 18 Aug 2023 12:02:39 -0400 Subject: [PATCH] chore(Auth): reorder exports in Auth component fix(PluginAuthForm): handle case when pluginKey is null or undefined fix(PluginStoreDialog): handle case when getAvailablePluginFromKey is null or undefined fix(AuthContext): make authConfig optional in AuthContextProvider feat(hooks): add useServerStream hook fix(conversation): setSubmission to null instead of empty object fix(preset): specify type for presets atom fix(search): specify type for isSearchEnabled atom fix(submission): specify type for submission atom --- client/src/components/Auth/index.ts | 3 ++- client/src/components/Plugins/Store/PluginAuthForm.tsx | 2 +- client/src/components/Plugins/Store/PluginStoreDialog.tsx | 7 +++---- client/src/hooks/AuthContext.tsx | 2 +- client/src/hooks/index.ts | 1 + client/src/store/conversation.ts | 4 ++-- client/src/store/preset.ts | 2 +- client/src/store/search.ts | 2 +- client/src/store/submission.ts | 2 +- 9 files changed, 13 insertions(+), 12 deletions(-) diff --git a/client/src/components/Auth/index.ts b/client/src/components/Auth/index.ts index 9003653cf2..c5bf50d0c4 100644 --- a/client/src/components/Auth/index.ts +++ b/client/src/components/Auth/index.ts @@ -1,4 +1,5 @@ export { default as Login } from './Login'; export { default as Registration } from './Registration'; -export { default as RequestPasswordReset } from './RequestPasswordReset'; export { default as ResetPassword } from './ResetPassword'; +export { default as ApiErrorWatcher } from './ApiErrorWatcher'; +export { default as RequestPasswordReset } from './RequestPasswordReset'; diff --git a/client/src/components/Plugins/Store/PluginAuthForm.tsx b/client/src/components/Plugins/Store/PluginAuthForm.tsx index 711cd8f685..2b08bb9924 100644 --- a/client/src/components/Plugins/Store/PluginAuthForm.tsx +++ b/client/src/components/Plugins/Store/PluginAuthForm.tsx @@ -23,7 +23,7 @@ function PluginAuthForm({ plugin, onSubmit }: TPluginAuthFormProps) { className="col-span-1 flex w-full flex-col items-start justify-start gap-2" method="POST" onSubmit={handleSubmit((auth) => - onSubmit({ pluginKey: plugin?.pluginKey, action: 'install', auth }), + onSubmit({ pluginKey: plugin?.pluginKey ?? '', action: 'install', auth }), )} > {plugin?.authConfig?.map((config: TPluginAuthConfig, i: number) => ( diff --git a/client/src/components/Plugins/Store/PluginStoreDialog.tsx b/client/src/components/Plugins/Store/PluginStoreDialog.tsx index c8913fd42f..01a826853c 100644 --- a/client/src/components/Plugins/Store/PluginStoreDialog.tsx +++ b/client/src/components/Plugins/Store/PluginStoreDialog.tsx @@ -84,10 +84,9 @@ function PluginStoreDialog({ isOpen, setIsOpen }: TPluginStoreDialogProps) { const getAvailablePluginFromKey = availablePlugins?.find((p) => p.pluginKey === pluginKey); setSelectedPlugin(getAvailablePluginFromKey); - if ( - getAvailablePluginFromKey?.authConfig.length > 0 && - !getAvailablePluginFromKey?.authenticated - ) { + const { authConfig, authenticated } = getAvailablePluginFromKey ?? {}; + + if (authConfig && authConfig.length > 0 && !authenticated) { setShowPluginAuthForm(true); } else { handleInstall({ pluginKey, action: 'install', auth: null }); diff --git a/client/src/hooks/AuthContext.tsx b/client/src/hooks/AuthContext.tsx index 7b70ff3a7c..a120cfd6b7 100644 --- a/client/src/hooks/AuthContext.tsx +++ b/client/src/hooks/AuthContext.tsx @@ -46,7 +46,7 @@ const AuthContextProvider = ({ authConfig, children, }: { - authConfig: TAuthConfig; + authConfig?: TAuthConfig; children: ReactNode; }) => { const [user, setUser] = useState(undefined); diff --git a/client/src/hooks/index.ts b/client/src/hooks/index.ts index a2d48280ef..552208df09 100644 --- a/client/src/hooks/index.ts +++ b/client/src/hooks/index.ts @@ -7,4 +7,5 @@ export { default as useLocalize } from './useLocalize'; export { default as useMediaQuery } from './useMediaQuery'; export { default as useSetOptions } from './useSetOptions'; export { default as useGenerations } from './useGenerations'; +export { default as useServerStream } from './useServerStream'; export { default as useMessageHandler } from './useMessageHandler'; diff --git a/client/src/store/conversation.ts b/client/src/store/conversation.ts index 33dcad4ca2..f938d620d7 100644 --- a/client/src/store/conversation.ts +++ b/client/src/store/conversation.ts @@ -51,7 +51,7 @@ const messagesSiblingIdxFamily = atomFamily({ const useConversation = () => { const setConversation = useSetRecoilState(conversation); const setMessages = useSetRecoilState(messages); - const setSubmission = useSetRecoilState(submission.submission); + const setSubmission = useSetRecoilState(submission.submission); const resetLatestMessage = useResetRecoilState(latestMessage); const _switchToConversation = ( @@ -73,7 +73,7 @@ const useConversation = () => { setConversation(conversation); setMessages(messages); - setSubmission({}); + setSubmission({} as TSubmission); resetLatestMessage(); }; diff --git a/client/src/store/preset.ts b/client/src/store/preset.ts index 171cf25602..d5953c8474 100644 --- a/client/src/store/preset.ts +++ b/client/src/store/preset.ts @@ -6,7 +6,7 @@ import { TPreset } from 'librechat-data-provider'; // an array of saved presets. // sample structure // [preset1, preset2, preset3] -const presets = atom({ +const presets = atom({ key: 'presets', default: [], }); diff --git a/client/src/store/search.ts b/client/src/store/search.ts index e10f15b68a..4f4099b473 100644 --- a/client/src/store/search.ts +++ b/client/src/store/search.ts @@ -2,7 +2,7 @@ import { TMessage } from 'librechat-data-provider'; import { atom, selector } from 'recoil'; import { buildTree } from '~/utils'; -const isSearchEnabled = atom({ +const isSearchEnabled = atom({ key: 'isSearchEnabled', default: null, }); diff --git a/client/src/store/submission.ts b/client/src/store/submission.ts index 1254415fb8..0cd0b3e97f 100644 --- a/client/src/store/submission.ts +++ b/client/src/store/submission.ts @@ -12,7 +12,7 @@ import { TSubmission } from 'librechat-data-provider'; // isRegenerate=false, // isRegenerate? // } -const submission = atom({ +const submission = atom({ key: 'submission', default: null, });