Refine story summary prompts and vector sync

This commit is contained in:
2026-01-30 00:55:04 +08:00
parent 6aaed2af4a
commit d87c8a0207
7 changed files with 1174 additions and 432 deletions

View File

@@ -1,7 +1,7 @@
// story-summary-ui.js
// iframe 内 UI 逻辑
(function() {
(function () {
'use strict';
// ═══════════════════════════════════════════════════════════════════════════
@@ -10,7 +10,7 @@
const $ = id => document.getElementById(id);
const $$ = sel => document.querySelectorAll(sel);
const h = v => String(v ?? '').replace(/[&<>"']/g, c =>
const h = v => String(v ?? '').replace(/[&<>"']/g, c =>
({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]
);
const setHtml = (el, html) => {
@@ -43,7 +43,7 @@
// ═══════════════════════════════════════════════════════════════════════════
const PARENT_ORIGIN = (() => {
try { return new URL(document.referrer).origin; }
try { return new URL(document.referrer).origin; }
catch { return window.location.origin; }
})();
@@ -154,7 +154,7 @@
saveConfig();
}
}
} catch {}
} catch { }
}
function applyConfig(cfg) {
@@ -299,16 +299,18 @@
const items = rules?.length ? rules : [];
setHtml(list, items.map((r, i) => `
<div class="filter-rule-item" data-idx="${i}" style="display:flex;gap:6px;align-items:center">
<input type="text" class="filter-rule-start" placeholder="起始(可空)" value="${h(r.start || '')}" style="flex:1;padding:6px 8px;font-size:.8125rem">
<span style="color:var(--txt3)">→</span>
<input type="text" class="filter-rule-end" placeholder="结束(可空)" value="${h(r.end || '')}" style="flex:1;padding:6px 8px;font-size:.8125rem">
<button class="btn btn-sm btn-del filter-rule-del" style="padding:4px 8px">✕</button>
<div class="filter-rule-item" data-idx="${i}">
<div class="filter-rule-inputs">
<input type="text" class="filter-rule-start" placeholder="起始(可空)" value="${h(r.start || '')}">
<span class="rule-arrow">⬇</span>
<input type="text" class="filter-rule-end" placeholder="结束(可空)" value="${h(r.end || '')}">
</div>
<button class="btn-del-rule">✕</button>
</div>
`).join(''));
// 绑定删除
list.querySelectorAll('.filter-rule-del').forEach(btn => {
list.querySelectorAll('.btn-del-rule').forEach(btn => {
btn.onclick = () => {
btn.closest('.filter-rule-item')?.remove();
};
@@ -338,14 +340,15 @@
const div = document.createElement('div');
div.className = 'filter-rule-item';
div.dataset.idx = idx;
div.style.cssText = 'display:flex;gap:6px;align-items:center';
setHtml(div, `
<input type="text" class="filter-rule-start" placeholder="起始(可空)" value="" style="flex:1;padding:6px 8px;font-size:.8125rem">
<span style="color:var(--txt3)">→</span>
<input type="text" class="filter-rule-end" placeholder="结束(可空)" value="" style="flex:1;padding:6px 8px;font-size:.8125rem">
<button class="btn btn-sm btn-del filter-rule-del" style="padding:4px 8px">✕</button>
<div class="filter-rule-inputs">
<input type="text" class="filter-rule-start" placeholder="起始(可空)" value="">
<span class="rule-arrow">⬇</span>
<input type="text" class="filter-rule-end" placeholder="结束(可空)" value="">
</div>
<button class="btn-del-rule">✕</button>
`);
div.querySelector('.filter-rule-del').onclick = () => div.remove();
div.querySelector('.btn-del-rule').onclick = () => div.remove();
list.appendChild(div);
}
@@ -550,7 +553,24 @@
updateProviderUI(config.api.provider);
if (config.vector) loadVectorConfig(config.vector);
// Initialize sub-options visibility
const autoSummaryOptions = $('auto-summary-options');
if (autoSummaryOptions) {
autoSummaryOptions.classList.toggle('hidden', !config.trigger.enabled);
}
const insertWrapperOptions = $('insert-wrapper-options');
if (insertWrapperOptions) {
insertWrapperOptions.classList.toggle('hidden', !config.trigger.forceInsertAtEnd);
}
$('settings-modal').classList.add('active');
// Default to first tab
$$('.settings-tab').forEach(t => t.classList.remove('active'));
$$('.settings-tab[data-tab="tab-summary"]').forEach(t => t.classList.add('active'));
$$('.tab-pane').forEach(p => p.classList.remove('active'));
$('tab-summary').classList.add('active');
postMsg('SETTINGS_OPENED');
}
@@ -1202,17 +1222,6 @@ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "
}
}
function openRecallLog() {
updateRecallLogDisplay();
$('recall-log-modal').classList.add('active');
postMsg('FULLSCREEN_OPENED');
}
function closeRecallLog() {
$('recall-log-modal').classList.remove('active');
postMsg('FULLSCREEN_CLOSED');
}
// ═══════════════════════════════════════════════════════════════════════════
// Editor
// ═══════════════════════════════════════════════════════════════════════════
@@ -1578,7 +1587,7 @@ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "
renderTimeline([]);
renderRelations(null);
renderArcs([]);
renderWorldState([]);
renderWorldState([]);
break;
}
@@ -1666,6 +1675,27 @@ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "
$('settings-cancel').onclick = () => closeSettings(false);
$('settings-save').onclick = () => closeSettings(true);
// Settings tabs
$$('.settings-tab').forEach(tab => {
tab.onclick = () => {
const targetId = tab.dataset.tab;
if (!targetId) return;
// Update tab active state
$$('.settings-tab').forEach(t => t.classList.remove('active'));
tab.classList.add('active');
// Update pane active state
$$('.tab-pane').forEach(p => p.classList.remove('active'));
$(targetId).classList.add('active');
// If switching to debug tab, refresh log
if (targetId === 'tab-debug') {
postMsg('REQUEST_RECALL_LOG');
}
};
});
// API provider change
$('api-provider').onchange = e => {
const pv = PROVIDER_DEFAULTS[e.target.value];
@@ -1729,11 +1759,6 @@ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "
$('hf-guide-backdrop').onclick = closeHfGuide;
$('hf-guide-close').onclick = closeHfGuide;
// Recall log
$('btn-recall').onclick = openRecallLog;
$('recall-log-backdrop').onclick = closeRecallLog;
$('recall-log-close').onclick = closeRecallLog;
// Character selector
$('char-sel-trigger').onclick = e => {
e.stopPropagation();
@@ -1748,6 +1773,36 @@ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "
// Vector UI
initVectorUI();
// Gen params collapsible
const genParamsToggle = $('gen-params-toggle');
const genParamsContent = $('gen-params-content');
if (genParamsToggle && genParamsContent) {
genParamsToggle.onclick = () => {
const collapse = genParamsToggle.closest('.settings-collapse');
collapse.classList.toggle('open');
genParamsContent.classList.toggle('hidden');
};
}
// Auto summary sub-options toggle
const triggerEnabled = $('trigger-enabled');
const autoSummaryOptions = $('auto-summary-options');
if (triggerEnabled && autoSummaryOptions) {
triggerEnabled.onchange = () => {
autoSummaryOptions.classList.toggle('hidden', !triggerEnabled.checked);
};
}
// Force insert sub-options toggle
const triggerInsertAtEnd = $('trigger-insert-at-end');
const insertWrapperOptions = $('insert-wrapper-options');
if (triggerInsertAtEnd && insertWrapperOptions) {
triggerInsertAtEnd.onchange = () => {
insertWrapperOptions.classList.toggle('hidden', !triggerInsertAtEnd.checked);
};
}
// Resize
window.onresize = () => {
relationChart?.resize();
@@ -1833,7 +1888,7 @@ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "
`).join('')}
</div>
`;
}).join('');
}).join('');
setHtml(container, html || '<div class="empty">暂无世界状态</div>');
}