From 645e47bd5908a94d0b91945952e5fa7eda92bcb7 Mon Sep 17 00:00:00 2001 From: newbie Date: Sat, 28 Nov 2026 11:10:18 +0800 Subject: [PATCH] chore(release): 0.10.5 Bumps the manifest, version fallback and README, and rebuilds lib/ and client/ so the committed artifacts match the sources. --- README.md | 6 +- client/index.js | 562 ++++++++++++++++++++++++++++++------ lib/entries/ui.js | 6 +- lib/local-memory/manager.js | 8 +- lib/local-memory/storage.js | 9 +- lib/mnemon/read-service.js | 62 ++++ lib/routes.js | 114 +++++++- lib/version.js | 2 +- package.json | 2 +- src/version.ts | 2 +- 10 files changed, 674 insertions(+), 99 deletions(-) create mode 100644 lib/mnemon/read-service.js diff --git a/README.md b/README.md index 1911dd3..51eaa58 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # dsh-brain +> **0.10.5**:记忆界面改为读取 Mnemon——Brain 面板的概览与记忆页签通过宿主里 +> Mnemon 的只读通道取数,dsh-brain 不再自存记忆(旧本地库保留作兜底,后续移除)。 +> 其余见下。 +> > **0.10.3**:插件按功能拆成六个可单独开关的子插件,新增可选的原始记录层 > `dsh-brain-raw`(见「六个子插件」);同步清理了不可达的防御性分支与重复 > 响应校验。0.10.1 起技能同步按内容与更新时间自动解决冲突(0.9.9/0.9.10 @@ -9,7 +13,7 @@ 活动记录(只上传元数据),并把云端记忆库变成 agent 可用的工具;同时双向 同步云端技能中心与本机技能目录。 -当前版本 **0.10.3**,含宿主端与浏览器端两部分:宿主端负责活动上报、 +当前版本 **0.10.5**,含宿主端与浏览器端两部分:宿主端负责活动上报、 记忆工具注册与技能同步。浏览器 UI 有三个入口: - 左侧栏 **Brain** 展示全局运行状态,管理全局记忆与部门。 diff --git a/client/index.js b/client/index.js index c5d6e92..4b7070f 100644 --- a/client/index.js +++ b/client/index.js @@ -630,6 +630,37 @@ window.__ModuleLoader__.load({ if (!Number.isFinite(stamp)) return value; return formatTime(stamp); } + function formatShort(value) { + if (typeof value !== "number" || value <= 0) return "—"; + var date = new Date(value); + var pad = function(n) { + return n < 10 ? "0" + String(n) : String(n); + }; + return pad(date.getMonth() + 1) + "-" + pad(date.getDate()) + " " + pad(date.getHours()) + ":" + pad(date.getMinutes()); + } + function memoryCategoryLabel(category) { + if (typeof category !== "string" || category === "") return "无分类"; + var map = { + rule: "规则", + preference: "偏好", + identity: "身份" + }; + return map[category] === void 0 ? "其他" : map[category]; + } + function memorySourceLabel(source, createdAt) { + if (typeof source !== "string" || source === "") return "本地记录"; + if (source.indexOf("session:") === 0) { + var stamp = typeof createdAt === "string" ? Date.parse(createdAt) : NaN; + return Number.isFinite(stamp) ? formatShort(stamp) + " 的对话" : "对话 · 时间不可查"; + } + if (source === "mnemon") return "Mnemon · 来源待核实"; + if (source === "memory_tool") return "助手写入"; + if (source === "mnemon-native") return "Mnemon 写入"; + if (source.indexOf("legacy:") === 0) return "旧数据导入"; + if (source.indexOf("department:") === 0) return "部门空间"; + if (source === "local") return "本地手动"; + return "其他来源"; + } function formatBytes(value) { if (typeof value !== "number" || value < 0) return "—"; if (value < 1024) return String(value) + " B"; @@ -4139,8 +4170,101 @@ window.__ModuleLoader__.load({ d: path }))); } + // src-client/mnemon.ts + const MNEMON = { + runtime: "/dsh-brain/mnemon/runtime", + list: "/dsh-brain/mnemon/list", + status: "/dsh-brain/mnemon/status", + search: "/dsh-brain/mnemon/search", + documents: "/dsh-brain/mnemon/documents" + }; + /** The bridge keeps Mnemon's {ok:false,error:{code,message}} envelope. */ + function envelopeError(result, fallback) { + const err = result.body?.error; + if (err !== null && typeof err === "object" && typeof err.message === "string" && err.message !== "") return err.message; + if (result.status === 503) return "Mnemon 读服务未接入:当前宿主没有 Mnemon,界面暂不显示记忆。"; + return bodyError(result, fallback); + } + /** Runtime snapshot → newest-created-first list. No id/category/source exists. */ + function runtimeEntriesToList(value) { + const items = (Array.isArray(value?.entries) ? value.entries : []).map((entry, index) => ({ + id: "mnemon_rt_" + String(index), + scope: "global", + content: String(entry?.content ?? ""), + category: void 0, + tags: [], + source: "mnemon", + revision: void 0, + createdAt: typeof entry?.created_at === "string" ? entry.created_at : void 0, + updatedAt: typeof entry?.updated_at === "string" ? entry.updated_at : void 0, + target: typeof entry?.target === "string" ? entry.target : void 0, + importance: typeof entry?.importance === "string" ? entry.importance : void 0, + mnemon: true + })); + items.sort((a, b) => String(b.createdAt ?? "").localeCompare(String(a.createdAt ?? ""))); + return items; + } + /** + * Memory list for the panel. Global = Mnemon runtime (the real store on this + * host); project = Memory Spaces `list`. Runtime has no offset, so paging is a + * client-side slice over the full fetched set. `categoriesAvailable` tells the + * overview whether a category mix can be computed at all. + */ + async function mnemonMemories(scope, offset, limit) { + if (scope === "project") { + const result = await request(MNEMON.list + "?limit=1000"); + if (result.status !== 200 || result.body === null || result.body.ok !== true) throw new Error(envelopeError(result, "读取 Mnemon 项目记忆失败")); + const value = result.body.value ?? {}; + const items = (Array.isArray(value.items) ? value.items : []).map((it, index) => ({ + id: typeof it?.id === "string" && it.id !== "" ? it.id : "mnemon_sp_" + String(index), + scope: "project", + content: String(it?.content ?? ""), + category: typeof it?.category === "string" ? it.category : void 0, + tags: Array.isArray(it?.tags) ? it.tags.filter((t) => typeof t === "string") : [], + source: "mnemon", + revision: typeof it?.revision === "number" ? it.revision : void 0, + createdAt: typeof it?.created_at === "string" ? it.created_at : typeof it?.createdAt === "string" ? it.createdAt : void 0, + updatedAt: typeof it?.updated_at === "string" ? it.updated_at : typeof it?.updatedAt === "string" ? it.updatedAt : void 0, + mnemon: true + })); + items.sort((a, b) => String(b.createdAt ?? "").localeCompare(String(a.createdAt ?? ""))); + return { + ok: true, + total: typeof value.total === "number" ? value.total : items.length, + items: items.slice(offset, offset + limit), + categoriesAvailable: items.some((it) => it.category !== void 0) + }; + } + const result = await request(MNEMON.runtime); + if (result.status !== 200 || result.body === null || result.body.ok !== true) throw new Error(envelopeError(result, "读取 Mnemon 记忆失败")); + const items = runtimeEntriesToList(result.body.value); + return { + ok: true, + total: items.length, + items: items.slice(offset, offset + limit), + categoriesAvailable: false + }; + } + /** Full runtime list (no paging) for the overview's totals and 7-day trend. */ + async function mnemonRuntimeAll() { + const result = await request(MNEMON.runtime); + if (result.status !== 200 || result.body === null || result.body.ok !== true) throw new Error(envelopeError(result, "读取 Mnemon 记忆失败")); + const items = runtimeEntriesToList(result.body.value); + return { + ok: true, + total: items.length, + items, + categoriesAvailable: false + }; + } + /** Mnemon status snapshot (storage root, sources, workspace mode). */ + async function mnemonStatus() { + const result = await request(MNEMON.status); + if (result.status !== 200 || result.body === null || result.body.ok !== true) throw new Error(envelopeError(result, "读取 Mnemon 状态失败")); + return result.body.value ?? {}; + } // \0dsh-brain-css:src-client/panel/BrainPanel.module.css.mjs - const css = "/* Adapted from dsh-mnemon MnemonWorkspace.dshbrain_1xedgey.dshbrain_holtzx (MIT), see vendor/dsh-mnemon/LICENSE. */\n.dshbrain_1y11fqi {\n box-sizing: border-box;\n position: relative;\n z-index: 2;\n display: flex;\n width: 100%;\n height: 100%;\n min-width: 0;\n min-height: 0;\n overflow: hidden;\n flex: 1 1 auto;\n padding-block-start: var(--dsh-frame-top-clearance, 0px);\n}\n\n.dshbrain_1y11fqi > * {\n min-width: 0;\n flex: 1 1 auto;\n}\n\n.dshbrain_131vunv {\n position: absolute;\n inset: 0 0 auto;\n height: var(--dsh-frame-top-clearance, 0px);\n}\n\n.dshbrain_oyvdy4 {\n display: flex;\n flex-direction: column;\n gap: 14px;\n padding: 18px 20px 24px;\n overflow: auto;\n font-size: 13px;\n line-height: 1.55;\n color: var(--dsw-alias-label-primary, inherit);\n}\n\n.dshbrain_of3f1r {\n display: flex;\n align-items: flex-start;\n justify-content: space-between;\n gap: 12px;\n flex-wrap: wrap;\n}\n\n.dshbrain_vnw8w9 {\n display: flex;\n flex-direction: column;\n gap: 2px;\n min-width: 0;\n}\n\n.dshbrain_g8fis8 {\n margin: 0;\n font-size: 16px;\n font-weight: 650;\n letter-spacing: 0.01em;\n}\n\n.dshbrain_1milhhm {\n margin: 0;\n font-size: 11.5px;\n opacity: 0.58;\n}\n\n.dshbrain_xnx8bm {\n display: flex;\n gap: 4px;\n padding: 3px;\n border-radius: 13px;\n border: 1px solid var(--dsw-alias-border-subtle, rgba(127,127,127,0.22));\n background: var(--dsw-alias-bg-subtle, rgba(127,127,127,0.06));\n flex-wrap: wrap;\n}\n\n.dshbrain_7mndvh {\n flex: 1 1 auto;\n min-width: 88px;\n font: inherit;\n font-size: 12.5px;\n padding: 7px 12px;\n border-radius: 10px;\n border: 1px solid transparent;\n background: transparent;\n color: inherit;\n cursor: pointer;\n white-space: nowrap;\n}\n\n.dshbrain_rvx7lj {\n border: 1px solid var(--dsw-alias-border-subtle, rgba(127,127,127,0.30));\n background: var(--dsw-alias-interactive-bg-hover, rgba(127,127,127,0.14));\n box-shadow: 0 1px 3px rgba(0,0,0,0.10);\n font-weight: 600;\n}\n\n.dshbrain_1rfmkcf {\n display: flex;\n flex-direction: column;\n gap: 12px;\n min-width: 0;\n}\n\n.dshbrain_c36neh {\n display: flex;\n flex-direction: column;\n gap: 12px;\n}\n\n.dshbrain_1a7ley4 {\n display: flex;\n flex-direction: column;\n gap: 10px;\n border: 1px solid var(--dsw-alias-border-subtle, rgba(127,127,127,0.22));\n border-radius: 16px;\n padding: 16px 18px;\n min-width: 0;\n}\n\n.dshbrain_1f1qv8u {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 10px;\n flex-wrap: wrap;\n}\n\n.dshbrain_1t5691m {\n margin: 0;\n font-size: 13.5px;\n font-weight: 650;\n}\n\n.dshbrain_updgou {\n display: flex;\n flex-wrap: wrap;\n gap: 8px;\n}\n\n.dshbrain_xwrsl5 {\n display: inline-flex;\n align-items: center;\n gap: 6px;\n padding: 3px 10px;\n border-radius: 999px;\n border: 1px solid var(--dsw-alias-border-subtle, rgba(127,127,127,0.35));\n font-size: 12px;\n white-space: nowrap;\n overflow: hidden;\n max-width: 100%;\n}\n\n.dshbrain_mvsf69 {\n opacity: 0.75;\n flex: 0 0 auto;\n}\n\n.dshbrain_1xby9uu {\n font-weight: 600;\n overflow: hidden;\n text-overflow: ellipsis;\n min-width: 0;\n}\n\n.dshbrain_1bzyta0 { border-color: rgba(22,163,74,0.55); background: rgba(22,163,74,0.12); }\n.dshbrain_1hx5ob5 { border-color: rgba(220,38,38,0.55); background: rgba(220,38,38,0.12); }\n.dshbrain_amukxq { border-color: rgba(217,119,6,0.55); background: rgba(217,119,6,0.12); }\n.dshbrain_uf6ztt { }\n\n.dshbrain_1vi102j {\n margin: 0;\n font-size: 11.5px;\n opacity: 0.58;\n}\n\n.dshbrain_qmj948 {\n padding: 10px 13px;\n border-radius: 11px;\n border: 1px solid rgba(220,38,38,0.55);\n background: rgba(220,38,38,0.12);\n font-size: 12.5px;\n}\n\n.dshbrain_1ex8b80 {\n display: flex;\n align-items: baseline;\n flex-wrap: wrap;\n}\n\n.dshbrain_1048ygk {\n display: inline-flex;\n align-items: baseline;\n gap: 6px;\n padding-right: 18px;\n margin-right: 18px;\n border-right: 1px solid var(--dsw-alias-border-subtle, rgba(127,127,127,0.20));\n}\n\n.dshbrain_1bvujjo {\n display: inline-flex;\n align-items: baseline;\n gap: 6px;\n}\n\n.dshbrain_d75ahw {\n font-size: 17px;\n font-weight: 700;\n}\n"; + const css = "/* Adapted from dsh-mnemon MnemonWorkspace.dshbrain_1xedgey.dshbrain_holtzx (MIT), see vendor/dsh-mnemon/LICENSE. */\n.dshbrain_1y11fqi {\n box-sizing: border-box;\n position: relative;\n z-index: 2;\n display: flex;\n width: 100%;\n height: 100%;\n min-width: 0;\n min-height: 0;\n overflow: hidden;\n flex: 1 1 auto;\n padding-block-start: var(--dsh-frame-top-clearance, 0px);\n}\n\n.dshbrain_1y11fqi > * {\n min-width: 0;\n flex: 1 1 auto;\n}\n\n.dshbrain_131vunv {\n position: absolute;\n inset: 0 0 auto;\n height: var(--dsh-frame-top-clearance, 0px);\n}\n\n.dshbrain_oyvdy4 {\n display: flex;\n flex-direction: column;\n gap: 14px;\n padding: 18px 20px 24px;\n overflow: auto;\n font-size: 13px;\n line-height: 1.55;\n color: var(--dsw-alias-label-primary, inherit);\n}\n\n.dshbrain_of3f1r {\n display: flex;\n align-items: flex-start;\n justify-content: space-between;\n gap: 12px;\n flex-wrap: wrap;\n}\n\n.dshbrain_vnw8w9 {\n display: flex;\n flex-direction: column;\n gap: 2px;\n min-width: 0;\n}\n\n.dshbrain_g8fis8 {\n margin: 0;\n font-size: 16px;\n font-weight: 650;\n letter-spacing: 0.01em;\n}\n\n.dshbrain_1milhhm {\n margin: 0;\n font-size: 11.5px;\n opacity: 0.58;\n}\n\n.dshbrain_xnx8bm {\n display: flex;\n gap: 4px;\n padding: 3px;\n border-radius: 13px;\n border: 1px solid var(--dsw-alias-border-subtle, rgba(127,127,127,0.22));\n background: var(--dsw-alias-bg-subtle, rgba(127,127,127,0.06));\n flex-wrap: wrap;\n}\n\n.dshbrain_7mndvh {\n flex: 1 1 auto;\n min-width: 88px;\n font: inherit;\n font-size: 12.5px;\n padding: 7px 12px;\n border-radius: 10px;\n border: 1px solid transparent;\n background: transparent;\n color: inherit;\n cursor: pointer;\n white-space: nowrap;\n}\n\n.dshbrain_rvx7lj {\n border: 1px solid var(--dsw-alias-border-subtle, rgba(127,127,127,0.30));\n background: var(--dsw-alias-interactive-bg-hover, rgba(127,127,127,0.14));\n box-shadow: 0 1px 3px rgba(0,0,0,0.10);\n font-weight: 600;\n}\n\n.dshbrain_1rfmkcf {\n display: flex;\n flex-direction: column;\n gap: 12px;\n min-width: 0;\n}\n\n.dshbrain_c36neh {\n display: flex;\n flex-direction: column;\n gap: 12px;\n}\n\n.dshbrain_1a7ley4 {\n display: flex;\n flex-direction: column;\n gap: 10px;\n border: 1px solid var(--dsw-alias-border-subtle, rgba(127,127,127,0.22));\n border-radius: 16px;\n padding: 16px 18px;\n min-width: 0;\n}\n\n.dshbrain_updgou {\n display: flex;\n flex-wrap: wrap;\n gap: 8px;\n}\n\n.dshbrain_xwrsl5 {\n display: inline-flex;\n align-items: center;\n gap: 6px;\n padding: 3px 10px;\n border-radius: 999px;\n border: 1px solid var(--dsw-alias-border-subtle, rgba(127,127,127,0.35));\n font-size: 12px;\n white-space: nowrap;\n overflow: hidden;\n max-width: 100%;\n}\n\n.dshbrain_mvsf69 {\n opacity: 0.75;\n flex: 0 0 auto;\n}\n\n.dshbrain_1xby9uu {\n font-weight: 600;\n overflow: hidden;\n text-overflow: ellipsis;\n min-width: 0;\n}\n\n.dshbrain_1bzyta0 { border-color: rgba(22,163,74,0.55); background: rgba(22,163,74,0.12); }\n.dshbrain_1hx5ob5 { border-color: rgba(220,38,38,0.55); background: rgba(220,38,38,0.12); }\n.dshbrain_amukxq { border-color: rgba(217,119,6,0.55); background: rgba(217,119,6,0.12); }\n.dshbrain_uf6ztt { }\n\n.dshbrain_1vi102j {\n margin: 0;\n font-size: 11.5px;\n opacity: 0.58;\n}\n\n.dshbrain_qmj948 {\n padding: 10px 13px;\n border-radius: 11px;\n border: 1px solid rgba(220,38,38,0.55);\n background: rgba(220,38,38,0.12);\n font-size: 12.5px;\n}\n\n/* ---- Overview v3 (artifacts/preview-overview-v3.dshbrain_1b429sz) ------------------- */\n/* Surfaces and text ride the host theme tokens; only translucent state tints\n (green/amber) are fixed, the same convention as .dshbrain_1bzyta0/.dshbrain_amukxq above, so both\n light and dark hosts stay readable. */\n\n.dshbrain_1q9il5y {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 10px;\n flex-wrap: wrap;\n}\n\n.dshbrain_oagb6v {\n margin: 0;\n font-size: 15px;\n font-weight: 700;\n}\n\n.dshbrain_jcli1h {\n display: flex;\n align-items: center;\n gap: 10px;\n flex-wrap: wrap;\n}\n\n.dshbrain_1a2ddj9 {\n margin: 0;\n font-size: 13.5px;\n font-weight: 650;\n}\n\n.dshbrain_1115a09 {\n display: grid;\n grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));\n gap: 0;\n padding: 0;\n overflow: hidden;\n background: var(--dsw-alias-bg-subtle, rgba(127,127,127,0.06));\n}\n\n.dshbrain_c3trnb {\n padding: 16px 18px;\n min-width: 0;\n display: flex;\n flex-direction: column;\n gap: 6px;\n}\n\n.dshbrain_vv2nbb {\n margin: 0;\n font-size: 40px;\n line-height: 1.05;\n font-weight: 720;\n font-variant-numeric: tabular-nums;\n}\n\n.dshbrain_vv2nbb small {\n margin-left: 6px;\n font-size: 15px;\n font-weight: 600;\n opacity: 0.7;\n}\n\n.dshbrain_78nbcy {\n margin: 0;\n font-size: 12.5px;\n opacity: 0.85;\n}\n\n.dshbrain_78nbcy strong {\n color: rgba(22,163,74,0.95);\n}\n\n.dshbrain_t4lamf {\n display: flex;\n flex-direction: column;\n gap: 6px;\n align-items: flex-start;\n}\n\n.dshbrain_1ch1t27 {\n padding: 16px 18px;\n min-width: 0;\n border-left: 1px solid var(--dsw-alias-border-subtle, rgba(127,127,127,0.22));\n display: flex;\n flex-direction: column;\n gap: 10px;\n justify-content: center;\n}\n\n.dshbrain_ukm6ev {\n display: flex;\n flex-direction: column;\n gap: 10px;\n}\n\n.dshbrain_3bylxp {\n height: 9px;\n display: flex;\n overflow: hidden;\n gap: 3px;\n border-radius: 8px;\n}\n\n.dshbrain_3bylxp span {\n min-width: 4px;\n}\n\n.dshbrain_1703oi3 { background: rgba(22,163,74,0.85); }\n.dshbrain_17a3a72 { background: rgba(22,163,74,0.45); }\n.dshbrain_17k2vw1 { background: rgba(127,127,127,0.45); }\n\n.dshbrain_15weix8 {\n display: flex;\n gap: 8px 18px;\n flex-wrap: wrap;\n margin: 0;\n padding: 0;\n list-style: none;\n font-size: 12.5px;\n}\n\n.dshbrain_15weix8 span {\n display: inline-block;\n width: 8px;\n height: 8px;\n margin-right: 6px;\n border-radius: 2px;\n}\n\n.dshbrain_1xdztoj {\n display: grid;\n grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));\n gap: 12px;\n}\n\n.dshbrain_1xdztoj > * {\n min-width: 0;\n}\n\n.dshbrain_1wbzl9q, .dshbrain_1p9g0za {\n padding: 16px 18px;\n}\n\n.dshbrain_x03n04 {\n display: flex;\n flex-direction: column;\n gap: 4px;\n padding: 22px 0;\n}\n\n.dshbrain_s9s46a {\n margin: 0;\n font-size: 15px;\n font-weight: 650;\n opacity: 0.6;\n}\n\n.dshbrain_nx4bax {\n margin: 10px 0 0;\n}\n\n.dshbrain_1jg0ih5 {\n position: relative;\n display: grid;\n grid-template-columns: repeat(7, minmax(0, 1fr));\n gap: 4px;\n margin: 0;\n padding: 0;\n list-style: none;\n}\n\n.dshbrain_1jg0ih5::before {\n content: \"\";\n position: absolute;\n pointer-events: none;\n inset: 0 0 27px;\n border-bottom: 1px solid var(--dsw-alias-border-subtle, rgba(127,127,127,0.30));\n background: repeating-linear-gradient(to top, transparent 0 calc(33.333% - 1px), var(--dsw-alias-border-subtle, rgba(127,127,127,0.14)) calc(33.333% - 1px) 33.333%);\n}\n\n.dshbrain_1jg0ih5 li {\n position: relative;\n display: flex;\n flex-direction: column;\n align-items: center;\n min-width: 0;\n}\n\n.dshbrain_1y1mwwd {\n position: relative;\n width: 100%;\n height: 121px;\n}\n\n.dshbrain_crtq12 {\n position: absolute;\n bottom: 0;\n left: 50%;\n transform: translateX(-50%);\n width: min(54%, 28px);\n height: var(--height);\n border-radius: 5px 5px 0 0;\n background: rgba(22,163,74,0.45);\n}\n\n.dshbrain_1jg0ih5 li:last-child .dshbrain_crtq12 {\n background: rgba(22,163,74,0.85);\n}\n\n.dshbrain_1asla79 {\n position: absolute;\n bottom: calc(var(--height) + 3px);\n left: 50%;\n transform: translateX(-50%);\n font-weight: 650;\n font-size: 12px;\n font-variant-numeric: tabular-nums;\n}\n\n.dshbrain_civ187 .dshbrain_1asla79 {\n opacity: 0.5;\n}\n\n.dshbrain_51ym0x {\n display: grid;\n place-items: center;\n height: 27px;\n font-size: 11px;\n white-space: nowrap;\n opacity: 0.6;\n}\n\n.dshbrain_1jg0ih5 li:last-child .dshbrain_51ym0x {\n opacity: 1;\n color: rgba(22,163,74,0.95);\n}\n\n.dshbrain_eqch83 {\n margin: 0;\n padding: 0;\n list-style: none;\n}\n\n.dshbrain_eqch83 li {\n display: grid;\n grid-template-columns: 8px minmax(0, 1fr);\n gap: 9px;\n padding: 9px 0;\n}\n\n.dshbrain_eqch83 li + li {\n border-top: 1px solid var(--dsw-alias-border-subtle, rgba(127,127,127,0.22));\n}\n\n.dshbrain_1snjuqt {\n width: 7px;\n height: 7px;\n border-radius: 50%;\n background: rgba(22,163,74,0.75);\n margin-top: 7px;\n}\n\n.dshbrain_1g8mv01 { background: rgba(217,119,6,0.9); }\n.dshbrain_1azwkk0 { background: rgba(127,127,127,0.55); }\n\n.dshbrain_xq6feh {\n margin: 0;\n font-weight: 650;\n}\n\n.dshbrain_13jj2hh { color: rgba(217,119,6,0.95); }\n\n.dshbrain_qzg51m {\n padding: 16px 18px;\n}\n\n.dshbrain_1k9l3b8 {\n display: flex;\n flex-wrap: wrap;\n justify-content: space-between;\n align-items: baseline;\n gap: 6px 14px;\n}\n\n.dshbrain_1xrv1b3 {\n margin: 0;\n color: rgba(217,119,6,0.95);\n font-size: 12px;\n font-weight: 650;\n}\n\n.dshbrain_6a0tlg {\n display: grid;\n grid-template-columns: repeat(auto-fit, minmax(min(96px, 100%), 1fr));\n margin: 12px 0 9px;\n gap: 8px 0;\n}\n\n.dshbrain_6a0tlg div {\n padding: 3px 12px;\n min-width: 0;\n}\n\n.dshbrain_6a0tlg div:first-child {\n padding-left: 0;\n}\n\n.dshbrain_6a0tlg div + div {\n border-left: 1px solid var(--dsw-alias-border-subtle, rgba(127,127,127,0.22));\n}\n\n.dshbrain_6a0tlg dt {\n font-size: 12px;\n opacity: 0.6;\n}\n\n.dshbrain_6a0tlg dd {\n margin: 0;\n font-size: 16px;\n font-weight: 650;\n font-variant-numeric: tabular-nums;\n}\n\n.dshbrain_sv335t {\n opacity: 0.5;\n}\n\n.dshbrain_15l1hqc {\n padding: 0 18px;\n}\n\n.dshbrain_16gqcks {\n padding: 12px 0;\n font-weight: 600;\n cursor: pointer;\n}\n\n.dshbrain_16gqcks:focus-visible {\n outline: 2px solid rgba(22,163,74,0.8);\n outline-offset: 3px;\n border-radius: 3px;\n}\n\n.dshbrain_172zfx {\n display: grid;\n grid-template-columns: auto minmax(0, 1fr);\n gap: 7px 18px;\n margin: 0 0 14px;\n padding-top: 12px;\n border-top: 1px solid var(--dsw-alias-border-subtle, rgba(127,127,127,0.22));\n font-size: 12.5px;\n}\n\n.dshbrain_172zfx dt {\n opacity: 0.6;\n}\n\n.dshbrain_172zfx dd {\n margin: 0;\n overflow-wrap: anywhere;\n}\n\n.dshbrain_u0dqm9 {\n position: absolute;\n width: 1px;\n height: 1px;\n padding: 0;\n margin: -1px;\n overflow: hidden;\n clip: rect(0, 0, 0, 0);\n white-space: nowrap;\n border: 0;\n}\n\n@media (max-width: 640px) {\n .dshbrain_1ch1t27 {\n border-left: 0;\n border-top: 1px solid var(--dsw-alias-border-subtle, rgba(127,127,127,0.22));\n }\n .dshbrain_6a0tlg div:nth-child(4) {\n padding-left: 0;\n border-left: 0;\n }\n}\n"; const tagId = "src-client/panel/BrainPanel.module.css"; if (typeof document !== "undefined" && typeof document.querySelector === "function" && typeof document.createElement === "function") { let tag = document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]"); @@ -4167,8 +4291,6 @@ window.__ModuleLoader__.load({ "content": "dshbrain_1rfmkcf", "overviewGrid": "dshbrain_c36neh", "card": "dshbrain_1a7ley4", - "cardHead": "dshbrain_1f1qv8u", - "cardTitle": "dshbrain_1t5691m", "pills": "dshbrain_updgou", "pill": "dshbrain_xwrsl5", "pillLabel": "dshbrain_mvsf69", @@ -4179,10 +4301,50 @@ window.__ModuleLoader__.load({ "muted": "dshbrain_uf6ztt", "hint": "dshbrain_1vi102j", "error": "dshbrain_qmj948", - "statRow": "dshbrain_1ex8b80", - "stat": "dshbrain_1048ygk", - "statLast": "dshbrain_1bvujjo", - "statNum": "dshbrain_d75ahw" + "html": "dshbrain_1b429sz", + "ovHeader": "dshbrain_1q9il5y", + "ovTitle": "dshbrain_oagb6v", + "ovHeadRight": "dshbrain_jcli1h", + "ovCardTitle": "dshbrain_1a2ddj9", + "ovSummary": "dshbrain_1115a09", + "ovTotal": "dshbrain_c3trnb", + "ovBig": "dshbrain_vv2nbb", + "ovMeta": "dshbrain_78nbcy", + "ovMetaBlock": "dshbrain_t4lamf", + "ovMix": "dshbrain_1ch1t27", + "ovMixBody": "dshbrain_ukm6ev", + "mixBar": "dshbrain_3bylxp", + "mixA": "dshbrain_1703oi3", + "mixB": "dshbrain_17a3a72", + "mixC": "dshbrain_17k2vw1", + "mixKeys": "dshbrain_15weix8", + "ovGrid": "dshbrain_1xdztoj", + "ovTrend": "dshbrain_1wbzl9q", + "ovChecks": "dshbrain_1p9g0za", + "ovPlaceholder": "dshbrain_x03n04", + "ovPlaceholderTitle": "dshbrain_s9s46a", + "ovChart": "dshbrain_nx4bax", + "plot": "dshbrain_1jg0ih5", + "plotSlot": "dshbrain_1y1mwwd", + "plotBar": "dshbrain_crtq12", + "plotAmount": "dshbrain_1asla79", + "plotZero": "dshbrain_civ187", + "plotDay": "dshbrain_51ym0x", + "rows": "dshbrain_eqch83", + "dot": "dshbrain_1snjuqt", + "dotWarn": "dshbrain_1g8mv01", + "dotMuted": "dshbrain_1azwkk0", + "rowName": "dshbrain_xq6feh", + "rowNameWarn": "dshbrain_13jj2hh", + "ovRecall": "dshbrain_qzg51m", + "ovRecallHead": "dshbrain_1k9l3b8", + "ovRecallState": "dshbrain_1xrv1b3", + "recallMetrics": "dshbrain_6a0tlg", + "recallMissing": "dshbrain_sv335t", + "ovDiag": "dshbrain_15l1hqc", + "ovDiagSummary": "dshbrain_16gqcks", + "diagGrid": "dshbrain_172zfx", + "srOnly": "dshbrain_u0dqm9" }; // src-client/panel/Overview.tsx const h$5 = react.createElement; @@ -4192,44 +4354,73 @@ window.__ModuleLoader__.load({ skills: "技能", mcp: "MCP", "settings-ui": "设置 UI", - ui: "设置 UI" + ui: "设置 UI", + raw: "原话记录" }; + const pad2 = (n) => n < 10 ? "0" + String(n) : String(n); + const dayKeyOf = (d) => String(d.getFullYear()) + "-" + pad2(d.getMonth() + 1) + "-" + pad2(d.getDate()); function Pill(props) { const tone = props.tone === void 0 ? BrainPanel_module_css_default.muted : props.tone === "ok" ? BrainPanel_module_css_default.ok : props.tone === "bad" ? BrainPanel_module_css_default.bad : props.tone === "warn" ? BrainPanel_module_css_default.warn : BrainPanel_module_css_default.muted; return h$5("span", { className: BrainPanel_module_css_default.pill + " " + tone }, h$5("span", { className: BrainPanel_module_css_default.pillLabel }, props.label), h$5("span", { className: BrainPanel_module_css_default.pillValue }, String(props.value))); } - function Card(props) { - return h$5("div", { className: BrainPanel_module_css_default.card }, h$5("div", { className: BrainPanel_module_css_default.cardHead }, h$5("h4", { className: BrainPanel_module_css_default.cardTitle }, props.title)), props.children); - } function Overview(props) { const active = props.active !== false; const [status, setStatus] = react.useState(null); const [capabilities, setCapabilities] = react.useState(null); const [memory, setMemory] = react.useState(null); + const [raw, setRaw] = react.useState(null); + const [list, setList] = react.useState(null); const [error, setError] = react.useState(null); + const [rawError, setRawError] = react.useState(null); + const [listError, setListError] = react.useState(null); + const [loadedAt, setLoadedAt] = react.useState(null); + const [tick, setTick] = react.useState(0); react.useEffect(() => { if (!active) return; let cancelled = false; const load = async () => { - const [statusSettled, capabilitiesSettled, memorySettled] = await Promise.allSettled([ + const [statusSettled, capabilitiesSettled, memorySettled, rawSettled, listSettled] = await Promise.allSettled([ request(API.status), request(API.capabilities), - request("/dsh-brain/local-memory/status?scope=global") + mnemonStatus(), + request("/dsh-brain/raw/status"), + mnemonRuntimeAll() ]); if (cancelled) return; + let anyOk = false; if (statusSettled.status === "fulfilled") { const result = statusSettled.value; if (result.status === 200 && result.body !== null && result.body.ok === true) { setStatus(result.body); setError(null); + anyOk = true; } else setError("读取插件状态失败(HTTP " + String(result.status) + ")"); } else setError(messageOf(statusSettled.reason)); if (capabilitiesSettled.status === "fulfilled") { const result = capabilitiesSettled.value; - if (result.status === 200 && result.body !== null && result.body.ok === true) setCapabilities(result.body); + if (result.status === 200 && result.body !== null && result.body.ok === true) { + setCapabilities(result.body); + anyOk = true; + } } - if (memorySettled.status === "fulfilled" && memorySettled.value.status === 200 && memorySettled.value.body !== null && memorySettled.value.body.ok === true) setMemory(memorySettled.value.body); - else setMemory(null); + if (memorySettled.status === "fulfilled") { + setMemory(memorySettled.value); + anyOk = true; + } + if (rawSettled.status === "fulfilled") { + const result = rawSettled.value; + if (result.status === 200 && result.body !== null && result.body.ok === true) { + setRaw(result.body); + setRawError(null); + anyOk = true; + } else setRawError("HTTP " + String(result.status)); + } else setRawError(messageOf(rawSettled.reason)); + if (listSettled.status === "fulfilled") { + setList(listSettled.value); + setListError(null); + anyOk = true; + } else setListError(messageOf(listSettled.reason)); + if (anyOk) setLoadedAt(Date.now()); }; load(); const timer = setInterval(() => { @@ -4239,7 +4430,13 @@ window.__ModuleLoader__.load({ cancelled = true; clearInterval(timer); }; - }, [active]); + }, [active, tick]); + const refresh = () => { + setTick((value) => value + 1); + }; + const settings = status?.settings ?? {}; + const reporter = status?.reporter ?? {}; + const skills = status?.skills; const bundles = status?.bundles ?? {}; const bundleKeys = Object.keys(bundles).length === 0 ? [ "cloudsync", @@ -4248,50 +4445,214 @@ window.__ModuleLoader__.load({ "mcp", "settings-ui" ] : Object.keys(bundles); - const settings = status?.settings ?? {}; - const reporter = status?.reporter ?? {}; - const skills = status?.skills ?? {}; - const memorySpaces = memory?.spaces ?? {}; const version = capabilities?.version ?? status?.capabilities?.version ?? "—"; + const items = Array.isArray(list?.items) ? list.items : []; + const total = list !== null && typeof list.total === "number" ? list.total : null; + const fullCoverage = list !== null && total !== null && items.length === total; + const hasCreated = items.length > 0 && items.every((item) => typeof item.createdAt === "string" && item.createdAt !== ""); + const categoriesAvailable = list?.categoriesAvailable === true; + let mix = null; + if (fullCoverage && categoriesAvailable) { + const counts = {}; + for (const item of items) { + const label = memoryCategoryLabel(item.category); + counts[label] = (counts[label] ?? 0) + 1; + } + mix = Object.keys(counts).map((label) => ({ + label, + count: counts[label] + })).sort((a, b) => b.count - a.count); + } + let trend = null; + let todayAdded = null; + let latestCreated = null; + if (fullCoverage && (hasCreated || total === 0)) { + const counts = {}; + let latest = 0; + for (const item of items) { + const stamp = Date.parse(item.createdAt); + if (!Number.isFinite(stamp)) continue; + if (stamp > latest) latest = stamp; + const key = dayKeyOf(new Date(stamp)); + counts[key] = (counts[key] ?? 0) + 1; + } + latestCreated = latest > 0 ? latest : null; + const now = /* @__PURE__ */ new Date(); + trend = []; + for (let i = 6; i >= 0; i -= 1) { + const day = new Date(now.getFullYear(), now.getMonth(), now.getDate() - i); + const key = dayKeyOf(day); + trend.push({ + key, + label: i === 6 ? pad2(day.getMonth() + 1) + "/" + pad2(day.getDate()) : pad2(day.getDate()), + full: String(day.getMonth() + 1) + " 月 " + String(day.getDate()) + " 日", + count: counts[key] ?? 0 + }); + } + todayAdded = trend[6].count; + } + const rows = []; + if (rawError !== null) rows.push({ + tone: "warn", + name: "读取原话档案失败", + meta: "可点右上「刷新」重试;详情见「原始记录」页签。" + }); + else if (raw === null) rows.push({ + tone: "muted", + name: "原话归档待核实", + meta: "宿主未返回原话档案状态。" + }); + else if (raw.enabled === false) rows.push({ + tone: "muted", + name: "原话采集已关闭", + meta: "在设置中开启后,对话原话会自动归档。" + }); + else if ((raw.records ?? 0) === 0) rows.push({ + tone: "muted", + name: "还没有原话记录", + meta: "开启采集后,新的对话会自动归档到这里。" + }); + else rows.push({ + tone: "ok", + name: "原话已归档", + meta: String(raw.sessions ?? 0) + " 个会话 · " + String(raw.records ?? 0) + " 条记录 · 最近 " + formatIso(raw.newestAt) + }); + if (status === null) rows.push({ + tone: "muted", + name: "自动摘要待核实", + meta: "宿主未返回设置,无法确认摘要开关。" + }); + else if (settings.autoSummaryEnabled === false) rows.push({ + tone: "muted", + name: "自动摘要已关闭", + meta: "在设置中开启后,会自动提炼对话要点。" + }); + else rows.push({ + tone: "muted", + name: "摘要处理进度待核实", + meta: "累计会话与轮数需检查点统计,接口补齐后显示。" + }); const lastChecks = Array.isArray(status?.lastCheck?.checks) ? status.lastCheck.checks : []; const lastFailed = lastChecks.filter((check) => check.state !== "ok" && check.state !== "unconfigured").length; - return h$5("div", { className: BrainPanel_module_css_default.overviewGrid }, error === null ? null : h$5("div", { className: BrainPanel_module_css_default.error }, error), h$5(Card, { title: "版本与构建" }, h$5("div", { className: BrainPanel_module_css_default.pills }, h$5(Pill, { - label: "版本", - value: version - }), h$5(Pill, { - label: "服务", - value: settings.baseUrlConfigured === false ? "未配置" : settings.baseUrlOrigin || "已配置", - tone: settings.baseUrlConfigured === false ? "warn" : "muted" - }), h$5(Pill, { - label: "上报", - value: settings.activityEnabled === true ? "开" : "关", - tone: settings.activityEnabled === true ? "ok" : "muted" - }), h$5(Pill, { - label: "记忆", - value: settings.memoryEnabled === true ? "开" : "关", - tone: settings.memoryEnabled === true ? "ok" : "muted" - }), h$5(Pill, { - label: "诊断日志", - value: settings.diagnosticsEnabled === false ? "关" : "开", - tone: settings.diagnosticsEnabled === false ? "muted" : "ok" - })), h$5("p", { className: BrainPanel_module_css_default.hint }, "全局诊断日志:$DSH_HOME/brain/logs"), status?.lastCheck === null || status?.lastCheck === void 0 ? null : h$5("p", { className: BrainPanel_module_css_default.hint }, "最近检查:" + formatTime(status.lastCheck.at) + (lastChecks.length === 0 ? "" : lastFailed === 0 ? " · 全部通过" : " · " + String(lastFailed) + " 项异常"))), h$5(Card, { title: "五个 bundle 开关态" }, h$5("div", { className: BrainPanel_module_css_default.pills }, bundleKeys.map((key) => h$5(Pill, { - key, - label: BUNDLE_LABELS[key] ?? key, - value: bundles[key] === true ? "启用" : bundles[key] === false ? "停用" : "未知", - tone: bundles[key] === true ? "ok" : bundles[key] === false ? "bad" : "muted" - })))), h$5(Card, { title: "本地记忆" }, h$5("div", { className: BrainPanel_module_css_default.pills }, h$5(Pill, { - label: "状态", - value: memory === null ? "不可用" : "已启用", - tone: memory === null ? "warn" : "ok" - }), h$5(Pill, { - label: "全局空间", - value: memorySpaces.global === null || memorySpaces.global === void 0 ? "未创建" : "就绪", - tone: memorySpaces.global === null || memorySpaces.global === void 0 ? "muted" : "ok" - }), h$5(Pill, { - label: "云同步", - value: memory?.cloudSyncEnabled === true ? "开" : "关", - tone: memory?.cloudSyncEnabled === true ? "ok" : "muted" - })), memory === null ? h$5("p", { className: BrainPanel_module_css_default.hint }, "本地记忆状态路由不可用;启用「本地记忆」后此处会显示空间状态。") : null), h$5(Card, { title: "同步统计" }, h$5("div", { className: BrainPanel_module_css_default.statRow }, h$5("span", { className: BrainPanel_module_css_default.stat }, h$5("span", { className: BrainPanel_module_css_default.statNum }, String(reporter.recorded ?? 0)), h$5("span", { className: BrainPanel_module_css_default.hint }, "已上报回合")), h$5("span", { className: BrainPanel_module_css_default.stat }, h$5("span", { className: BrainPanel_module_css_default.statNum }, String(skills.downloaded?.length ?? 0)), h$5("span", { className: BrainPanel_module_css_default.hint }, "技能下载")), h$5("span", { className: BrainPanel_module_css_default.stat }, h$5("span", { className: BrainPanel_module_css_default.statNum }, String(skills.uploaded?.length ?? 0)), h$5("span", { className: BrainPanel_module_css_default.hint }, "技能上传")), h$5("span", { className: BrainPanel_module_css_default.statLast }, h$5("span", { className: BrainPanel_module_css_default.statNum }, String(skills.conflicts?.length ?? 0)), h$5("span", { className: BrainPanel_module_css_default.hint }, "待处理冲突"))))); + if (error !== null) rows.push({ + tone: "warn", + name: "实时状态待核实", + meta: "当前宿主未返回 Brain 状态。在目标宿主打开 Brain 后刷新,查看采集与召回状态。" + }); + else if (status?.lastCheck === null || status?.lastCheck === void 0) rows.push({ + tone: "muted", + name: "尚未检查", + meta: "在「连接与上报」设置里运行一次连接检查,结果会显示在这里。" + }); + else if (lastFailed === 0) rows.push({ + tone: "ok", + name: "暂无已知异常", + meta: "最近检查 " + formatTime(status.lastCheck.at) + (lastChecks.length === 0 ? "" : " · 全部通过") + }); + else rows.push({ + tone: "warn", + name: String(lastFailed) + " 项检查异常", + meta: "最近检查 " + formatTime(status.lastCheck.at) + " · 详情见「连接与上报」设置。" + }); + const tokenText = status === null ? "暂不可读取" : (() => { + const entries = [ + ["上报", status.tokens?.activity], + ["记忆", status.tokens?.memory], + ["摘要", status.tokens?.summary] + ]; + if (entries.every(([, token]) => token?.configured === true)) return "上报、记忆、摘要均已配置"; + return entries.map(([name, token]) => name + (token?.configured === true ? "已配置" : "未配置")).join(" · "); + })(); + const rawDetail = rawError !== null ? "暂不可读取" : raw === null ? "待核实" : raw.enabled === false ? "采集已关闭" : formatBytes(raw.bytes) + " · " + formatIso(raw.oldestAt) + " 至 " + formatIso(raw.newestAt); + const skillReceipt = skills === void 0 || skills === null ? "暂无回执" : "下发 " + String(skills.downloaded?.length ?? 0) + " 条 · 上传 " + String(skills.uploaded?.length ?? 0) + " 条" + ((skills.conflicts?.length ?? 0) > 0 ? " · 待处理冲突 " + String(skills.conflicts.length) + " 条" : ""); + const localMemoryText = memory === null ? "Mnemon 未接入" : (typeof memory.storage?.activeRoot === "string" ? String(memory.storage.activeRoot) : "已接入") + (typeof memory.workspaceContext?.mode === "string" ? " · 存储范围 " + String(memory.workspaceContext.mode) : ""); + const diag = [ + ["插件版本", version], + ["原话档案", rawDetail], + ["服务地址", status === null ? "暂不可读取" : settings.baseUrlConfigured === false ? "未配置" : settings.baseUrlOrigin || "已配置"], + ["磁盘令牌配置", tokenText], + ["服务默认召回条数", status === null ? "暂不可读取" : String(settings.defaultK ?? "—")], + ["本地记忆召回条数", status === null ? "暂不可读取" : String(settings.localMemoryK ?? "未配置")], + ["技能同步回执", skillReceipt], + ["已上报回合", status === null ? "待核实" : String(reporter.recorded ?? 0)], + ["Mnemon 存储", localMemoryText], + ["bundle 开关", h$5("div", { className: BrainPanel_module_css_default.pills }, bundleKeys.map((key) => h$5(Pill, { + key, + label: BUNDLE_LABELS[key] ?? key, + value: bundles[key] === true ? "启用" : bundles[key] === false ? "停用" : "未知", + tone: bundles[key] === true ? "ok" : bundles[key] === false ? "bad" : "muted" + })))] + ]; + const trendMax = trend === null ? 1 : Math.max(1, ...trend.map((day) => day.count)); + return h$5("div", { className: BrainPanel_module_css_default.overviewGrid }, h$5("div", { className: BrainPanel_module_css_default.ovHeader }, h$5("h4", { className: BrainPanel_module_css_default.ovTitle }, "记忆概览"), h$5("div", { className: BrainPanel_module_css_default.ovHeadRight }, loadedAt === null ? null : h$5("p", { className: BrainPanel_module_css_default.hint }, "本机数据快照 " + formatTime(loadedAt)), h$5(Btn, { + label: "刷新", + variant: "small", + onClick: refresh + }))), error === null ? null : h$5("div", { className: BrainPanel_module_css_default.error }, error), h$5("section", { + className: BrainPanel_module_css_default.card + " " + BrainPanel_module_css_default.ovSummary, + "aria-labelledby": "ov-total-title" + }, h$5("div", { className: BrainPanel_module_css_default.ovTotal }, h$5("h4", { + id: "ov-total-title", + className: BrainPanel_module_css_default.ovCardTitle + }, "全局记忆"), list !== null ? h$5("p", { className: BrainPanel_module_css_default.ovBig }, String(total ?? "—"), h$5("small", {}, "条")) : h$5("p", { className: BrainPanel_module_css_default.ovBig }, "—"), list === null && listError !== null ? h$5("div", { className: BrainPanel_module_css_default.ovMetaBlock }, h$5("p", { className: BrainPanel_module_css_default.hint }, "全局记忆暂不可读(" + listError + ")"), h$5(Btn, { + label: "重试", + variant: "small", + onClick: refresh + })) : total === 0 ? h$5("p", { className: BrainPanel_module_css_default.ovMeta }, "Mnemon 里还没有记忆条目。") : h$5("p", { className: BrainPanel_module_css_default.ovMeta }, todayAdded === null ? "今日新增待核实" : h$5("strong", {}, "今日新增 " + String(todayAdded) + " 条"), latestCreated === null ? "" : " · 最近一条 " + formatTime(latestCreated).slice(6, 11))), h$5("div", { className: BrainPanel_module_css_default.ovMix }, h$5("h4", { className: BrainPanel_module_css_default.ovCardTitle }, "记忆分类"), mix === null ? h$5("p", { className: BrainPanel_module_css_default.hint }, list === null ? "分类统计暂不可读。" : !categoriesAvailable ? "分类待核实:Mnemon 记忆没有分类字段。" : "分类统计待核实。") : mix.length === 0 ? h$5("p", { className: BrainPanel_module_css_default.hint }, "暂无分类可显示。") : h$5("div", { className: BrainPanel_module_css_default.ovMixBody }, h$5("div", { + className: BrainPanel_module_css_default.mixBar, + "aria-hidden": "true" + }, mix.map((entry, index) => h$5("span", { + key: entry.label, + className: index === 0 ? BrainPanel_module_css_default.mixA : index === 1 ? BrainPanel_module_css_default.mixB : BrainPanel_module_css_default.mixC, + style: { flex: String(entry.count) } + }))), h$5("ul", { className: BrainPanel_module_css_default.mixKeys }, mix.map((entry, index) => h$5("li", { key: entry.label }, h$5("span", { + "aria-hidden": "true", + className: index === 0 ? BrainPanel_module_css_default.mixA : index === 1 ? BrainPanel_module_css_default.mixB : BrainPanel_module_css_default.mixC + }), entry.label + " " + String(entry.count) + " 条")))))), h$5("div", { className: BrainPanel_module_css_default.ovGrid }, h$5("section", { + className: BrainPanel_module_css_default.card + " " + BrainPanel_module_css_default.ovTrend, + "aria-labelledby": "ov-trend-title" + }, h$5("h4", { + id: "ov-trend-title", + className: BrainPanel_module_css_default.ovCardTitle + }, "最近 7 天新增"), trend === null ? h$5("div", { className: BrainPanel_module_css_default.ovPlaceholder }, h$5("p", { className: BrainPanel_module_css_default.ovPlaceholderTitle }, "待核实"), h$5("p", { className: BrainPanel_module_css_default.hint }, listError !== null ? "暂时无法统计新增记忆。" : "Mnemon 记忆带创建时间后,这里显示每日新增。")) : h$5("figure", { className: BrainPanel_module_css_default.ovChart }, h$5("ul", { + className: BrainPanel_module_css_default.plot, + "aria-label": "每日新增的全局记忆条数" + }, trend.map((day) => h$5("li", { + key: day.key, + className: day.count === 0 ? BrainPanel_module_css_default.plotZero : "", + style: { "--height": (day.count === 0 ? 0 : Math.max(3, day.count / trendMax * 100)) + "%" } + }, h$5("span", { className: BrainPanel_module_css_default.srOnly }, day.full + "," + String(day.count) + " 条"), h$5("span", { + className: BrainPanel_module_css_default.plotSlot, + "aria-hidden": "true" + }, day.count === 0 ? null : h$5("span", { className: BrainPanel_module_css_default.plotBar }), h$5("span", { className: BrainPanel_module_css_default.plotAmount }, String(day.count))), h$5("time", { + className: BrainPanel_module_css_default.plotDay, + "aria-hidden": "true", + dateTime: day.key + }, day.label)))), h$5("figcaption", { className: BrainPanel_module_css_default.hint }, total === 0 ? "近 7 天没有新增。" : "按现存记忆的创建日期统计,今天截至快照时间。"))), h$5("section", { + className: BrainPanel_module_css_default.card + " " + BrainPanel_module_css_default.ovChecks, + "aria-labelledby": "ov-checks-title" + }, h$5("h4", { + id: "ov-checks-title", + className: BrainPanel_module_css_default.ovCardTitle + }, "记录与处理"), h$5("ul", { className: BrainPanel_module_css_default.rows }, rows.map((row) => h$5("li", { + key: row.name, + className: row.tone === "warn" ? BrainPanel_module_css_default.rowAttention : "" + }, h$5("span", { + className: BrainPanel_module_css_default.dot + (row.tone === "warn" ? " " + BrainPanel_module_css_default.dotWarn : row.tone === "muted" ? " " + BrainPanel_module_css_default.dotMuted : ""), + "aria-hidden": "true" + }), h$5("div", {}, h$5("p", { className: BrainPanel_module_css_default.rowName + (row.tone === "warn" ? " " + BrainPanel_module_css_default.rowNameWarn : "") }, row.name), h$5("p", { className: BrainPanel_module_css_default.hint }, row.meta))))))), h$5("section", { + className: BrainPanel_module_css_default.card + " " + BrainPanel_module_css_default.ovRecall, + "aria-labelledby": "ov-recall-title" + }, h$5("div", { className: BrainPanel_module_css_default.ovRecallHead }, h$5("h4", { + id: "ov-recall-title", + className: BrainPanel_module_css_default.ovCardTitle + }, "最近一次召回"), h$5("p", { className: BrainPanel_module_css_default.ovRecallState }, "待核实")), h$5("dl", { className: BrainPanel_module_css_default.recallMetrics }, [ + "命中条数", + "高", + "中", + "未知分档", + "召回时间" + ].map((label) => h$5("div", { key: label }, h$5("dt", {}, label), h$5("dd", { className: BrainPanel_module_css_default.recallMissing }, h$5("span", { "aria-hidden": "true" }, "—"), h$5("span", { className: BrainPanel_module_css_default.srOnly }, "待核实"))))), h$5("p", { className: BrainPanel_module_css_default.hint }, "当前未能取得 Mnemon 的最近一次召回结果。")), h$5("details", { className: BrainPanel_module_css_default.card + " " + BrainPanel_module_css_default.ovDiag }, h$5("summary", { className: BrainPanel_module_css_default.ovDiagSummary }, "诊断详情"), h$5("dl", { className: BrainPanel_module_css_default.diagGrid }, diag.map(([term, value]) => [h$5("dt", { key: term + "-t" }, term), h$5("dd", { key: term + "-d" }, value)])))); } // src-client/panel/useApi.ts function useApi(loader, options = {}) { @@ -4359,30 +4720,30 @@ window.__ModuleLoader__.load({ const scopeLabel = project ? "项目" : "全局"; const [offset, setOffset] = react.useState(0); const [search, setSearch] = react.useState(""); + const [searchOpen, setSearchOpen] = react.useState(false); const [notice, setNotice] = react.useState(null); const [pendingForget, setPendingForget] = react.useState(null); const [busy, setBusy] = react.useState(""); - const status = useApi(async () => { - const result = await request("/dsh-brain/local-memory/status?" + scope.toString()); - if (result.status !== 200 || result.body === null || result.body.ok !== true) throw new Error(bodyError(result, "读取本地记忆状态失败")); - return result.body; - }, { + const searchExpanded = searchOpen || search !== ""; + const searchRef = react.useRef(null); + react.useEffect(() => { + const node = searchRef.current; + if (searchExpanded && node !== null && typeof node.focus === "function") node.focus(); + }, [searchExpanded]); + const status = useApi(async () => mnemonStatus(), { visible: active, pollMs: 15e3 }); - const memories = useApi(async () => { - const result = await request("/dsh-brain/local-memory/memories?limit=" + String(PAGE_SIZE) + "&offset=" + String(offset) + "&" + scope.toString()); - if (result.status !== 200 || result.body === null || result.body.ok !== true) throw new Error(bodyError(result, "读取记忆列表失败")); - return result.body; - }, { + const memories = useApi(async () => mnemonMemories(props.scope, offset, PAGE_SIZE), { visible: active, pollMs: project ? 3e4 : void 0, deps: [offset] }); const documents = useApi(async () => { - const result = await request("/dsh-brain/local-memory/documents?" + scope.toString()); - if (result.status !== 200 || result.body === null || result.body.ok !== true) throw new Error(bodyError(result, "读取文档列表失败")); - return result.body; + const result = await request(MNEMON.documents + "?" + scope.toString()); + if (result.status !== 200 || result.body === null || result.body.ok !== true) throw new Error(bodyError(result, "读取 Mnemon 文档失败")); + const value = result.body.value ?? {}; + return { documents: Array.isArray(value.items) ? value.items : Array.isArray(value.documents) ? value.documents : [] }; }, { visible: active && project }); const items = Array.isArray(memories.data?.items) ? memories.data.items : []; const needle = String(search).trim().toLowerCase(); @@ -4424,8 +4785,8 @@ window.__ModuleLoader__.load({ setBusy(""); } }; - const space = status.data?.spaces?.[props.scope]; - const root = project ? status.data?.projectRoot : status.data?.globalRoot; + const storageRoot = status.data?.storage?.activeRoot; + const workspaceMode = status.data?.workspaceContext?.mode; return h$4("div", { style: { display: "flex", flexDirection: "column", @@ -4442,22 +4803,41 @@ window.__ModuleLoader__.load({ } }) }, h$4(Pill$1, { - label: "空间状态", - value: status.status === "loading" ? "读取中" : space?.name ?? (space ? "就绪" : "未创建"), - tone: space ? "ok" : "muted" - }), root === void 0 ? null : h$4("p", { style: styles.hint }, String(root))), h$4(Section, { + label: "数据源", + value: status.status === "loading" ? "读取中" : status.error !== null ? "Mnemon 未接入" : "Mnemon 已接入", + tone: status.error !== null ? "warn" : "ok" + }), typeof storageRoot === "string" && storageRoot !== "" ? h$4("p", { style: styles.hint }, String(storageRoot)) : null, typeof workspaceMode === "string" && workspaceMode !== "" ? h$4("p", { style: styles.hint }, "存储范围:" + String(workspaceMode)) : null), h$4(Section, { title: "记忆条目(" + String(total) + ")", - hint: "只显示当前页;搜索只在当前页内过滤。删除需要二次确认并带 revision 校验。", - aside: h$4("div", { style: styles.actions }, h$4(Field, { - label: "搜索当前页", + hint: "数据来自 Mnemon(本轮只读);搜索在当前页内过滤,暂不开放删除。", + aside: h$4("div", { style: styles.actions }, searchExpanded ? h$4("input", { + ref: searchRef, + style: Object.assign({}, styles.input, { + width: "200px", + flex: "0 1 auto" + }), + type: "text", value: search, - onChange: setSearch + placeholder: "搜索当前页", + spellCheck: false, + autoComplete: "off", + "aria-label": "搜索当前页", + onChange: (event) => setSearch(event.target.value), + onKeyDown: (event) => { + if (event.key === "Escape" && search === "") setSearchOpen(false); + }, + onBlur: () => { + if (search === "") setSearchOpen(false); + } + }) : h$4(IconBtn, { + glyph: "🔍", + ariaLabel: "搜索当前页", + onClick: () => setSearchOpen(true) }), h$4(Btn, { label: "刷新", variant: "small", onClick: () => memories.reload() })) - }, notice === null ? null : h$4(Banner, { tone: notice.tone }, notice.text), memories.error === null ? null : h$4(Banner, { tone: "bad" }, memories.error), memories.status === "loading" && items.length === 0 ? h$4("p", { style: styles.hint }, "正在读取记忆…") : null, filtered.length === 0 ? h$4("p", { style: styles.hint }, total === 0 && needle === "" ? "还没有记忆条目。对话中让助手记住,或用 memory_add 写入。" : "当前页没有匹配的记忆条目。") : h$4("div", { style: { + }, notice === null ? null : h$4(Banner, { tone: notice.tone }, notice.text), memories.error === null ? null : h$4(Banner, { tone: "bad" }, memories.error), memories.status === "loading" && items.length === 0 ? h$4("p", { style: styles.hint }, "正在读取记忆…") : null, filtered.length === 0 ? h$4("p", { style: styles.hint }, total === 0 && needle === "" ? "Mnemon 里还没有记忆条目。" : "当前页没有匹配的记忆条目。") : h$4("div", { style: { display: "flex", flexDirection: "column", gap: "8px" @@ -4465,29 +4845,35 @@ window.__ModuleLoader__.load({ key: item.id, style: styles.row }, h$4("div", { style: styles.rowHead }, h$4("div", { style: styles.pills }, h$4(Pill$1, { - label: "scope", - value: item.scope ?? "—", + label: "归属", + value: item.scope === "global" ? "全局" : item.scope === "project" ? "项目记忆" : "—", tone: "muted" - }), item.category === void 0 ? null : h$4(Pill$1, { + }), h$4(Pill$1, { label: "分类", - value: item.category, + value: item.category === void 0 ? item.mnemon === true ? "待核实" : "无分类" : memoryCategoryLabel(item.category), tone: "muted" }), h$4(Pill$1, { label: "rev", value: item.revision ?? "—", tone: "muted" - }), h$4(Pill$1, { + }), typeof item.createdAt === "string" && item.createdAt !== "" ? h$4(Pill$1, { + label: "创建", + value: formatIso(item.createdAt), + tone: "muted" + }) : h$4(Pill$1, { label: "更新", value: formatIso(item.updatedAt), tone: "muted" })), h$4("div", { style: styles.actions }, pendingForget === item.id ? null : h$4(Btn, { label: "删除…", variant: "small", + disabled: item.mnemon === true, + ariaLabel: item.mnemon === true ? "本轮只读,暂不支持删除 Mnemon 记忆" : void 0, onClick: () => { setPendingForget(item.id); setNotice(null); } - }))), h$4("div", { style: styles.clamp2 }, String(item.content ?? "")), Array.isArray(item.tags) && item.tags.length > 0 ? h$4("p", { style: styles.hint }, "标签:" + item.tags.join("、")) : null, pendingForget === item.id ? h$4("div", { style: styles.nested }, h$4("p", { style: styles.hint }, "确认删除这条记忆?此操作不可撤销。"), h$4("div", { style: styles.actions }, h$4(Btn, { + }))), h$4("div", { style: styles.clamp2 }, String(item.content ?? "")), h$4("p", { style: styles.hint }, "来源:" + memorySourceLabel(item.source, item.createdAt)), Array.isArray(item.tags) && item.tags.length > 0 ? h$4("p", { style: styles.hint }, "标签:" + item.tags.join("、")) : null, pendingForget === item.id ? h$4("div", { style: styles.nested }, h$4("p", { style: styles.hint }, "确认删除这条记忆?此操作不可撤销。"), h$4("div", { style: styles.actions }, h$4(Btn, { variant: "danger", label: busy === item.id ? "删除中…" : "确认删除", disabled: busy !== "", diff --git a/lib/entries/ui.js b/lib/entries/ui.js index 154efcf..b8ae02f 100644 --- a/lib/entries/ui.js +++ b/lib/entries/ui.js @@ -1,4 +1,5 @@ import { brainKernel, VERSION } from "../kernel.js"; +import { mnemonReadFromContext } from "../mnemon/read-service.js"; import { createCoreRoutes, legacyAliases } from "../routes.js"; import { createSettingsUiRoutes } from "../settings-ui/routes.js"; export const name = 'dsh-brain-ui'; @@ -34,7 +35,10 @@ export function apply(ctx, config) { } const routes = [ ...createSettingsUiRoutes({ version: VERSION, store: kernel.store }), - ...createCoreRoutes(kernel.routeDeps()), + ...createCoreRoutes({ + ...kernel.routeDeps(), + mnemon: () => mnemonReadFromContext(ctx), + }), ]; routes.push(...legacyAliases(routes)); for (const route of routes) { diff --git a/lib/local-memory/manager.js b/lib/local-memory/manager.js index 844658d..0dc70aa 100644 --- a/lib/local-memory/manager.js +++ b/lib/local-memory/manager.js @@ -282,9 +282,13 @@ export class LocalMemoryManager { return record.scope === 'project' && record.projectId === projectId; }); const seen = new Set(); + // The whole merged set is ordered before pagination (never just the page). + // `updated` keeps the historical order; `created` is the API's new default. + const compare = options.order === 'created' + ? (a, b) => b.createdAt.localeCompare(a.createdAt) || a.id.localeCompare(b.id) + : (a, b) => b.updatedAt.localeCompare(a.updatedAt) || a.id.localeCompare(b.id); const ordered = scoped.filter((record) => { if (seen.has(record.id)) - return false; seen.add(record.id); return true; }) - .sort((a, b) => b.updatedAt.localeCompare(a.updatedAt) || a.id.localeCompare(b.id)); + return false; seen.add(record.id); return true; }).sort(compare); const offset = Math.max(0, Math.trunc(options.offset ?? 0)); const limit = Math.max(1, Math.min(1000, Math.trunc(options.limit ?? 50))); return { items: ordered.slice(offset, offset + limit), total: ordered.length }; diff --git a/lib/local-memory/storage.js b/lib/local-memory/storage.js index e1293f7..541029e 100644 --- a/lib/local-memory/storage.js +++ b/lib/local-memory/storage.js @@ -187,10 +187,15 @@ export class JsonMemoryStore { } async list(options = {}) { const file = await this.readFile(); - const records = this.activeRecords(file).sort((a, b) => b.updatedAt.localeCompare(a.updatedAt)); + const records = this.activeRecords(file); + // Order the whole set before slicing: paging must stay stable across pages. + // `updated` keeps the historical order; `created` is the API's new default. + const ordered = options.order === 'created' + ? records.sort((a, b) => b.createdAt.localeCompare(a.createdAt) || a.id.localeCompare(b.id)) + : records.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt)); const offset = Math.max(0, Math.trunc(options.offset ?? 0)); const limit = Math.max(1, Math.min(1000, Math.trunc(options.limit ?? 50))); - return { items: records.slice(offset, offset + limit), total: records.length }; + return { items: ordered.slice(offset, offset + limit), total: ordered.length }; } async update(id, patch, expectedRevision) { return withFileLock(this.lockPath, async () => { const file = await this.readFile(); const record = file.records.find((item) => item.id === id && item.deleted !== true); if (record === undefined) diff --git a/lib/mnemon/read-service.js b/lib/mnemon/read-service.js new file mode 100644 index 0000000..a3c06cd --- /dev/null +++ b/lib/mnemon/read-service.js @@ -0,0 +1,62 @@ +/** + * Read-only bridge to the live Mnemon Host RPC service. + * + * Mnemon registers `mnemonRemote` as a Typert service; its `read` method is the + * same read handler its own `/dsh-mnemon-read` channel serves. dsh-brain reads + * through that service instead of copying Mnemon data: no storage layout is + * touched, and no write/forget endpoint is exposed here. + * + * The service name is resolved lazily from the live Cordis context, so the + * plugin loads and runs when Mnemon is absent; the read routes then answer + * 503 instead of failing plugin activation. + */ +import { resolve } from 'node:path'; +/** + * Resolve the live Mnemon read service from a host Context. + * + * `mnemonRemote` is provided by the installed `dsh-mnemon` Host entry. A + * missing service (Mnemon not installed, entry disabled, or a host without the + * web transport) returns undefined; the caller exposes that as a capability + * gap, never as a read of stale data. + */ +export function mnemonReadFromContext(ctx) { + const get = ctx.get; + if (typeof get !== 'function') + return undefined; + const lookup = (name) => { + try { + return get.call(ctx, name, false); + } + catch { + return undefined; + } + }; + const candidate = lookup('mnemonRemote'); + if (candidate === null || typeof candidate !== 'object') + return undefined; + const read = candidate.read; + if (typeof read !== 'function') + return undefined; + const service = candidate; + return { + read: (endpoint, payload, signal) => signal === undefined + ? service.read(endpoint, payload) + : service.read(endpoint, payload, signal), + workspaceIdForPath: (path) => { + const registry = lookup('workspaceRegistry'); + if (registry === undefined || typeof registry.list !== 'function') + return undefined; + let spaces; + try { + spaces = registry.list(); + } + catch { + return undefined; + } + const target = resolve(path); + const found = spaces.find((space) => typeof space.id === 'string' + && typeof space.path === 'string' && resolve(space.path) === target); + return typeof found?.id === 'string' ? found.id : undefined; + }, + }; +} diff --git a/lib/routes.js b/lib/routes.js index 28bfb7a..cce8005 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -21,6 +21,7 @@ export const ROUTES = { migrate: '/dsh-brain/migrate', localMemory: '/dsh-brain/local-memory', departments: '/dsh-brain/departments', + mnemon: '/dsh-brain/mnemon', }; /** Reported when the MCP sub-plugin entry is not applied; the client keeps the tab hidden. */ const MCP_UNAVAILABLE = { @@ -164,10 +165,16 @@ async function serveLocalMemory(deps, req, res) { json(res, 200, { ok: true, ...(await manager.storageStatus(workspace, scope)) }); return; } + const orderParam = url.searchParams.get('order'); + if (orderParam !== null && orderParam !== 'created' && orderParam !== 'updated') { + fail(res, 400, 'invalid-order'); + return; + } + const order = orderParam === 'updated' ? 'updated' : 'created'; const limit = Math.max(1, Math.min(1000, Number.parseInt(url.searchParams.get('limit') ?? '50', 10) || 50)); const offset = Math.max(0, Number.parseInt(url.searchParams.get('offset') ?? '0', 10) || 0); - const page = await manager.list({ limit, offset, scope }, workspace); - json(res, 200, { ok: true, total: page.total, items: page.items.map((record) => ({ id: record.id, scope: record.scope, content: record.content, category: record.category, tags: record.tags, source: record.source, revision: record.revision, updatedAt: record.updatedAt })) }); + const page = await manager.list({ limit, offset, scope, order }, workspace); + json(res, 200, { ok: true, total: page.total, items: page.items.map((record) => ({ id: record.id, scope: record.scope, content: record.content, category: record.category, tags: record.tags, source: record.source, revision: record.revision, createdAt: record.createdAt, updatedAt: record.updatedAt })) }); return; } if (suffix === '/spaces') { @@ -350,6 +357,104 @@ async function serveMigrate(_deps, req, res) { } fail(res, 404, 'unknown-migrate-route'); } +/** + * Read-only Mnemon bridge: `GET /dsh-brain/mnemon/`. + * + * The body is Mnemon's own RPC result envelope (`{ok,value}` / `{ok,error}`); + * query parameters map 1:1 onto the endpoint's payload. Only reads are + * exposed: there is no remember/forget route here, by design. + */ +async function serveMnemonRead(deps, req, res) { + if (req.method !== 'GET') { + fail(res, 405, 'method-not-allowed'); + return; + } + const bridge = deps.mnemon?.(); + if (bridge === undefined) { + json(res, 503, { ok: false, error: { code: 'mnemon-unavailable', message: 'Mnemon 读服务未接入:当前宿主没有 mnemonRemote 服务。' } }); + return; + } + const url = new URL(req.url ?? '/', 'http://localhost'); + const suffix = url.pathname.slice(ROUTES.mnemon.length).replace(/\/+$/, ''); + const endpoints = { + '/list': 'list', + '/status': 'status', + '/search': 'search', + '/runtime': 'runtime-memory', + '/documents': 'documents', + }; + const endpoint = endpoints[suffix]; + if (endpoint === undefined) { + fail(res, 404, 'unknown-mnemon-route'); + return; + } + const workspaceIdParam = url.searchParams.get('workspaceId')?.trim(); + const workspacePath = url.searchParams.get('workspace')?.trim(); + const sessionId = url.searchParams.get('sessionId')?.trim() || undefined; + const workspaceId = workspaceIdParam !== undefined && workspaceIdParam !== '' + ? workspaceIdParam + : workspacePath !== undefined && workspacePath !== '' + ? bridge.workspaceIdForPath(workspacePath) + : undefined; + const scope = { + ...(workspaceId === undefined ? {} : { workspaceId }), + ...(sessionId === undefined ? {} : { sessionId }), + }; + const ids = url.searchParams.getAll('memoryBodyIds').flatMap((value) => value.split(',')).map((value) => value.trim()).filter((value) => value !== ''); + const memoryBodyIds = ids.length === 0 ? undefined : [...new Set(ids)]; + const limit = (fallback) => { + const parsed = Number.parseInt(url.searchParams.get('limit') ?? '', 10); + return Number.isFinite(parsed) ? Math.max(1, Math.min(1000, parsed)) : fallback; + }; + let payload; + if (endpoint === 'list') { + const query = url.searchParams.get('query')?.trim(); + const category = url.searchParams.get('category')?.trim(); + payload = { + ...scope, + limit: limit(50), + ...(query === undefined || query === '' ? {} : { query }), + ...(category === undefined || category === '' ? {} : { category }), + ...(memoryBodyIds === undefined ? {} : { memoryBodyIds }), + }; + } + else if (endpoint === 'search') { + const query = (url.searchParams.get('q') ?? url.searchParams.get('query') ?? '').trim(); + if (query === '') { + fail(res, 400, 'query-required'); + return; + } + const mode = url.searchParams.get('mode')?.trim(); + const category = url.searchParams.get('category')?.trim(); + const source = url.searchParams.get('source')?.trim(); + const intent = url.searchParams.get('intent')?.trim(); + payload = { + query, + ...scope, + limit: limit(10), + ...(mode === undefined || mode === '' ? {} : { mode }), + ...(category === undefined || category === '' ? {} : { category }), + ...(source === undefined || source === '' ? {} : { source }), + ...(intent === undefined || intent === '' ? {} : { intent }), + ...(memoryBodyIds === undefined ? {} : { memoryBodyIds }), + }; + } + else { + payload = scope; + } + try { + const result = await bridge.read(endpoint, payload); + if (result.ok) { + json(res, 200, { ok: true, value: result.value }); + return; + } + const status = result.error.code === 'bad-request' ? 400 : 502; + json(res, status, { ok: false, error: result.error }); + } + catch (error) { + json(res, 502, { ok: false, error: { code: 'mnemon-error', message: error instanceof Error ? error.message : String(error) } }); + } +} /** * Pre-rename aliases (0.8.0): the same route objects under the old * `/cloud-memory` prefix. Each sub-plugin entry aliases its own slice this @@ -408,6 +513,11 @@ export function createCoreRoutes(deps) { path: ROUTES.departments, handler: (req, res) => serveDepartments(deps, req, res), }, + { + kind: 'prefix', + path: ROUTES.mnemon, + handler: (req, res) => serveMnemonRead(deps, req, res), + }, { kind: 'exact', path: ROUTES.status, diff --git a/lib/version.js b/lib/version.js index 70428c5..38c4218 100644 --- a/lib/version.js +++ b/lib/version.js @@ -8,7 +8,7 @@ */ import { readFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; -const FALLBACK_VERSION = '0.10.4'; +const FALLBACK_VERSION = '0.10.5'; function readVersion() { try { const manifest = JSON.parse(readFileSync(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf8')); diff --git a/package.json b/package.json index 37af750..8be782a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dsh-brain", - "version": "0.10.4", + "version": "0.10.5", "description": "Cloud memory for DSH: report one activity turn per conversation round and expose memory_search / memory_read / memory_add tools against a LongMemory cloud endpoint.", "type": "module", "license": "MIT", diff --git a/src/version.ts b/src/version.ts index 3c80107..118713b 100644 --- a/src/version.ts +++ b/src/version.ts @@ -9,7 +9,7 @@ import { readFileSync } from 'node:fs' import { fileURLToPath } from 'node:url' -const FALLBACK_VERSION = '0.10.4' +const FALLBACK_VERSION = '0.10.5' function readVersion(): string { try {