Files
ST-Bionic-Memory-Ecology/st-context.js
Youzini-afk d31c0325d3 feat: Phase 3 世界书引擎移植 + EJS 支持
- 新增 task-worldinfo.js: 从 EW 移植世界书激活/分桶引擎
- 新增 task-ejs.js: 从 EW 移植 EJS 模板渲染引擎
- 新增 vendor/ejs.js: EJS runtime vendor
- prompt-builder.js: 改为异步, 接入 worldInfoBefore/After/atDepth
- prompt-profiles.js: 新增内置块 charDescription/userPersona/worldInfoBefore/After
- 更新 extractor/retriever/compressor/consolidator 接入新 builder
- st-context.js: 扩展 ST 上下文字段兜底
- 新增 tests/task-worldinfo.mjs: 世界书引擎测试
2026-03-26 13:57:07 +08:00

48 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ST-BME: SillyTavern 上下文数据读取辅助
// 为 prompt 变量扩展Phase 2提供统一的 ST 上下文数据接口
import { getContext } from "../../../extensions.js";
/**
* 从 SillyTavern 的 getContext() 提取当前上下文数据,
* 返回的字段可直接展开传入 buildTaskPrompt 的 context 参数,
* 用户在自定义 prompt 块中可通过 {{key}} 引用。
*
* @returns {object} 上下文字段映射
*/
export function getSTContextForPrompt() {
try {
const ctx = getContext?.() || {};
const charId = ctx.characterId;
const char =
ctx.characters?.[Number(charId)] ||
ctx.characters?.[charId] ||
null;
return {
userPersona:
ctx.powerUserSettings?.persona_description ||
ctx.extensionSettings?.persona_description ||
ctx.name1_description ||
ctx.persona ||
"",
charDescription:
char?.description ||
char?.data?.description ||
"",
charName: ctx.name2 || "",
userName: ctx.name1 || "",
currentTime: new Date().toLocaleString("zh-CN"),
};
} catch (e) {
console.warn("[ST-BME] getSTContextForPrompt 失败:", e);
return {
userPersona: "",
charDescription: "",
charName: "",
userName: "",
currentTime: new Date().toLocaleString("zh-CN"),
};
}
}