mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-05-15 22:30:38 +08:00
Stabilize recall UI persistence recovery
This commit is contained in:
@@ -34,6 +34,11 @@ import {
|
||||
getNode,
|
||||
serializeGraph,
|
||||
} from "../graph.js";
|
||||
import {
|
||||
buildPersistedRecallRecord,
|
||||
readPersistedRecallFromUserMessage,
|
||||
} from "../recall-persistence.js";
|
||||
import { getNodeDisplayName } from "../node-labels.js";
|
||||
import { normalizeGraphRuntimeState } from "../runtime-state.js";
|
||||
import {
|
||||
clampFloat,
|
||||
@@ -216,6 +221,7 @@ async function createGraphPersistenceHarness({
|
||||
deserializeGraph,
|
||||
getGraphStats,
|
||||
getNode,
|
||||
getNodeDisplayName,
|
||||
createUiStatus,
|
||||
createGraphPersistenceState,
|
||||
createRecallInputRecord,
|
||||
@@ -229,6 +235,7 @@ async function createGraphPersistenceHarness({
|
||||
clampInt,
|
||||
clampFloat,
|
||||
formatRecallContextLine,
|
||||
readPersistedRecallFromUserMessage,
|
||||
cloneGraphForPersistence,
|
||||
cloneRuntimeDebugValue,
|
||||
onMessageReceivedController,
|
||||
@@ -511,6 +518,12 @@ result = {
|
||||
getCurrentGraph() {
|
||||
return currentGraph;
|
||||
},
|
||||
getLastInjectionContent() {
|
||||
return lastInjectionContent;
|
||||
},
|
||||
getLastRecalledItems() {
|
||||
return lastRecalledItems;
|
||||
},
|
||||
setGraphPersistenceState(patch = {}) {
|
||||
graphPersistenceState = {
|
||||
...graphPersistenceState,
|
||||
@@ -605,6 +618,54 @@ result = {
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
const graph = createMeaningfulGraph("chat-recall-ui", "recall-ui");
|
||||
graph.nodes[0].id = "restore-node";
|
||||
graph.lastRecallResult = [{ id: "restore-node" }];
|
||||
stampPersistedGraph(graph, {
|
||||
revision: 7,
|
||||
chatId: "chat-recall-ui",
|
||||
reason: "recall-ui-restore",
|
||||
});
|
||||
|
||||
const harness = await createGraphPersistenceHarness({
|
||||
chatId: "chat-recall-ui",
|
||||
globalChatId: "chat-recall-ui",
|
||||
indexedDbSnapshot: buildSnapshotFromGraph(graph, {
|
||||
chatId: "chat-recall-ui",
|
||||
revision: 7,
|
||||
}),
|
||||
chat: [
|
||||
{
|
||||
is_user: true,
|
||||
mes: "用户楼层",
|
||||
extra: {
|
||||
bme_recall: buildPersistedRecallRecord({
|
||||
injectionText: "已持久化的召回注入",
|
||||
selectedNodeIds: [],
|
||||
nowIso: "2026-01-01T00:00:00.000Z",
|
||||
}),
|
||||
},
|
||||
},
|
||||
{
|
||||
is_user: false,
|
||||
mes: "assistant",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const result = harness.api.syncGraphLoadFromLiveContext({
|
||||
source: "indexeddb-recall-ui-restore",
|
||||
});
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
||||
assert.equal(result.synced, true);
|
||||
assert.equal(harness.api.getGraphPersistenceState().dbReady, true);
|
||||
assert.equal(harness.api.getLastInjectionContent(), "已持久化的召回注入");
|
||||
assert.equal(harness.api.getLastRecalledItems().length, 1);
|
||||
assert.equal(harness.api.getLastRecalledItems()[0]?.id, "restore-node");
|
||||
}
|
||||
|
||||
{
|
||||
const harness = await createGraphPersistenceHarness({
|
||||
chatId: "",
|
||||
|
||||
@@ -3594,6 +3594,44 @@ async function testGenerationRecallFinalInjectionRebindsLatestMatchingUserFloor(
|
||||
|
||||
assert.equal(resolution.targetUserMessageIndex, 0);
|
||||
}
|
||||
|
||||
{
|
||||
const harness = await createGenerationRecallHarness({ realApplyFinal: true });
|
||||
harness.chat = [
|
||||
{ is_user: true, mes: "酒馆最终写入的用户楼层文本" },
|
||||
{ is_user: false, mes: "assistant-tail" },
|
||||
];
|
||||
harness.result.recordRecallSentUserMessage(0, "发送前捕获的原始文本", "message-sent");
|
||||
|
||||
const resolution =
|
||||
harness.result.applyFinalRecallInjectionForGeneration({
|
||||
generationType: "normal",
|
||||
hookName: "GENERATION_AFTER_COMMANDS",
|
||||
freshRecallResult: {
|
||||
status: "completed",
|
||||
didRecall: true,
|
||||
injectionText: "fresh-memory",
|
||||
sourceCandidates: [
|
||||
{
|
||||
text: "发送前捕获的原始文本",
|
||||
},
|
||||
],
|
||||
},
|
||||
transaction: {
|
||||
frozenRecallOptions: {
|
||||
generationType: "normal",
|
||||
targetUserMessageIndex: null,
|
||||
overrideUserMessage: "发送前捕获的原始文本",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(
|
||||
resolution.targetUserMessageIndex,
|
||||
0,
|
||||
"normal 生成时即便用户文本被宿主改写,也应回绑到最新 user 楼层",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function testRecallSubGraphAndDataLayerEntryPoints() {
|
||||
|
||||
Reference in New Issue
Block a user