mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-06-14 02:40:45 +08:00
177 lines
5.4 KiB
JavaScript
177 lines
5.4 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import {
|
|
cloneTaskProfile,
|
|
createBuiltinPromptBlock,
|
|
createCustomPromptBlock,
|
|
createDefaultTaskProfiles,
|
|
createLocalRegexRule,
|
|
exportTaskProfile,
|
|
getActiveTaskProfile,
|
|
getBuiltinBlockDefinitions,
|
|
getLegacyPromptFieldForTask,
|
|
getTaskTypeMeta,
|
|
getTaskTypeOptions,
|
|
getTaskTypes,
|
|
importTaskProfile,
|
|
restoreDefaultTaskProfile,
|
|
upsertTaskProfile,
|
|
} from "../prompting/prompt-profiles.js";
|
|
|
|
const taskProfiles = createDefaultTaskProfiles();
|
|
const baseProfile = taskProfiles.extract.profiles[0];
|
|
assert.equal(baseProfile.generation.llm_preset, "");
|
|
|
|
const clonedProfile = cloneTaskProfile(baseProfile, {
|
|
taskType: "extract",
|
|
name: "激进提取",
|
|
});
|
|
clonedProfile.generation.llm_preset = "Recall-API";
|
|
clonedProfile.blocks = [
|
|
...clonedProfile.blocks,
|
|
createBuiltinPromptBlock("extract", "userMessage", {
|
|
name: "用户消息块",
|
|
injectionMode: "prepend",
|
|
order: 1,
|
|
}),
|
|
createCustomPromptBlock("extract", {
|
|
name: "补充说明",
|
|
content: "请关注 {{userMessage}}",
|
|
role: "user",
|
|
order: 2,
|
|
}),
|
|
];
|
|
clonedProfile.regex.localRules = [
|
|
createLocalRegexRule("extract", {
|
|
script_name: "裁边",
|
|
find_regex: "/^foo/g",
|
|
replace_string: "bar",
|
|
}),
|
|
];
|
|
|
|
const updatedProfiles = upsertTaskProfile(taskProfiles, "extract", clonedProfile, {
|
|
setActive: true,
|
|
});
|
|
|
|
const activeProfile = getActiveTaskProfile(
|
|
{ taskProfiles: updatedProfiles },
|
|
"extract",
|
|
);
|
|
assert.equal(activeProfile.name, "激进提取");
|
|
assert.equal(activeProfile.blocks.length, 18);
|
|
const builtinBlock = activeProfile.blocks.find(
|
|
(block) => block.type === "builtin" && block.sourceKey === "userMessage",
|
|
);
|
|
const customBlock = activeProfile.blocks.find(
|
|
(block) => block.type === "custom" && block.name === "补充说明",
|
|
);
|
|
assert.ok(builtinBlock);
|
|
assert.equal(builtinBlock.injectionMode, "prepend");
|
|
assert.equal(builtinBlock.role, "system");
|
|
assert.ok(customBlock);
|
|
assert.equal(customBlock.role, "user");
|
|
assert.equal(activeProfile.regex.localRules.length, 1);
|
|
assert.equal(activeProfile.regex.localRules[0].script_name, "裁边");
|
|
assert.equal(activeProfile.generation.llm_preset, "Recall-API");
|
|
|
|
const exported = exportTaskProfile(
|
|
updatedProfiles,
|
|
"extract",
|
|
clonedProfile.id,
|
|
);
|
|
assert.equal(exported.format, "st-bme-task-profile");
|
|
assert.equal(exported.taskType, "extract");
|
|
assert.equal(exported.profile.name, "激进提取");
|
|
assert.equal(exported.profile.generation.llm_preset, "Recall-API");
|
|
|
|
const imported = importTaskProfile(updatedProfiles, JSON.stringify(exported));
|
|
assert.equal(imported.taskType, "extract");
|
|
assert.notEqual(imported.profile.id, clonedProfile.id);
|
|
assert.equal(imported.profile.generation.llm_preset, "Recall-API");
|
|
assert.ok(
|
|
imported.profile.blocks.some(
|
|
(block) => block.type === "builtin" && block.sourceKey === "userMessage",
|
|
),
|
|
);
|
|
|
|
const restoredProfiles = restoreDefaultTaskProfile(imported.taskProfiles, "extract");
|
|
const restoredActive = getActiveTaskProfile(
|
|
{ taskProfiles: restoredProfiles },
|
|
"extract",
|
|
);
|
|
assert.equal(restoredActive.id, "default");
|
|
assert.equal(getLegacyPromptFieldForTask("extract"), "extractPrompt");
|
|
assert.equal(getTaskTypeMeta("extract").label, "旧提取");
|
|
|
|
assert.ok(getTaskTypes().includes("extract_objective"));
|
|
assert.ok(getTaskTypes().includes("extract_subjective"));
|
|
assert.equal(
|
|
getTaskTypeOptions().some((option) => option.id === "extract_objective"),
|
|
true,
|
|
);
|
|
assert.equal(
|
|
getTaskTypeOptions().some((option) => option.id === "extract_subjective"),
|
|
true,
|
|
);
|
|
assert.deepEqual(
|
|
{
|
|
objective: getTaskTypeMeta("extract_objective"),
|
|
subjective: getTaskTypeMeta("extract_subjective"),
|
|
},
|
|
{
|
|
objective: {
|
|
id: "extract_objective",
|
|
label: "客观提取",
|
|
description: "从当前对话批次中抽取客观层结构化记忆。",
|
|
hidden: false,
|
|
},
|
|
subjective: {
|
|
id: "extract_subjective",
|
|
label: "主观提取",
|
|
description: "从客观提取草稿与视角上下文中抽取主观记忆。",
|
|
hidden: false,
|
|
},
|
|
},
|
|
);
|
|
assert.ok(taskProfiles.extract_objective?.profiles?.length > 0);
|
|
assert.ok(taskProfiles.extract_subjective?.profiles?.length > 0);
|
|
assert.equal(
|
|
taskProfiles.extract_objective.profiles[0].metadata.legacyPromptField,
|
|
"extractObjectivePrompt",
|
|
);
|
|
assert.equal(
|
|
taskProfiles.extract_subjective.profiles[0].metadata.legacyPromptField,
|
|
"extractSubjectivePrompt",
|
|
);
|
|
assert.ok(
|
|
taskProfiles.extract_objective.profiles[0].blocks.find((block) => block.id === "default-role")?.content?.includes("客观事实提取师"),
|
|
"extract_objective role block should identify as objective-only extractor",
|
|
);
|
|
assert.ok(
|
|
taskProfiles.extract_subjective.profiles[0].blocks.find((block) => block.id === "default-rules")?.content?.includes("POV 记忆字段"),
|
|
"extract_subjective rules block should contain POV memory rules",
|
|
);
|
|
assert.deepEqual(
|
|
getBuiltinBlockDefinitions("extract_subjective")
|
|
.map((definition) => definition.sourceKey)
|
|
.filter((sourceKey) =>
|
|
[
|
|
"objectiveExtractionDraft",
|
|
"objectiveRefMap",
|
|
"ownerContext",
|
|
"batchStoryTime",
|
|
"relevantPovMemories",
|
|
"cognitionStateDigest",
|
|
].includes(sourceKey),
|
|
),
|
|
[
|
|
"objectiveExtractionDraft",
|
|
"objectiveRefMap",
|
|
"ownerContext",
|
|
"batchStoryTime",
|
|
"relevantPovMemories",
|
|
"cognitionStateDigest",
|
|
],
|
|
);
|
|
|
|
console.log("task-profile-storage tests passed");
|