diff --git a/www/app.js b/www/app.js index cea10cb..38a7b40 100644 --- a/www/app.js +++ b/www/app.js @@ -3957,6 +3957,9 @@ async function streamGenerate(userMsgIndex) { syncConversationToBackend(currentConversation); renderMessages(); + // 记录统计到 backend + logStatsToBackend('llm_call', currentConversation.agentId || 'chat', 1); + // 自动总结标题:第一次对话和每隔5次对话 const totalMessages = currentConversation.messages.length; // 第一次对话(用户+AI=2条)或每5次对话(10条) @@ -3966,6 +3969,15 @@ async function streamGenerate(userMsgIndex) { } } +// 记录统计到 backend +function logStatsToBackend(type, key, value = 1) { + fetch('/api/admin/stats/log', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ type, key, value }) + }).catch(e => console.error('统计记录失败:', e)); +} + // 执行 Tavily 搜索 async function performSearch(query) { try { @@ -3988,6 +4000,10 @@ async function performSearch(query) { } const data = await response.json(); + + // 记录搜索统计 + logStatsToBackend('search_call', 'tavily', 1); + return data.results || []; } catch (error) { console.error('搜索错误:', error);