diff --git a/backend/app/service/chat_service.py b/backend/app/service/chat_service.py index 18bab0ac..4b438e64 100644 --- a/backend/app/service/chat_service.py +++ b/backend/app/service/chat_service.py @@ -558,8 +558,7 @@ async def step_solve(options: Chat, request: Request, task_lock: TaskLock): task_lock.add_conversation('assistant', answer_content) - # Send response to user - yield sse_json("confirmed", {"question": new_task_content}) + # Send response to user (don't send confirmed if simple response) yield sse_json("wait_confirm", {"content": answer_content, "question": new_task_content}) except Exception as e: logger.error(f"Error generating simple answer in multi-turn: {e}") diff --git a/src/store/chatStore.ts b/src/store/chatStore.ts index 1c939400..97804c0a 100644 --- a/src/store/chatStore.ts +++ b/src/store/chatStore.ts @@ -624,8 +624,12 @@ const chatStore = (initial?: Partial) => createStore()( const currentChatStore = getCurrentChatStore(); //Make sure to add user Message on replay and avoid duplication of first msg - if(type === "replay" && question && - !(currentChatStore.tasks[currentTaskId].messages.length === 1)) { + if(question && !(currentChatStore.tasks[currentTaskId].messages.length === 1)) { + //Replace the optimistic update if existent. + const lastMessage = currentChatStore.tasks[currentTaskId]?.messages.at(-1); + if(lastMessage?.role === "user" && lastMessage.id && lastMessage.content === question) { + currentChatStore.removeMessage(currentTaskId, lastMessage.id) + } addMessages(currentTaskId, { id: generateUniqueId(), role: "user",