Update recall logic and remove unused state-recall

This commit is contained in:
2026-02-09 10:09:16 +08:00
parent 24f97f605e
commit 5b9da7aaf4
5 changed files with 827 additions and 695 deletions

View File

@@ -1,12 +1,11 @@
// ═══════════════════════════════════════════════════════════════════════════
// Story Summary - 主入口(最终版)
// ═══════════════════════════════════════════════════════════════════════════
// Story Summary - 主入口
//
// 稳定目标:
// 1) "聊天时隐藏已总结" 永远只隐藏"已总结"部分,绝不影响未总结部分
// 2) 关闭隐藏 = 暴力全量 unhide确保立刻恢复
// 3) 开启隐藏 / 改Y / 切Chat / 收新消息:先全量 unhide再按边界重新 hide
// 4) Prompt 注入位置稳定:永远插在"最后一条 user 消息"之前
// 5) 注入回归 extension_prompts + IN_CHAT + depth动态计算
// 4) Prompt 注入extension_prompts + IN_CHAT + depth动态计算最小为2
// ═══════════════════════════════════════════════════════════════════════════
import { getContext } from "../../../../../extensions.js";
@@ -108,7 +107,7 @@ let vectorCancelled = false;
let vectorAbortController = null;
let anchorGenerating = false;
// 用户消息缓存(解决 GENERATION_STARTED 时 chat 尚未包含用户消息的问题)
// 用户消息缓存(解决 GENERATION_STARTED 时 chat 尚未包含用户消息的问题)
let lastSentUserMessage = null;
let lastSentTimestamp = 0;
@@ -142,6 +141,7 @@ let lastVectorWarningAt = 0;
const VECTOR_WARNING_COOLDOWN_MS = 120000; // 2分钟内不重复提醒
const EXT_PROMPT_KEY = "LittleWhiteBox_StorySummary";
const MIN_INJECTION_DEPTH = 2;
// role 映射
const ROLE_MAP = {
@@ -1208,7 +1208,7 @@ async function handleChatChanged() {
initButtonsForAll();
const store = getSummaryStore();
if (store?.hideSummarizedHistory) {
await applyHideState();
}
@@ -1216,7 +1216,7 @@ async function handleChatChanged() {
if (frameReady) {
await sendFrameBaseData(store, newLength);
sendFrameFullData(store, newLength);
sendAnchorStatsToFrame();
sendVectorStatsToFrame();
}
@@ -1307,7 +1307,7 @@ async function handleGenerationStarted(type, _params, isDryRun) {
clearExtensionPrompt();
// ★ 保留:判断是否使用缓存的用户消息30秒内有效
// 判断是否使用缓存的用户消息30秒内有效
let pendingUserMessage = null;
if (type === "normal" && lastSentUserMessage && (Date.now() - lastSentTimestamp < 30000)) {
pendingUserMessage = lastSentUserMessage;
@@ -1322,7 +1322,7 @@ async function handleGenerationStarted(type, _params, isDryRun) {
const store = getSummaryStore();
// 1) boundary
// 确定注入边界
// - 向量开meta.lastChunkFloor若无则回退 lastSummarizedMesId
// - 向量关lastSummarizedMesId
let boundary = -1;
@@ -1335,12 +1335,12 @@ async function handleGenerationStarted(type, _params, isDryRun) {
}
if (boundary < 0) return;
// 2) depth:倒序插入,从末尾往前数
// 最小为 1避免插入到最底部导致 AI 看到的最后是总结
const depth = Math.max(2, chatLen - boundary - 1);
// 计算深度:倒序插入,从末尾往前数
// 最小为 MIN_INJECTION_DEPTH避免插入太靠近底部
const depth = Math.max(MIN_INJECTION_DEPTH, chatLen - boundary - 1);
if (depth < 0) return;
// 3) 构建注入文本(保持原逻辑)
// 构建注入文本
let text = "";
if (vectorCfg?.enabled) {
const r = await buildVectorPromptText(excludeLastAi, {
@@ -1354,12 +1354,12 @@ async function handleGenerationStarted(type, _params, isDryRun) {
}
if (!text.trim()) return;
// 4) 写入 extension_prompts
// 获取用户配置的 role
const cfg = getSummaryPanelConfig();
const roleKey = cfg.trigger?.role || 'system';
const role = ROLE_MAP[roleKey] || extension_prompt_roles.SYSTEM;
// 写入 extension_prompts
extension_prompts[EXT_PROMPT_KEY] = {
value: text,
position: extension_prompt_types.IN_CHAT,