Skip to content

Commit fbaff71

Browse files
Merge pull request #320 from SmythOS/fix/chat-stopped-request-response
Chat Interface – Fixed Response to Previous Stopped Request Instead of New Message
2 parents 101ba92 + 433a820 commit fbaff71

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

packages/app/src/react/features/ai-chat/components/system-message.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export const SystemMessage: FC<ISystemMessageProps> = (props) => {
3434

3535
const contentRef = useRef<HTMLDivElement>(null);
3636

37+
if (!message) return null; // if message is empty, return null
38+
3739
return (
3840
<div className="system-message-bubble relative">
3941
{isError ? (

packages/app/src/react/features/ai-chat/hooks/use-chat.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,23 @@ export const useChat = (config: IUseChatConfig): IUseChatReturn => {
308308
setIsProcessing(true);
309309
clearError();
310310

311+
// Remove any previous error messages and loading messages before sending new message
312+
setMessages((prev) => {
313+
// Check if there are any error messages (indicates stopped generation)
314+
const hasErrorMessages = prev.some((msg) => msg.type === 'error');
315+
316+
// Remove error messages
317+
const filtered = prev.filter((msg) => msg.type !== 'error');
318+
319+
// If there were error messages and the last message is loading,
320+
if (hasErrorMessages && filtered.length > 0) {
321+
const lastMessage = filtered[filtered.length - 1];
322+
if (lastMessage.type === 'loading') return filtered.slice(0, -1);
323+
}
324+
325+
return filtered;
326+
});
327+
311328
// Upload files if present
312329
let attachments: IFileAttachment[] = [];
313330
if (files && files.length > 0) {

0 commit comments

Comments
 (0)