fix(chat): prevent duplicate user messages in conversation history (#258)
Build conversation_history before adding the new user message to the session, so the message is sent only via `input` and not duplicated in `conversation_history` as well. Closes #257 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -777,6 +777,14 @@ export const useChatStore = defineStore('chat', () => {
|
|||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
attachments: attachments && attachments.length > 0 ? attachments : undefined,
|
attachments: attachments && attachments.length > 0 ? attachments : undefined,
|
||||||
}
|
}
|
||||||
|
// Build conversation history BEFORE adding the new message, so the
|
||||||
|
// user's current message appears only in `input` — not duplicated in
|
||||||
|
// `conversation_history` as well.
|
||||||
|
const sessionMsgs = getSessionMsgs(sid)
|
||||||
|
const history: ChatMessage[] = sessionMsgs
|
||||||
|
.filter(m => (m.role === 'user' || m.role === 'assistant') && m.content.trim())
|
||||||
|
.map(m => ({ role: m.role as 'user' | 'assistant' | 'system', content: m.content }))
|
||||||
|
|
||||||
addMessage(sid, userMsg)
|
addMessage(sid, userMsg)
|
||||||
updateSessionTitle(sid)
|
updateSessionTitle(sid)
|
||||||
// Persist immediately so a refresh before the first SSE event (e.g. the
|
// Persist immediately so a refresh before the first SSE event (e.g. the
|
||||||
@@ -788,11 +796,6 @@ export const useChatStore = defineStore('chat', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Build conversation history from past messages
|
|
||||||
const sessionMsgs = getSessionMsgs(sid)
|
|
||||||
const history: ChatMessage[] = sessionMsgs
|
|
||||||
.filter(m => (m.role === 'user' || m.role === 'assistant') && m.content.trim())
|
|
||||||
.map(m => ({ role: m.role as 'user' | 'assistant' | 'system', content: m.content }))
|
|
||||||
|
|
||||||
// Upload attachments and build input with file paths
|
// Upload attachments and build input with file paths
|
||||||
let inputText = content.trim()
|
let inputText = content.trim()
|
||||||
|
|||||||
Reference in New Issue
Block a user