mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-05-26 09:55:59 +00:00
fix(frontend): avoid duplicate optimistic user message (#3002)
This commit is contained in:
@@ -135,6 +135,20 @@ function getMessagesAfterBaseline(
|
||||
});
|
||||
}
|
||||
|
||||
export function getVisibleOptimisticMessages(
|
||||
optimisticMessages: Message[],
|
||||
previousHumanMessageCount: number,
|
||||
currentHumanMessageCount: number,
|
||||
): Message[] {
|
||||
if (
|
||||
optimisticMessages.some((message) => message.type === "human") &&
|
||||
currentHumanMessageCount > previousHumanMessageCount
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
return optimisticMessages;
|
||||
}
|
||||
|
||||
function getStreamErrorMessage(error: unknown): string {
|
||||
if (typeof error === "string" && error.trim()) {
|
||||
return error;
|
||||
@@ -627,10 +641,16 @@ export function useThreadStream({
|
||||
messagesRef.current = thread.messages;
|
||||
}
|
||||
|
||||
const visibleOptimisticMessages = getVisibleOptimisticMessages(
|
||||
optimisticMessages,
|
||||
prevHumanMsgCountRef.current,
|
||||
humanMessageCount,
|
||||
);
|
||||
|
||||
const mergedMessages = mergeMessages(
|
||||
history,
|
||||
thread.messages,
|
||||
optimisticMessages,
|
||||
visibleOptimisticMessages,
|
||||
);
|
||||
const pendingUsageMessages = thread.isLoading
|
||||
? getMessagesAfterBaseline(
|
||||
|
||||
Reference in New Issue
Block a user