feat: 新增「数据清理」配置页

- 图谱清理:清空当前图谱、按楼层范围删除节点
- 缓存清理:清空向量缓存、清空提取历史
- 存储清理:清空当前/全部 IDB、清空服务端同步文件
- 高危操作全部需要 confirm 弹窗确认
- 清空全部 IDB 和清空服务端同步文件需要输入 DELETE 确认
This commit is contained in:
Youzini-afk
2026-04-08 14:28:44 +08:00
parent 20f64138b1
commit 29af3d164e
5 changed files with 526 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ import {
import {
autoSyncOnChatChange,
autoSyncOnVisibility,
deleteRemoteSyncFile,
scheduleUpload,
syncNow,
} from "./sync/bme-sync.js";
@@ -212,6 +213,13 @@ import {
onTestMemoryLLMController,
onViewGraphController,
onViewLastInjectionController,
onClearGraphController,
onClearGraphRangeController,
onClearVectorCacheController,
onClearBatchJournalController,
onDeleteCurrentIdbController,
onDeleteAllIdbController,
onDeleteServerSyncFileController,
} from "./ui/ui-actions-controller.js";
import {
clampInt,
@@ -10917,6 +10925,70 @@ async function onReembedDirect() {
});
}
// ==================== 数据清理 ====================
const _cleanupRuntime = () => ({
confirm: (msg) => (typeof globalThis.confirm === "function" ? globalThis.confirm(msg) : false),
prompt: (msg) => (typeof globalThis.prompt === "function" ? globalThis.prompt(msg) : null),
createEmptyGraph,
clearInjectionState,
ensureGraphMutationReady,
getCurrentChatId,
getCurrentGraph: () => currentGraph,
markVectorStateDirty: (reason) => {
if (currentGraph?.vectorIndexState) {
currentGraph.vectorIndexState.dirty = true;
currentGraph.vectorIndexState.dirtyReason = reason;
}
},
normalizeGraphRuntimeState,
refreshPanelLiveState,
removeNode: (graph, nodeId) => removeNode(graph, nodeId),
saveGraphToChat,
setCurrentGraph: (graph) => { currentGraph = graph; },
setExtractionCount: (count) => {
if (currentGraph?.historyState) {
currentGraph.historyState.extractionCount = count;
}
},
setLastExtractedItems: () => { lastExtractedItems = []; },
buildBmeDbName,
closeBmeDb: null,
deleteRemoteSyncFile: (chatId) => deleteRemoteSyncFile(chatId, {
fetch: globalThis.fetch?.bind(globalThis),
getRequestHeaders: typeof getRequestHeaders === "function" ? getRequestHeaders : undefined,
}),
toastr,
});
async function onClearGraph() {
return await onClearGraphController(_cleanupRuntime());
}
async function onClearGraphRange(startSeq, endSeq) {
return await onClearGraphRangeController(_cleanupRuntime(), startSeq, endSeq);
}
async function onClearVectorCache() {
return await onClearVectorCacheController(_cleanupRuntime());
}
async function onClearBatchJournal() {
return await onClearBatchJournalController(_cleanupRuntime());
}
async function onDeleteCurrentIdb() {
return await onDeleteCurrentIdbController(_cleanupRuntime());
}
async function onDeleteAllIdb() {
return await onDeleteAllIdbController(_cleanupRuntime());
}
async function onDeleteServerSyncFile() {
return await onDeleteServerSyncFileController(_cleanupRuntime());
}
// ==================== 初始化 ====================
(async function init() {
@@ -10953,6 +11025,13 @@ async function onReembedDirect() {
rebuildVectorRange: (range) => onRebuildVectorIndex(range),
reembedDirect: onReembedDirect,
reroll: onReroll,
clearGraph: onClearGraph,
clearGraphRange: (startSeq, endSeq) => onClearGraphRange(startSeq, endSeq),
clearVectorCache: onClearVectorCache,
clearBatchJournal: onClearBatchJournal,
deleteCurrentIdb: onDeleteCurrentIdb,
deleteAllIdb: onDeleteAllIdb,
deleteServerSyncFile: onDeleteServerSyncFile,
},
console,
document,