fix: 修复 AI 客服回复内容重复(区分 SSE delta/completed 事件,completed 仅作兜底)

This commit is contained in:
2026-10-19 19:31:04 +08:00
parent c8e651b7a6
commit e134209d16
2 changed files with 39 additions and 4 deletions
@@ -73,8 +73,13 @@ module.exports = {
if (p.conversation_id) conversationId = p.conversation_id;
// 处理回答内容
// 注意:conversation.message.completed 携带的是该条消息的完整内容,
// 若前面已经通过 delta 拼过,再拼一次就会重复,这里做去重
if (p.type === 'answer' && p.content) {
answer += p.content;
const isDup = eventName === 'conversation.message.completed' && answer.indexOf(p.content) >= 0;
if (!isDup) {
answer += p.content;
}
// 每积累 200 字更新一次数据库(前端轮询能看到进度)
if (answer.length - lastUpdateLen >= 200) {