mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-05-15 22:30:38 +08:00
fix: clear stale recovery sources during graph cleanup
This commit is contained in:
@@ -11627,6 +11627,7 @@ function _isPersistenceRevisionAccepted(persistence = null, loadInfo = {}) {
|
||||
|
||||
function _formatDashboardPersistMeta(loadInfo = {}, batchStatus = null) {
|
||||
const persistence = batchStatus?.persistence || null;
|
||||
const localPersistError = String(loadInfo?.indexedDbLastError || "").trim();
|
||||
if (_hasMeaningfulPersistenceRecord(persistence)) {
|
||||
const accepted = _isPersistenceRevisionAccepted(persistence, loadInfo);
|
||||
const parts = [
|
||||
@@ -11640,6 +11641,7 @@ function _formatDashboardPersistMeta(loadInfo = {}, batchStatus = null) {
|
||||
? `rev ${Number(persistence.revision)}`
|
||||
: "",
|
||||
persistence.reason || "",
|
||||
!accepted && localPersistError ? `本地错误 ${localPersistError}` : "",
|
||||
].filter(Boolean);
|
||||
return parts.join(" · ") || "尚无持久化记录";
|
||||
}
|
||||
@@ -11674,6 +11676,7 @@ function _formatDashboardHistoryMeta(graph = null, loadInfo = {}, batchStatus =
|
||||
graph?.historyState?.lastProcessedAssistantFloor ?? -1;
|
||||
const persistence = batchStatus?.persistence || null;
|
||||
const accepted = _isPersistenceRevisionAccepted(persistence, loadInfo);
|
||||
const localPersistError = String(loadInfo?.indexedDbLastError || "").trim();
|
||||
const processedRange = Array.isArray(batchStatus?.processedRange)
|
||||
? batchStatus.processedRange
|
||||
: [];
|
||||
@@ -11683,7 +11686,7 @@ function _formatDashboardHistoryMeta(graph = null, loadInfo = {}, batchStatus =
|
||||
: null;
|
||||
|
||||
if (_hasMeaningfulPersistenceRecord(persistence) && !accepted && pendingFloor != null) {
|
||||
return `持久化待确认:本地已抽取到楼层 ${pendingFloor},已确认楼层 ${lastConfirmedFloor}`;
|
||||
return `持久化待确认:本地已抽取到楼层 ${pendingFloor},已确认楼层 ${lastConfirmedFloor}${localPersistError ? ` · 本地错误 ${localPersistError}` : ""}`;
|
||||
}
|
||||
|
||||
if (loadInfo?.persistMismatchReason) {
|
||||
|
||||
@@ -1056,6 +1056,18 @@ export async function onClearGraphController(runtime) {
|
||||
return { cancelled: true };
|
||||
}
|
||||
if (!runtime.ensureGraphMutationReady("清空图谱")) return;
|
||||
const chatId = runtime.getCurrentChatId?.();
|
||||
|
||||
if (chatId && typeof runtime.clearCurrentChatRecoveryAnchors === "function") {
|
||||
runtime.clearCurrentChatRecoveryAnchors({
|
||||
chatId,
|
||||
reason: "manual-clear-graph",
|
||||
immediate: true,
|
||||
clearMetadataFull: true,
|
||||
clearCommitMarker: true,
|
||||
clearPendingPersist: true,
|
||||
});
|
||||
}
|
||||
|
||||
const nextGraph = runtime.normalizeGraphRuntimeState(
|
||||
runtime.createEmptyGraph(),
|
||||
@@ -1066,9 +1078,21 @@ export async function onClearGraphController(runtime) {
|
||||
runtime.markVectorStateDirty?.("清空图谱后需要重建向量索引");
|
||||
runtime.setExtractionCount(0);
|
||||
runtime.setLastExtractedItems([]);
|
||||
runtime.saveGraphToChat({ reason: "manual-clear-graph" });
|
||||
runtime.saveGraphToChat({
|
||||
reason: "manual-clear-graph",
|
||||
persistMetadata: true,
|
||||
captureShadow: false,
|
||||
});
|
||||
runtime.refreshPanelLiveState();
|
||||
runtime.toastr.success("当前图谱已清空");
|
||||
const persistenceState = runtime.getGraphPersistenceState?.() || {};
|
||||
const remoteSyncMayRestore =
|
||||
Number(persistenceState.lastSyncedRevision || 0) > 0 &&
|
||||
String(runtime.getSettings?.()?.cloudStorageMode || "automatic") !== "manual";
|
||||
runtime.toastr.success(
|
||||
remoteSyncMayRestore
|
||||
? "当前图谱已清空;若刷新后旧节点重新出现,请再清空服务端同步数据"
|
||||
: "当前图谱已清空",
|
||||
);
|
||||
return { handledToast: true };
|
||||
}
|
||||
|
||||
@@ -1256,8 +1280,11 @@ export async function onDeleteCurrentIdbController(runtime) {
|
||||
const deletedOpfs =
|
||||
currentOpfsResult?.deleted === true ||
|
||||
restoreSafetyOpfsResult?.deleted === true;
|
||||
const remoteSyncMayRestore =
|
||||
Number(runtime.getGraphPersistenceState?.()?.lastSyncedRevision || 0) > 0 &&
|
||||
String(runtime.getSettings?.()?.cloudStorageMode || "automatic") !== "manual";
|
||||
runtime.toastr.success(
|
||||
`已清空当前聊天本地存储:IndexedDB ${deletedIndexedDbCount > 0 ? "已处理" : "无"},OPFS ${deletedOpfs ? "已处理" : "无"}`,
|
||||
`已清空当前聊天本地存储:IndexedDB ${deletedIndexedDbCount > 0 ? "已处理" : "无"},OPFS ${deletedOpfs ? "已处理" : "无"}${remoteSyncMayRestore ? ";若刷新后旧图恢复,请再删除服务端同步数据" : ""}`,
|
||||
);
|
||||
} catch (error) {
|
||||
runtime.toastr.error(`删除失败: ${error?.message || error}`);
|
||||
|
||||
Reference in New Issue
Block a user