Files
ST-Bionic-Memory-Ecology/st-context.js
Youzini-afk 2f9524d993 feat: 优化默认提示词(HARD GATE约束) + 扩展prompt变量(Phase1+2)
Phase 1: 重写 DEFAULT_TASK_BLOCKS 全部6个任务的 role/format/rules
- 统一应用 HARD GATE 约束段 + 常见错误负例
- compress/synopsis 增加自检清单
- 增强 JSON 稳定性约束

Phase 2: 扩展 prompt 内置变量
- 新建 st-context.js: 统一读取 ST 上下文
- 新增变量: charName/userName/charDescription/userPersona/currentTime
- 更新 extractor/retriever/compressor/consolidator 共6处调用端
- 更新 BUILTIN_BLOCK_DEFINITIONS 帮助文案(多轮对话指引)
2026-03-26 10:30:26 +08:00

46 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.name1_description ||
"",
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"),
};
}
}