mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-06-13 18:31:16 +08:00
Normalize mistaken user owners across extraction and cognition
This commit is contained in:
@@ -209,4 +209,78 @@ globalThis.__stBmeTestContext = {
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const graph = createEmptyGraph();
|
||||
globalThis.__stBmeTestContext.name1 = "邱谁";
|
||||
globalThis.__stBmeTestContext.name2 = "群像卡";
|
||||
const restore = setTestOverrides({
|
||||
llm: {
|
||||
async callLLMForJSON() {
|
||||
return {
|
||||
operations: [
|
||||
{
|
||||
action: "create",
|
||||
type: "pov_memory",
|
||||
scope: {
|
||||
layer: "pov",
|
||||
ownerType: "character",
|
||||
ownerName: "邱 谁",
|
||||
ownerId: "邱 谁",
|
||||
},
|
||||
fields: { summary: "她感觉对方在试探自己的底线" },
|
||||
},
|
||||
],
|
||||
cognitionUpdates: [
|
||||
{
|
||||
ownerType: "character",
|
||||
ownerName: "【邱谁】",
|
||||
knownRefs: [],
|
||||
},
|
||||
],
|
||||
regionUpdates: {},
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
const result = await extractMemories({
|
||||
graph,
|
||||
messages: [{ seq: 7, role: "assistant", content: "用户名误标测试" }],
|
||||
startSeq: 7,
|
||||
endSeq: 7,
|
||||
schema: DEFAULT_NODE_SCHEMA,
|
||||
embeddingConfig: null,
|
||||
settings: {},
|
||||
});
|
||||
|
||||
assert.equal(result.success, true);
|
||||
const povNode = graph.nodes.find(
|
||||
(node) => !node.archived && node.type === "pov_memory",
|
||||
);
|
||||
assert.ok(povNode);
|
||||
assert.equal(povNode.scope?.ownerType, "user");
|
||||
assert.equal(povNode.scope?.ownerName, "邱谁");
|
||||
const knowledgeOwners = Object.values(graph.knowledgeState?.owners || {});
|
||||
assert.equal(
|
||||
knowledgeOwners.some(
|
||||
(entry) =>
|
||||
String(entry?.ownerType || "") === "character" &&
|
||||
String(entry?.ownerName || "") === "邱谁",
|
||||
),
|
||||
false,
|
||||
);
|
||||
assert.equal(
|
||||
knowledgeOwners.some(
|
||||
(entry) =>
|
||||
String(entry?.ownerType || "") === "user" &&
|
||||
String(entry?.ownerName || "") === "邱谁",
|
||||
),
|
||||
true,
|
||||
);
|
||||
} finally {
|
||||
restore();
|
||||
}
|
||||
}
|
||||
|
||||
console.log("extractor-owner-scope tests passed");
|
||||
|
||||
@@ -14,6 +14,14 @@ import {
|
||||
setManualActiveRegion,
|
||||
} from "../graph/knowledge-state.js";
|
||||
|
||||
globalThis.SillyTavern = {
|
||||
getContext() {
|
||||
return {
|
||||
name1: "露西亚",
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
const graph = createEmptyGraph();
|
||||
const erinA = createNode({
|
||||
type: "character",
|
||||
@@ -168,4 +176,24 @@ assert.deepEqual(
|
||||
["character", "user"],
|
||||
);
|
||||
|
||||
const aliasMatchedUserOwner = resolveKnowledgeOwner(graph, {
|
||||
ownerType: "character",
|
||||
ownerName: "露 西 亚",
|
||||
});
|
||||
assert.equal(aliasMatchedUserOwner.ownerType, "user");
|
||||
assert.equal(aliasMatchedUserOwner.ownerName, "露西亚");
|
||||
|
||||
const syntheticGraph = createEmptyGraph();
|
||||
syntheticGraph.historyState.activeUserPovOwner = "玩家";
|
||||
addNode(
|
||||
syntheticGraph,
|
||||
createNode({
|
||||
type: "character",
|
||||
fields: { name: "玩 家" },
|
||||
seq: 1,
|
||||
}),
|
||||
);
|
||||
const syntheticOwners = listKnowledgeOwners(syntheticGraph);
|
||||
assert.equal(syntheticOwners.some((entry) => entry.ownerType === "character"), false);
|
||||
|
||||
console.log("knowledge-state tests passed");
|
||||
|
||||
Reference in New Issue
Block a user