mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-05-15 14:20:35 +08:00
feat(ui): show hidden floor count and render limit
This commit is contained in:
@@ -34,6 +34,13 @@ function getTimerApi(runtime = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
function notifyRuntimeHideStateChanged(runtime = {}) {
|
||||
try {
|
||||
runtime.refreshPanelLiveState?.();
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
|
||||
function getCurrentContext(runtime = {}) {
|
||||
try {
|
||||
return typeof runtime.getContext === "function" ? runtime.getContext() : null;
|
||||
@@ -487,10 +494,15 @@ export function scheduleHideSettingsApply(
|
||||
const snapshot = normalizeHideSettings(settings);
|
||||
hideState.scheduledTimer = timers.setTimeout(() => {
|
||||
hideState.scheduledTimer = null;
|
||||
void applyHideSettings(snapshot, runtime).catch((error) => {
|
||||
console.warn?.("[ST-BME] scheduled hide apply failed", error);
|
||||
});
|
||||
void applyHideSettings(snapshot, runtime)
|
||||
.then(() => {
|
||||
notifyRuntimeHideStateChanged(runtime);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.warn?.("[ST-BME] scheduled hide apply failed", error);
|
||||
});
|
||||
}, Math.max(0, Math.trunc(Number(delayMs) || 0)));
|
||||
notifyRuntimeHideStateChanged(runtime);
|
||||
}
|
||||
|
||||
export async function unhideAll(runtime = {}) {
|
||||
|
||||
@@ -151,6 +151,7 @@ async function ensurePanelBridgeReady(runtime) {
|
||||
getLastInjection: runtime.getLastInjection,
|
||||
getRuntimeDebugSnapshot: runtime.getRuntimeDebugSnapshot,
|
||||
getGraphPersistenceState: runtime.getGraphPersistenceState,
|
||||
getHideStateSnapshot: runtime.getHideStateSnapshot,
|
||||
updateSettings: (patch) => {
|
||||
const nextSettings = runtime.updateSettings(patch);
|
||||
if (Object.prototype.hasOwnProperty.call(patch || {}, "panelTheme")) {
|
||||
|
||||
@@ -1366,6 +1366,41 @@
|
||||
<div class="bme-config-help">
|
||||
设置修改后会自动生效。`0` 表示不隐藏;“取消全部隐藏”会立即把当前聊天里由 ST-BME 隐藏的楼层恢复。
|
||||
</div>
|
||||
<div class="bme-config-help">
|
||||
当前隐藏:<strong id="bme-hide-old-messages-hidden-count">0</strong>
|
||||
层;<span id="bme-hide-old-messages-status-detail">未应用</span>
|
||||
</div>
|
||||
<label
|
||||
class="bme-toggle-item"
|
||||
for="bme-setting-hide-old-messages-render-limit-enabled"
|
||||
>
|
||||
<span class="bme-toggle-copy">
|
||||
<span class="bme-toggle-title">限制聊天区渲染楼层</span>
|
||||
<span class="bme-toggle-desc">
|
||||
只控制前端最多加载最近多少层;不等于隐藏,未隐藏楼层仍可能进入上下文。
|
||||
</span>
|
||||
</span>
|
||||
<input
|
||||
id="bme-setting-hide-old-messages-render-limit-enabled"
|
||||
type="checkbox"
|
||||
/>
|
||||
</label>
|
||||
<div class="bme-config-row">
|
||||
<label for="bme-setting-hide-old-messages-render-limit">
|
||||
最多渲染最近 N 条消息
|
||||
</label>
|
||||
<input
|
||||
id="bme-setting-hide-old-messages-render-limit"
|
||||
class="bme-config-input"
|
||||
type="number"
|
||||
min="0"
|
||||
max="1000"
|
||||
placeholder="0 = 不限制渲染"
|
||||
/>
|
||||
</div>
|
||||
<div class="bme-config-help">
|
||||
参考隐藏助手的“限制楼层”:用于减少超长聊天界面卡顿;真正节省上下文 token 仍由上方“旧楼层隐藏”负责。
|
||||
</div>
|
||||
<div class="bme-config-actions">
|
||||
<button
|
||||
class="bme-config-secondary-btn"
|
||||
|
||||
67
ui/panel.js
67
ui/panel.js
@@ -388,6 +388,7 @@ let _getLastRecallStatus = null;
|
||||
let _getLastInjection = null;
|
||||
let _getRuntimeDebugSnapshot = null;
|
||||
let _getGraphPersistenceState = null;
|
||||
let _getHideStateSnapshot = null;
|
||||
let _updateSettings = null;
|
||||
let _actionHandlers = {};
|
||||
|
||||
@@ -952,6 +953,7 @@ export async function initPanel({
|
||||
getLastInjection,
|
||||
getRuntimeDebugSnapshot,
|
||||
getGraphPersistenceState,
|
||||
getHideStateSnapshot,
|
||||
updateSettings,
|
||||
actions,
|
||||
}) {
|
||||
@@ -967,6 +969,7 @@ export async function initPanel({
|
||||
_getLastInjection = getLastInjection;
|
||||
_getRuntimeDebugSnapshot = getRuntimeDebugSnapshot;
|
||||
_getGraphPersistenceState = getGraphPersistenceState;
|
||||
_getHideStateSnapshot = getHideStateSnapshot;
|
||||
_updateSettings = updateSettings;
|
||||
_actionHandlers = actions || {};
|
||||
|
||||
@@ -1277,6 +1280,7 @@ export function refreshLiveState() {
|
||||
_applyGraphRuntimeConfig(_getSettings?.() || {});
|
||||
_refreshRuntimeStatus();
|
||||
_refreshNativeRolloutStatusUi(_getSettings?.() || {});
|
||||
_refreshHideOldMessagesStatus(_getSettings?.() || {});
|
||||
|
||||
switch (currentTabId) {
|
||||
case "dashboard":
|
||||
@@ -1300,6 +1304,45 @@ export function refreshLiveState() {
|
||||
_scheduleVisibleGraphWorkspaceRefresh();
|
||||
}
|
||||
|
||||
function _refreshHideOldMessagesStatus(settings = _getSettings?.() || {}) {
|
||||
const countEl = document.getElementById("bme-hide-old-messages-hidden-count");
|
||||
const detailEl = document.getElementById("bme-hide-old-messages-status-detail");
|
||||
if (!countEl && !detailEl) return;
|
||||
|
||||
const snapshot =
|
||||
typeof _getHideStateSnapshot === "function" ? _getHideStateSnapshot() || {} : {};
|
||||
const hiddenCount = Math.max(
|
||||
0,
|
||||
Math.trunc(Number(snapshot.managedHiddenCount ?? 0) || 0),
|
||||
);
|
||||
const scannedCount = Math.max(
|
||||
0,
|
||||
Math.trunc(Number(snapshot.lastProcessedLength ?? 0) || 0),
|
||||
);
|
||||
const keepLastN = Math.max(
|
||||
0,
|
||||
Math.trunc(Number(settings.hideOldMessagesKeepLastN ?? 0) || 0),
|
||||
);
|
||||
const detailParts = [];
|
||||
|
||||
if (settings.hideOldMessagesEnabled !== true) {
|
||||
detailParts.push("旧楼层隐藏未启用");
|
||||
} else if (keepLastN <= 0) {
|
||||
detailParts.push("保留最近 N 为 0,不会隐藏");
|
||||
} else {
|
||||
detailParts.push(`保留最近 ${keepLastN} 层`);
|
||||
}
|
||||
if (scannedCount > 0) {
|
||||
detailParts.push(`已扫描 ${scannedCount} 层`);
|
||||
}
|
||||
if (snapshot.scheduled === true) {
|
||||
detailParts.push("等待自动应用");
|
||||
}
|
||||
|
||||
if (countEl) countEl.textContent = String(hiddenCount);
|
||||
if (detailEl) detailEl.textContent = detailParts.join(" · ") || "未应用";
|
||||
}
|
||||
|
||||
// ==================== Tab 切换 ====================
|
||||
|
||||
function _bindTabs() {
|
||||
@@ -6587,6 +6630,10 @@ function _refreshConfigTab() {
|
||||
"bme-setting-hide-old-messages-enabled",
|
||||
settings.hideOldMessagesEnabled ?? false,
|
||||
);
|
||||
_setCheckboxValue(
|
||||
"bme-setting-hide-old-messages-render-limit-enabled",
|
||||
settings.hideOldMessagesRenderLimitEnabled ?? false,
|
||||
);
|
||||
_setCheckboxValue(
|
||||
"bme-setting-recall-enabled",
|
||||
settings.recallEnabled ?? true,
|
||||
@@ -6746,6 +6793,11 @@ function _refreshConfigTab() {
|
||||
"bme-setting-hide-old-messages-keep-last-n",
|
||||
settings.hideOldMessagesKeepLastN ?? 12,
|
||||
);
|
||||
_setInputValue(
|
||||
"bme-setting-hide-old-messages-render-limit",
|
||||
settings.hideOldMessagesRenderLimit ?? 0,
|
||||
);
|
||||
_refreshHideOldMessagesStatus(settings);
|
||||
_setInputValue(
|
||||
"bme-setting-extract-context-turns",
|
||||
settings.extractContextTurns ?? 2,
|
||||
@@ -7057,6 +7109,12 @@ function _bindConfigControls() {
|
||||
bindCheckbox("bme-setting-hide-old-messages-enabled", (checked) => {
|
||||
_patchSettings({ hideOldMessagesEnabled: checked });
|
||||
});
|
||||
bindCheckbox(
|
||||
"bme-setting-hide-old-messages-render-limit-enabled",
|
||||
(checked) => {
|
||||
_patchSettings({ hideOldMessagesRenderLimitEnabled: checked });
|
||||
},
|
||||
);
|
||||
bindCheckbox("bme-setting-recall-enabled", (checked) => {
|
||||
_patchSettings({ recallEnabled: checked });
|
||||
_refreshGuardedConfigStates();
|
||||
@@ -7254,6 +7312,13 @@ function _bindConfigControls() {
|
||||
200,
|
||||
(value) => _patchSettings({ hideOldMessagesKeepLastN: value }),
|
||||
);
|
||||
bindNumber(
|
||||
"bme-setting-hide-old-messages-render-limit",
|
||||
0,
|
||||
0,
|
||||
1000,
|
||||
(value) => _patchSettings({ hideOldMessagesRenderLimit: value }),
|
||||
);
|
||||
bindNumber("bme-setting-extract-context-turns", 2, 0, 20, (value) =>
|
||||
_patchSettings({ extractContextTurns: value }),
|
||||
);
|
||||
@@ -7775,6 +7840,7 @@ function _bindConfigControls() {
|
||||
toastr.error(result.error, "ST-BME");
|
||||
return;
|
||||
}
|
||||
_refreshHideOldMessagesStatus(_getSettings?.() || {});
|
||||
toastr.success("当前聊天的隐藏设置已重新应用", "ST-BME");
|
||||
});
|
||||
document
|
||||
@@ -7786,6 +7852,7 @@ function _bindConfigControls() {
|
||||
toastr.error(result.error, "ST-BME");
|
||||
return;
|
||||
}
|
||||
_refreshHideOldMessagesStatus(_getSettings?.() || {});
|
||||
toastr.info("已取消当前聊天里由 ST-BME 应用的隐藏", "ST-BME");
|
||||
});
|
||||
document
|
||||
|
||||
Reference in New Issue
Block a user