@@ -179,3 +184,62 @@ function ChatAttachments({ attachments = [] }) {
);
}
+
+const RenderChatContent = memo(
+ ({ role, message, expanded = false }) => {
+ // If the message is not from the assistant, we can render it directly
+ // as normal since the user cannot think (lol)
+ if (role !== "assistant")
+ return (
+
+ );
+ let thoughtChain = null;
+ let msgToRender = message;
+
+ // If the message is a perfect thought chain, we can render it directly
+ // Complete == open and close tags match perfectly.
+ if (message.match(THOUGHT_REGEX_COMPLETE)) {
+ thoughtChain = message.match(THOUGHT_REGEX_COMPLETE)?.[0];
+ msgToRender = message.replace(THOUGHT_REGEX_COMPLETE, "");
+ }
+
+ // If the message is a thought chain but not a complete thought chain (matching opening tags but not closing tags),
+ // we can render it as a thought chain if we can at least find a closing tag
+ // This can occur when the assistant starts with and then 's later.
+ if (
+ message.match(THOUGHT_REGEX_OPEN) &&
+ message.match(THOUGHT_REGEX_CLOSE)
+ ) {
+ const closingTag = message.match(THOUGHT_REGEX_CLOSE)?.[0];
+ const splitMessage = message.split(closingTag);
+ thoughtChain = splitMessage[0] + closingTag;
+ msgToRender = splitMessage[1];
+ }
+
+ return (
+ <>
+ {thoughtChain && (
+
+ )}
+
+ >
+ );
+ },
+ (prevProps, nextProps) => {
+ return (
+ prevProps.role === nextProps.role &&
+ prevProps.message === nextProps.message &&
+ prevProps.expanded === nextProps.expanded
+ );
+ }
+);
diff --git a/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/PromptReply/index.jsx b/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/PromptReply/index.jsx
index a562a89811d..71169bf4e03 100644
--- a/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/PromptReply/index.jsx
+++ b/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/PromptReply/index.jsx
@@ -1,8 +1,14 @@
-import { memo } from "react";
+import { memo, useRef, useEffect } from "react";
import { Warning } from "@phosphor-icons/react";
import UserIcon from "../../../../UserIcon";
import renderMarkdown from "@/utils/chat/markdown";
import Citations from "../Citation";
+import {
+ THOUGHT_REGEX_CLOSE,
+ THOUGHT_REGEX_COMPLETE,
+ THOUGHT_REGEX_OPEN,
+ ThoughtChainComponent,
+} from "../ThoughtContainer";
const PromptReply = ({
uuid,
@@ -61,9 +67,9 @@ const PromptReply = ({