diff --git a/packages/app/src/react/features/ai-chat/components/system-message.tsx b/packages/app/src/react/features/ai-chat/components/system-message.tsx index 8b03f6c5..5c6ffbd2 100644 --- a/packages/app/src/react/features/ai-chat/components/system-message.tsx +++ b/packages/app/src/react/features/ai-chat/components/system-message.tsx @@ -34,6 +34,8 @@ export const SystemMessage: FC = (props) => { const contentRef = useRef(null); + if (!message) return null; // if message is empty, return null + return (
{isError ? ( diff --git a/packages/app/src/react/features/ai-chat/hooks/use-chat.ts b/packages/app/src/react/features/ai-chat/hooks/use-chat.ts index 0b84f0e3..40c63f7a 100644 --- a/packages/app/src/react/features/ai-chat/hooks/use-chat.ts +++ b/packages/app/src/react/features/ai-chat/hooks/use-chat.ts @@ -308,6 +308,23 @@ export const useChat = (config: IUseChatConfig): IUseChatReturn => { setIsProcessing(true); clearError(); + // Remove any previous error messages and loading messages before sending new message + setMessages((prev) => { + // Check if there are any error messages (indicates stopped generation) + const hasErrorMessages = prev.some((msg) => msg.type === 'error'); + + // Remove error messages + const filtered = prev.filter((msg) => msg.type !== 'error'); + + // If there were error messages and the last message is loading, + if (hasErrorMessages && filtered.length > 0) { + const lastMessage = filtered[filtered.length - 1]; + if (lastMessage.type === 'loading') return filtered.slice(0, -1); + } + + return filtered; + }); + // Upload files if present let attachments: IFileAttachment[] = []; if (files && files.length > 0) {