🧹 chore: pre-release cleanup 2 (#3600)

* refactor: scrollToEnd

* fix(validateConvoAccess): search conversation by ID for proper validation

* feat: Add unique index for conversationId and user in convoSchema

* refactor: Update font sizes 1 rem -> font-size-base in style.css

* fix: Assistants map type issues

* refactor: Remove obsolete scripts

* fix: Update DropdownNoState component to handle both string and OptionType values

* refactor: Remove config/loader.js file

* fix: remove crypto.randomBytes(); refactor: Create reusable function for generating token and hash
This commit is contained in:
Danny Avila 2024-08-09 15:17:13 -04:00 committed by GitHub
parent 6fead1005b
commit 1ff4841603
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 172 additions and 637 deletions

View file

@ -7,7 +7,7 @@ export default function useAssistantsMap({
isAuthenticated,
}: {
isAuthenticated: boolean;
}): TAssistantsMap {
}): TAssistantsMap | undefined {
const { data: assistants = {} } = useListAssistantsQuery(EModelEndpoint.assistants, undefined, {
select: (res) => mapAssistants(res.data),
enabled: isAuthenticated,

View file

@ -32,7 +32,7 @@ export default function useMessageActions(props: TMessageActions) {
} = useChatContext();
const { conversation: addedConvo, isSubmitting: isSubmittingAdditional } = useAddedChatContext();
const conversation = useMemo(
() => (isMultiMessage ? addedConvo : rootConvo),
() => (isMultiMessage === true ? addedConvo : rootConvo),
[isMultiMessage, addedConvo, rootConvo],
);
const assistantMap = useAssistantsMapContext();
@ -41,24 +41,28 @@ export default function useMessageActions(props: TMessageActions) {
const edit = useMemo(() => messageId === currentEditId, [messageId, currentEditId]);
const enterEdit = useCallback(
(cancel?: boolean) => setCurrentEditId && setCurrentEditId(cancel ? -1 : messageId),
(cancel?: boolean) => setCurrentEditId && setCurrentEditId(cancel === true ? -1 : messageId),
[messageId, setCurrentEditId],
);
const assistant = useMemo(
() =>
isAssistantsEndpoint(conversation?.endpoint) &&
assistantMap?.[conversation?.endpoint ?? '']?.[message?.model ?? ''],
[assistantMap, conversation?.endpoint, message?.model],
);
const assistant = useMemo(() => {
if (!isAssistantsEndpoint(conversation?.endpoint)) {
return undefined;
}
const endpointKey = conversation?.endpoint ?? '';
const modelKey = message?.model ?? '';
return assistantMap?.[endpointKey] ? assistantMap[endpointKey][modelKey] : undefined;
}, [conversation?.endpoint, message?.model, assistantMap]);
const isSubmitting = useMemo(
() => (isMultiMessage ? isSubmittingAdditional : isSubmittingRoot),
() => (isMultiMessage === true ? isSubmittingAdditional : isSubmittingRoot),
[isMultiMessage, isSubmittingAdditional, isSubmittingRoot],
);
const regenerateMessage = useCallback(() => {
if ((isSubmitting && isCreatedByUser) || !message) {
if ((isSubmitting && isCreatedByUser === true) || !message) {
return;
}
@ -68,8 +72,8 @@ export default function useMessageActions(props: TMessageActions) {
const copyToClipboard = useCopyToClipboard({ text, content });
const messageLabel = useMemo(() => {
if (message?.isCreatedByUser) {
return UsernameDisplay ? user?.name || user?.username : localize('com_user_message');
if (message?.isCreatedByUser === true) {
return UsernameDisplay ? user?.name != null || user?.username : localize('com_user_message');
} else if (assistant) {
return assistant.name ?? 'Assistant';
} else {

View file

@ -1,4 +1,4 @@
import { useEffect, useRef, useCallback } from 'react';
import { useEffect, useRef, useCallback, useMemo } from 'react';
import { Constants, isAssistantsEndpoint } from 'librechat-data-provider';
import type { TMessageProps } from '~/common';
import { useChatContext, useAssistantsMapContext } from '~/Providers';
@ -24,7 +24,7 @@ export default function useMessageHelpers(props: TMessageProps) {
const { text, content, children, messageId = null, isCreatedByUser } = message ?? {};
const edit = messageId === currentEditId;
const isLast = !children?.length;
const isLast = children?.length === 0 || children?.length === undefined;
useEffect(() => {
const convoId = conversation?.conversationId;
@ -44,7 +44,7 @@ export default function useMessageHelpers(props: TMessageProps) {
const logInfo = {
textKey,
'latestText.current': latestText.current,
messageId: message?.messageId,
messageId: message.messageId,
convoId,
};
if (
@ -60,7 +60,7 @@ export default function useMessageHelpers(props: TMessageProps) {
}, [isLast, message, setLatestMessage, conversation?.conversationId]);
const enterEdit = useCallback(
(cancel?: boolean) => setCurrentEditId && setCurrentEditId(cancel ? -1 : messageId),
(cancel?: boolean) => setCurrentEditId && setCurrentEditId(cancel === true ? -1 : messageId),
[messageId, setCurrentEditId],
);
@ -72,12 +72,19 @@ export default function useMessageHelpers(props: TMessageProps) {
}
}, [isSubmitting, setAbortScroll]);
const assistant =
isAssistantsEndpoint(conversation?.endpoint) &&
assistantMap?.[conversation?.endpoint ?? '']?.[message?.model ?? ''];
const assistant = useMemo(() => {
if (!isAssistantsEndpoint(conversation?.endpoint)) {
return undefined;
}
const endpointKey = conversation?.endpoint ?? '';
const modelKey = message?.model ?? '';
return assistantMap?.[endpointKey] ? assistantMap[endpointKey][modelKey] : undefined;
}, [conversation?.endpoint, message?.model, assistantMap]);
const regenerateMessage = () => {
if ((isSubmitting && isCreatedByUser) || !message) {
if ((isSubmitting && isCreatedByUser === true) || !message) {
return;
}