fix: appendMessage 接收 extraData 参数,在创建消息时直接处理搜索结果显示
This commit is contained in:
@@ -304,7 +304,7 @@
|
||||
}
|
||||
|
||||
// 消息渲染
|
||||
function appendMessage(role, content, thinking = null, agentName = null) {
|
||||
function appendMessage(role, content, thinking = null, agentName = null, extraData = null) {
|
||||
const container = document.getElementById('messagesContainer');
|
||||
container.querySelector('.welcome')?.remove();
|
||||
|
||||
@@ -372,6 +372,15 @@
|
||||
html += '</div>';
|
||||
div.innerHTML = html;
|
||||
container.appendChild(div);
|
||||
|
||||
// 如果是用户消息且有搜索结果,追加显示
|
||||
if (role === 'user' && extraData && extraData.search_results && extraData.search_results.length > 0) {
|
||||
const msgBody = div.querySelector('.message-body');
|
||||
if (msgBody) {
|
||||
msgBody.innerHTML += buildSearchResultsHtml(extraData.search_results, extraData.search_query || content);
|
||||
}
|
||||
}
|
||||
|
||||
container.scrollTop = container.scrollHeight;
|
||||
}
|
||||
|
||||
@@ -623,29 +632,10 @@
|
||||
const container = document.getElementById('messagesContainer');
|
||||
container.innerHTML = '';
|
||||
messages.forEach(m => {
|
||||
appendMessage(m.role, m.content, m.thinking_content);
|
||||
// 如果用户消息有搜索结果,追加显示
|
||||
if (m.role === 'user' && m.extra_data && m.extra_data.search_results) {
|
||||
displaySearchResultsForHistory(m.extra_data.search_results, m.extra_data.search_query || m.content);
|
||||
}
|
||||
appendMessage(m.role, m.content, m.thinking_content, null, m.extra_data);
|
||||
});
|
||||
}
|
||||
|
||||
function displaySearchResultsForHistory(results, query) {
|
||||
if (!results || results.length === 0) return;
|
||||
|
||||
const container = document.getElementById('messagesContainer');
|
||||
const userMessages = container.querySelectorAll('.message.user');
|
||||
const lastUserMsg = userMessages[userMessages.length - 1];
|
||||
|
||||
if (lastUserMsg) {
|
||||
const msgBody = lastUserMsg.querySelector('.message-body');
|
||||
if (msgBody) {
|
||||
msgBody.innerHTML += buildSearchResultsHtml(results, query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function clearMessages() {
|
||||
document.getElementById('messagesContainer').innerHTML = '<div class="welcome"><h2>👋 开始对话</h2></div>';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user