Decouple panel bootstrap from host UI helpers

This commit is contained in:
Youzini-afk
2026-04-08 02:17:49 +08:00
parent 84d42bbef3
commit 82edd86fee
2 changed files with 29 additions and 9 deletions

View File

@@ -37,9 +37,14 @@ function injectOptionsMenuEntry(runtime) {
<span>记忆图谱</span> <span>记忆图谱</span>
</a> </a>
`).on("click", async () => { `).on("click", async () => {
await ensurePanelBridgeReady(runtime); try {
openPanelController(runtime); await ensurePanelBridgeReady(runtime);
runtime.$("#options").hide(); openPanelController(runtime);
runtime.$("#options").hide();
} catch (error) {
runtime.console.error("[ST-BME] 点击菜单打开面板失败:", error);
globalThis.toastr?.error?.("记忆图谱面板加载失败,请查看控制台报错", "ST-BME");
}
}); });
const $optionsContent = runtime.$("#options .options-content"); const $optionsContent = runtime.$("#options .options-content");
@@ -129,5 +134,6 @@ export async function initializePanelBridgeController(runtime) {
"[ST-BME] 操控面板加载失败(核心功能不受影响):", "[ST-BME] 操控面板加载失败(核心功能不受影响):",
panelError, panelError,
); );
globalThis.toastr?.error?.("记忆图谱面板预加载失败,可稍后重试点击菜单", "ST-BME");
} }
} }

View File

@@ -1,8 +1,6 @@
// ST-BME: 操控面板交互逻辑 // ST-BME: 操控面板交互逻辑
import { callGenericPopup, POPUP_TYPE } from "../../../../popup.js";
import { getContext } from "../../../../extensions.js"; import { getContext } from "../../../../extensions.js";
import { renderTemplateAsync } from "../../../../templates.js";
import { GraphRenderer } from "./graph-renderer.js"; import { GraphRenderer } from "./graph-renderer.js";
import { getNodeDisplayName } from "../graph/node-labels.js"; import { getNodeDisplayName } from "../graph/node-labels.js";
import { import {
@@ -221,6 +219,7 @@ let fetchedMemoryLLMModels = [];
let fetchedBackendEmbeddingModels = []; let fetchedBackendEmbeddingModels = [];
let fetchedDirectEmbeddingModels = []; let fetchedDirectEmbeddingModels = [];
let viewportSyncBound = false; let viewportSyncBound = false;
let popupRuntimePromise = null;
// 由 index.js 注入的引用 // 由 index.js 注入的引用
let _getGraph = null; let _getGraph = null;
@@ -238,15 +237,29 @@ let _updateSettings = null;
let _actionHandlers = {}; let _actionHandlers = {};
async function loadLocalTemplate(templateName) { async function loadLocalTemplate(templateName) {
const templatePath = new URL(`./${templateName}.html`, import.meta.url) const templateUrl = new URL(`./${templateName}.html`, import.meta.url);
.pathname; const response = await fetch(templateUrl.href, {
const html = await renderTemplateAsync(templatePath, {}, true, true, true); cache: "no-store",
});
if (!response.ok) {
throw new Error(
`Template request failed: ${templateUrl.pathname} (${response.status} ${response.statusText})`,
);
}
const html = await response.text();
if (typeof html !== "string" || html.trim().length === 0) { if (typeof html !== "string" || html.trim().length === 0) {
throw new Error(`Template render returned empty content: ${templatePath}`); throw new Error(`Template returned empty content: ${templateUrl.pathname}`);
} }
return html; return html;
} }
async function getPopupRuntime() {
if (!popupRuntimePromise) {
popupRuntimePromise = import("../../../../popup.js");
}
return await popupRuntimePromise;
}
function mountPanelHtml(html) { function mountPanelHtml(html) {
const markup = String(html || "").trim(); const markup = String(html || "").trim();
if (!markup) { if (!markup) {
@@ -4545,6 +4558,7 @@ async function _openRegexReuseInspector(taskType) {
try { try {
const snapshot = await _actionHandlers.inspectTaskRegexReuse(taskType); const snapshot = await _actionHandlers.inspectTaskRegexReuse(taskType);
const content = _buildRegexReusePopupContent(snapshot || {}); const content = _buildRegexReusePopupContent(snapshot || {});
const { callGenericPopup, POPUP_TYPE } = await getPopupRuntime();
await callGenericPopup(content, POPUP_TYPE.TEXT, "", { await callGenericPopup(content, POPUP_TYPE.TEXT, "", {
okButton: "关闭", okButton: "关闭",
wide: true, wide: true,