fix: 搜索功能修复

- 添加详细日志帮助调试
- 搜索结果发送到前端展示
- 前端增加搜索结果展示组件
- 修复 datetime 导入错误
This commit is contained in:
2026-04-13 16:34:00 +08:00
parent 142904dff4
commit 25e92b1fb1
3 changed files with 66 additions and 5 deletions

View File

@@ -86,6 +86,13 @@
.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-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; }
/* Agent信息 */
.agent-info { font-size: 12px; color: #999; margin-top: 8px; }
@@ -286,6 +293,7 @@
document.getElementById('sendBtn').disabled = false;
break;
case 'error': showError(data.message); document.getElementById('sendBtn').disabled = false; break;
case 'search_results': displaySearchResults(data.results, data.query); break;
}
}
@@ -623,6 +631,33 @@
container.appendChild(div);
}
function displaySearchResults(results, query) {
if (!results || results.length === 0) return;
const container = document.getElementById('messagesContainer');
const div = document.createElement('div');
div.className = 'message assistant';
let html = `<div class="message-avatar">🔍</div><div class="message-body">
<div class="search-results-box">
<h5>搜索: ${escapeHtml(query.substring(0, 50))}${query.length > 50 ? '...' : ''}</h5>`;
for (const r of results) {
html += `<div class="search-result-item">
<div class="search-result-title">${escapeHtml(r.title)}</div>
<div class="search-result-snippet">${escapeHtml(r.snippet)}</div>
<div class="search-result-url">${escapeHtml(r.url)}</div>
</div>`;
}
html += '</div></div>';
div.innerHTML = html;
container.appendChild(div);
// 滚动到底部
container.scrollTop = container.scrollHeight;
}
// 会话管理
async function loadConversations() {
const res = await fetch('/api/conversations');