dsh-memory-engine 0.5.7 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +20 -0
- package/lib/client.js +28 -6
- package/lib/index.js +31 -7
- package/package.json +9 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 阿木
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -4,6 +4,22 @@ DSH 插件的本地记忆引擎,带神经网络可视化。它让 agent 保存
|
|
|
4
4
|
|
|
5
5
|
当前版本:0.5.2。Node ≥22,零新增依赖;DSH 宿主提供 `@deepseek-ai/dsh-tools@0.2.1-rc.3`。本机安装已启用,无需重复安装。
|
|
6
6
|
|
|
7
|
+
## 支持的 DSH 版本
|
|
8
|
+
|
|
9
|
+
实测可用范围:**@deepseek-ai/dsh-tools 0.1.0-rc.8 ~ 0.2.2-alpha.2**(本插件只用其中的 defineTool,这几个版本签名一致)。
|
|
10
|
+
|
|
11
|
+
插件对宿主做了三处兜底,所以版本不合适时也不会「装上了却什么都没有」:
|
|
12
|
+
|
|
13
|
+
| 宿主情况 | 插件行为 |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| 有 ctx.effect | 正常注册,随插件卸载一起清理 |
|
|
16
|
+
| 没有 ctx.effect | 直接注册工具,功能不减少,日志留一条提示 |
|
|
17
|
+
| 解析不到 @deepseek-ai/dsh-tools | 用内置直通 defineTool,工具照常可用 |
|
|
18
|
+
| 没有 header.actions 插槽 | 图谱按钮退到 iews.actions(在「更多视图」菜单里) |
|
|
19
|
+
| 完全没有 slots 服务 | 跳过按钮,记忆工具不受影响 |
|
|
20
|
+
|
|
21
|
+
peerDependencies 已放宽为 >=0.1.0-rc.8 <0.3.0 并标为 optional——宿主自带这份 SDK,不该因为版本号不匹配而装不上。
|
|
22
|
+
|
|
7
23
|
## 界面
|
|
8
24
|
|
|
9
25
|
安装并启用插件后,完全退出 DSH 再打开。进入任意会话,头部第一行会出现 **🧠 记忆图谱** 按钮。
|
|
@@ -219,3 +235,7 @@ node --test test/*.test.mjs
|
|
|
219
235
|
本地开发安装:将本包作为目标 DSH profile 的 link 依赖,并启用同名 bundle;客户端入口已声明为 web/immediately。完全退出再打开 DSH。不要复制宿主 SDK 到包里。
|
|
220
236
|
|
|
221
237
|
文件写入仍继承原 MemoryStore 的单进程同步事务方式;多个独立宿主同时修改同一文件不提供跨进程锁。历史验收和本次截图、反向验证 HTML、文件变更清单位于相邻的 dsh-memory-engine-deliveries 目录。
|
|
238
|
+
|
|
239
|
+
## 许可
|
|
240
|
+
|
|
241
|
+
MIT。可以商用、可以修改、可以再发布,保留版权声明即可(见 [LICENSE](./LICENSE))。
|
package/lib/client.js
CHANGED
|
@@ -9,6 +9,9 @@ window.__ModuleLoader__.load({
|
|
|
9
9
|
// views.actions 是「更多视图」下拉菜单的行(Chat/Trajectory 旁边的 ⋯),
|
|
10
10
|
// 注册进去只是菜单里多一行,看不见;header.actions 才是头部正常按钮区。
|
|
11
11
|
var SLOT_NAME = "conversation.session.header.actions";
|
|
12
|
+
// 不同 DSH 版本暴露的插槽名不一样:新版本用 header.actions,
|
|
13
|
+
// 老版本没有这个槽时退回 views.actions(会出现在「更多视图」菜单里,虽然不显眼但能用)。
|
|
14
|
+
var SLOT_FALLBACKS = ["conversation.session.header.actions", "conversation.session.header.views.actions"];
|
|
12
15
|
var VIEW_URL = "http://127.0.0.1:18886/index.html";
|
|
13
16
|
|
|
14
17
|
function MemoryButton() {
|
|
@@ -56,16 +59,35 @@ window.__ModuleLoader__.load({
|
|
|
56
59
|
return React.createElement(React.Fragment, null, button, ReactDOM.createPortal(overlay, document.body));
|
|
57
60
|
}
|
|
58
61
|
|
|
59
|
-
function
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
function registerOn(slots, name) {
|
|
63
|
+
var disposable = null;
|
|
64
|
+
slots.inject(name, function () {
|
|
65
|
+
try {
|
|
66
|
+
disposable = slots.register({
|
|
67
|
+
name: name,
|
|
64
68
|
id: "memory-engine-map",
|
|
65
69
|
order: 50,
|
|
66
70
|
label: function () { return "记忆图谱"; },
|
|
67
71
|
}, MemoryButton);
|
|
68
|
-
})
|
|
72
|
+
} catch (error) {
|
|
73
|
+
try { console.error("[dsh-memory-engine] 注册到 " + name + " 失败:", error); } catch (ignored) {}
|
|
74
|
+
}
|
|
75
|
+
return disposable;
|
|
76
|
+
});
|
|
77
|
+
return disposable;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function apply(ctx) {
|
|
81
|
+
try {
|
|
82
|
+
if (!ctx || !ctx.slots || typeof ctx.slots.inject !== "function") {
|
|
83
|
+
try { console.warn("[dsh-memory-engine] 宿主没有 slots 服务,跳过图谱按钮(记忆工具不受影响)"); } catch (ignored) {}
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
// 只注册第一个能用的插槽:优先 header.actions,老宿主没有就退到 views.actions
|
|
87
|
+
var target = ctx.slots && typeof ctx.slots.has === "function" && !ctx.slots.has(SLOT_FALLBACKS[0])
|
|
88
|
+
? SLOT_FALLBACKS[1]
|
|
89
|
+
: SLOT_NAME;
|
|
90
|
+
registerOn(ctx.slots, target);
|
|
69
91
|
} catch (error) {
|
|
70
92
|
try { console.error("[dsh-memory-engine] 插槽注册失败:", error); } catch (ignored) {}
|
|
71
93
|
}
|
package/lib/index.js
CHANGED
|
@@ -154,15 +154,33 @@ export function createTools(defineTool, store = new MemoryStore(), { map = gener
|
|
|
154
154
|
];
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
+
// 宿主 SDK 的 defineTool 在不同 DSH 版本间签名一致(实测 0.1.0-rc.8 ~ 0.2.2-alpha.2 都是
|
|
158
|
+
// defineTool(options)),但**包不一定能解析到**——比如插件被装在宿主 node_modules 之外。
|
|
159
|
+
// 解析失败时退回一个直通实现:工具照常注册,只是少了宿主的返回值包装。
|
|
160
|
+
async function resolveDefineTool(warning) {
|
|
161
|
+
try {
|
|
162
|
+
const sdk = await import('@deepseek-ai/dsh-tools');
|
|
163
|
+
if (typeof sdk.defineTool === 'function') {
|
|
164
|
+
const version = sdk.version ?? '';
|
|
165
|
+
if (version) warning(`宿主 dsh-tools 版本 ${version}`);
|
|
166
|
+
return sdk.defineTool;
|
|
167
|
+
}
|
|
168
|
+
warning('@deepseek-ai/dsh-tools 没有导出 defineTool,改用内置直通实现');
|
|
169
|
+
} catch (error) {
|
|
170
|
+
warning(`解析 @deepseek-ai/dsh-tools 失败(${error.message}),改用内置直通实现`);
|
|
171
|
+
}
|
|
172
|
+
return options => options;
|
|
173
|
+
}
|
|
174
|
+
|
|
157
175
|
export function apply(ctx) {
|
|
158
176
|
try {
|
|
159
177
|
if (typeof ctx?.tools?.register !== 'function') throw new Error('tools 服务不可用');
|
|
160
|
-
|
|
161
|
-
|
|
178
|
+
// ctx.effect 是较新宿主才有的生命周期钩子。没有它就直接注册——
|
|
179
|
+
// 否则老版本 DSH 上插件会「装上了但一个工具都没有」,这是最糟的失败方式。
|
|
180
|
+
const setup = async () => {
|
|
162
181
|
const disposers = [];
|
|
163
182
|
try {
|
|
164
|
-
|
|
165
|
-
const { defineTool } = await import('@deepseek-ai/dsh-tools');
|
|
183
|
+
const defineTool = await resolveDefineTool(message => warn(ctx, message));
|
|
166
184
|
const store = new MemoryStore();
|
|
167
185
|
for (const tool of createTools(defineTool, store, { warning: message => warn(ctx, message) })) disposers.push(ctx.tools.register(tool));
|
|
168
186
|
try {
|
|
@@ -182,8 +200,14 @@ export function apply(ctx) {
|
|
|
182
200
|
for (const dispose of disposers.reverse()) { try { dispose(); } catch { /* keep unwinding */ } }
|
|
183
201
|
report(ctx, error);
|
|
184
202
|
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
if (typeof ctx.effect === 'function') {
|
|
206
|
+
const registration = ctx.effect(setup, 'memory-engine.tools');
|
|
207
|
+
// Await setup without returning its disposer as a second plugin teardown.
|
|
208
|
+
return Promise.resolve(registration).then(() => undefined, error => { report(ctx, error); });
|
|
209
|
+
}
|
|
210
|
+
warn(ctx, '宿主没有 ctx.effect,直接用注册式初始化(功能不减少)');
|
|
211
|
+
return Promise.resolve(setup()).then(() => undefined, error => { report(ctx, error); });
|
|
188
212
|
} catch (error) { report(ctx, error); }
|
|
189
213
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-memory-engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Local DSH memory engine with neuron network visualization and private file import",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|
|
@@ -29,14 +29,15 @@
|
|
|
29
29
|
"lib/",
|
|
30
30
|
"scripts/",
|
|
31
31
|
"cordis.patch.yml",
|
|
32
|
-
"README.md"
|
|
32
|
+
"README.md",
|
|
33
|
+
"LICENSE"
|
|
33
34
|
],
|
|
34
35
|
"engines": {
|
|
35
36
|
"node": ">=22"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {},
|
|
38
39
|
"peerDependencies": {
|
|
39
|
-
"@deepseek-ai/dsh-tools": "0.
|
|
40
|
+
"@deepseek-ai/dsh-tools": ">=0.1.0-rc.8 <0.3.0"
|
|
40
41
|
},
|
|
41
42
|
"dsh": {
|
|
42
43
|
"bundle": {
|
|
@@ -48,6 +49,11 @@
|
|
|
48
49
|
}
|
|
49
50
|
},
|
|
50
51
|
"bugs": "https://github.com/",
|
|
52
|
+
"peerDependenciesMeta": {
|
|
53
|
+
"@deepseek-ai/dsh-tools": {
|
|
54
|
+
"optional": true
|
|
55
|
+
}
|
|
56
|
+
},
|
|
51
57
|
"scripts": {
|
|
52
58
|
"test": "node --test test/*.test.mjs"
|
|
53
59
|
}
|