From e563acdf4da6a7fdc8b31c355ca714ad0fbb4c32 Mon Sep 17 00:00:00 2001 From: timothycarambat Date: Fri, 2 May 2025 16:05:22 -0700 Subject: [PATCH 1/2] handle no thoughts in container use imperative handler to handle thoughtless streaming and complete responses --- .../ChatHistory/ThoughtContainer/index.jsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ThoughtContainer/index.jsx b/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ThoughtContainer/index.jsx index cbc89a864ac..e9e714d3c19 100644 --- a/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ThoughtContainer/index.jsx +++ b/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ThoughtContainer/index.jsx @@ -22,6 +22,16 @@ export const THOUGHT_REGEX_COMPLETE = new RegExp( ); const THOUGHT_PREVIEW_LENGTH = isMobile ? 25 : 50; +function contentIsNotEmpty(content) { + return ( + content + .trim() + .replace(THOUGHT_REGEX_OPEN, "") + .replace(THOUGHT_REGEX_CLOSE, "") + .replace(/[\n\s]/g, "").length > 0 + ); +} + /** * Component to render a thought chain. * @param {string} content - The content of the thought chain. @@ -31,10 +41,14 @@ const THOUGHT_PREVIEW_LENGTH = isMobile ? 25 : 50; export const ThoughtChainComponent = forwardRef( ({ content: initialContent, expanded }, ref) => { const [content, setContent] = useState(initialContent); + const [hasReadableContent, setHasReadableContent] = useState( + contentIsNotEmpty(initialContent) + ); const [isExpanded, setIsExpanded] = useState(expanded); useImperativeHandle(ref, () => ({ updateContent: (newContent) => { setContent(newContent); + setHasReadableContent(contentIsNotEmpty(newContent)); }, })); @@ -49,7 +63,7 @@ export const ThoughtChainComponent = forwardRef( const autoExpand = isThinking && tagStrippedContent.length > THOUGHT_PREVIEW_LENGTH; const canExpand = tagStrippedContent.length > THOUGHT_PREVIEW_LENGTH; - if (!content || !content.length) return null; + if (!content || !content.length || !hasReadableContent) return null; function handleExpandClick() { if (!canExpand) return; From 4f092f98ff258a06965630e643bf989fad70cd7d Mon Sep 17 00:00:00 2001 From: timothycarambat Date: Fri, 2 May 2025 16:07:59 -0700 Subject: [PATCH 2/2] option chain --- .../ChatHistory/ThoughtContainer/index.jsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ThoughtContainer/index.jsx b/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ThoughtContainer/index.jsx index e9e714d3c19..53fb60dd80c 100644 --- a/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ThoughtContainer/index.jsx +++ b/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/ThoughtContainer/index.jsx @@ -22,13 +22,18 @@ export const THOUGHT_REGEX_COMPLETE = new RegExp( ); const THOUGHT_PREVIEW_LENGTH = isMobile ? 25 : 50; -function contentIsNotEmpty(content) { +/** + * Checks if the content has readable content. + * @param {string} content - The content to check. + * @returns {boolean} - Whether the content has readable content. + */ +function contentIsNotEmpty(content = "") { return ( content - .trim() - .replace(THOUGHT_REGEX_OPEN, "") - .replace(THOUGHT_REGEX_CLOSE, "") - .replace(/[\n\s]/g, "").length > 0 + ?.trim() + ?.replace(THOUGHT_REGEX_OPEN, "") + ?.replace(THOUGHT_REGEX_CLOSE, "") + ?.replace(/[\n\s]/g, "")?.length > 0 ); }