Fix message ordering - create final response at end instead of updating existing
- Remove logic that updates existing assistant message - Always create new final response message at end of conversation - This ensures proper order: thinking → tool call → tool result → final response - Still prevents duplicates by checking existing content
This commit is contained in:
parent
55d54bce60
commit
8159950ffd
1 changed files with 12 additions and 22 deletions
|
|
@ -489,29 +489,19 @@ export const useStreamResponse = ({
|
||||||
const updated = [...prev]
|
const updated = [...prev]
|
||||||
const conv = updated.find((c) => c.id === conversationId)
|
const conv = updated.find((c) => c.id === conversationId)
|
||||||
if (conv) {
|
if (conv) {
|
||||||
// Check if there's already an assistant message with only reasoning content
|
// Always create a NEW message at the end (after tool calls) for final response
|
||||||
const existingAssistantMsg = assistantMessageIndex >= 0 ? conv.messages[assistantMessageIndex] : null
|
// Check if we already have a message with this content to avoid duplicates
|
||||||
if (existingAssistantMsg &&
|
const isDuplicate = conv.messages.some(msg =>
|
||||||
existingAssistantMsg.role === 'assistant' &&
|
msg.role === 'assistant' && msg.content === finalContent
|
||||||
(!existingAssistantMsg.content || existingAssistantMsg.content.trim() === '') &&
|
)
|
||||||
existingAssistantMsg.reasoning) {
|
if (!isDuplicate) {
|
||||||
// Update the existing assistant message with final content
|
conv.messages.push({
|
||||||
existingAssistantMsg.content = finalContent
|
role: 'assistant',
|
||||||
debugLog(`[useStreamResponse] Updated existing assistant message with final content:`, finalContent)
|
content: finalContent
|
||||||
|
})
|
||||||
|
debugLog(`[useStreamResponse] Added final assistant response at end:`, finalContent)
|
||||||
} else {
|
} else {
|
||||||
// Check if we already have a message with this content to avoid duplicates
|
debugLog(`[useStreamResponse] Skipping duplicate assistant response:`, finalContent)
|
||||||
const isDuplicate = conv.messages.some(msg =>
|
|
||||||
msg.role === 'assistant' && msg.content === finalContent
|
|
||||||
)
|
|
||||||
if (!isDuplicate) {
|
|
||||||
conv.messages.push({
|
|
||||||
role: 'assistant',
|
|
||||||
content: finalContent
|
|
||||||
})
|
|
||||||
debugLog(`[useStreamResponse] Added new final assistant response:`, finalContent)
|
|
||||||
} else {
|
|
||||||
debugLog(`[useStreamResponse] Skipping duplicate assistant response:`, finalContent)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return updated
|
return updated
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue