Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 67 additions & 7 deletions src/main/presenter/devicePresenter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,12 @@ export class DevicePresenter implements IDevicePresenter {

/**
* 根据类型重置数据
* @param resetType 重置类型:'chat' | 'config' | 'all'
* @param resetType 重置类型:'chat' | 'knowledge' | 'config' | 'all'
*/
async resetDataByType(resetType: 'chat' | 'config' | 'all'): Promise<void> {
async resetDataByType(resetType: 'chat' | 'knowledge' | 'config' | 'all'): Promise<void> {
try {
const userDataPath = app.getPath('userData')
const { presenter } = await import('../index')

const removeDirectory = (dirPath: string): void => {
if (fs.existsSync(dirPath)) {
Expand All @@ -309,10 +310,55 @@ export class DevicePresenter implements IDevicePresenter {

switch (resetType) {
case 'chat': {
// 只删除聊天数据
const dbPath = path.join(userDataPath, 'app_db')
console.log('Resetting chat data:', dbPath)
removeDirectory(dbPath)
// 删除聊天数据
console.log('Resetting chat data...')
try {
if (presenter.sqlitePresenter) {
presenter.sqlitePresenter.close()
console.log('SQLite database connection closed')
}
await new Promise((resolve) => setTimeout(resolve, 500))
} catch (closeError) {
console.warn('Error closing SQLite connection:', closeError)
}
const appDbPath = path.join(userDataPath, 'app_db')
const mainDbFile = path.join(appDbPath, 'chat.db')
try {
removeFile(mainDbFile)
console.log('Removed chat database file')
} catch (error) {
console.warn('Failed to remove chat database file:', error)
}
const auxiliaryFiles = ['chat.db-wal', 'chat.db-shm']
auxiliaryFiles.forEach((fileName) => {
const filePath = path.join(appDbPath, fileName)
if (fs.existsSync(filePath)) {
try {
removeFile(filePath)
console.log('Cleaned up auxiliary file:', fileName)
} catch (error) {
console.warn('Failed to clean auxiliary file:', fileName, error)
}
}
})
break
}

case 'knowledge': {
// 删除知识库数据
console.log('Resetting knowledge base data...')
try {
if (presenter.knowledgePresenter) {
await presenter.knowledgePresenter.destroy()
console.log('Knowledge database connections closed')
}
await new Promise((resolve) => setTimeout(resolve, 500))
} catch (closeError) {
console.warn('Error closing knowledge database connections:', closeError)
}
const knowledgeDbPath = path.join(userDataPath, 'app_db', 'KnowledgeBase')
console.log('Removing knowledge base directory:', knowledgeDbPath)
removeDirectory(knowledgeDbPath)
break
}

Expand Down Expand Up @@ -346,7 +392,21 @@ export class DevicePresenter implements IDevicePresenter {

case 'all': {
// 删除整个用户数据目录
console.log('Performing complete reset of user data:', userDataPath)
console.log('Performing complete reset of user data...')
try {
if (presenter.sqlitePresenter) {
presenter.sqlitePresenter.close()
console.log('SQLite database connection closed')
}
if (presenter.knowledgePresenter) {
await presenter.knowledgePresenter.destroy()
console.log('Knowledge database connections closed')
}
await new Promise((resolve) => setTimeout(resolve, 1000))
} catch (closeError) {
console.warn('Error closing database connections:', closeError)
}
console.log('Removing user data directory:', userDataPath)
removeDirectory(userDataPath)
break
}
Expand Down
16 changes: 15 additions & 1 deletion src/renderer/src/components/settings/DataSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@
</p>
</div>
</div>
<div
class="flex items-start space-x-3 cursor-pointer hover:bg-accent rounded-lg p-2 -m-2"
@click="resetType = 'knowledge'"
>
<RadioGroupItem value="knowledge" id="reset-knowledge" class="mt-1" />
<div class="flex flex-col">
<Label for="reset-knowledge" class="font-medium cursor-pointer">{{
t('settings.data.resetKnowledgeData')
}}</Label>
<p class="text-xs text-muted-foreground">
{{ t('settings.data.resetKnowledgeDataDesc') }}
</p>
</div>
</div>
<div
class="flex items-start space-x-3 cursor-pointer hover:bg-accent rounded-lg p-2 -m-2"
@click="resetType = 'config'"
Expand Down Expand Up @@ -266,7 +280,7 @@ const isImportDialogOpen = ref(false)
const importMode = ref('increment')

const isResetDialogOpen = ref(false)
const resetType = ref<'chat' | 'config' | 'all'>('chat')
const resetType = ref<'chat' | 'knowledge' | 'config' | 'all'>('chat')
const isResetting = ref(false)

// 使用计算属性处理双向绑定
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/i18n/en-US/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
"resetConfirmDescription": "Please select the type of data to reset. This operation cannot be undone and the application will restart automatically after reset.",
"resetChatData": "Reset Chat Data",
"resetChatDataDesc": "Delete all chat history and conversation records",
"resetKnowledgeData": "Reset Knowledge Base Data",
"resetKnowledgeDataDesc": "Delete all knowledge base files and vector data",
"resetConfig": "Reset Configuration",
"resetConfigDesc": "Delete all app settings, model configurations and custom prompts",
"resetAll": "Complete Reset",
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/i18n/fa-IR/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
"resetConfirmDescription": "لطفاً نوع داده‌هایی که می‌خواهید بازنشانی کنید را انتخاب کنید. این عملیات غیرقابل بازگشت است و پس از بازنشانی، برنامه به طور خودکار مجدداً راه‌اندازی خواهد شد.",
"resetChatData": "بازنشانی داده‌های گفت‌وگو",
"resetChatDataDesc": "حذف تمام تاریخچه گفت‌وگوها و سوابق مکالمات",
"resetKnowledgeData": "بازنشانی داده‌های پایگاه دانش",
"resetKnowledgeDataDesc": "حذف تمام فایل‌های پایگاه دانش و داده‌های برداری",
"resetConfig": "بازنشانی پیکربندی",
"resetConfigDesc": "حذف تمام تنظیمات برنامه، پیکربندی‌های مدل و دستورکارهای سفارشی",
"resetAll": "بازنشانی کامل",
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/i18n/fr-FR/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
"resetConfirmDescription": "Veuillez sélectionner le type de données à réinitialiser. Cette opération est irréversible et l'application redémarrera automatiquement après la réinitialisation.",
"resetChatData": "Réinitialiser les données de chat",
"resetChatDataDesc": "Supprimer tout l'historique des conversations et les enregistrements de dialogue",
"resetKnowledgeData": "Réinitialiser les données de base de connaissances",
"resetKnowledgeDataDesc": "Supprimer tous les fichiers de base de connaissances et les données vectorielles",
"resetConfig": "Réinitialiser la configuration",
"resetConfigDesc": "Supprimer tous les paramètres de l'application, les configurations de modèles et les prompts personnalisés",
"resetAll": "Réinitialisation complète",
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/i18n/ja-JP/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
"resetConfirmDescription": "リセットするデータの種類を選択してください。この操作は元に戻せません。リセット後、アプリケーションは自動的に再起動されます。",
"resetChatData": "チャットデータをリセット",
"resetChatDataDesc": "すべてのチャット履歴と会話記録を削除",
"resetKnowledgeData": "ナレッジベースデータをリセット",
"resetKnowledgeDataDesc": "すべてのナレッジベースファイルとベクターデータを削除",
"resetConfig": "設定をリセット",
"resetConfigDesc": "すべてのアプリ設定、モデル設定、カスタムプロンプトを削除",
"resetAll": "完全リセット",
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/i18n/ko-KR/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
"resetConfirmDescription": "초기화할 데이터 유형을 선택하세요. 이 작업은 되돌릴 수 없으며, 초기화 후 애플리케이션이 자동으로 재시작됩니다.",
"resetChatData": "채팅 데이터 초기화",
"resetChatDataDesc": "모든 채팅 기록과 대화 내역을 삭제",
"resetKnowledgeData": "지식베이스 데이터 초기화",
"resetKnowledgeDataDesc": "모든 지식베이스 파일과 벡터 데이터를 삭제",
"resetConfig": "설정 초기화",
"resetConfigDesc": "모든 앱 설정, 모델 설정, 사용자 정의 프롬프트를 삭제",
"resetAll": "완전 초기화",
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/i18n/ru-RU/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
"resetConfirmDescription": "Выберите тип данных для сброса. Эта операция необратима, после сброса приложение автоматически перезапустится.",
"resetChatData": "Сбросить данные чатов",
"resetChatDataDesc": "Удалить всю историю чатов и записи разговоров",
"resetKnowledgeData": "Сбросить данные базы знаний",
"resetKnowledgeDataDesc": "Удалить все файлы базы знаний и векторные данные",
"resetConfig": "Сбросить настройки",
"resetConfigDesc": "Удалить все настройки приложения, конфигурации моделей и пользовательские промпты",
"resetAll": "Полный сброс",
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/i18n/zh-CN/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
"resetConfirmDescription": "请选择要重置的数据类型。此操作不可撤销,重置后应用将自动重启。",
"resetChatData": "重置聊天数据",
"resetChatDataDesc": "删除所有聊天记录和对话历史",
"resetKnowledgeData": "重置知识库数据",
"resetKnowledgeDataDesc": "删除所有知识库文件和向量数据",
"resetConfig": "重置配置",
"resetConfigDesc": "删除所有应用设置、模型配置和自定义提示词",
"resetAll": "完全重置",
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/i18n/zh-HK/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
"resetConfirmDescription": "請選擇要重置的數據類型。此操作不可撤銷,重置後應用程式將自動重新啟動。",
"resetChatData": "重置聊天數據",
"resetChatDataDesc": "刪除所有聊天記錄和對話歷史",
"resetKnowledgeData": "重置知識庫數據",
"resetKnowledgeDataDesc": "刪除所有知識庫檔案和向量數據",
Comment on lines +79 to +80
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

New keys look good – confirm cross-language coverage.

resetKnowledgeData / resetKnowledgeDataDesc follow the existing naming pattern and slot into the "data" block correctly.
Please double-check that:

  1. The same two keys exist in all other language JSONs (including those not in this PR, e.g. de-DE, es-ES if they exist).
  2. The settings UI (DataSettings.vue) already references these keys via $t('data.resetKnowledgeData') / $t('data.resetKnowledgeDataDesc').

Quick grep to verify other languages:

If any file is missing, add stubs soon to keep the structure consistent.


🏁 Script executed:

rg -l '"resetKnowledgeData"' src/renderer/src/i18n

Length of output: 430


🏁 Script executed:

#!/bin/bash
echo "Checking presence of resetKnowledgeDataDesc in i18n JSON files:"
rg -l '"resetKnowledgeDataDesc"' src/renderer/src/i18n

echo
echo "Locating DataSettings.vue:"
fd DataSettings.vue

DATA_SETTINGS_FILE=$(fd DataSettings.vue | head -n 1)

echo
echo "Verifying translation key usages in $DATA_SETTINGS_FILE:"
rg -n "\$t\('data.resetKnowledgeData'\)" "$DATA_SETTINGS_FILE"
rg -n "\$t\('data.resetKnowledgeDataDesc'\)" "$DATA_SETTINGS_FILE"

Length of output: 1236


Missing translation usage in DataSettings.vue

All language JSONs under src/renderer/src/i18n/*/settings.json include the new keys (resetKnowledgeData, resetKnowledgeDataDesc), but the settings UI does not reference them.

Please update src/renderer/src/components/settings/DataSettings.vue to use:

  • $t('data.resetKnowledgeData')
  • $t('data.resetKnowledgeDataDesc')

so the new translations actually appear in the UI.

🤖 Prompt for AI Agents
In src/renderer/src/components/settings/DataSettings.vue, update the UI code to
reference the new translation keys by replacing or adding text bindings with
$t('data.resetKnowledgeData') and $t('data.resetKnowledgeDataDesc'). This will
ensure the new translations from the JSON files are displayed in the settings
interface.

"resetConfig": "重置配置",
"resetConfigDesc": "刪除所有應用程式設置、模型配置和自定義提示詞",
"resetAll": "完全重置",
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/i18n/zh-TW/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
"resetConfirmDescription": "請選擇要重設的資料類型。此操作無法復原,重設後應用程式將自動重新啟動。",
"resetChatData": "重設聊天資料",
"resetChatDataDesc": "刪除所有聊天記錄和對話歷史",
"resetKnowledgeData": "重設知識庫資料",
"resetKnowledgeDataDesc": "刪除所有知識庫檔案和向量資料",
"resetConfig": "重設設定",
"resetConfigDesc": "刪除所有應用程式設定、模型設定和自訂提示詞",
"resetAll": "完全重設",
Expand Down
2 changes: 1 addition & 1 deletion src/shared/presenter.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ export interface IDevicePresenter {
getMemoryUsage(): Promise<MemoryInfo>
getDiskSpace(): Promise<DiskInfo>
resetData(): Promise<void>
resetDataByType(resetType: 'chat' | 'config' | 'all'): Promise<void>
resetDataByType(resetType: 'chat' | 'knowledge' | 'config' | 'all'): Promise<void>

// 目录选择和应用重启
selectDirectory(): Promise<{ canceled: boolean; filePaths: string[] }>
Expand Down