mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-05-15 22:30:38 +08:00
feat(ui): show hidden floor count and render limit
This commit is contained in:
131
index.js
131
index.js
@@ -4953,11 +4953,119 @@ function getMessageHideSettings(settings = null) {
|
||||
};
|
||||
}
|
||||
|
||||
function getMessageRenderLimitSettings(settings = null) {
|
||||
let sourceSettings = settings;
|
||||
if (!sourceSettings || typeof sourceSettings !== "object") {
|
||||
try {
|
||||
sourceSettings =
|
||||
typeof getSettings === "function" ? getSettings() : {};
|
||||
} catch {
|
||||
sourceSettings = {};
|
||||
}
|
||||
}
|
||||
return {
|
||||
enabled:
|
||||
sourceSettings.enabled !== false &&
|
||||
Boolean(sourceSettings.hideOldMessagesRenderLimitEnabled),
|
||||
render_last_n: Math.max(
|
||||
0,
|
||||
Math.trunc(Number(sourceSettings.hideOldMessagesRenderLimit ?? 0) || 0),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
function getHostPowerUserSettings() {
|
||||
try {
|
||||
const context = typeof getContext === "function" ? getContext() : null;
|
||||
return (
|
||||
context?.power_user ||
|
||||
context?.powerUserSettings ||
|
||||
globalThis.power_user ||
|
||||
null
|
||||
);
|
||||
} catch {
|
||||
return globalThis.power_user || null;
|
||||
}
|
||||
}
|
||||
|
||||
function applyMessageRenderLimit(settings = null, options = {}) {
|
||||
const normalized = getMessageRenderLimitSettings(settings);
|
||||
const shouldClear = options.clearWhenDisabled === true;
|
||||
if (!normalized.enabled && !shouldClear) {
|
||||
return {
|
||||
active: false,
|
||||
renderLimit: 0,
|
||||
applied: false,
|
||||
skipped: true,
|
||||
};
|
||||
}
|
||||
|
||||
const renderLimit =
|
||||
normalized.enabled && normalized.render_last_n > 0
|
||||
? normalized.render_last_n
|
||||
: 0;
|
||||
let applied = false;
|
||||
const powerUserSettings = getHostPowerUserSettings();
|
||||
if (powerUserSettings && typeof powerUserSettings === "object") {
|
||||
powerUserSettings.chat_truncation = renderLimit;
|
||||
applied = true;
|
||||
}
|
||||
|
||||
try {
|
||||
const jq = typeof $ === "function" ? $ : null;
|
||||
if (jq) {
|
||||
const value = String(renderLimit);
|
||||
const truncationInput = jq("#chat_truncation");
|
||||
if (
|
||||
truncationInput &&
|
||||
Number(truncationInput.length || 0) > 0 &&
|
||||
typeof truncationInput.val === "function"
|
||||
) {
|
||||
truncationInput.val(value);
|
||||
if (typeof truncationInput.trigger === "function") {
|
||||
truncationInput.trigger("change");
|
||||
}
|
||||
applied = true;
|
||||
}
|
||||
const truncationCounter = jq("#chat_truncation_counter");
|
||||
if (
|
||||
truncationCounter &&
|
||||
Number(truncationCounter.length || 0) > 0 &&
|
||||
typeof truncationCounter.val === "function"
|
||||
) {
|
||||
truncationCounter.val(value);
|
||||
applied = true;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("[ST-BME] 同步聊天区渲染楼层限制失败:", error);
|
||||
}
|
||||
|
||||
if (options.reloadCurrentChat === true) {
|
||||
try {
|
||||
const context = typeof getContext === "function" ? getContext() : null;
|
||||
if (typeof context?.reloadCurrentChat === "function") {
|
||||
context.reloadCurrentChat();
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("[ST-BME] 重新加载聊天区渲染楼层失败:", error);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
active: renderLimit > 0,
|
||||
renderLimit,
|
||||
applied,
|
||||
skipped: false,
|
||||
};
|
||||
}
|
||||
|
||||
function getHideRuntimeAdapters() {
|
||||
return {
|
||||
$,
|
||||
clearTimeout,
|
||||
getContext,
|
||||
refreshPanelLiveState,
|
||||
setTimeout,
|
||||
};
|
||||
}
|
||||
@@ -4969,6 +5077,7 @@ async function applyMessageHideNow(reason = "manual-apply") {
|
||||
getHideRuntimeAdapters(),
|
||||
);
|
||||
debugLog("[ST-BME] 已应用旧楼层隐藏:", reason, result);
|
||||
refreshPanelLiveState();
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.warn("[ST-BME] 应用旧楼层隐藏失败:", reason, error);
|
||||
@@ -5000,6 +5109,7 @@ async function runIncrementalMessageHide(reason = "incremental") {
|
||||
if (result?.active) {
|
||||
debugLog("[ST-BME] 已增量更新旧楼层隐藏:", reason, result);
|
||||
}
|
||||
refreshPanelLiveState();
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.warn("[ST-BME] 增量更新旧楼层隐藏失败:", reason, error);
|
||||
@@ -5014,6 +5124,7 @@ function clearMessageHideState(reason = "reset") {
|
||||
try {
|
||||
resetHideState(getHideRuntimeAdapters());
|
||||
debugLog("[ST-BME] 已重置旧楼层隐藏状态:", reason);
|
||||
refreshPanelLiveState();
|
||||
} catch (error) {
|
||||
console.warn("[ST-BME] 重置旧楼层隐藏状态失败:", reason, error);
|
||||
}
|
||||
@@ -5023,6 +5134,7 @@ async function clearAllHiddenMessages(reason = "manual-clear") {
|
||||
try {
|
||||
const result = await unhideAll(getHideRuntimeAdapters());
|
||||
debugLog("[ST-BME] 已取消全部旧楼层隐藏:", reason, result);
|
||||
refreshPanelLiveState();
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.warn("[ST-BME] 取消全部旧楼层隐藏失败:", reason, error);
|
||||
@@ -12368,6 +12480,10 @@ function refreshPanelLiveState() {
|
||||
});
|
||||
}
|
||||
|
||||
function getMessageHideStateSnapshotForPanel() {
|
||||
return getHideStateSnapshot();
|
||||
}
|
||||
|
||||
function notifyStatusToast(key, kind, message, title = "ST-BME") {
|
||||
const now = Date.now();
|
||||
if (now - (lastStatusToastAt[key] || 0) < STATUS_TOAST_THROTTLE_MS) return;
|
||||
@@ -13080,6 +13196,11 @@ function updateModuleSettings(patch = {}) {
|
||||
"hideOldMessagesEnabled",
|
||||
"hideOldMessagesKeepLastN",
|
||||
]);
|
||||
const messageRenderLimitKeys = new Set([
|
||||
"enabled",
|
||||
"hideOldMessagesRenderLimitEnabled",
|
||||
"hideOldMessagesRenderLimit",
|
||||
]);
|
||||
const recallUiKeys = new Set(["recallCardUserInputDisplayMode"]);
|
||||
const noticeUiKeys = new Set(["noticeDisplayMode"]);
|
||||
const settings = getSettings();
|
||||
@@ -13147,6 +13268,14 @@ function updateModuleSettings(patch = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
if (Object.keys(patch).some((key) => messageRenderLimitKeys.has(key))) {
|
||||
const renderResult = applyMessageRenderLimit(settings, {
|
||||
clearWhenDisabled: true,
|
||||
reloadCurrentChat: true,
|
||||
});
|
||||
debugLog("[ST-BME] 已同步聊天区渲染楼层限制:", renderResult);
|
||||
}
|
||||
|
||||
if (Object.keys(patch).some((key) => recallUiKeys.has(key))) {
|
||||
schedulePersistedRecallMessageUiRefresh(30);
|
||||
}
|
||||
@@ -19834,6 +19963,7 @@ async function onCompactLukerSidecar() {
|
||||
document,
|
||||
getGraph: () => currentGraph,
|
||||
getGraphPersistenceState: () => getGraphPersistenceLiveState(),
|
||||
getHideStateSnapshot: () => getMessageHideStateSnapshotForPanel(),
|
||||
getLastBatchStatus: () =>
|
||||
currentGraph?.historyState?.lastBatchStatus || null,
|
||||
getLastExtract: () => lastExtractedItems,
|
||||
@@ -19864,6 +19994,7 @@ async function onCompactLukerSidecar() {
|
||||
scheduleBmeIndexedDbWarmup("init");
|
||||
initializeHostCapabilityBridge();
|
||||
installSendIntentHooks();
|
||||
applyMessageRenderLimit(getSettings());
|
||||
autoSyncOnVisibility(buildBmeSyncRuntimeOptions());
|
||||
scheduleMessageHideApply("init", 180);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user