Merge branch 'test' into main

This commit is contained in:
RT15548
2026-02-25 23:11:53 +08:00
committed by GitHub

View File

@@ -1,8 +1,6 @@
import { extension_settings } from '../../../../../extensions.js'; import { extension_settings } from '../../../../../extensions.js';
import { getRequestHeaders, saveSettingsDebounced, substituteParamsExtended } from '../../../../../../script.js'; import { getRequestHeaders, saveSettingsDebounced, substituteParamsExtended } from '../../../../../../script.js';
import { getStorySummaryForEna } from '../story-summary/story-summary.js'; import { getStorySummaryForEna } from '../story-summary/story-summary.js';
import { buildVectorPromptText } from '../story-summary/generate/prompt.js';
import { getVectorConfig } from '../story-summary/data/config.js';
const EXT_NAME = 'ena-planner'; const EXT_NAME = 'ena-planner';
@@ -1084,27 +1082,8 @@ async function buildPlannerMessages(rawUserInput) {
const charBlockRaw = formatCharCardBlock(charObj); const charBlockRaw = formatCharCardBlock(charObj);
// --- Story memory: try fresh recall with current user input --- // --- Story summary (cached from previous generation via interceptor) ---
let cachedSummary = ''; const cachedSummary = getCachedStorySummary();
let _recallSource = 'none'; // ← 新增
try {
const vectorCfg = getVectorConfig();
if (vectorCfg?.enabled) {
const r = await buildVectorPromptText(false, {
pendingUserMessage: rawUserInput,
});
cachedSummary = r?.text?.trim() || '';
if (cachedSummary) _recallSource = 'fresh'; // ← 新增
}
} catch (e) {
console.warn('[Ena] Fresh vector recall failed, falling back to cached data:', e);
}
// Fallback: use stale cache from previous generation
if (!cachedSummary) {
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:
@@ -1114,7 +1093,7 @@ async function buildPlannerMessages(rawUserInput) {
const recentChatRaw = collectRecentChatSnippet(chat, 2); const recentChatRaw = collectRecentChatSnippet(chat, 2);
const plotsRaw = formatPlotsBlock(extractLastNPlots(chat, s.plotCount)); const plotsRaw = formatPlotsBlock(extractLastNPlots(chat, s.plotCount));
const vectorRaw = ''; // Now included in fresh cachedSummary above const vectorRaw = formatVectorRecallBlock(extPrompts);
// Build scanText for worldbook keyword activation // Build scanText for worldbook keyword activation
const scanText = [charBlockRaw, cachedSummary, recentChatRaw, vectorRaw, plotsRaw, rawUserInput].join('\n\n'); const scanText = [charBlockRaw, cachedSummary, recentChatRaw, vectorRaw, plotsRaw, rawUserInput].join('\n\n');
@@ -1144,16 +1123,15 @@ 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 });
// 4) Chat history (last 2 AI responses — floors N-1 & N-3) // 3.5) Cached story summary (小白X 剧情记忆 from previous turn)
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>` });
} }
// 5) Vector recall — now merged into story_summary above, kept for compatibility // 4) Chat history (last 2 AI responses — floors N-1 & N-3)
// (vectorRaw is empty; this block intentionally does nothing) if (String(recentChat).trim()) messages.push({ role: 'system', content: recentChat });
// 5) Vector recall
if (String(vector).trim()) messages.push({ role: 'system', content: vector }); if (String(vector).trim()) messages.push({ role: 'system', content: vector });
// 6) Previous plots // 6) Previous plots