Update ena-planner.js for vector log and sequence

This commit is contained in:
Hao19911125
2026-02-25 10:28:45 +08:00
committed by GitHub
parent 86e08348af
commit c8fc81c3b7

View File

@@ -1086,6 +1086,7 @@ async function buildPlannerMessages(rawUserInput) {
// --- Story memory: try fresh recall with current user input --- // --- Story memory: try fresh recall with current user input ---
let cachedSummary = ''; let cachedSummary = '';
let _recallSource = 'none'; // ← 新增
try { try {
const vectorCfg = getVectorConfig(); const vectorCfg = getVectorConfig();
if (vectorCfg?.enabled) { if (vectorCfg?.enabled) {
@@ -1093,6 +1094,7 @@ async function buildPlannerMessages(rawUserInput) {
pendingUserMessage: rawUserInput, pendingUserMessage: rawUserInput,
}); });
cachedSummary = r?.text?.trim() || ''; cachedSummary = r?.text?.trim() || '';
if (cachedSummary) _recallSource = 'fresh'; // ← 新增
} }
} catch (e) { } catch (e) {
console.warn('[Ena] Fresh vector recall failed, falling back to cached data:', e); console.warn('[Ena] Fresh vector recall failed, falling back to cached data:', e);
@@ -1100,7 +1102,9 @@ async function buildPlannerMessages(rawUserInput) {
// Fallback: use stale cache from previous generation // Fallback: use stale cache from previous generation
if (!cachedSummary) { if (!cachedSummary) {
cachedSummary = getCachedStorySummary(); cachedSummary = getCachedStorySummary();
if (cachedSummary) _recallSource = 'stale'; // ← 新增
} }
console.log(`[Ena] Story memory source: ${_recallSource}`); // ← 新增
// --- Chat history: last 2 AI messages (floors N-1 & N-3) --- // --- Chat history: last 2 AI messages (floors N-1 & N-3) ---
// Two messages instead of one to avoid cross-device cache miss: // Two messages instead of one to avoid cross-device cache miss:
@@ -1140,14 +1144,14 @@ async function buildPlannerMessages(rawUserInput) {
// 3) Worldbook // 3) Worldbook
if (String(worldbook).trim()) messages.push({ role: 'system', content: worldbook }); if (String(worldbook).trim()) messages.push({ role: 'system', content: worldbook });
// 3.5) Story memory (小白X <剧情记忆> — fresh recall when available, stale cache as fallback) // 4) Chat history (last 2 AI responses — floors N-1 & N-3)
if (String(recentChat).trim()) messages.push({ role: 'system', content: recentChat });
// 4.5) Story memory (小白X <剧情记忆> — after chat context, before plots)
if (storySummary.trim()) { if (storySummary.trim()) {
messages.push({ role: 'system', content: `<story_summary>\n${storySummary}\n</story_summary>` }); messages.push({ role: 'system', content: `<story_summary>\n${storySummary}\n</story_summary>` });
} }
// 4) Chat history (last 2 AI responses — floors N-1 & N-3)
if (String(recentChat).trim()) messages.push({ role: 'system', content: recentChat });
// 5) Vector recall — now merged into story_summary above, kept for compatibility // 5) Vector recall — now merged into story_summary above, kept for compatibility
// (vectorRaw is empty; this block intentionally does nothing) // (vectorRaw is empty; this block intentionally does nothing)
if (String(vector).trim()) messages.push({ role: 'system', content: vector }); if (String(vector).trim()) messages.push({ role: 'system', content: vector });