mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-05-15 22:30:38 +08:00
refactor: move sleep synopsis and evolve actions into ui actions controller
This commit is contained in:
82
index.js
82
index.js
@@ -81,6 +81,9 @@ import {
|
||||
onExportGraphController,
|
||||
onImportGraphController,
|
||||
onManualCompressController,
|
||||
onManualEvolveController,
|
||||
onManualSleepController,
|
||||
onManualSynopsisController,
|
||||
onRebuildVectorIndexController,
|
||||
onRebuildController,
|
||||
onTestEmbeddingController,
|
||||
@@ -4812,66 +4815,43 @@ async function onReroll({ fromFloor } = {}) {
|
||||
}
|
||||
|
||||
async function onManualSleep() {
|
||||
if (!currentGraph) return;
|
||||
if (!ensureGraphMutationReady("执行遗忘")) return;
|
||||
const beforeSnapshot = cloneGraphSnapshot(currentGraph);
|
||||
const result = sleepCycle(currentGraph, getSettings());
|
||||
await recordGraphMutation({
|
||||
beforeSnapshot,
|
||||
artifactTags: ["sleep"],
|
||||
return await onManualSleepController({
|
||||
cloneGraphSnapshot,
|
||||
ensureGraphMutationReady,
|
||||
getCurrentGraph: () => currentGraph,
|
||||
getSettings,
|
||||
recordGraphMutation,
|
||||
sleepCycle,
|
||||
toastr,
|
||||
});
|
||||
toastr.info(`执行完成:归档 ${result.forgotten} 个节点`);
|
||||
}
|
||||
|
||||
async function onManualSynopsis() {
|
||||
if (!currentGraph) return;
|
||||
if (!ensureGraphMutationReady("更新概要")) return;
|
||||
const beforeSnapshot = cloneGraphSnapshot(currentGraph);
|
||||
await generateSynopsis({
|
||||
graph: currentGraph,
|
||||
schema: getSchema(),
|
||||
currentSeq: getCurrentChatSeq(),
|
||||
customPrompt: undefined,
|
||||
settings: getSettings(),
|
||||
return await onManualSynopsisController({
|
||||
cloneGraphSnapshot,
|
||||
ensureGraphMutationReady,
|
||||
generateSynopsis,
|
||||
getCurrentChatSeq,
|
||||
getCurrentGraph: () => currentGraph,
|
||||
getSchema,
|
||||
getSettings,
|
||||
recordGraphMutation,
|
||||
toastr,
|
||||
});
|
||||
await recordGraphMutation({
|
||||
beforeSnapshot,
|
||||
artifactTags: ["synopsis"],
|
||||
});
|
||||
toastr.success("概要生成完成");
|
||||
}
|
||||
|
||||
async function onManualEvolve() {
|
||||
if (!currentGraph) return;
|
||||
if (!ensureGraphMutationReady("强制进化")) return;
|
||||
|
||||
const candidateIds = lastExtractedItems
|
||||
.map((item) => item.id)
|
||||
.filter(Boolean);
|
||||
if (candidateIds.length === 0) {
|
||||
toastr.info("暂无最近提取节点可用于进化");
|
||||
return;
|
||||
}
|
||||
|
||||
const beforeSnapshot = cloneGraphSnapshot(currentGraph);
|
||||
const result = await consolidateMemories({
|
||||
graph: currentGraph,
|
||||
newNodeIds: candidateIds,
|
||||
embeddingConfig: getEmbeddingConfig(),
|
||||
customPrompt: undefined,
|
||||
settings: getSettings(),
|
||||
options: {
|
||||
neighborCount: getSettings().consolidationNeighborCount,
|
||||
conflictThreshold: getSettings().consolidationThreshold,
|
||||
},
|
||||
return await onManualEvolveController({
|
||||
cloneGraphSnapshot,
|
||||
consolidateMemories,
|
||||
ensureGraphMutationReady,
|
||||
getCurrentGraph: () => currentGraph,
|
||||
getEmbeddingConfig,
|
||||
getLastExtractedItems: () => lastExtractedItems,
|
||||
getSettings,
|
||||
recordGraphMutation,
|
||||
toastr,
|
||||
});
|
||||
await recordGraphMutation({
|
||||
beforeSnapshot,
|
||||
artifactTags: ["consolidation"],
|
||||
});
|
||||
toastr.success(
|
||||
`整合完成:合并 ${result.merged},跳过 ${result.skipped},保留 ${result.kept},进化 ${result.evolved},新链接 ${result.connections},回溯更新 ${result.updates}`,
|
||||
);
|
||||
}
|
||||
|
||||
async function onRebuildVectorIndex(range = null) {
|
||||
|
||||
@@ -378,3 +378,72 @@ export async function onReembedDirectController(runtime) {
|
||||
|
||||
await runtime.onRebuildVectorIndex();
|
||||
}
|
||||
|
||||
export async function onManualSleepController(runtime) {
|
||||
const graph = runtime.getCurrentGraph();
|
||||
if (!graph) return;
|
||||
if (!runtime.ensureGraphMutationReady("执行遗忘")) return;
|
||||
|
||||
const beforeSnapshot = runtime.cloneGraphSnapshot(graph);
|
||||
const result = runtime.sleepCycle(graph, runtime.getSettings());
|
||||
await runtime.recordGraphMutation({
|
||||
beforeSnapshot,
|
||||
artifactTags: ["sleep"],
|
||||
});
|
||||
runtime.toastr.info(`执行完成:归档 ${result.forgotten} 个节点`);
|
||||
}
|
||||
|
||||
export async function onManualSynopsisController(runtime) {
|
||||
const graph = runtime.getCurrentGraph();
|
||||
if (!graph) return;
|
||||
if (!runtime.ensureGraphMutationReady("更新概要")) return;
|
||||
|
||||
const beforeSnapshot = runtime.cloneGraphSnapshot(graph);
|
||||
await runtime.generateSynopsis({
|
||||
graph,
|
||||
schema: runtime.getSchema(),
|
||||
currentSeq: runtime.getCurrentChatSeq(),
|
||||
customPrompt: undefined,
|
||||
settings: runtime.getSettings(),
|
||||
});
|
||||
await runtime.recordGraphMutation({
|
||||
beforeSnapshot,
|
||||
artifactTags: ["synopsis"],
|
||||
});
|
||||
runtime.toastr.success("概要生成完成");
|
||||
}
|
||||
|
||||
export async function onManualEvolveController(runtime) {
|
||||
const graph = runtime.getCurrentGraph();
|
||||
if (!graph) return;
|
||||
if (!runtime.ensureGraphMutationReady("强制进化")) return;
|
||||
|
||||
const candidateIds = runtime.getLastExtractedItems()
|
||||
.map((item) => item.id)
|
||||
.filter(Boolean);
|
||||
if (candidateIds.length === 0) {
|
||||
runtime.toastr.info("暂无最近提取节点可用于进化");
|
||||
return;
|
||||
}
|
||||
|
||||
const beforeSnapshot = runtime.cloneGraphSnapshot(graph);
|
||||
const settings = runtime.getSettings();
|
||||
const result = await runtime.consolidateMemories({
|
||||
graph,
|
||||
newNodeIds: candidateIds,
|
||||
embeddingConfig: runtime.getEmbeddingConfig(),
|
||||
customPrompt: undefined,
|
||||
settings,
|
||||
options: {
|
||||
neighborCount: settings.consolidationNeighborCount,
|
||||
conflictThreshold: settings.consolidationThreshold,
|
||||
},
|
||||
});
|
||||
await runtime.recordGraphMutation({
|
||||
beforeSnapshot,
|
||||
artifactTags: ["consolidation"],
|
||||
});
|
||||
runtime.toastr.success(
|
||||
`整合完成:合并 ${result.merged},跳过 ${result.skipped},保留 ${result.kept},进化 ${result.evolved},新链接 ${result.connections},回溯更新 ${result.updates}`,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user