feat(cognition): finish multi-character knowledge and monitor workflow

This commit is contained in:
Youzini-afk
2026-04-08 18:21:27 +08:00
parent 5818562145
commit a4fed87e6e
20 changed files with 3451 additions and 19 deletions

View File

@@ -3,6 +3,11 @@ import {
normalizeEdgeMemoryScope,
normalizeNodeMemoryScope,
} from "../graph/memory-scope.js";
import {
createDefaultKnowledgeState,
createDefaultRegionState,
normalizeGraphCognitiveState,
} from "../graph/knowledge-state.js";
const BATCH_JOURNAL_LIMIT = 96;
const MAINTENANCE_JOURNAL_LIMIT = 20;
@@ -28,8 +33,11 @@ export function createDefaultHistoryState(chatId = "") {
lastBatchStatus: null,
lastExtractedRegion: "",
activeRegion: "",
activeRegionSource: "",
activeCharacterPovOwner: "",
activeUserPovOwner: "",
activeRecallOwnerKey: "",
recentRecallOwnerKeys: [],
};
}
@@ -113,12 +121,29 @@ export function normalizeGraphRuntimeState(graph, chatId = "") {
if (typeof historyState.activeRegion !== "string") {
historyState.activeRegion = historyState.lastExtractedRegion || "";
}
if (typeof historyState.activeRegionSource !== "string") {
historyState.activeRegionSource = historyState.activeRegion ? "history" : "";
}
if (typeof historyState.activeCharacterPovOwner !== "string") {
historyState.activeCharacterPovOwner = "";
}
if (typeof historyState.activeUserPovOwner !== "string") {
historyState.activeUserPovOwner = "";
}
if (typeof historyState.activeRecallOwnerKey !== "string") {
historyState.activeRecallOwnerKey = "";
}
if (!Array.isArray(historyState.recentRecallOwnerKeys)) {
historyState.recentRecallOwnerKeys = [];
} else {
historyState.recentRecallOwnerKeys = [
...new Set(
historyState.recentRecallOwnerKeys
.map((value) => String(value || "").trim())
.filter(Boolean),
),
].slice(0, 8);
}
if (
!historyState.processedMessageHashes ||
@@ -220,6 +245,9 @@ export function normalizeGraphRuntimeState(graph, chatId = "") {
.filter((entry) => entry && typeof entry === "object")
.slice(-MAINTENANCE_JOURNAL_LIMIT)
: createDefaultMaintenanceJournal();
graph.knowledgeState = createDefaultKnowledgeState(graph.knowledgeState);
graph.regionState = createDefaultRegionState(graph.regionState);
normalizeGraphCognitiveState(graph);
graph.lastProcessedSeq = historyState.lastProcessedAssistantFloor;
return graph;
}