From 7799f5ae81f1472ceaf8edda225675ad114d846c Mon Sep 17 00:00:00 2001 From: Youzini-afk <13153778771cx@gmail.com> Date: Mon, 23 Mar 2026 22:47:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=9D=A2=E6=9D=BF=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=8A=A8=E6=80=81=20import=20=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=8A=A0=E8=BD=BD=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - panel.js/themes.js 从顶层静态 import 改为 try-catch 动态 import() - 面板加载失败时核心功能不受影响 - 添加移动端图谱预览 canvas + REALTIME 标签 - 修复移动端 CSS (sidebar 全宽显示) --- index.js | 199 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 106 insertions(+), 93 deletions(-) diff --git a/index.js b/index.js index e7a6936..b3c3fa6 100644 --- a/index.js +++ b/index.js @@ -31,8 +31,10 @@ import { import { estimateTokens, formatInjection } from "./injector.js"; import { retrieve } from "./retriever.js"; import { DEFAULT_NODE_SCHEMA, validateSchema } from "./schema.js"; -import { initPanel, openPanel, updatePanelTheme } from "./panel.js"; -import { applyTheme } from "./themes.js"; + +// 操控面板模块(动态加载,防止加载失败崩溃整个扩展) +let _panelModule = null; +let _themesModule = null; const MODULE_NAME = "st_bme"; const GRAPH_METADATA_KEY = "st_bme_graph"; @@ -960,101 +962,112 @@ function bindSettingsUI() { // ==================== 操控面板初始化 ==================== - // 应用主题 - const settings = getSettings(); - applyTheme(settings.panelTheme || 'crimson'); + try { + // 动态加载面板模块 + _panelModule = await import('./panel.js'); + _themesModule = await import('./themes.js'); - // 初始化操控面板 - await initPanel({ - getGraph: () => currentGraph, - getSettings: () => getSettings(), - getLastExtract: () => lastExtractedItems, - getLastRecall: () => lastRecalledItems, - actions: { - extract: async () => { - const context = getContext(); - const chat = context.chat; - if (!chat || !chat.length) return; - const s = getSettings(); - const result = await extractMemories( - currentGraph, chat, chat.length - 1, s.extractContextTurns, - getSchema(), getEmbeddingConfig(), s, - ); - if (result?.newNodes?.length) { - lastExtractedItems = result.newNodes.map(n => ({ - type: n.type, name: n.content?.name || '', time: new Date().toLocaleTimeString(), - })).slice(0, 5); - } - saveGraphToChat(); - }, - compress: async () => { - await compressAll(currentGraph, getSettings()); - saveGraphToChat(); - }, - sleep: async () => { - await sleepCycle(currentGraph, getSettings()); - saveGraphToChat(); - }, - synopsis: async () => { - await generateSynopsis(currentGraph, getSettings()); - saveGraphToChat(); - }, - export: () => { - const json = exportGraph(currentGraph); - const blob = new Blob([json], { type: 'application/json' }); - const url = URL.createObjectURL(blob); - const a = document.createElement('a'); - a.href = url; a.download = 'st-bme-graph.json'; a.click(); - URL.revokeObjectURL(url); - }, - import: () => { - const input = document.createElement('input'); - input.type = 'file'; input.accept = '.json'; - input.addEventListener('change', async (e) => { - const file = e.target.files?.[0]; - if (!file) return; - const text = await file.text(); - currentGraph = importGraph(text); + // 应用主题 + const settings = getSettings(); + _themesModule.applyTheme(settings.panelTheme || 'crimson'); + + // 初始化操控面板 + await _panelModule.initPanel({ + getGraph: () => currentGraph, + getSettings: () => getSettings(), + getLastExtract: () => lastExtractedItems, + getLastRecall: () => lastRecalledItems, + actions: { + extract: async () => { + const context = getContext(); + const chat = context.chat; + if (!chat || !chat.length) return; + const s = getSettings(); + const result = await extractMemories( + currentGraph, chat, chat.length - 1, s.extractContextTurns, + getSchema(), getEmbeddingConfig(), s, + ); + if (result?.newNodes?.length) { + lastExtractedItems = result.newNodes.map(n => ({ + type: n.type, name: n.content?.name || '', time: new Date().toLocaleTimeString(), + })).slice(0, 5); + } saveGraphToChat(); - }); - input.click(); + }, + compress: async () => { + await compressAll(currentGraph, getSettings()); + saveGraphToChat(); + }, + sleep: async () => { + await sleepCycle(currentGraph, getSettings()); + saveGraphToChat(); + }, + synopsis: async () => { + await generateSynopsis(currentGraph, getSettings()); + saveGraphToChat(); + }, + export: () => { + const json = exportGraph(currentGraph); + const blob = new Blob([json], { type: 'application/json' }); + const url = URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; a.download = 'st-bme-graph.json'; a.click(); + URL.revokeObjectURL(url); + }, + import: () => { + const input = document.createElement('input'); + input.type = 'file'; input.accept = '.json'; + input.addEventListener('change', async (e) => { + const file = e.target.files?.[0]; + if (!file) return; + const text = await file.text(); + currentGraph = importGraph(text); + saveGraphToChat(); + }); + input.click(); + }, + rebuild: async () => { + if (!confirm('确定要重建图谱吗?这将清除所有现有数据。')) return; + currentGraph = createEmptyGraph(); + saveGraphToChat(); + }, + evolve: async () => { + await evolveMemories(currentGraph, getEmbeddingConfig(), getSettings()); + saveGraphToChat(); + }, }, - rebuild: async () => { - if (!confirm('确定要重建图谱吗?这将清除所有现有数据。')) return; - currentGraph = createEmptyGraph(); - saveGraphToChat(); - }, - evolve: async () => { - await evolveMemories(currentGraph, getEmbeddingConfig(), getSettings()); - saveGraphToChat(); - }, - }, - }); - - // 注入 Options 菜单按钮 - const $menuItem = $('