dsh-plugin-agent-memory 0.1.2 → 0.1.4
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/client.js +50 -17
- package/index.js +19 -4
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -140,6 +140,7 @@ window.__ModuleLoader__.load({
|
|
|
140
140
|
const [health, setHealth] = React.useState({ state: 'idle', text: '连接未检测' });
|
|
141
141
|
const [form, setForm] = React.useState({ hubUrl: '', instanceId: '', userKey: '' });
|
|
142
142
|
const [flags, setFlags] = React.useState({ injectMemory: true, writeMemory: false });
|
|
143
|
+
const [refreshMs, setRefreshMs] = React.useState(10000);
|
|
143
144
|
const [saving, setSaving] = React.useState(false);
|
|
144
145
|
|
|
145
146
|
const loadState = React.useCallback(() => {
|
|
@@ -151,6 +152,7 @@ window.__ModuleLoader__.load({
|
|
|
151
152
|
setSelection(payload.selection ?? null);
|
|
152
153
|
setTeamId(payload.selection?.teamId ?? payload.teams?.[0]?.teamId ?? '');
|
|
153
154
|
setConfigured(payload.configured !== false);
|
|
155
|
+
if (Number.isFinite(payload.config?.refreshMs)) setRefreshMs(payload.config.refreshMs);
|
|
154
156
|
if (typeof payload.error === 'string' && payload.error !== '') setError(payload.error);
|
|
155
157
|
const current = payload.config ?? null;
|
|
156
158
|
if (current) {
|
|
@@ -198,6 +200,7 @@ window.__ModuleLoader__.load({
|
|
|
198
200
|
instanceId: form.instanceId,
|
|
199
201
|
userKey: form.userKey,
|
|
200
202
|
injectMemory: flags.injectMemory,
|
|
203
|
+
refreshMs,
|
|
201
204
|
writeMemory: flags.writeMemory,
|
|
202
205
|
}),
|
|
203
206
|
})
|
|
@@ -229,12 +232,24 @@ window.__ModuleLoader__.load({
|
|
|
229
232
|
.finally(() => setBusy(false));
|
|
230
233
|
}, []);
|
|
231
234
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
235
|
+
// Someone added to a team elsewhere (Hub console, another user) would otherwise keep
|
|
236
|
+
// seeing the list from the moment this panel was first opened. Poll while the panel is
|
|
237
|
+
// open; the Host caches with the same interval, so this costs one Hub round trip.
|
|
238
|
+
React.useEffect(() => {
|
|
239
|
+
if (!open) return undefined;
|
|
240
|
+
const id = window.setInterval(() => {
|
|
241
|
+
loadState();
|
|
242
|
+
if (teamId !== '') loadAgents(teamId);
|
|
243
|
+
}, Math.max(3000, refreshMs));
|
|
244
|
+
return () => window.clearInterval(id);
|
|
245
|
+
}, [open, teamId, refreshMs, loadState, loadAgents]);
|
|
246
|
+
|
|
247
|
+
// Only agents this user key owns can serve as an expert; the Hub refuses cross-owner
|
|
248
|
+
// memory reads, so listing the rest would only offer dead entries.
|
|
249
|
+
const visibleAgents = React.useMemo(
|
|
250
|
+
() => agents.filter((agent) => agent.owned !== false),
|
|
251
|
+
[agents],
|
|
252
|
+
);
|
|
238
253
|
|
|
239
254
|
const choose = React.useCallback(
|
|
240
255
|
(agent) => {
|
|
@@ -404,6 +419,24 @@ window.__ModuleLoader__.load({
|
|
|
404
419
|
}),
|
|
405
420
|
h('span', { style: { fontSize: '12px' } }, '对话结束后写回记忆库'),
|
|
406
421
|
),
|
|
422
|
+
h(
|
|
423
|
+
'label',
|
|
424
|
+
{ style: fieldStyle },
|
|
425
|
+
h('span', { style: fieldLabelStyle }, '列表刷新间隔(秒)'),
|
|
426
|
+
h('input', {
|
|
427
|
+
style: inputStyle,
|
|
428
|
+
type: 'number',
|
|
429
|
+
min: 3,
|
|
430
|
+
max: 600,
|
|
431
|
+
value: String(Math.round(refreshMs / 1000)),
|
|
432
|
+
onChange: (event) => {
|
|
433
|
+
const seconds = Number(event.target.value);
|
|
434
|
+
if (Number.isFinite(seconds)) {
|
|
435
|
+
setRefreshMs(Math.max(3000, Math.min(600000, Math.round(seconds) * 1000)));
|
|
436
|
+
}
|
|
437
|
+
},
|
|
438
|
+
}),
|
|
439
|
+
),
|
|
407
440
|
h(
|
|
408
441
|
'div',
|
|
409
442
|
{ style: { display: 'flex', gap: '8px', padding: '8px' } },
|
|
@@ -456,32 +489,32 @@ window.__ModuleLoader__.load({
|
|
|
456
489
|
? null
|
|
457
490
|
: h('div', { style: { ...mutedStyle, marginTop: '4px' } }, 'Agent / 专家'),
|
|
458
491
|
busy ? h('div', { style: mutedStyle }, '加载中…') : null,
|
|
459
|
-
...
|
|
492
|
+
...visibleAgents.map((agent) =>
|
|
460
493
|
h(
|
|
461
494
|
'button',
|
|
462
495
|
{
|
|
463
496
|
key: agent.agentId,
|
|
464
497
|
type: 'button',
|
|
465
|
-
|
|
466
|
-
title: agent.owned === false ? '这是他人的 agent,你的 userkey 无权读写其记忆' : agent.description,
|
|
498
|
+
title: agent.description,
|
|
467
499
|
style: {
|
|
468
500
|
...rowStyle,
|
|
469
|
-
opacity: agent.
|
|
470
|
-
cursor:
|
|
501
|
+
opacity: agent.status === 'active' ? 1 : 0.5,
|
|
502
|
+
cursor: 'pointer',
|
|
471
503
|
},
|
|
472
504
|
onClick: () => choose(agent),
|
|
473
505
|
},
|
|
474
|
-
agent.
|
|
506
|
+
agent.name,
|
|
475
507
|
agent.description
|
|
476
508
|
? h('span', { style: { display: 'block', opacity: 0.6, fontSize: '11px' } }, agent.description)
|
|
477
509
|
: null,
|
|
478
510
|
),
|
|
479
511
|
),
|
|
480
|
-
|
|
481
|
-
? h(
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
512
|
+
visibleAgents.length === 0 && !busy && teams.length > 0
|
|
513
|
+
? h(
|
|
514
|
+
'div',
|
|
515
|
+
{ style: mutedStyle },
|
|
516
|
+
agents.length === 0 ? '该团队下没有 agent' : '该团队下没有属于你的 agent,无法作为专家',
|
|
517
|
+
)
|
|
485
518
|
: null,
|
|
486
519
|
selection
|
|
487
520
|
? h(
|
package/index.js
CHANGED
|
@@ -16,7 +16,8 @@ import { appendFileSync, rmSync, statSync } from 'node:fs';
|
|
|
16
16
|
import { homedir } from 'node:os';
|
|
17
17
|
import z from '@deepseek-ai/schemastery';
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
/** How long a team / agent list stays cached; the composer selector polls at the same rate. */
|
|
20
|
+
const DEFAULT_REFRESH_MS = 10 * 1000;
|
|
20
21
|
const LAYERS = ['L3', 'L2', 'L1', 'L0'];
|
|
21
22
|
const DEBUG_LOG_LIMIT = 256 * 1024;
|
|
22
23
|
|
|
@@ -36,6 +37,13 @@ export const Config = z.object({
|
|
|
36
37
|
writeMemory: z.boolean().default(false).description('每轮对话结束后把用户消息写回记忆库'),
|
|
37
38
|
topK: z.number().min(1).max(10).step(1).default(4).description('每次召回的记忆条数'),
|
|
38
39
|
timeoutMs: z.number().min(1000).step(500).default(6000).description('单次 Hub 请求超时(毫秒)'),
|
|
40
|
+
refreshMs: z
|
|
41
|
+
.number()
|
|
42
|
+
.min(3000)
|
|
43
|
+
.max(600000)
|
|
44
|
+
.step(1000)
|
|
45
|
+
.default(DEFAULT_REFRESH_MS)
|
|
46
|
+
.description('团队/agent 列表缓存与选择器自动刷新的间隔(毫秒,默认 10 秒)'),
|
|
39
47
|
debug: z.boolean().default(false).description('把召回/写回诊断写入 ~/.dsh/agent-memory-debug.log'),
|
|
40
48
|
});
|
|
41
49
|
|
|
@@ -90,6 +98,7 @@ function normalizeConfig(config) {
|
|
|
90
98
|
writeMemory: value.writeMemory === true,
|
|
91
99
|
topK: Number.isFinite(value.topK) ? Math.max(1, Math.min(10, value.topK)) : 4,
|
|
92
100
|
timeoutMs: Number.isFinite(value.timeoutMs) ? Math.max(1000, value.timeoutMs) : 6000,
|
|
101
|
+
refreshMs: Number.isFinite(value.refreshMs) ? Math.max(3000, Math.min(600000, value.refreshMs)) : DEFAULT_REFRESH_MS,
|
|
93
102
|
debug: value.debug === true,
|
|
94
103
|
};
|
|
95
104
|
}
|
|
@@ -168,7 +177,7 @@ export function apply(ctx, config) {
|
|
|
168
177
|
}
|
|
169
178
|
|
|
170
179
|
async function teams() {
|
|
171
|
-
if (state.teams.length > 0 && Date.now() - state.teamsAt <
|
|
180
|
+
if (state.teams.length > 0 && Date.now() - state.teamsAt < settings.refreshMs) return state.teams;
|
|
172
181
|
const me = await identity();
|
|
173
182
|
const data = await hub('team/list', { user_id: me.userId });
|
|
174
183
|
state.teams = Array.isArray(data.items) ? data.items : [];
|
|
@@ -178,7 +187,7 @@ export function apply(ctx, config) {
|
|
|
178
187
|
|
|
179
188
|
async function agents(teamId) {
|
|
180
189
|
const cached = state.agentsByTeam.get(teamId);
|
|
181
|
-
if (cached !== undefined && Date.now() - cached.at <
|
|
190
|
+
if (cached !== undefined && Date.now() - cached.at < settings.refreshMs) return cached.items;
|
|
182
191
|
const data = await hub('agent/list', { team_id: teamId, limit: 100 });
|
|
183
192
|
const items = Array.isArray(data.items) ? data.items : [];
|
|
184
193
|
state.agentsByTeam.set(teamId, { at: Date.now(), items });
|
|
@@ -283,7 +292,9 @@ export function apply(ctx, config) {
|
|
|
283
292
|
debug({ at: 'skip-no-selection', sessionId });
|
|
284
293
|
return decision;
|
|
285
294
|
}
|
|
286
|
-
|
|
295
|
+
// The expert is part of the key: switching experts mid-session must re-recall even
|
|
296
|
+
// when the user repeats the same question.
|
|
297
|
+
const dedupeKey = `${sessionId}:${selection.agentId}:${query}`;
|
|
287
298
|
if (state.lastInjection.get(sessionId) === dedupeKey) return decision;
|
|
288
299
|
const hits = await recall(selection, query);
|
|
289
300
|
debug({ at: 'recall', sessionId, agent: selection.agentId, query: query.slice(0, 60), hits: hits.length });
|
|
@@ -454,6 +465,7 @@ export function apply(ctx, config) {
|
|
|
454
465
|
injectMemory: settings.injectMemory,
|
|
455
466
|
writeMemory: settings.writeMemory,
|
|
456
467
|
topK: settings.topK,
|
|
468
|
+
refreshMs: settings.refreshMs,
|
|
457
469
|
debug: settings.debug,
|
|
458
470
|
},
|
|
459
471
|
});
|
|
@@ -551,6 +563,9 @@ export function apply(ctx, config) {
|
|
|
551
563
|
if (typeof body.writeMemory === 'boolean') patch.writeMemory = body.writeMemory;
|
|
552
564
|
if (Number.isFinite(body.topK)) patch.topK = Math.max(1, Math.min(10, body.topK));
|
|
553
565
|
if (Number.isFinite(body.timeoutMs)) patch.timeoutMs = Math.max(1000, body.timeoutMs);
|
|
566
|
+
if (Number.isFinite(body.refreshMs)) {
|
|
567
|
+
patch.refreshMs = Math.max(3000, Math.min(600000, body.refreshMs));
|
|
568
|
+
}
|
|
554
569
|
if (typeof body.debug === 'boolean') patch.debug = body.debug;
|
|
555
570
|
if (Object.keys(patch).length === 0) {
|
|
556
571
|
reply(response, 400, { error: 'no editable field in request' });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-agent-memory",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Tencent agent-memory integration: pick a team agent as an expert at the composer and its long-term memories are recalled into each turn.",
|
|
6
6
|
"license": "MIT",
|