Fix plugin-only memory settings and UI flow

This commit is contained in:
Youzini-afk
2026-03-24 11:42:10 +08:00
parent 00ae535873
commit 7b68eebb9e
8 changed files with 276 additions and 48 deletions

View File

@@ -1,7 +1,7 @@
// ST-BME: 层级压缩引擎
// 超过阈值的节点被 LLM 总结为更高层级的压缩节点
import { createNode, addNode, getActiveNodes, getNode } from './graph.js';
import { createNode, addNode, createEdge, addEdge, getActiveNodes, getNode } from './graph.js';
import { callLLMForJSON } from './llm.js';
import { embedText } from './embedding.js';
@@ -100,6 +100,7 @@ async function compressLevel({ graph, typeDef, level, embeddingConfig, force })
}
addNode(graph, compressedNode);
migrateBatchEdges(graph, batch, compressedNode);
created++;
// 归档子节点
@@ -113,6 +114,40 @@ async function compressLevel({ graph, typeDef, level, embeddingConfig, force })
return { created, archived };
}
function migrateBatchEdges(graph, batch, compressedNode) {
const batchIds = new Set(batch.map(node => node.id));
const activeNodeIds = new Set(getActiveNodes(graph).map(node => node.id));
for (const edge of graph.edges) {
if (edge.invalidAt || edge.expiredAt) continue;
const fromInside = batchIds.has(edge.fromId);
const toInside = batchIds.has(edge.toId);
if (!fromInside && !toInside) continue;
if (fromInside && toInside) continue;
const newFromId = fromInside ? compressedNode.id : edge.fromId;
const newToId = toInside ? compressedNode.id : edge.toId;
if (newFromId === newToId) continue;
if (!activeNodeIds.has(newFromId) || !activeNodeIds.has(newToId)) continue;
if (!getNode(graph, newFromId) || !getNode(graph, newToId)) continue;
const migratedEdge = createEdge({
fromId: newFromId,
toId: newToId,
relation: edge.relation,
strength: edge.strength,
edgeType: edge.edgeType,
});
migratedEdge.validAt = edge.validAt ?? migratedEdge.validAt;
migratedEdge.invalidAt = edge.invalidAt ?? migratedEdge.invalidAt;
migratedEdge.expiredAt = edge.expiredAt ?? migratedEdge.expiredAt;
addEdge(graph, migratedEdge);
}
}
/**
* 调用 LLM 总结一批节点
*/