Skip to content

Commit bca96b7

Browse files
Update src/components/ai-assistant/AITeachingAssistant.tsx
Co-authored-by: Copilot <[email protected]>
1 parent 4139e3e commit bca96b7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/components/ai-assistant/AITeachingAssistant.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,13 @@ export default function AITeachingAssistant({
154154
} catch (err) {
155155
console.error('Chat error:', err);
156156
setError(err instanceof Error ? err.message : 'An error occurred');
157-
// Remove the empty assistant message if there was an error
158-
setMessages((prev) => prev.filter((msg) => msg.content !== ''));
157+
// Remove the last assistant message if there was an error
158+
setMessages((prev) => {
159+
if (prev.length > 0 && prev[prev.length - 1].role === 'assistant') {
160+
return prev.slice(0, -1);
161+
}
162+
return prev;
163+
});
159164
} finally {
160165
setIsLoading(false);
161166
}

0 commit comments

Comments
 (0)