From 5edbc4e4be3870b2c989e3a6b341c822c7e1cc96 Mon Sep 17 00:00:00 2001 From: Youzini-afk <13153778771cx@gmail.com> Date: Sun, 29 Mar 2026 17:14:25 +0800 Subject: [PATCH] fix: add missing ui action controller exports --- ui-actions-controller.js | 61 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/ui-actions-controller.js b/ui-actions-controller.js index f02c8c4..8219c0d 100644 --- a/ui-actions-controller.js +++ b/ui-actions-controller.js @@ -85,3 +85,64 @@ export async function onFetchEmbeddingModelsController(runtime, mode = null) { return result; } + +export async function onManualCompressController(runtime) { + const graph = runtime.getCurrentGraph(); + if (!graph) return; + if (!runtime.ensureGraphMutationReady("手动压缩")) return; + + const beforeSnapshot = runtime.cloneGraphSnapshot(graph); + const result = await runtime.compressAll( + graph, + runtime.getSchema(), + runtime.getEmbeddingConfig(), + false, + undefined, + undefined, + runtime.getSettings(), + ); + await runtime.recordGraphMutation({ + beforeSnapshot, + artifactTags: ["compression"], + }); + + runtime.toastr.info(`压缩完成: 新建 ${result.created}, 归档 ${result.archived}`); +} + +export async function onExportGraphController(runtime) { + const graph = runtime.getCurrentGraph(); + if (!graph) return; + + const json = runtime.exportGraph(graph); + const blob = new Blob([json], { type: "application/json" }); + const url = URL.createObjectURL(blob); + const a = runtime.document.createElement("a"); + a.href = url; + a.download = `st-bme-graph-${Date.now()}.json`; + a.click(); + URL.revokeObjectURL(url); + + runtime.toastr.success("图谱已导出"); +} + +export async function onViewLastInjectionController(runtime) { + const content = runtime.getLastInjectionContent(); + if (!content) { + runtime.toastr.info("暂无注入内容"); + return; + } + + const popup = runtime.document.createElement("div"); + popup.style.cssText = + "position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);background:#1a1a2e;color:#eee;padding:24px;border-radius:12px;max-width:80vw;max-height:80vh;overflow:auto;z-index:99999;white-space:pre-wrap;font-size:13px;box-shadow:0 8px 32px rgba(0,0,0,0.5);"; + popup.textContent = content; + + const close = runtime.document.createElement("button"); + close.textContent = "关闭"; + close.style.cssText = + "position:absolute;top:8px;right:12px;background:#e94560;color:white;border:none;padding:4px 12px;border-radius:4px;cursor:pointer;"; + close.onclick = () => popup.remove(); + popup.appendChild(close); + + runtime.document.body.appendChild(popup); +}