feat(ena-planner): make preserved response tags configurable with UI validation

This commit is contained in:
2026-02-25 22:23:19 +08:00
parent ad825c1189
commit b92d3bce28
2 changed files with 47 additions and 4 deletions

View File

@@ -256,6 +256,11 @@
<section class="card">
<div class="card-title">聊天与历史</div>
<div class="form-group">
<label class="form-label">保留的规划输出标签(逗号分隔)</label>
<input id="ep_keep_tags" type="text" class="input" placeholder="plot, note">
<p class="form-hint">仅支持英文标签(如 plot, note, memory。留空表示不按标签过滤仅去除 think。无效标签会自动忽略。</p>
</div>
<div class="form-group">
<label class="form-label">清理 AI 回复中的干扰标签(逗号分隔)</label>
<input id="ep_exclude_tags" type="text" class="input"
@@ -461,6 +466,16 @@
function csvToArr(text) {
return String(text || '').split(/[,]/).map(x => x.trim()).filter(Boolean);
}
function normalizeKeepTagsInput(text) {
const src = csvToArr(text);
const out = [];
src.forEach(item => {
const tag = String(item || '').replace(/^<+|>+$/g, '').toLowerCase();
if (!/^[a-z][a-z0-9_-]*$/.test(tag)) return;
if (!out.includes(tag)) out.push(tag);
});
return out;
}
function escapeHtml(str) {
return String(str || '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
@@ -669,6 +684,7 @@
$('ep_wb_pos4').value = String(toBool(cfg.excludeWorldbookPosition4, true));
$('ep_wb_exclude_names').value = arrToCsv(cfg.worldbookExcludeNames);
$('ep_plot_n').value = String(toNum(cfg.plotCount, 2));
$('ep_keep_tags').value = arrToCsv(cfg.responseKeepTags || ['plot', 'note']);
$('ep_exclude_tags').value = arrToCsv(cfg.chatExcludeTags);
$('ep_logs_persist').value = String(toBool(cfg.logsPersist, true));
@@ -708,6 +724,7 @@
p.excludeWorldbookPosition4 = toBool($('ep_wb_pos4').value, true);
p.worldbookExcludeNames = csvToArr($('ep_wb_exclude_names').value);
p.plotCount = Math.max(0, Math.floor(toNum($('ep_plot_n').value, 2)));
p.responseKeepTags = normalizeKeepTagsInput($('ep_keep_tags').value);
p.chatExcludeTags = csvToArr($('ep_exclude_tags').value);
p.logsPersist = toBool($('ep_logs_persist').value, true);
@@ -761,6 +778,10 @@
const val = $('ep_model_select').value;
if (val) { $('ep_model').value = val; scheduleSave(); }
});
$('ep_keep_tags').addEventListener('change', () => {
const normalized = normalizeKeepTagsInput($('ep_keep_tags').value);
$('ep_keep_tags').value = normalized.join(', ');
});
$('ep_add_prompt').addEventListener('click', () => {
cfg.promptBlocks = cfg.promptBlocks || [];