From 213b11c7070240358b8806187bfb0e8593f72c9c Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Mon, 27 Apr 2026 00:26:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=99=BA=E8=83=BD=E4=BD=93=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E6=94=B9=E4=B8=BA=E6=98=BE=E7=A4=BA=E6=AF=8F=E6=AC=A1?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D=E8=AE=B0=E5=BD=95=E8=80=8C=E9=9D=9E=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- www/app.js | 138 +++++++++++++++---------------------------------- www/index.html | 6 +-- www/style.css | 16 ++++++ 3 files changed, 61 insertions(+), 99 deletions(-) diff --git a/www/app.js b/www/app.js index ac6e73f..314e337 100644 --- a/www/app.js +++ b/www/app.js @@ -45,69 +45,19 @@ let agents = [ let currentAgent = null; // 当前选中的智能体 -// 智能体使用历史记录 -let agentUsageHistory = []; - -// 加载智能体使用历史 -function loadAgentUsageHistory() { - const saved = localStorage.getItem('agentUsageHistory'); - if (saved) { - agentUsageHistory = JSON.parse(saved); - } -} - -// 保存智能体使用历史 -function saveAgentUsageHistory() { - localStorage.setItem('agentUsageHistory', JSON.stringify(agentUsageHistory)); -} - -// 记录智能体使用 -function recordAgentUsage(agentId) { - const record = agentUsageHistory.find(r => r.agentId === agentId); - if (record) { - record.usageCount++; - record.lastUsedAt = Date.now(); - } else { - agentUsageHistory.push({ - agentId: agentId, - usageCount: 1, - lastUsedAt: Date.now() - }); - } - saveAgentUsageHistory(); -} - -// 格式化使用时间 -function formatUsageTime(timestamp) { - const now = Date.now(); - const diff = now - timestamp; - - const minute = 60 * 1000; - const hour = 60 * minute; - const day = 24 * hour; - const week = 7 * day; - const month = 30 * day; - const year = 365 * day; - - if (diff < minute) return '刚刚'; - if (diff < hour) return Math.floor(diff / minute) + '分钟前'; - if (diff < day) return Math.floor(diff / hour) + '小时前'; - if (diff < week) return Math.floor(diff / day) + '天前'; - if (diff < month) return Math.floor(diff / week) + '周前'; - if (diff < year) return Math.floor(diff / month) + '月前'; - return Math.floor(diff / year) + '年前'; -} - -// 获取最近使用的智能体(最多5个) -function getRecentUsedAgents(limit = 5) { - return agentUsageHistory - .sort((a, b) => b.lastUsedAt - a.lastUsedAt) +// 获取使用智能体的对话列表(按时间倒序) +function getAgentConversationHistory(limit = 5) { + return conversations + .filter(conv => conv.agentId) // 筛选有智能体的对话 + .sort((a, b) => b.updatedAt - a.updatedAt) // 按更新时间倒序 .slice(0, limit) - .map(record => { - const agent = agents.find(a => a.id === record.agentId); - return { ...agent, ...record }; - }) - .filter(a => a.id); // 过滤掉可能被删除的智能体 + .map(conv => { + const agent = agents.find(a => a.id === conv.agentId); + return { + ...conv, + agent: agent + }; + }); } // 功能开关 @@ -136,9 +86,6 @@ document.addEventListener('DOMContentLoaded', () => { conversations = JSON.parse(saved); } - // 加载智能体使用历史 - loadAgentUsageHistory(); - // 兼容旧数据格式(chat_history) const oldHistory = localStorage.getItem('chat_history'); if (oldHistory && conversations.length === 0) { @@ -401,9 +348,9 @@ function renderAgentsPage() { const studyAgents = agents.filter(a => a.category === 'study'); const lifeAgents = agents.filter(a => a.category === 'life'); - // 获取最近使用的智能体(最多5个) - const recentAgents = getRecentUsedAgents(5); - const totalRecentCount = agentUsageHistory.length; + // 获取使用智能体的对话历史(最多5个) + const recentAgentConvos = getAgentConversationHistory(5); + const totalAgentConvos = conversations.filter(c => c.agentId).length; return `