fix(chat): prevent duplicate renderer requests and thinking messages (#870)
Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Haze <hazeone@users.noreply.github.com>
This commit is contained in:
@@ -5,11 +5,13 @@ import {
|
||||
clearHistoryPoll,
|
||||
enrichWithCachedImages,
|
||||
enrichWithToolResultFiles,
|
||||
getLatestOptimisticUserMessage,
|
||||
getMessageText,
|
||||
hasNonToolAssistantContent,
|
||||
isInternalMessage,
|
||||
isToolResultRole,
|
||||
loadMissingPreviews,
|
||||
matchesOptimisticUserMessage,
|
||||
toMs,
|
||||
} from './helpers';
|
||||
import { buildCronSessionHistoryPath, isCronSessionKey } from './cron-session-utils';
|
||||
@@ -101,17 +103,12 @@ export function createHistoryActions(
|
||||
const userMsgAt = get().lastUserMessageAt;
|
||||
if (get().sending && userMsgAt) {
|
||||
const userMsMs = toMs(userMsgAt);
|
||||
const hasRecentUser = enrichedMessages.some(
|
||||
(m) => m.role === 'user' && m.timestamp && Math.abs(toMs(m.timestamp) - userMsMs) < 5000,
|
||||
);
|
||||
if (!hasRecentUser) {
|
||||
const currentMsgs = get().messages;
|
||||
const optimistic = [...currentMsgs].reverse().find(
|
||||
(m) => m.role === 'user' && m.timestamp && Math.abs(toMs(m.timestamp) - userMsMs) < 5000,
|
||||
);
|
||||
if (optimistic) {
|
||||
finalMessages = [...enrichedMessages, optimistic];
|
||||
}
|
||||
const optimistic = getLatestOptimisticUserMessage(get().messages, userMsMs);
|
||||
const hasMatchingUser = optimistic
|
||||
? enrichedMessages.some((message) => matchesOptimisticUserMessage(message, optimistic, userMsMs))
|
||||
: false;
|
||||
if (optimistic && !hasMatchingUser) {
|
||||
finalMessages = [...enrichedMessages, optimistic];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user