dsh-plugin-agent-memory 0.0.0-stage → 0.1.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 +76 -2
- package/client.js +526 -0
- package/cordis.patch.yml +3 -0
- package/docs/DETAIL.md +36 -0
- package/icon.svg +8 -0
- package/index.js +714 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +46 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 赵寒 (whalezhao)
|
|
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
|
@@ -1,3 +1,77 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-plugin-agent-memory
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
DeepSeek Harness (DSH) plugin that connects a self-hosted **Tencent agent-memory** Hub (the
|
|
4
|
+
`Memory Hub` RPC service on port `8125`) into the conversation.
|
|
5
|
+
|
|
6
|
+
It adds an **expert selector** to the left of the composer. An *expert* is one agent of one team
|
|
7
|
+
in the Hub; that agent's long-term memories are recalled for each user message and appended to the
|
|
8
|
+
step as an `<agent-memory>` block, so the model sees them without any tool call.
|
|
9
|
+
|
|
10
|
+
## Requirements
|
|
11
|
+
|
|
12
|
+
- DSH `>=0.2.2-rc.5` (the plugin declares `dsh.bundle` and a Web client half).
|
|
13
|
+
- A reachable agent-memory Hub: the RPC endpoint `POST {hubUrl}/api/v1/...` that accepts
|
|
14
|
+
`X-Tdai-Service-Id` (instance id) and `X-Tdai-User-Key` (user key) headers.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
dsh plugin --profile <profile> add dsh-plugin-agent-memory
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
It is listed on the [DSH plugin market](https://awesome-dsh-plugin.com/) too. Without npm access,
|
|
23
|
+
install the prebuilt release asset or the checked-out source:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
dsh plugin --profile <profile> add \
|
|
27
|
+
https://github.com/whalezhao/dsh-plugin-agent-memory/releases/download/v0.1.0/dsh-plugin-agent-memory-0.1.0.tgz
|
|
28
|
+
dsh plugin --profile <profile> add /path/to/dsh-plugin-agent-memory
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
From a running DSH session, the plugin manager can install the same npm name or tarball URL.
|
|
32
|
+
|
|
33
|
+
## Configure
|
|
34
|
+
|
|
35
|
+
Open the plugin's settings page (or the panel's gear button) and set:
|
|
36
|
+
|
|
37
|
+
| Field | Meaning |
|
|
38
|
+
| --- | --- |
|
|
39
|
+
| `hubUrl` | Memory Hub base URL, e.g. `http://10.0.0.10:8125` |
|
|
40
|
+
| `instanceId` | Hub instance id, sent as `X-Tdai-Service-Id` |
|
|
41
|
+
| `userKey` | Hub user key, sent as `X-Tdai-User-Key` (stored as a secret field) |
|
|
42
|
+
| `defaultAgentId` | Agent used before the user picks an expert; empty means "pick one" |
|
|
43
|
+
| `injectMemory` | Recall memories and inject them before each step (default on) |
|
|
44
|
+
| `writeMemory` | Write each turn's user message back to the expert's memory (default off) |
|
|
45
|
+
| `topK` | Max memories per recall (1–10, default 4) |
|
|
46
|
+
| `timeoutMs` | Per-request timeout (default 6000) |
|
|
47
|
+
| `debug` | Append diagnostics to `~/.dsh/agent-memory-debug.log` (default off, 256 KiB cap) |
|
|
48
|
+
|
|
49
|
+
With no `hubUrl` or `userKey` the plugin stays idle: the selector is hidden and nothing is sent.
|
|
50
|
+
|
|
51
|
+
## What data leaves the machine
|
|
52
|
+
|
|
53
|
+
- The Hub URL and user key are only used by the Host half; the browser talks to same-origin
|
|
54
|
+
plugin routes and never sees the key.
|
|
55
|
+
- With `injectMemory`, the last user message of a turn is sent to the Hub as a recall query.
|
|
56
|
+
- With `writeMemory`, each turn's user message is also sent to the Hub to be stored.
|
|
57
|
+
- Nothing is sent to any third party.
|
|
58
|
+
|
|
59
|
+
## Limits
|
|
60
|
+
|
|
61
|
+
- Only agents owned by the configured user key can be selected; selecting someone else's agent is
|
|
62
|
+
rejected (`403 NOT_YOUR_AGENT`) because the Hub refuses cross-owner reads and writes.
|
|
63
|
+
- The Hub's public RPC surface has no per-message delete endpoint, so memories are curated in the
|
|
64
|
+
Hub's own memory UI, not from DSH.
|
|
65
|
+
- Recalled memories are injected as a user-role message; a turn whose message has no relevant hit
|
|
66
|
+
injects nothing.
|
|
67
|
+
|
|
68
|
+
## 中文说明
|
|
69
|
+
|
|
70
|
+
在输入框左侧点「选择专家」 → 右上角「设置」里填 Hub 地址、实例 ID 与 userkey → 保存后点
|
|
71
|
+
「检测连接」确认连通 → 回到列表选团队与 agent。选中后,该 agent 的长期记忆会在每轮对话前被
|
|
72
|
+
召回并注入上下文;打开写回后,每轮用户消息也会写入记忆库。插件默认保持空闲,直到你填好地址与
|
|
73
|
+
userkey。只允许选择自己 userkey 名下拥有的 agent。
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
MIT — see [LICENSE](./LICENSE).
|
package/client.js
ADDED
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client half: the "专家" (expert) selector at the left of the composer tool row.
|
|
3
|
+
*
|
|
4
|
+
* It renders the cached team / agent list served by this bundle's Host half and stores the
|
|
5
|
+
* selection back through the same origin-scoped HTTP routes, so the Host can recall that
|
|
6
|
+
* expert's memories on the next turn.
|
|
7
|
+
*/
|
|
8
|
+
window.__ModuleLoader__.load({
|
|
9
|
+
id: '@local/agent-memory',
|
|
10
|
+
factory(require) {
|
|
11
|
+
const React = require('react');
|
|
12
|
+
const h = React.createElement;
|
|
13
|
+
|
|
14
|
+
const ROUTE = '/plugins/agent-memory';
|
|
15
|
+
|
|
16
|
+
const chipStyle = {
|
|
17
|
+
display: 'inline-flex',
|
|
18
|
+
alignItems: 'center',
|
|
19
|
+
gap: '6px',
|
|
20
|
+
height: '28px',
|
|
21
|
+
padding: '0 10px',
|
|
22
|
+
borderRadius: '999px',
|
|
23
|
+
border: '1px solid var(--dsw-alias-border-subtle, rgba(128,128,128,0.32))',
|
|
24
|
+
background: 'transparent',
|
|
25
|
+
color: 'var(--dsw-alias-text-secondary, #555)',
|
|
26
|
+
font: 'inherit',
|
|
27
|
+
fontSize: '12px',
|
|
28
|
+
lineHeight: '1',
|
|
29
|
+
cursor: 'pointer',
|
|
30
|
+
maxWidth: '220px',
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const panelStyle = {
|
|
34
|
+
position: 'absolute',
|
|
35
|
+
bottom: 'calc(100% + 8px)',
|
|
36
|
+
left: '0',
|
|
37
|
+
width: '320px',
|
|
38
|
+
maxHeight: '70vh',
|
|
39
|
+
overflowY: 'auto',
|
|
40
|
+
padding: '6px',
|
|
41
|
+
borderRadius: '10px',
|
|
42
|
+
border: '1px solid var(--dsw-alias-border-subtle, rgba(128,128,128,0.32))',
|
|
43
|
+
background: 'var(--dsw-alias-bg-elevated, #fff)',
|
|
44
|
+
boxShadow: '0 8px 24px rgba(0,0,0,0.16)',
|
|
45
|
+
zIndex: 60,
|
|
46
|
+
color: 'var(--dsw-alias-text-primary, #111)',
|
|
47
|
+
fontSize: '12px',
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const rowStyle = {
|
|
51
|
+
display: 'block',
|
|
52
|
+
width: '100%',
|
|
53
|
+
textAlign: 'left',
|
|
54
|
+
padding: '6px 8px',
|
|
55
|
+
borderRadius: '6px',
|
|
56
|
+
border: 'none',
|
|
57
|
+
background: 'transparent',
|
|
58
|
+
color: 'inherit',
|
|
59
|
+
font: 'inherit',
|
|
60
|
+
fontSize: '12px',
|
|
61
|
+
cursor: 'pointer',
|
|
62
|
+
whiteSpace: 'normal',
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const mutedStyle = { padding: '6px 8px', opacity: 0.6, fontSize: '11px' };
|
|
66
|
+
|
|
67
|
+
const inputStyle = {
|
|
68
|
+
width: '100%',
|
|
69
|
+
boxSizing: 'border-box',
|
|
70
|
+
height: '26px',
|
|
71
|
+
padding: '0 8px',
|
|
72
|
+
borderRadius: '6px',
|
|
73
|
+
border: '1px solid var(--dsw-alias-border-subtle, rgba(128,128,128,0.32))',
|
|
74
|
+
background: 'var(--dsw-alias-bg-sunken, rgba(128,128,128,0.06))',
|
|
75
|
+
color: 'inherit',
|
|
76
|
+
font: 'inherit',
|
|
77
|
+
fontSize: '12px',
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const fieldStyle = { display: 'block', padding: '4px 8px' };
|
|
81
|
+
|
|
82
|
+
const fieldLabelStyle = { display: 'block', fontSize: '11px', opacity: 0.65, marginBottom: '3px' };
|
|
83
|
+
|
|
84
|
+
const buttonStyle = {
|
|
85
|
+
display: 'inline-flex',
|
|
86
|
+
alignItems: 'center',
|
|
87
|
+
justifyContent: 'center',
|
|
88
|
+
height: '26px',
|
|
89
|
+
padding: '0 10px',
|
|
90
|
+
borderRadius: '6px',
|
|
91
|
+
border: '1px solid var(--dsw-alias-border-subtle, rgba(128,128,128,0.32))',
|
|
92
|
+
background: 'transparent',
|
|
93
|
+
color: 'inherit',
|
|
94
|
+
font: 'inherit',
|
|
95
|
+
fontSize: '12px',
|
|
96
|
+
cursor: 'pointer',
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const primaryButtonStyle = {
|
|
100
|
+
...buttonStyle,
|
|
101
|
+
border: '1px solid var(--dsw-alias-accent, #247bbf)',
|
|
102
|
+
background: 'var(--dsw-alias-accent, #247bbf)',
|
|
103
|
+
color: '#fff',
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const linkButtonStyle = {
|
|
107
|
+
border: 'none',
|
|
108
|
+
background: 'transparent',
|
|
109
|
+
color: 'var(--dsw-alias-accent, #247bbf)',
|
|
110
|
+
font: 'inherit',
|
|
111
|
+
fontSize: '11px',
|
|
112
|
+
cursor: 'pointer',
|
|
113
|
+
padding: '2px 4px',
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
async function json(url, init) {
|
|
117
|
+
const response = await fetch(url, {
|
|
118
|
+
credentials: 'same-origin',
|
|
119
|
+
...init,
|
|
120
|
+
});
|
|
121
|
+
const payload = await response.json().catch(() => null);
|
|
122
|
+
if (!response.ok) throw new Error(payload?.error ?? `HTTP ${response.status}`);
|
|
123
|
+
return payload;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function ExpertSelector(props) {
|
|
127
|
+
const sessionId = props.sessionId;
|
|
128
|
+
const [open, setOpen] = React.useState(false);
|
|
129
|
+
const [teams, setTeams] = React.useState([]);
|
|
130
|
+
const [selection, setSelection] = React.useState(null);
|
|
131
|
+
const [teamId, setTeamId] = React.useState('');
|
|
132
|
+
const [agents, setAgents] = React.useState([]);
|
|
133
|
+
const [error, setError] = React.useState('');
|
|
134
|
+
const [busy, setBusy] = React.useState(false);
|
|
135
|
+
const [view, setView] = React.useState('list');
|
|
136
|
+
const [config, setConfig] = React.useState(null);
|
|
137
|
+
const [configured, setConfigured] = React.useState(true);
|
|
138
|
+
const [health, setHealth] = React.useState({ state: 'idle', text: '连接未检测' });
|
|
139
|
+
const [form, setForm] = React.useState({ hubUrl: '', instanceId: '', userKey: '' });
|
|
140
|
+
const [flags, setFlags] = React.useState({ injectMemory: true, writeMemory: false });
|
|
141
|
+
const [saving, setSaving] = React.useState(false);
|
|
142
|
+
|
|
143
|
+
const loadState = React.useCallback(() => {
|
|
144
|
+
let alive = true;
|
|
145
|
+
json(`${ROUTE}/state?session=${encodeURIComponent(String(sessionId ?? ''))}`)
|
|
146
|
+
.then((payload) => {
|
|
147
|
+
if (!alive) return;
|
|
148
|
+
setTeams(payload.teams ?? []);
|
|
149
|
+
setSelection(payload.selection ?? null);
|
|
150
|
+
setTeamId(payload.selection?.teamId ?? payload.teams?.[0]?.teamId ?? '');
|
|
151
|
+
setConfigured(payload.configured !== false);
|
|
152
|
+
if (typeof payload.error === 'string' && payload.error !== '') setError(payload.error);
|
|
153
|
+
const current = payload.config ?? null;
|
|
154
|
+
if (current) {
|
|
155
|
+
setConfig(current);
|
|
156
|
+
setForm({
|
|
157
|
+
hubUrl: String(current.hubUrl ?? ''),
|
|
158
|
+
instanceId: String(current.instanceId ?? ''),
|
|
159
|
+
userKey: '',
|
|
160
|
+
});
|
|
161
|
+
setFlags({
|
|
162
|
+
injectMemory: current.injectMemory !== false,
|
|
163
|
+
writeMemory: current.writeMemory === true,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
.catch((failure) => {
|
|
168
|
+
if (alive) setError(String(failure.message ?? failure));
|
|
169
|
+
});
|
|
170
|
+
return () => {
|
|
171
|
+
alive = false;
|
|
172
|
+
};
|
|
173
|
+
}, [sessionId]);
|
|
174
|
+
|
|
175
|
+
const checkHealth = React.useCallback(() => {
|
|
176
|
+
setHealth({ state: 'busy', text: '检测中…' });
|
|
177
|
+
json(`${ROUTE}/health`)
|
|
178
|
+
.then((payload) => {
|
|
179
|
+
const agents = (payload.teams ?? []).reduce((total, team) => total + (team.agents ?? 0), 0);
|
|
180
|
+
setHealth({
|
|
181
|
+
state: 'ok',
|
|
182
|
+
text: `已连接 · ${payload.user?.username ?? '未知用户'} · ${(payload.teams ?? []).length} 团队 / ${agents} agent · ${payload.latencyMs ?? '?'}ms`,
|
|
183
|
+
});
|
|
184
|
+
})
|
|
185
|
+
.catch((failure) => setHealth({ state: 'bad', text: `连接失败:${String(failure.message ?? failure)}` }));
|
|
186
|
+
}, []);
|
|
187
|
+
|
|
188
|
+
const saveConfig = React.useCallback(() => {
|
|
189
|
+
setSaving(true);
|
|
190
|
+
setError('');
|
|
191
|
+
json(`${ROUTE}/config`, {
|
|
192
|
+
method: 'POST',
|
|
193
|
+
headers: { 'Content-Type': 'application/json' },
|
|
194
|
+
body: JSON.stringify({
|
|
195
|
+
hubUrl: form.hubUrl,
|
|
196
|
+
instanceId: form.instanceId,
|
|
197
|
+
userKey: form.userKey,
|
|
198
|
+
injectMemory: flags.injectMemory,
|
|
199
|
+
writeMemory: flags.writeMemory,
|
|
200
|
+
}),
|
|
201
|
+
})
|
|
202
|
+
.then((payload) => {
|
|
203
|
+
setView('list');
|
|
204
|
+
setForm((previous) => ({ ...previous, userKey: '' }));
|
|
205
|
+
// The Host restarts this plugin to apply an ordinary config field.
|
|
206
|
+
window.setTimeout(() => {
|
|
207
|
+
loadState();
|
|
208
|
+
checkHealth();
|
|
209
|
+
}, 1200);
|
|
210
|
+
setHealth({ state: 'busy', text: `已保存(${(payload.saved ?? []).join(', ')}),正在重启插件…` });
|
|
211
|
+
})
|
|
212
|
+
.catch((failure) => setError(String(failure.message ?? failure)))
|
|
213
|
+
.finally(() => setSaving(false));
|
|
214
|
+
}, [form, flags, loadState, checkHealth]);
|
|
215
|
+
|
|
216
|
+
React.useEffect(loadState, [loadState]);
|
|
217
|
+
|
|
218
|
+
const loadAgents = React.useCallback((id) => {
|
|
219
|
+
if (id === '') return;
|
|
220
|
+
setBusy(true);
|
|
221
|
+
json(`${ROUTE}/agents?team=${encodeURIComponent(id)}`)
|
|
222
|
+
.then((payload) => {
|
|
223
|
+
setAgents(payload.agents ?? []);
|
|
224
|
+
setError('');
|
|
225
|
+
})
|
|
226
|
+
.catch((failure) => setError(String(failure.message ?? failure)))
|
|
227
|
+
.finally(() => setBusy(false));
|
|
228
|
+
}, []);
|
|
229
|
+
|
|
230
|
+
const sortedAgents = React.useMemo(() => {
|
|
231
|
+
const owned = agents.filter((agent) => agent.owned !== false);
|
|
232
|
+
const rest = agents.filter((agent) => agent.owned === false);
|
|
233
|
+
return [...owned, ...rest];
|
|
234
|
+
}, [agents]);
|
|
235
|
+
const ownedCount = sortedAgents.filter((agent) => agent.owned !== false).length;
|
|
236
|
+
|
|
237
|
+
const choose = React.useCallback(
|
|
238
|
+
(agent) => {
|
|
239
|
+
if (agent.owned === false) return;
|
|
240
|
+
setBusy(true);
|
|
241
|
+
json(`${ROUTE}/select`, {
|
|
242
|
+
method: 'POST',
|
|
243
|
+
headers: { 'Content-Type': 'application/json' },
|
|
244
|
+
body: JSON.stringify({ sessionId: String(sessionId ?? ''), teamId, agentId: agent.agentId }),
|
|
245
|
+
})
|
|
246
|
+
.then((payload) => {
|
|
247
|
+
setSelection(payload.selection ?? null);
|
|
248
|
+
setOpen(false);
|
|
249
|
+
})
|
|
250
|
+
.catch((failure) => setError(String(failure.message ?? failure)))
|
|
251
|
+
.finally(() => setBusy(false));
|
|
252
|
+
},
|
|
253
|
+
[sessionId, teamId],
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
const clear = React.useCallback(() => {
|
|
257
|
+
json(`${ROUTE}/select`, {
|
|
258
|
+
method: 'POST',
|
|
259
|
+
headers: { 'Content-Type': 'application/json' },
|
|
260
|
+
body: JSON.stringify({ sessionId: String(sessionId ?? ''), teamId: '', agentId: '' }),
|
|
261
|
+
})
|
|
262
|
+
.then(() => {
|
|
263
|
+
setSelection(null);
|
|
264
|
+
setOpen(false);
|
|
265
|
+
})
|
|
266
|
+
.catch((failure) => setError(String(failure.message ?? failure)));
|
|
267
|
+
}, [sessionId]);
|
|
268
|
+
|
|
269
|
+
const label = selection ? `专家:${selection.agentName}` : '选择专家';
|
|
270
|
+
const healthColor =
|
|
271
|
+
health.state === 'ok' ? '#2e7d32' : health.state === 'bad' ? '#c0392b' : 'rgba(128,128,128,0.85)';
|
|
272
|
+
|
|
273
|
+
const chip = h(
|
|
274
|
+
'button',
|
|
275
|
+
{
|
|
276
|
+
type: 'button',
|
|
277
|
+
title: selection ? `${selection.teamName} / ${selection.agentName}` : '选择 agent-memory 专家',
|
|
278
|
+
style: chipStyle,
|
|
279
|
+
onClick: () => {
|
|
280
|
+
const next = !open;
|
|
281
|
+
setOpen(next);
|
|
282
|
+
if (next) {
|
|
283
|
+
loadAgents(teamId);
|
|
284
|
+
checkHealth();
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
h('span', {
|
|
289
|
+
style: {
|
|
290
|
+
width: '6px',
|
|
291
|
+
height: '6px',
|
|
292
|
+
borderRadius: '50%',
|
|
293
|
+
flex: '0 0 auto',
|
|
294
|
+
background: selection
|
|
295
|
+
? 'var(--dsw-alias-accent, #247bbf)'
|
|
296
|
+
: 'var(--dsw-alias-border-subtle, rgba(128,128,128,0.5))',
|
|
297
|
+
},
|
|
298
|
+
}),
|
|
299
|
+
h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, label),
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
const healthLine = h(
|
|
303
|
+
'div',
|
|
304
|
+
{
|
|
305
|
+
style: {
|
|
306
|
+
display: 'flex',
|
|
307
|
+
alignItems: 'center',
|
|
308
|
+
gap: '6px',
|
|
309
|
+
padding: '4px 8px 6px',
|
|
310
|
+
fontSize: '11px',
|
|
311
|
+
opacity: 0.85,
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
h('span', {
|
|
315
|
+
style: { width: '6px', height: '6px', borderRadius: '50%', flex: '0 0 auto', background: healthColor },
|
|
316
|
+
}),
|
|
317
|
+
h(
|
|
318
|
+
'span',
|
|
319
|
+
{ style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } },
|
|
320
|
+
health.text,
|
|
321
|
+
),
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
const header = h(
|
|
325
|
+
'div',
|
|
326
|
+
{
|
|
327
|
+
style: {
|
|
328
|
+
display: 'flex',
|
|
329
|
+
alignItems: 'center',
|
|
330
|
+
justifyContent: 'space-between',
|
|
331
|
+
padding: '2px 8px 2px',
|
|
332
|
+
},
|
|
333
|
+
},
|
|
334
|
+
h('span', { style: { fontSize: '11px', opacity: 0.6 } }, view === 'settings' ? '连接设置' : '团队 / 专家'),
|
|
335
|
+
h(
|
|
336
|
+
'button',
|
|
337
|
+
{
|
|
338
|
+
type: 'button',
|
|
339
|
+
style: linkButtonStyle,
|
|
340
|
+
onClick: () => setView(view === 'settings' ? 'list' : 'settings'),
|
|
341
|
+
},
|
|
342
|
+
view === 'settings' ? '返回列表' : '设置',
|
|
343
|
+
),
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
const settingsView = h(
|
|
347
|
+
'div',
|
|
348
|
+
null,
|
|
349
|
+
h(
|
|
350
|
+
'label',
|
|
351
|
+
{ style: fieldStyle },
|
|
352
|
+
h('span', { style: fieldLabelStyle }, 'Hub 地址'),
|
|
353
|
+
h('input', {
|
|
354
|
+
style: inputStyle,
|
|
355
|
+
type: 'text',
|
|
356
|
+
value: form.hubUrl,
|
|
357
|
+
placeholder: 'http://memhub.example.com:8125',
|
|
358
|
+
onChange: (event) => setForm({ ...form, hubUrl: event.target.value }),
|
|
359
|
+
}),
|
|
360
|
+
),
|
|
361
|
+
h(
|
|
362
|
+
'label',
|
|
363
|
+
{ style: fieldStyle },
|
|
364
|
+
h('span', { style: fieldLabelStyle }, '实例 ID'),
|
|
365
|
+
h('input', {
|
|
366
|
+
style: inputStyle,
|
|
367
|
+
type: 'text',
|
|
368
|
+
value: form.instanceId,
|
|
369
|
+
placeholder: 'default',
|
|
370
|
+
onChange: (event) => setForm({ ...form, instanceId: event.target.value }),
|
|
371
|
+
}),
|
|
372
|
+
),
|
|
373
|
+
h(
|
|
374
|
+
'label',
|
|
375
|
+
{ style: fieldStyle },
|
|
376
|
+
h('span', { style: fieldLabelStyle }, 'Userkey'),
|
|
377
|
+
h('input', {
|
|
378
|
+
style: inputStyle,
|
|
379
|
+
type: 'password',
|
|
380
|
+
value: form.userKey,
|
|
381
|
+
placeholder: config?.userKeySet ? `已保存 ${config.userKeyHint ?? ''}(留空不修改)` : 'sk-mem-...',
|
|
382
|
+
onChange: (event) => setForm({ ...form, userKey: event.target.value }),
|
|
383
|
+
}),
|
|
384
|
+
),
|
|
385
|
+
h(
|
|
386
|
+
'label',
|
|
387
|
+
{ style: { ...fieldStyle, display: 'flex', alignItems: 'center', gap: '6px' } },
|
|
388
|
+
h('input', {
|
|
389
|
+
type: 'checkbox',
|
|
390
|
+
checked: flags.injectMemory,
|
|
391
|
+
onChange: (event) => setFlags({ ...flags, injectMemory: event.target.checked }),
|
|
392
|
+
}),
|
|
393
|
+
h('span', { style: { fontSize: '12px' } }, '召回记忆并注入上下文'),
|
|
394
|
+
),
|
|
395
|
+
h(
|
|
396
|
+
'label',
|
|
397
|
+
{ style: { ...fieldStyle, display: 'flex', alignItems: 'center', gap: '6px' } },
|
|
398
|
+
h('input', {
|
|
399
|
+
type: 'checkbox',
|
|
400
|
+
checked: flags.writeMemory,
|
|
401
|
+
onChange: (event) => setFlags({ ...flags, writeMemory: event.target.checked }),
|
|
402
|
+
}),
|
|
403
|
+
h('span', { style: { fontSize: '12px' } }, '对话结束后写回记忆库'),
|
|
404
|
+
),
|
|
405
|
+
h(
|
|
406
|
+
'div',
|
|
407
|
+
{ style: { display: 'flex', gap: '8px', padding: '8px' } },
|
|
408
|
+
h(
|
|
409
|
+
'button',
|
|
410
|
+
{
|
|
411
|
+
type: 'button',
|
|
412
|
+
style: primaryButtonStyle,
|
|
413
|
+
disabled: saving,
|
|
414
|
+
onClick: saveConfig,
|
|
415
|
+
},
|
|
416
|
+
saving ? '保存中…' : '保存',
|
|
417
|
+
),
|
|
418
|
+
h('button', { type: 'button', style: buttonStyle, onClick: checkHealth }, '检测连接'),
|
|
419
|
+
),
|
|
420
|
+
);
|
|
421
|
+
|
|
422
|
+
const listView = h(
|
|
423
|
+
'div',
|
|
424
|
+
null,
|
|
425
|
+
...teams.map((team) =>
|
|
426
|
+
h(
|
|
427
|
+
'button',
|
|
428
|
+
{
|
|
429
|
+
key: team.teamId,
|
|
430
|
+
type: 'button',
|
|
431
|
+
style: {
|
|
432
|
+
...rowStyle,
|
|
433
|
+
fontWeight: teamId === team.teamId ? 600 : 400,
|
|
434
|
+
background:
|
|
435
|
+
teamId === team.teamId
|
|
436
|
+
? 'var(--dsw-alias-bg-sunken, rgba(128,128,128,0.12))'
|
|
437
|
+
: 'transparent',
|
|
438
|
+
},
|
|
439
|
+
onClick: () => {
|
|
440
|
+
setTeamId(team.teamId);
|
|
441
|
+
setAgents([]);
|
|
442
|
+
loadAgents(team.teamId);
|
|
443
|
+
},
|
|
444
|
+
},
|
|
445
|
+
team.name,
|
|
446
|
+
),
|
|
447
|
+
),
|
|
448
|
+
configured === false
|
|
449
|
+
? h('div', { style: mutedStyle }, '未配置:点右上「设置」填 Hub 地址与 userkey')
|
|
450
|
+
: teams.length === 0
|
|
451
|
+
? h('div', { style: mutedStyle }, '没有取到团队,请检查连接设置')
|
|
452
|
+
: null,
|
|
453
|
+
teams.length === 0
|
|
454
|
+
? null
|
|
455
|
+
: h('div', { style: { ...mutedStyle, marginTop: '4px' } }, 'Agent / 专家'),
|
|
456
|
+
busy ? h('div', { style: mutedStyle }, '加载中…') : null,
|
|
457
|
+
...sortedAgents.map((agent) =>
|
|
458
|
+
h(
|
|
459
|
+
'button',
|
|
460
|
+
{
|
|
461
|
+
key: agent.agentId,
|
|
462
|
+
type: 'button',
|
|
463
|
+
disabled: agent.owned === false,
|
|
464
|
+
title: agent.owned === false ? '这是他人的 agent,你的 userkey 无权读写其记忆' : agent.description,
|
|
465
|
+
style: {
|
|
466
|
+
...rowStyle,
|
|
467
|
+
opacity: agent.owned === false ? 0.4 : agent.status === 'active' ? 1 : 0.5,
|
|
468
|
+
cursor: agent.owned === false ? 'not-allowed' : 'pointer',
|
|
469
|
+
},
|
|
470
|
+
onClick: () => choose(agent),
|
|
471
|
+
},
|
|
472
|
+
agent.owned === false ? `${agent.name} · 无权限` : agent.name,
|
|
473
|
+
agent.description
|
|
474
|
+
? h('span', { style: { display: 'block', opacity: 0.6, fontSize: '11px' } }, agent.description)
|
|
475
|
+
: null,
|
|
476
|
+
),
|
|
477
|
+
),
|
|
478
|
+
sortedAgents.length === 0 && !busy && teams.length > 0
|
|
479
|
+
? h('div', { style: mutedStyle }, '该团队下没有 agent')
|
|
480
|
+
: null,
|
|
481
|
+
sortedAgents.length > 0 && ownedCount === 0 && !busy
|
|
482
|
+
? h('div', { style: mutedStyle }, '该团队下没有属于你的 agent,无法作为专家')
|
|
483
|
+
: null,
|
|
484
|
+
selection
|
|
485
|
+
? h(
|
|
486
|
+
'button',
|
|
487
|
+
{ type: 'button', style: { ...rowStyle, opacity: 0.7, marginTop: '4px' }, onClick: clear },
|
|
488
|
+
'清除选择',
|
|
489
|
+
)
|
|
490
|
+
: null,
|
|
491
|
+
);
|
|
492
|
+
|
|
493
|
+
return h(
|
|
494
|
+
'div',
|
|
495
|
+
{ style: { position: 'relative', display: 'inline-flex' } },
|
|
496
|
+
chip,
|
|
497
|
+
open
|
|
498
|
+
? h(
|
|
499
|
+
'div',
|
|
500
|
+
{ style: panelStyle },
|
|
501
|
+
healthLine,
|
|
502
|
+
header,
|
|
503
|
+
view === 'settings' ? settingsView : listView,
|
|
504
|
+
error ? h('div', { style: { ...mutedStyle, color: '#c0392b' } }, error) : null,
|
|
505
|
+
)
|
|
506
|
+
: null,
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
return {
|
|
511
|
+
inject: ['slots'],
|
|
512
|
+
apply(ctx) {
|
|
513
|
+
ctx.slots.inject('conversation.input.left', () =>
|
|
514
|
+
ctx.slots.register(
|
|
515
|
+
{
|
|
516
|
+
name: 'conversation.input.left',
|
|
517
|
+
id: 'agent-memory-expert',
|
|
518
|
+
order: 10,
|
|
519
|
+
},
|
|
520
|
+
ExpertSelector,
|
|
521
|
+
),
|
|
522
|
+
);
|
|
523
|
+
},
|
|
524
|
+
};
|
|
525
|
+
},
|
|
526
|
+
});
|
package/cordis.patch.yml
ADDED
package/docs/DETAIL.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Agent Memory 专家
|
|
2
|
+
|
|
3
|
+
把私有化部署的腾讯 agent-memory(Memory Hub)接进 DeepSeek Harness。
|
|
4
|
+
|
|
5
|
+
## 用法
|
|
6
|
+
|
|
7
|
+
1. 在对话框工具行左侧点「选择专家」,展开后点右上角「设置」,直接填 `Hub 地址`、`实例 ID`、`Userkey` 并点「检测连接」;保存后写入本 profile 的 `cordis.patch.yml`(也可以手改该行)。
|
|
8
|
+
2. 「设置」旁边的「返回列表」回到团队 / agent 列表,先选团队,再选 agent;选中的专家记录在当前会话上。
|
|
9
|
+
3. 每轮对话开始时,Host 半侧会用该 agent 的记忆块做检索(L3 / L2 / L1 / L0 依次尝试),把命中的记忆以 `<agent-memory>` 段落追加到该 step 的消息里,模型因此能看到专家的长期记忆。
|
|
10
|
+
|
|
11
|
+
## 配置项
|
|
12
|
+
|
|
13
|
+
| 字段 | 说明 |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| `hubUrl` | Memory Hub 地址,例如 `http://memhub.example.com:8125`;留空则插件保持空闲 |
|
|
16
|
+
| `instanceId` | 实例 id,对应 `X-Tdai-Service-Id` |
|
|
17
|
+
| `userKey` | 该实例的 user key,对应 `X-Tdai-User-Key` |
|
|
18
|
+
| `defaultAgentId` | 会话未选择专家时使用的 agent id;留空则等用户在选择器里挑 |
|
|
19
|
+
| `injectMemory` | 关闭后只保留选择器,不注入记忆 |
|
|
20
|
+
| `writeMemory` | 打开后每轮结束时把该轮用户消息写回专家记忆块(插件默认关闭,本实例安装配置里已开启) |
|
|
21
|
+
| `topK` | 每层最多取回的记忆条数(1–10) |
|
|
22
|
+
| `timeoutMs` | 单次 Hub 请求超时 |
|
|
23
|
+
| `debug` | 是否写诊断日志(默认关) |
|
|
24
|
+
|
|
25
|
+
Host 半侧导出了 `z.object` 形式的 `Config`(`userKey` 标了 `role('secret')`),因此插件详情页也能看到同名字段的表单;字段保存走框架的 `configEditor`,写入后提示重启插件以重建内存状态。
|
|
26
|
+
|
|
27
|
+
## 边界
|
|
28
|
+
|
|
29
|
+
- user key 只存在 Host 进程里,浏览器侧只访问本机同源路由,不接触凭据。
|
|
30
|
+
- 记忆写入走 Hub 的 `chat-memory/import`(`writeMemory: true` 时启用);官方 proxy 网关那条链路要求上游模型名在该实例的账号组里可用,本实例当前不满足,故未采用。
|
|
31
|
+
- 只允许选中自己的 agent(`owner_user_id` 必须等于当前 user key 的用户);他人 agent 的选择请求返回 403 `NOT_YOUR_AGENT`,因为记忆块读写都会被 Hub 拒绝。
|
|
32
|
+
- 写回时会丢掉运行期注入的噪声文本(子 agent 完成通知、审批策略变更通知、计划任务消息、技能注入),否则这些模板文字会污染记忆。
|
|
33
|
+
- Hub 没有可用的按条删除路由(`chat-memory/clear` 恒返回 `BLOCK_NOT_FOUND`),写错的记忆只能在记忆管理界面清理。
|
|
34
|
+
- 团队与 agent 列表缓存 5 分钟。
|
|
35
|
+
- 插件自带 `GET /plugins/agent-memory/health`(回连 Hub 校验 userkey 并汇总团队 / agent 数)与 `POST /plugins/agent-memory/config`(保存设置);两条路由都只接受回环地址来源的浏览器请求,跨站请求返回 403。
|
|
36
|
+
- 诊断日志写入 `~/.dsh/agent-memory-debug.log`(单个文件上限 256 KB),需 `debug: true` 才开启。
|
package/icon.svg
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="Agent memory">
|
|
2
|
+
<rect x="6" y="10" width="52" height="44" rx="12" fill="#12324f"/>
|
|
3
|
+
<circle cx="22" cy="26" r="5" fill="#5ec8f2"/>
|
|
4
|
+
<circle cx="42" cy="24" r="4" fill="#a7e4ff"/>
|
|
5
|
+
<circle cx="32" cy="42" r="5.5" fill="#2f9fd6"/>
|
|
6
|
+
<path d="M26 27 L38 25 M24 30 L30 38 M39 27 L34 38" stroke="#8fd7f7" stroke-width="2" stroke-linecap="round" fill="none"/>
|
|
7
|
+
<rect x="14" y="46" width="36" height="3" rx="1.5" fill="#2f9fd6" opacity="0.55"/>
|
|
8
|
+
</svg>
|