SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.
JavaScript a2aagentic-aiai-agentsdevtoolsmcp-clientn8n-alternativeno-codeopen-sourceorchestrationsmythosvisual-builder
Refactor chat actions to streamline thinking message handling
Salman-Ahamed3f9bcc4f64df
diff --git a/packages/app/src/react/features/ai-chat/hooks/use-chat-actions.ts b/packages/app/src/react/features/ai-chat/hooks/use-chat-actions.tsindex 58f0e083..168a6812 100644--- a/packages/app/src/react/features/ai-chat/hooks/use-chat-actions.ts+++ b/packages/app/src/react/features/ai-chat/hooks/use-chat-actions.ts@@ -136,6 +136,7 @@ export const useChatActions = ({updatedBubbles[lastSystemMessageIndex].isReplying = false;updatedBubbles[lastSystemMessageIndex].isError = errorInfo?.isError || false;updatedBubbles[lastSystemMessageIndex].hideMessageBubble = false; // Show the message bubble+ updatedBubbles[lastSystemMessageIndex].thinkingMessage = undefined; // Clear thinking messagereturn updatedBubbles;}return filteredBubbles;@@ -154,43 +155,15 @@ export const useChatActions = ({.filter(({ msg }) => msg.type === 'system').pop()?.index ?? -1;- // Check if there's already a thinking message after the last system message- const thinkingAfterSystem = bubbles- .slice(lastSystemIndex + 1)- .find((msg) => msg.type === 'thinking');-- if (thinkingAfterSystem) {- // Update existing thinking message- thinkingAfterSystem.message = thinking.message;- return [...bubbles];- } else {- // Add new thinking message after the last system message- const thinkingMessage: IChatMessage = {- me: false,- message: thinking.message,- type: 'thinking',- avatar,- isReplying: false, // Hide loading indicator for thinking messages- };-- const newBubbles = [...bubbles];- if (lastSystemIndex !== -1) {- // Insert after the last system message- newBubbles.splice(lastSystemIndex + 1, 0, thinkingMessage);-- // Hide the system message when thinking starts- // newBubbles[lastSystemIndex].hideMessageBubble = true;-- // Don't hide the system message when thinking starts - keep it visible during debug- // The message will only be hidden when actual content starts arriving- newBubbles[lastSystemIndex].isReplying = false;- } else {- // Add at the end if no system message- newBubbles.push(thinkingMessage);- }-- return newBubbles;+ if (lastSystemIndex !== -1) {+ // Update the existing system message with thinking message instead of creating separate bubble+ const updatedBubbles = [...bubbles];+ updatedBubbles[lastSystemIndex].thinkingMessage = thinking.message;+ updatedBubbles[lastSystemIndex].isReplying = false;+ return updatedBubbles;}++ return bubbles;});},onStart: () => {@@ -210,6 +183,14 @@ export const useChatActions = ({// Remove thinking messages when response is completeconst filteredMessages = prev.filter((msg) => msg.type !== 'thinking');const newMessages = [...filteredMessages];++ // Clear thinkingMessage from all system messages+ newMessages.forEach((msg) => {+ if (msg.type === 'system') {+ msg.thinkingMessage = undefined;+ }+ });+const lastMessage = newMessages[newMessages.length - 1];if (lastMessage) {lastMessage.isReplying = false;