mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-03-09 09:32:36 +01:00
* refactor: `ExecuteCode` component with submission state handling and cancellation message * fix: Remove unnecessary argument check for execute_code tool call * refactor: streamlined messages context * chore: remove unused Convo prop * chore: remove unnecessary whitespace in Message component * refactor: enhance message context with submission state and latest message tracking * chore: import order
50 lines
1.7 KiB
TypeScript
50 lines
1.7 KiB
TypeScript
import { memo, useMemo, ReactElement } from 'react';
|
|
import { useRecoilValue } from 'recoil';
|
|
import MarkdownLite from '~/components/Chat/Messages/Content/MarkdownLite';
|
|
import Markdown from '~/components/Chat/Messages/Content/Markdown';
|
|
import { useMessageContext } from '~/Providers';
|
|
import { cn } from '~/utils';
|
|
import store from '~/store';
|
|
|
|
type TextPartProps = {
|
|
text: string;
|
|
showCursor: boolean;
|
|
isCreatedByUser: boolean;
|
|
};
|
|
|
|
type ContentType =
|
|
| ReactElement<React.ComponentProps<typeof Markdown>>
|
|
| ReactElement<React.ComponentProps<typeof MarkdownLite>>
|
|
| ReactElement;
|
|
|
|
const TextPart = memo(({ text, isCreatedByUser, showCursor }: TextPartProps) => {
|
|
const { isSubmitting = false, isLatestMessage = false } = useMessageContext();
|
|
const enableUserMsgMarkdown = useRecoilValue(store.enableUserMsgMarkdown);
|
|
const showCursorState = useMemo(() => showCursor && isSubmitting, [showCursor, isSubmitting]);
|
|
|
|
const content: ContentType = useMemo(() => {
|
|
if (!isCreatedByUser) {
|
|
return <Markdown content={text} isLatestMessage={isLatestMessage} />;
|
|
} else if (enableUserMsgMarkdown) {
|
|
return <MarkdownLite content={text} />;
|
|
} else {
|
|
return <>{text}</>;
|
|
}
|
|
}, [isCreatedByUser, enableUserMsgMarkdown, text, isLatestMessage]);
|
|
|
|
return (
|
|
<div
|
|
className={cn(
|
|
isSubmitting ? 'submitting' : '',
|
|
showCursorState && !!text.length ? 'result-streaming' : '',
|
|
'markdown prose message-content dark:prose-invert light w-full break-words',
|
|
isCreatedByUser && !enableUserMsgMarkdown && 'whitespace-pre-wrap',
|
|
isCreatedByUser ? 'dark:text-gray-20' : 'dark:text-gray-100',
|
|
)}
|
|
>
|
|
{content}
|
|
</div>
|
|
);
|
|
});
|
|
|
|
export default TextPart;
|