From 34d711d15fc5aa12bd5dffbd9c9259569fed0e59 Mon Sep 17 00:00:00 2001 From: lyingbug Date: Fri, 20 Mar 2026 22:38:09 +0000 Subject: [PATCH] fix(frontend): unify think tag parsing between stream and history Two consistency fixes for tag parsing in index.vue: 1. Streaming path (line 579): Changed indexOf to lastIndexOf when splitting thinking content from answer, matching the history loading path. Prevents incorrect splitting if appears multiple times (e.g., model discusses think tags in answer). 2. History loading path (line 274-281): Removed redundant split() call, now uses only lastIndexOf consistently. The split was creating an unnecessary intermediate array that could produce wrong results with multiple occurrences. Both paths now use identical logic: lastIndexOf('') to find the boundary, substring(0, index) for thinkContent, substring(index+8) for answer content. --- frontend/src/views/chat/index.vue | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/frontend/src/views/chat/index.vue b/frontend/src/views/chat/index.vue index 3d30eba6..d7690859 100644 --- a/frontend/src/views/chat/index.vue +++ b/frontend/src/views/chat/index.vue @@ -273,12 +273,11 @@ const handleMsgList = async (data, isScrollType = false, newScrollHeight) => { item.thinking = false; } else if (item.content.includes('<\/think>')) { // 历史消息中包含完整的 ... 标签,说明 thinking 已完成 - const arr = item.content.trim().split('<\/think>'); item.showThink = true; item.thinking = false; // 关键:标记 thinking 已完成,使 deepThink 默认折叠 - item.thinkContent = arr[0].trim().replace('', ''); - let index = item.content.trim().lastIndexOf('<\/think>') - item.content = item.content.substring(index + 8); + const index = item.content.trim().lastIndexOf('<\/think>'); + item.thinkContent = item.content.trim().substring(0, index).replace('', '').trim(); + item.content = item.content.trim().substring(index + 8); } else if (item.content.includes('')) { // 内容包含 但没有 ,说明 thinking 还在进行中(不太可能出现在历史消息中) item.showThink = true; @@ -576,7 +575,9 @@ onChunk((data) => { } else if (fullContent.value.includes('') && fullContent.value.includes('<\/think>')) { obj.thinking = false; obj.showThink = true; - const index = fullContent.value.indexOf('<\/think>'); + // Use lastIndexOf to handle edge cases with multiple occurrences, + // consistent with history loading logic (line 280) + const index = fullContent.value.lastIndexOf('<\/think>'); obj.thinkContent = fullContent.value.substring(0, index).replace('', '').trim(); obj.content = fullContent.value.substring(index + 8).trim(); } else {