mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-06-13 18:31:16 +08:00
fix: align default task profiles with runtime prompt blocks
This commit is contained in:
@@ -22,6 +22,7 @@ async function loadDefaultSettings() {
|
||||
compress: { activeProfileId: "default", profiles: [] },
|
||||
synopsis: { activeProfileId: "default", profiles: [] },
|
||||
reflection: { activeProfileId: "default", profiles: [] },
|
||||
consolidation: { activeProfileId: "default", profiles: [] },
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -44,7 +45,7 @@ assert.equal(defaultSettings.recallDiffusionTopK, 100);
|
||||
assert.equal(defaultSettings.recallLlmCandidatePool, 30);
|
||||
assert.equal(defaultSettings.recallLlmContextMessages, 4);
|
||||
assert.equal(defaultSettings.injectDepth, 9999);
|
||||
assert.equal(defaultSettings.taskProfilesVersion, 1);
|
||||
assert.equal(defaultSettings.taskProfilesVersion, 2);
|
||||
assert.ok(defaultSettings.taskProfiles);
|
||||
assert.ok(defaultSettings.taskProfiles.extract);
|
||||
assert.ok(defaultSettings.taskProfiles.recall);
|
||||
|
||||
93
tests/prompt-builder-defaults.mjs
Normal file
93
tests/prompt-builder-defaults.mjs
Normal file
@@ -0,0 +1,93 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { registerHooks } from "node:module";
|
||||
|
||||
const extensionsShimSource = [
|
||||
"export function getContext() {",
|
||||
" return {",
|
||||
" chat: [],",
|
||||
" chatMetadata: {},",
|
||||
" extensionSettings: {},",
|
||||
" powerUserSettings: {},",
|
||||
" characters: {},",
|
||||
" characterId: null,",
|
||||
" name1: '',",
|
||||
" name2: '',",
|
||||
" chatId: 'test-chat',",
|
||||
" };",
|
||||
"}",
|
||||
].join("\n");
|
||||
|
||||
registerHooks({
|
||||
resolve(specifier, context, nextResolve) {
|
||||
if (
|
||||
specifier === "../../../extensions.js" ||
|
||||
specifier === "../../../../extensions.js"
|
||||
) {
|
||||
return {
|
||||
shortCircuit: true,
|
||||
url: `data:text/javascript,${encodeURIComponent(extensionsShimSource)}`,
|
||||
};
|
||||
}
|
||||
return nextResolve(specifier, context);
|
||||
},
|
||||
});
|
||||
|
||||
const { buildTaskLlmPayload, buildTaskPrompt } = await import("../prompt-builder.js");
|
||||
const { createDefaultTaskProfiles } = await import("../prompt-profiles.js");
|
||||
|
||||
const settings = {
|
||||
taskProfilesVersion: 2,
|
||||
taskProfiles: createDefaultTaskProfiles(),
|
||||
};
|
||||
|
||||
const extractPromptBuild = await buildTaskPrompt(settings, "extract", {
|
||||
taskName: "extract",
|
||||
charDescription: "角色描述",
|
||||
userPersona: "用户设定",
|
||||
recentMessages: "A: 你好\nB: 世界",
|
||||
graphStats: "node_count=3",
|
||||
schema: "event(title, summary)",
|
||||
currentRange: "1 ~ 2",
|
||||
});
|
||||
const extractPayload = buildTaskLlmPayload(extractPromptBuild, "fallback-user");
|
||||
assert.equal(extractPayload.userPrompt, "");
|
||||
assert.deepEqual(
|
||||
extractPayload.promptMessages
|
||||
.map((message) => message.sourceKey)
|
||||
.filter(Boolean),
|
||||
[
|
||||
"charDescription",
|
||||
"userPersona",
|
||||
"recentMessages",
|
||||
"graphStats",
|
||||
"schema",
|
||||
"currentRange",
|
||||
],
|
||||
);
|
||||
|
||||
const recallPromptBuild = await buildTaskPrompt(settings, "recall", {
|
||||
taskName: "recall",
|
||||
charDescription: "角色描述",
|
||||
userPersona: "用户设定",
|
||||
recentMessages: "上下文",
|
||||
userMessage: "用户最新发言",
|
||||
candidateNodes: "候选 1\n候选 2",
|
||||
graphStats: "candidate_count=2",
|
||||
});
|
||||
const recallPayload = buildTaskLlmPayload(recallPromptBuild, "fallback-user");
|
||||
assert.equal(recallPayload.userPrompt, "");
|
||||
assert.deepEqual(
|
||||
recallPayload.promptMessages
|
||||
.map((message) => message.sourceKey)
|
||||
.filter(Boolean),
|
||||
[
|
||||
"charDescription",
|
||||
"userPersona",
|
||||
"recentMessages",
|
||||
"userMessage",
|
||||
"candidateNodes",
|
||||
"graphStats",
|
||||
],
|
||||
);
|
||||
|
||||
console.log("prompt-builder-defaults tests passed");
|
||||
@@ -15,7 +15,7 @@ const legacySettings = {
|
||||
};
|
||||
|
||||
const migrated = migrateLegacyTaskProfiles(legacySettings);
|
||||
assert.equal(migrated.taskProfilesVersion, 1);
|
||||
assert.equal(migrated.taskProfilesVersion, 2);
|
||||
assert.ok(migrated.taskProfiles);
|
||||
assert.ok(migrated.taskProfiles.extract);
|
||||
assert.ok(migrated.taskProfiles.recall);
|
||||
@@ -30,7 +30,7 @@ const extractProfile = getActiveTaskProfile(
|
||||
assert.equal(extractProfile.taskType, "extract");
|
||||
assert.equal(extractProfile.id, "default");
|
||||
assert.ok(Array.isArray(extractProfile.blocks));
|
||||
assert.equal(extractProfile.blocks.length, 7);
|
||||
assert.equal(extractProfile.blocks.length, 11);
|
||||
assert.deepEqual(
|
||||
extractProfile.blocks.map((block) => block.name),
|
||||
[
|
||||
@@ -39,13 +39,45 @@ assert.deepEqual(
|
||||
"用户设定",
|
||||
"世界书前块",
|
||||
"世界书后块",
|
||||
"最近消息",
|
||||
"图统计",
|
||||
"Schema",
|
||||
"当前范围",
|
||||
"输出格式",
|
||||
"行为规则",
|
||||
],
|
||||
);
|
||||
assert.deepEqual(
|
||||
extractProfile.blocks.map((block) => block.type),
|
||||
["custom", "builtin", "builtin", "builtin", "builtin", "custom", "custom"],
|
||||
[
|
||||
"custom",
|
||||
"builtin",
|
||||
"builtin",
|
||||
"builtin",
|
||||
"builtin",
|
||||
"builtin",
|
||||
"builtin",
|
||||
"builtin",
|
||||
"builtin",
|
||||
"custom",
|
||||
"custom",
|
||||
],
|
||||
);
|
||||
assert.deepEqual(
|
||||
extractProfile.blocks.map((block) => block.role),
|
||||
[
|
||||
"system",
|
||||
"system",
|
||||
"system",
|
||||
"system",
|
||||
"system",
|
||||
"user",
|
||||
"user",
|
||||
"user",
|
||||
"user",
|
||||
"system",
|
||||
"system",
|
||||
],
|
||||
);
|
||||
assert.equal(
|
||||
extractProfile.metadata.legacyPromptField,
|
||||
@@ -62,5 +94,124 @@ assert.ok(defaults.recall.profiles.length > 0);
|
||||
assert.ok(defaults.compress.profiles.length > 0);
|
||||
assert.ok(defaults.synopsis.profiles.length > 0);
|
||||
assert.ok(defaults.reflection.profiles.length > 0);
|
||||
assert.deepEqual(
|
||||
defaults.recall.profiles[0].blocks.map((block) => block.sourceKey || block.id),
|
||||
[
|
||||
"default-role",
|
||||
"charDescription",
|
||||
"userPersona",
|
||||
"worldInfoBefore",
|
||||
"worldInfoAfter",
|
||||
"recentMessages",
|
||||
"userMessage",
|
||||
"candidateNodes",
|
||||
"graphStats",
|
||||
"default-format",
|
||||
"default-rules",
|
||||
],
|
||||
);
|
||||
assert.deepEqual(
|
||||
defaults.synopsis.profiles[0].blocks.map((block) => block.sourceKey || block.id),
|
||||
[
|
||||
"default-role",
|
||||
"charDescription",
|
||||
"userPersona",
|
||||
"worldInfoBefore",
|
||||
"worldInfoAfter",
|
||||
"eventSummary",
|
||||
"characterSummary",
|
||||
"threadSummary",
|
||||
"graphStats",
|
||||
"default-format",
|
||||
"default-rules",
|
||||
],
|
||||
);
|
||||
|
||||
const upgradedLegacyDefault = getActiveTaskProfile(
|
||||
{
|
||||
taskProfilesVersion: 1,
|
||||
taskProfiles: {
|
||||
extract: {
|
||||
activeProfileId: "default",
|
||||
profiles: [
|
||||
{
|
||||
id: "default",
|
||||
taskType: "extract",
|
||||
builtin: true,
|
||||
blocks: [
|
||||
{
|
||||
id: "default-role",
|
||||
name: "角色定义",
|
||||
type: "custom",
|
||||
role: "system",
|
||||
content: "保留我自己的角色定义",
|
||||
order: 0,
|
||||
},
|
||||
{
|
||||
id: "default-char-desc",
|
||||
name: "角色描述",
|
||||
type: "builtin",
|
||||
role: "system",
|
||||
sourceKey: "charDescription",
|
||||
order: 1,
|
||||
},
|
||||
{
|
||||
id: "default-user-persona",
|
||||
name: "用户设定",
|
||||
type: "builtin",
|
||||
role: "system",
|
||||
sourceKey: "userPersona",
|
||||
order: 2,
|
||||
},
|
||||
{
|
||||
id: "default-wi-before",
|
||||
name: "世界书前块",
|
||||
type: "builtin",
|
||||
role: "system",
|
||||
sourceKey: "worldInfoBefore",
|
||||
order: 3,
|
||||
},
|
||||
{
|
||||
id: "default-wi-after",
|
||||
name: "世界书后块",
|
||||
type: "builtin",
|
||||
role: "system",
|
||||
sourceKey: "worldInfoAfter",
|
||||
order: 4,
|
||||
},
|
||||
{
|
||||
id: "default-format",
|
||||
name: "输出格式",
|
||||
type: "custom",
|
||||
role: "system",
|
||||
content: "保留我自己的输出格式",
|
||||
order: 5,
|
||||
},
|
||||
{
|
||||
id: "default-rules",
|
||||
name: "行为规则",
|
||||
type: "custom",
|
||||
role: "system",
|
||||
content: "保留我自己的行为规则",
|
||||
order: 6,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
"extract",
|
||||
);
|
||||
assert.equal(upgradedLegacyDefault.blocks.length, 11);
|
||||
assert.equal(upgradedLegacyDefault.blocks[0].content, "保留我自己的角色定义");
|
||||
assert.equal(upgradedLegacyDefault.blocks[9].content, "保留我自己的输出格式");
|
||||
assert.equal(upgradedLegacyDefault.blocks[10].content, "保留我自己的行为规则");
|
||||
assert.deepEqual(
|
||||
upgradedLegacyDefault.blocks
|
||||
.slice(5, 9)
|
||||
.map((block) => block.sourceKey),
|
||||
["recentMessages", "graphStats", "schema", "currentRange"],
|
||||
);
|
||||
|
||||
console.log("task-profile-migration tests passed");
|
||||
|
||||
@@ -51,7 +51,7 @@ const activeProfile = getActiveTaskProfile(
|
||||
"extract",
|
||||
);
|
||||
assert.equal(activeProfile.name, "激进提取");
|
||||
assert.equal(activeProfile.blocks.length, 9);
|
||||
assert.equal(activeProfile.blocks.length, 13);
|
||||
const builtinBlock = activeProfile.blocks.find(
|
||||
(block) => block.type === "builtin" && block.sourceKey === "userMessage",
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user