diff --git a/templates/index.html b/templates/index.html index 21a4a16..2bce544 100644 --- a/templates/index.html +++ b/templates/index.html @@ -86,13 +86,17 @@ .thinking-toggle { font-size: 12px; color: #667eea; } .thinking-content { margin-top: 12px; display: none; } .thinking-content.expanded { display: block; } - .search-results-box { margin: 8px 0; padding: 12px; background: #f8f9fa; border-radius: 8px; border: 1px solid #e9ecef; } - .search-results-box h5 { margin: 0 0 8px; font-size: 14px; color: #495057; } - .search-result-item { margin-bottom: 8px; padding: 8px; background: white; border-radius: 6px; } + .search-results-box { margin: 12px 0; padding: 10px 12px; background: linear-gradient(135deg, #f0f7ff 0%, #e8f4f8 100%); border-radius: 8px; border: 1px solid #d0e8f0; } + .search-results-header { display: flex; align-items: center; justify-content: space-between; cursor: pointer; } + .search-results-header h5 { margin: 0; font-size: 13px; color: #10a37f; display: flex; align-items: center; gap: 6px; } + .search-results-toggle { font-size: 12px; color: #666; } + .search-results-content { margin-top: 10px; display: none; } + .search-results-content.expanded { display: block; } + .search-result-item { margin-bottom: 8px; padding: 8px 10px; background: white; border-radius: 6px; border: 1px solid #eee; } .search-result-item:last-child { margin-bottom: 0; } .search-result-title { font-size: 13px; color: #10a37f; font-weight: 500; margin-bottom: 4px; } .search-result-snippet { font-size: 12px; color: #666; line-height: 1.4; } - .search-result-url { font-size: 11px; color: #999; margin-top: 4px; } + .search-result-url { font-size: 11px; color: #999; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; } /* Agent信息 */ .agent-info { font-size: 12px; color: #999; margin-top: 8px; } @@ -635,12 +639,37 @@ if (!results || results.length === 0) return; const container = document.getElementById('messagesContainer'); - const div = document.createElement('div'); - div.className = 'message assistant'; - let html = `
🔍
-
-
搜索: ${escapeHtml(query.substring(0, 50))}${query.length > 50 ? '...' : ''}
`; + // 找到最后一条用户消息 + const userMessages = container.querySelectorAll('.message.user'); + const lastUserMsg = userMessages[userMessages.length - 1]; + + if (!lastUserMsg) { + // 没有用户消息,作为独立消息显示 + const div = document.createElement('div'); + div.className = 'message assistant'; + div.innerHTML = `
🔍
${buildSearchResultsHtml(results, query)}
`; + container.appendChild(div); + } else { + // 在用户消息的 message-body 中追加搜索结果 + const msgBody = lastUserMsg.querySelector('.message-body'); + if (msgBody) { + msgBody.innerHTML += buildSearchResultsHtml(results, query); + } + } + + // 滚动到底部 + container.scrollTop = container.scrollHeight; + } + + function buildSearchResultsHtml(results, query) { + const resultId = 'sr-' + Date.now(); + let html = `
+
+
搜索: ${escapeHtml(query.substring(0, 30))}${query.length > 30 ? '...' : ''} (${results.length}条结果)
+ 展开 +
+
`; for (const r of results) { html += `
@@ -651,11 +680,19 @@ } html += '
'; - div.innerHTML = html; - container.appendChild(div); - - // 滚动到底部 - container.scrollTop = container.scrollHeight; + return html; + } + + function toggleSearchResults(id) { + const content = document.getElementById(id); + const toggle = document.getElementById(id + '-toggle'); + if (content.classList.contains('expanded')) { + content.classList.remove('expanded'); + toggle.innerHTML = '展开 '; + } else { + content.classList.add('expanded'); + toggle.innerHTML = '收起 '; + } } // 会话管理