From cd65d6b3deb3a0d5ee9cec566f8f02cf67d68f18 Mon Sep 17 00:00:00 2001 From: duanfuxiang Date: Thu, 3 Jul 2025 12:15:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B8=85=E7=90=86=E8=BF=87?= =?UTF-8?q?=E6=97=B6=E5=AF=B9=E8=AF=9D=E7=9A=84=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=81=8A=E5=A4=A9=E7=AE=A1=E7=90=86=E5=99=A8?= =?UTF-8?q?=E4=BB=A5=E6=94=AF=E6=8C=81=E5=88=A0=E9=99=A4=E6=97=A7=E7=89=88?= =?UTF-8?q?=E6=9C=AC=EF=BC=8C=E4=BC=98=E5=8C=96=E6=9F=A5=E6=89=BE=E6=9C=80?= =?UTF-8?q?=E6=96=B0=E5=AF=B9=E8=AF=9D=E7=9A=84=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E5=9C=A8=E8=81=8A=E5=A4=A9=E5=8E=86=E5=8F=B2=E8=A7=86?= =?UTF-8?q?=E5=9B=BE=E4=B8=AD=E6=B7=BB=E5=8A=A0=E6=B8=85=E7=90=86=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/chat-view/ChatHistoryView.tsx | 32 +++++++++- src/database/json/chat/ChatManager.ts | 67 ++++++++++++++++++-- src/hooks/use-chat-history.ts | 8 +++ 3 files changed, 99 insertions(+), 8 deletions(-) diff --git a/src/components/chat-view/ChatHistoryView.tsx b/src/components/chat-view/ChatHistoryView.tsx index 3fa63cf..27e6ae6 100644 --- a/src/components/chat-view/ChatHistoryView.tsx +++ b/src/components/chat-view/ChatHistoryView.tsx @@ -1,4 +1,4 @@ -import { CheckSquare, Clock, Edit3, MessageSquare, Pencil, Search, Square, Trash2, CopyPlus } from 'lucide-react' +import { CheckSquare, Clock, CopyPlus, MessageSquare, Pencil, Search, Sparkles, Square, Trash2 } from 'lucide-react' import { Notice } from 'obsidian' import React, { useMemo, useRef, useState } from 'react' @@ -23,6 +23,7 @@ const ChatHistoryView = ({ deleteConversation, updateConversationTitle, chatList, + cleanupOutdatedChats, } = useChatHistory() // search term @@ -37,6 +38,25 @@ const ChatHistoryView = ({ const titleInputRefs = useRef>(new Map()) + const handleCleanup = async () => { + const confirmed = confirm('此操作将永久删除所有对话的历史版本,只保留最新版。这有助于清理数据,但操作不可撤销。确定要继续吗?') + if (!confirmed) { + return + } + + try { + const count = await cleanupOutdatedChats() + if (count > 0) { + new Notice(`成功清理了 ${count} 个过时的对话文件。`) + } else { + new Notice('没有需要清理的对话文件。') + } + } catch (error) { + new Notice('清理失败,请检查开发者控制台获取更多信息。') + console.error('Failed to cleanup outdated chats', error) + } + } + // handle search const handleSearch = (e: React.ChangeEvent) => { setSearchTerm(e.target.value) @@ -192,6 +212,14 @@ const ChatHistoryView = ({

{t('chat.history.title')}

+