mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
most recent error only
This commit is contained in:
1 parent
3a8e040212
commit
e88a11ce21
2 files changed
+35
-7
No files matched your search
@@ -276,7 +276,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
// Function to suggest error fix
|
||||
// Clean alert hooks with proper interfaces
|
||||
const aiModelAlert = useAIModelErrorAlert(messages, _onNewChat, openModelSelector);
|
||||
const consoleAlert = useConsoleErrorAlert();
|
||||
const consoleAlert = useConsoleErrorAlert(messages, isBuildLoading, internalIsLoading);
|
||||
|
||||
// Scroll to bottom when alerts appear
|
||||
useEffect(() => {
|
||||
|
||||
@@ -9,26 +9,51 @@ export interface ConsoleErrorAlert {
|
||||
dismiss: () => void;
|
||||
}
|
||||
|
||||
export const useConsoleErrorAlert = (): ConsoleErrorAlert => {
|
||||
export const useConsoleErrorAlert = (
|
||||
aiMessages: AIMessage[],
|
||||
isBuilding?: boolean,
|
||||
isLoading?: boolean
|
||||
): ConsoleErrorAlert => {
|
||||
const { messages } = useConsoleMessages();
|
||||
const [dismissedErrorSummary, setDismissedErrorSummary] = useState<string>('');
|
||||
|
||||
const { hasError, errorSummary, errorCount } = useMemo(() => {
|
||||
const errors = messages.filter(msg => msg.level === 'error');
|
||||
// Don't show alerts while building or AI is working
|
||||
if (isBuilding || isLoading) {
|
||||
return { hasError: false, errorSummary: null, errorCount: 0 };
|
||||
}
|
||||
|
||||
if (errors.length === 0) {
|
||||
// Find the timestamp of the last AI assistant message
|
||||
// Since AIMessage doesn't have timestamps, we'll use a different approach:
|
||||
// Only show errors if there are any errors at all and no recent user activity
|
||||
const lastMessage = aiMessages[aiMessages.length - 1];
|
||||
const isLastMessageFromAssistant = lastMessage?.role === 'assistant';
|
||||
|
||||
// Only show console errors if the last message was from assistant (AI just responded)
|
||||
if (!isLastMessageFromAssistant) {
|
||||
return { hasError: false, errorSummary: null, errorCount: 0 };
|
||||
}
|
||||
|
||||
// Get recent errors (last 10 seconds worth to catch errors from recent AI actions)
|
||||
const recentTimeThreshold = Date.now() - (10 * 1000); // 10 seconds ago
|
||||
const recentErrors = messages.filter(msg =>
|
||||
msg.level === 'error' &&
|
||||
msg.timestamp > recentTimeThreshold
|
||||
);
|
||||
|
||||
if (recentErrors.length === 0) {
|
||||
return { hasError: false, errorSummary: null, errorCount: 0 };
|
||||
}
|
||||
|
||||
// Just return the raw error messages, no formatting
|
||||
const summary = errors.slice(-3).map(e => e.message).join('\n');
|
||||
const summary = recentErrors.slice(-3).map(e => e.message).join('\n');
|
||||
|
||||
return {
|
||||
hasError: dismissedErrorSummary !== summary,
|
||||
errorSummary: summary,
|
||||
errorCount: errors.length
|
||||
errorCount: recentErrors.length
|
||||
};
|
||||
}, [messages, dismissedErrorSummary]);
|
||||
}, [messages, dismissedErrorSummary, aiMessages, isBuilding, isLoading]);
|
||||
|
||||
const dismiss = useCallback(() => {
|
||||
if (errorSummary) {
|
||||
@@ -61,6 +86,9 @@ export const useAIModelErrorAlert = (
|
||||
|
||||
const { hasError, errorMessage, errorType, action } = useMemo(() => {
|
||||
const lastMessage = messages[messages.length - 1];
|
||||
|
||||
// Only show AI model alerts if the last message is from the assistant
|
||||
// This ensures we don't show stale alerts when user continues the conversation
|
||||
if (!lastMessage || lastMessage.role !== 'assistant') {
|
||||
return { hasError: false, errorMessage: null, errorType: null, action: undefined };
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user