fix(frontend): unify think tag parsing between stream and history

Two consistency fixes for <think> 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 </think> 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 </think> occurrences.

Both paths now use identical logic: lastIndexOf('</think>') to find
the boundary, substring(0, index) for thinkContent, substring(index+8)
for answer content.
This commit is contained in:
lyingbug
2026-03-20 22:38:09 +00:00
committed by lyingbug
parent e5c46642e9
commit 34d711d15f
+6 -5
View File
@@ -273,12 +273,11 @@ const handleMsgList = async (data, isScrollType = false, newScrollHeight) => {
item.thinking = false;
} else if (item.content.includes('<\/think>')) {
// 历史消息中包含完整的 <think>...</think> 标签,说明 thinking 已完成
const arr = item.content.trim().split('<\/think>');
item.showThink = true;
item.thinking = false; // 关键:标记 thinking 已完成,使 deepThink 默认折叠
item.thinkContent = arr[0].trim().replace('<think>', '');
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('<think>', '').trim();
item.content = item.content.trim().substring(index + 8);
} else if (item.content.includes('<think>')) {
// 内容包含 <think> 但没有 </think>,说明 thinking 还在进行中(不太可能出现在历史消息中)
item.showThink = true;
@@ -576,7 +575,9 @@ onChunk((data) => {
} else if (fullContent.value.includes('<think>') && fullContent.value.includes('<\/think>')) {
obj.thinking = false;
obj.showThink = true;
const index = fullContent.value.indexOf('<\/think>');
// Use lastIndexOf to handle edge cases with multiple </think> occurrences,
// consistent with history loading logic (line 280)
const index = fullContent.value.lastIndexOf('<\/think>');
obj.thinkContent = fullContent.value.substring(0, index).replace('<think>', '').trim();
obj.content = fullContent.value.substring(index + 8).trim();
} else {