fix: resolve local template loading for third-party extension

This commit is contained in:
Youzini-afk
2026-03-23 23:22:45 +08:00
parent e747d66478
commit 1964ad6ffd
2 changed files with 28 additions and 9 deletions

View File

@@ -9,9 +9,9 @@ import {
import {
extension_settings,
getContext,
renderExtensionTemplateAsync,
saveMetadataDebounced,
} from "../../../extensions.js";
import { renderTemplateAsync } from "../../../templates.js";
import { compressAll, sleepCycle } from "./compressor.js";
import { testConnection as testEmbeddingConnection } from "./embedding.js";
@@ -39,7 +39,15 @@ let _themesModule = null;
const MODULE_NAME = "st_bme";
const GRAPH_METADATA_KEY = "st_bme_graph";
const TEMPLATE_PATH = "third-party/ST-BME";
async function loadLocalTemplate(templateName) {
const templatePath = new URL(`./${templateName}.html`, import.meta.url).pathname;
const html = await renderTemplateAsync(templatePath, {}, true, true, true);
if (typeof html !== "string" || html.trim().length === 0) {
throw new Error(`Template render returned empty content: ${templatePath}`);
}
return html;
}
// ==================== 默认设置 ====================
@@ -1130,11 +1138,10 @@ function bindSettingsUI() {
(async function init() {
try {
const settingsHtml = await renderExtensionTemplateAsync(
TEMPLATE_PATH,
"settings",
);
$("#extensions_settings2").append(settingsHtml);
if (!document.getElementById("st_bme_enabled")) {
const settingsHtml = await loadLocalTemplate("settings");
$("#extensions_settings2").append(settingsHtml);
}
bindSettingsUI();
} catch (settingsError) {
console.error("[ST-BME] 设置面板加载失败:", settingsError);

View File

@@ -1,6 +1,6 @@
// ST-BME: 操控面板交互逻辑
import { renderExtensionTemplateAsync } from "../../../extensions.js";
import { renderTemplateAsync } from "../../../templates.js";
import { GraphRenderer } from "./graph-renderer.js";
import { getNodeColors } from "./themes.js";
@@ -17,6 +17,15 @@ let _getLastRecall = null;
let _getLastInjection = null;
let _actionHandlers = {};
async function loadLocalTemplate(templateName) {
const templatePath = new URL(`./${templateName}.html`, import.meta.url).pathname;
const html = await renderTemplateAsync(templatePath, {}, true, true, true);
if (typeof html !== "string" || html.trim().length === 0) {
throw new Error(`Template render returned empty content: ${templatePath}`);
}
return html;
}
/**
* 初始化面板(由 index.js 调用一次)
*/
@@ -39,10 +48,13 @@ export async function initPanel({
panelEl = document.getElementById("st-bme-panel");
if (!overlayEl || !panelEl) {
const html = await renderExtensionTemplateAsync("third-party/ST-BME", "panel");
const html = await loadLocalTemplate("panel");
$("body").append(html);
overlayEl = document.getElementById("st-bme-panel-overlay");
panelEl = document.getElementById("st-bme-panel");
if (!overlayEl || !panelEl) {
throw new Error("Panel template rendered but required DOM nodes were not found");
}
}
_bindTabs();