Implement scoped memory graph and refresh defaults

This commit is contained in:
Youzini-afk
2026-04-03 20:48:07 +08:00
parent fbd8b00f1f
commit c60f60f349
21 changed files with 1706 additions and 352 deletions

View File

@@ -1,4 +1,8 @@
// ST-BME: 运行时状态与历史恢复辅助
import {
normalizeEdgeMemoryScope,
normalizeNodeMemoryScope,
} from "./memory-scope.js";
const BATCH_JOURNAL_LIMIT = 96;
const MAINTENANCE_JOURNAL_LIMIT = 20;
@@ -22,6 +26,10 @@ export function createDefaultHistoryState(chatId = "") {
extractionCount: 0,
lastRecoveryResult: null,
lastBatchStatus: null,
lastExtractedRegion: "",
activeRegion: "",
activeCharacterPovOwner: "",
activeUserPovOwner: "",
};
}
@@ -99,6 +107,18 @@ export function normalizeGraphRuntimeState(graph, chatId = "") {
historyAdvanced: false,
};
}
if (typeof historyState.lastExtractedRegion !== "string") {
historyState.lastExtractedRegion = "";
}
if (typeof historyState.activeRegion !== "string") {
historyState.activeRegion = historyState.lastExtractedRegion || "";
}
if (typeof historyState.activeCharacterPovOwner !== "string") {
historyState.activeCharacterPovOwner = "";
}
if (typeof historyState.activeUserPovOwner !== "string") {
historyState.activeUserPovOwner = "";
}
if (
!historyState.processedMessageHashes ||
@@ -186,6 +206,12 @@ export function normalizeGraphRuntimeState(graph, chatId = "") {
graph.historyState = historyState;
graph.vectorIndexState = vectorIndexState;
if (Array.isArray(graph.nodes)) {
graph.nodes.forEach((node) => normalizeNodeMemoryScope(node));
}
if (Array.isArray(graph.edges)) {
graph.edges.forEach((edge) => normalizeEdgeMemoryScope(edge));
}
graph.batchJournal = Array.isArray(graph.batchJournal)
? graph.batchJournal.slice(-BATCH_JOURNAL_LIMIT)
: createDefaultBatchJournal();