dsh-plugin-agent-memory 0.1.3 → 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 +33 -0
- package/index.js +16 -3
- 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,6 +232,18 @@ window.__ModuleLoader__.load({
|
|
|
229
232
|
.finally(() => setBusy(false));
|
|
230
233
|
}, []);
|
|
231
234
|
|
|
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
|
+
|
|
232
247
|
// Only agents this user key owns can serve as an expert; the Hub refuses cross-owner
|
|
233
248
|
// memory reads, so listing the rest would only offer dead entries.
|
|
234
249
|
const visibleAgents = React.useMemo(
|
|
@@ -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' } },
|
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 });
|
|
@@ -456,6 +465,7 @@ export function apply(ctx, config) {
|
|
|
456
465
|
injectMemory: settings.injectMemory,
|
|
457
466
|
writeMemory: settings.writeMemory,
|
|
458
467
|
topK: settings.topK,
|
|
468
|
+
refreshMs: settings.refreshMs,
|
|
459
469
|
debug: settings.debug,
|
|
460
470
|
},
|
|
461
471
|
});
|
|
@@ -553,6 +563,9 @@ export function apply(ctx, config) {
|
|
|
553
563
|
if (typeof body.writeMemory === 'boolean') patch.writeMemory = body.writeMemory;
|
|
554
564
|
if (Number.isFinite(body.topK)) patch.topK = Math.max(1, Math.min(10, body.topK));
|
|
555
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
|
+
}
|
|
556
569
|
if (typeof body.debug === 'boolean') patch.debug = body.debug;
|
|
557
570
|
if (Object.keys(patch).length === 0) {
|
|
558
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",
|