feat: variables 2.0 state + L0 summary integration

This commit is contained in:
2026-01-31 23:06:03 +08:00
parent 201c74dc71
commit 4b0541610b
22 changed files with 1949 additions and 2314 deletions

View File

@@ -75,6 +75,8 @@ import {
syncOnMessageSwiped,
syncOnMessageReceived,
} from "./vector/chunk-builder.js";
import { initStateIntegration, rebuildStateVectors } from "./vector/state-integration.js";
import { clearStateVectors, getStateAtomsCount, getStateVectorsCount } from "./vector/state-store.js";
// vector io
import { exportVectors, importVectors } from "./vector/vector-io.js";
@@ -210,6 +212,8 @@ async function sendVectorStatsToFrame() {
const stats = await getStorageStats(chatId);
const chunkStatus = await getChunkBuildStatus();
const totalMessages = chat?.length || 0;
const stateAtomsCount = getStateAtomsCount();
const stateVectorsCount = await getStateVectorsCount(chatId);
const cfg = getVectorConfig();
let mismatch = false;
@@ -228,6 +232,8 @@ async function sendVectorStatsToFrame() {
builtFloors: chunkStatus.builtFloors,
totalFloors: chunkStatus.totalFloors,
totalMessages,
stateAtoms: stateAtomsCount,
stateVectors: stateVectorsCount,
},
mismatch,
});
@@ -350,6 +356,14 @@ async function handleGenerateVectors(vectorCfg) {
const batchSize = isLocal ? 5 : 25;
const concurrency = isLocal ? 1 : 2;
// L0 向量重建
try {
await rebuildStateVectors(chatId, vectorCfg);
} catch (e) {
xbLog.error(MODULE_ID, "L0 向量重建失败", e);
// 不阻塞,继续 L1/L2
}
await clearAllChunks(chatId);
await updateMeta(chatId, { lastChunkFloor: -1, fingerprint });
@@ -649,6 +663,7 @@ async function handleClearVectors() {
await clearEventVectors(chatId);
await clearAllChunks(chatId);
await clearStateVectors(chatId);
await updateMeta(chatId, { lastChunkFloor: -1 });
await sendVectorStatsToFrame();
await executeSlashCommand('/echo severity=info 向量数据已清除。如需恢复召回功能,请重新点击"生成向量"。');
@@ -1400,7 +1415,7 @@ async function handleGenerationStarted(type, _params, isDryRun) {
// 2) depth倒序插入从末尾往前数
// 最小为 1避免插入到最底部导致 AI 看到的最后是总结
const depth = Math.max(1, chatLen - boundary - 1);
const depth = Math.max(2, chatLen - boundary - 1);
if (depth < 0) return;
// 3) 构建注入文本(保持原逻辑)
@@ -1504,4 +1519,5 @@ $(document).on("xiaobaix:storySummary:toggle", (_e, enabled) => {
jQuery(() => {
if (!getSettings().storySummary?.enabled) return;
registerEvents();
initStateIntegration();
});