dsh-foxy-memory 0.4.3 → 0.4.5
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 +1 -1
- package/README.md +11 -1
- package/lib/client.js +70 -6
- package/lib/index.js +44 -3
- package/package.json +47 -47
package/LICENSE
CHANGED
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -49,6 +49,16 @@
|
|
|
49
49
|
|
|
50
50
|
`platform` 统一小写(`dsh`),显示时用 `sourceLabel`(如 `DSH`);`presetId` 允许 Foxy 主预设和 Character 预设分开存档。
|
|
51
51
|
|
|
52
|
+
## Koishi 预设链接
|
|
53
|
+
|
|
54
|
+
Provider 为 `livingmemory` 时,设置页的「Koishi 记忆预设」会从 Koishi 的 `chatluna_foxy_memory` 读取预设列表(主预设 + `(Character)` + 数据库里已有的预设),选择后点“链接此预设”会:
|
|
55
|
+
|
|
56
|
+
1. 把当前 DSH 侧未落盘的记忆 flush 到旧预设;
|
|
57
|
+
2. 将 `bridgePresetId` 写入 `~/.dsh/foxy/settings.json`;
|
|
58
|
+
3. 之后 DSH 的读写都落到新预设。
|
|
59
|
+
|
|
60
|
+
这不会复制或删除任何记忆,只是切换 DSH 使用的预设池;想复制预设数据请用 Koishi 侧已有的导出/导入接口(`GET /foxy-memory/export`、`POST /foxy-memory/import`)。
|
|
61
|
+
|
|
52
62
|
## 配置
|
|
53
63
|
|
|
54
64
|
| 字段 | 默认 | 说明 |
|
|
@@ -76,7 +86,7 @@ Foxy 面板的「记忆桥设置」可以修改这些值,保存到 `$DSH_HOME/
|
|
|
76
86
|
|
|
77
87
|
## 记忆浏览界面
|
|
78
88
|
|
|
79
|
-
安装并重启 DSH
|
|
89
|
+
安装并重启 DSH 后,入口在 **Foxy → 记忆**。页面提供:
|
|
80
90
|
|
|
81
91
|
- 记忆总数、待写入数、来源平台数和当前 provider;
|
|
82
92
|
- 按平台(QQ / 微博 / B站 / DSH)、状态筛选;
|
package/lib/client.js
CHANGED
|
@@ -70,6 +70,9 @@ window.__ModuleLoader__.load({
|
|
|
70
70
|
const [loading, setLoading] = useState(false)
|
|
71
71
|
const [error, setError] = useState('')
|
|
72
72
|
const [notice, setNotice] = useState('')
|
|
73
|
+
const [presets, setPresets] = useState([])
|
|
74
|
+
const [presetId, setPresetId] = useState('')
|
|
75
|
+
const [presetBusy, setPresetBusy] = useState(false)
|
|
73
76
|
|
|
74
77
|
const load = useCallback(async () => {
|
|
75
78
|
setLoading(true)
|
|
@@ -97,10 +100,42 @@ window.__ModuleLoader__.load({
|
|
|
97
100
|
}
|
|
98
101
|
}, [platform, query, status])
|
|
99
102
|
|
|
103
|
+
const loadPresets = useCallback(async () => {
|
|
104
|
+
try {
|
|
105
|
+
const data = await request('/presets')
|
|
106
|
+
setPresets(Array.isArray(data.presets) ? data.presets : [])
|
|
107
|
+
setPresetId(data.currentPreset || data.presets?.[0] || '')
|
|
108
|
+
} catch {
|
|
109
|
+
setPresets([])
|
|
110
|
+
setPresetId('')
|
|
111
|
+
}
|
|
112
|
+
}, [])
|
|
113
|
+
|
|
100
114
|
useEffect(() => {
|
|
101
115
|
void load()
|
|
116
|
+
void loadPresets()
|
|
102
117
|
}, [])
|
|
103
118
|
|
|
119
|
+
const linkPreset = async () => {
|
|
120
|
+
if (!presetId) return
|
|
121
|
+
setPresetBusy(true)
|
|
122
|
+
setError('')
|
|
123
|
+
setNotice('')
|
|
124
|
+
try {
|
|
125
|
+
const data = await request('/presets/link', {
|
|
126
|
+
method: 'POST',
|
|
127
|
+
body: JSON.stringify({ presetId }),
|
|
128
|
+
})
|
|
129
|
+
setNotice(`已链接 Koishi 记忆预设:${data.presetId}`)
|
|
130
|
+
await load()
|
|
131
|
+
await loadPresets()
|
|
132
|
+
} catch (cause) {
|
|
133
|
+
setError(cause instanceof Error ? cause.message : String(cause))
|
|
134
|
+
} finally {
|
|
135
|
+
setPresetBusy(false)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
104
139
|
const archive = async (item) => {
|
|
105
140
|
if (!item?.id) return
|
|
106
141
|
if (!window.confirm('归档这条记忆?归档后默认列表不再显示。')) return
|
|
@@ -148,6 +183,23 @@ window.__ModuleLoader__.load({
|
|
|
148
183
|
h('div', { className: 'fm-stat' }, h('span', null, '来源平台'), h('strong', null, Object.keys(platforms).length || '—')),
|
|
149
184
|
h('div', { className: 'fm-stat' }, h('span', null, 'Provider'), h('strong', null, stats.provider || 'local')),
|
|
150
185
|
),
|
|
186
|
+
h(
|
|
187
|
+
'section',
|
|
188
|
+
{ className: 'fm-toolbar' },
|
|
189
|
+
h('strong', { style: { fontSize: '12px' } }, 'Koishi 记忆预设'),
|
|
190
|
+
h(
|
|
191
|
+
'select',
|
|
192
|
+
{
|
|
193
|
+
className: 'fm-input',
|
|
194
|
+
value: presetId,
|
|
195
|
+
onChange: (event) => setPresetId(event.target.value),
|
|
196
|
+
},
|
|
197
|
+
presets.length === 0 ? h('option', { value: '' }, '没有读取到预设') : null,
|
|
198
|
+
presets.map((preset) => h('option', { key: preset, value: preset }, preset)),
|
|
199
|
+
),
|
|
200
|
+
h('button', { type: 'button', className: 'fm-button', onClick: linkPreset, disabled: presetBusy || !presetId }, presetBusy ? '链接中…' : '链接此预设'),
|
|
201
|
+
h('span', { style: { color: 'var(--dsw-alias-label-tertiary, #6b7280)', fontSize: '11px' } }, `当前:${stats.bridgePresetId || '未链接'}`),
|
|
202
|
+
),
|
|
151
203
|
h(
|
|
152
204
|
'section',
|
|
153
205
|
{ className: 'fm-toolbar' },
|
|
@@ -252,6 +304,23 @@ window.__ModuleLoader__.load({
|
|
|
252
304
|
const name = 'dsh-foxy-memory'
|
|
253
305
|
const inject = ['slots']
|
|
254
306
|
|
|
307
|
+
function registerConsolePage() {
|
|
308
|
+
const root = window.__FOXY_CONSOLE__ || (window.__FOXY_CONSOLE__ = { pages: [], listeners: new Set() })
|
|
309
|
+
if (!Array.isArray(root.pages)) root.pages = []
|
|
310
|
+
if (!(root.listeners instanceof Set)) root.listeners = new Set()
|
|
311
|
+
const entry = { id: PANEL_ID, label: '记忆', order: 15, Component: Panel }
|
|
312
|
+
const index = root.pages.findIndex((page) => page.id === entry.id)
|
|
313
|
+
if (index >= 0) root.pages[index] = entry
|
|
314
|
+
else root.pages.push(entry)
|
|
315
|
+
for (const listener of root.listeners) {
|
|
316
|
+
try {
|
|
317
|
+
listener()
|
|
318
|
+
} catch {
|
|
319
|
+
// 单个面板的渲染错误不应影响其他标签页
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
255
324
|
function apply(ctx) {
|
|
256
325
|
const style = document.createElement('style')
|
|
257
326
|
style.setAttribute('data-plugin-css', 'dsh-foxy-memory')
|
|
@@ -259,18 +328,13 @@ window.__ModuleLoader__.load({
|
|
|
259
328
|
document.head.appendChild(style)
|
|
260
329
|
ctx.effect(() => () => style.remove(), 'dsh-foxy-memory: style')
|
|
261
330
|
|
|
331
|
+
registerConsolePage()
|
|
262
332
|
ctx.slots.inject('main', () =>
|
|
263
333
|
ctx.slots.register(
|
|
264
334
|
{ name: 'main', key: PANEL_ID, inject: () => ({ workbench: true }) },
|
|
265
335
|
() => h(Panel),
|
|
266
336
|
),
|
|
267
337
|
)
|
|
268
|
-
ctx.slots.inject('sidebar.panellist', () =>
|
|
269
|
-
ctx.slots.register(
|
|
270
|
-
{ name: 'sidebar.panellist', id: PANEL_ID, order: 15, label: () => LABEL },
|
|
271
|
-
MemoryIcon,
|
|
272
|
-
),
|
|
273
|
-
)
|
|
274
338
|
ctx.slots.inject('settings.section', () =>
|
|
275
339
|
ctx.slots.register(
|
|
276
340
|
{ name: 'settings.section', id: 'foxy-memory', order: 33, label: LABEL },
|
package/lib/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { randomUUID } from 'node:crypto'
|
|
|
2
2
|
import { appendFile, mkdir, readFile, rename, writeFile } from 'node:fs/promises'
|
|
3
3
|
import { readFileSync } from 'node:fs'
|
|
4
4
|
import { homedir } from 'node:os'
|
|
5
|
-
import { join } from 'node:path'
|
|
5
|
+
import { dirname, join } from 'node:path'
|
|
6
6
|
|
|
7
7
|
export const name = 'dsh-foxy-memory'
|
|
8
8
|
export const inject = ['foxy']
|
|
@@ -63,8 +63,8 @@ function formatEntry(entry, config) {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
export function apply(ctx, config = {}) {
|
|
66
|
+
const settingsFile = join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'foxy', 'settings.json')
|
|
66
67
|
try {
|
|
67
|
-
const settingsFile = join(process.env.DSH_HOME || join(homedir(), '.dsh'), 'foxy', 'settings.json')
|
|
68
68
|
const saved = JSON.parse(readFileSync(settingsFile, 'utf8'))
|
|
69
69
|
for (const key of ['provider', 'bridgeUrl', 'bridgeToken', 'bridgePresetId', 'batchSize', 'flushIntervalMs', 'extractModel']) {
|
|
70
70
|
if (saved[key] !== undefined) config[key] = saved[key]
|
|
@@ -274,7 +274,7 @@ export function apply(ctx, config = {}) {
|
|
|
274
274
|
|
|
275
275
|
const bridgeUrl = String(config.bridgeUrl || '').trim().replace(/\/+$/, '')
|
|
276
276
|
const bridgeToken = String(config.bridgeToken || '').trim()
|
|
277
|
-
|
|
277
|
+
let bridgePresetId = String(config.bridgePresetId || config.presetId || 'foxy3(Character)')
|
|
278
278
|
const bridgeTimeoutMs = Math.max(1000, Number(config.bridgeTimeoutMs) || 15000)
|
|
279
279
|
|
|
280
280
|
const batchSize = Math.max(1, Number(config.batchSize) || 8)
|
|
@@ -343,6 +343,19 @@ export function apply(ctx, config = {}) {
|
|
|
343
343
|
return data
|
|
344
344
|
}
|
|
345
345
|
|
|
346
|
+
async function persistBridgePreset(presetId) {
|
|
347
|
+
const value = String(presetId || '').trim()
|
|
348
|
+
if (!value) throw new Error('presetId is required')
|
|
349
|
+
await flushAll()
|
|
350
|
+
bridgePresetId = value
|
|
351
|
+
let saved = {}
|
|
352
|
+
try { saved = JSON.parse(readFileSync(settingsFile, 'utf8')) } catch {}
|
|
353
|
+
saved.bridgePresetId = value
|
|
354
|
+
await mkdir(dirname(settingsFile), { recursive: true })
|
|
355
|
+
await writeFile(settingsFile, `${JSON.stringify(saved, null, 2)}\n`, 'utf8')
|
|
356
|
+
return { ok: true, presetId: value }
|
|
357
|
+
}
|
|
358
|
+
|
|
346
359
|
const bridgeProvider = bridgeUrl
|
|
347
360
|
? Object.freeze({
|
|
348
361
|
name: 'livingmemory',
|
|
@@ -421,6 +434,17 @@ export function apply(ctx, config = {}) {
|
|
|
421
434
|
return search(query, input)
|
|
422
435
|
}
|
|
423
436
|
},
|
|
437
|
+
async listPresets() {
|
|
438
|
+
const result = await bridgePost('/presets')
|
|
439
|
+
return {
|
|
440
|
+
presets: Array.isArray(result.presets) ? result.presets : [],
|
|
441
|
+
defaultPreset: result.defaultPreset || '',
|
|
442
|
+
currentPreset: bridgePresetId,
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
async linkPreset(presetId) {
|
|
446
|
+
return await persistBridgePreset(presetId)
|
|
447
|
+
},
|
|
424
448
|
archive,
|
|
425
449
|
stats() {
|
|
426
450
|
const pending = [...pendingBySession.values()].reduce((sum, list) => sum + list.length, 0)
|
|
@@ -465,6 +489,23 @@ export function apply(ctx, config = {}) {
|
|
|
465
489
|
json({ ok: true, stats: typeof active.stats === 'function' ? active.stats() : {} }),
|
|
466
490
|
)
|
|
467
491
|
|
|
492
|
+
route('/api/dsh-foxy-memory/presets', ['GET'], async () => {
|
|
493
|
+
if (typeof active.listPresets !== 'function') {
|
|
494
|
+
return json({ ok: false, error: '当前 Provider 不支持 Koishi 预设列表,请切换到 livingmemory Bridge' }, 400)
|
|
495
|
+
}
|
|
496
|
+
return json({ ok: true, ...(await active.listPresets()) })
|
|
497
|
+
})
|
|
498
|
+
|
|
499
|
+
route('/api/dsh-foxy-memory/presets/link', ['POST'], async (request) => {
|
|
500
|
+
if (typeof active.linkPreset !== 'function') {
|
|
501
|
+
return json({ ok: false, error: '当前 Provider 不支持预设链接,请切换到 livingmemory Bridge' }, 400)
|
|
502
|
+
}
|
|
503
|
+
const body = await readJsonBody(request)
|
|
504
|
+
const presetId = String(body.presetId || '').trim()
|
|
505
|
+
if (!presetId) return json({ ok: false, error: '缺少 presetId' }, 400)
|
|
506
|
+
return json({ ok: true, ...(await active.linkPreset(presetId)) })
|
|
507
|
+
})
|
|
508
|
+
|
|
468
509
|
route('/api/dsh-foxy-memory/list', ['GET'], async (request) => {
|
|
469
510
|
const url = new URL(request.url, 'http://dsh.local')
|
|
470
511
|
const input = {
|
package/package.json
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-foxy-memory",
|
|
3
|
-
"version": "0.4.
|
|
4
|
-
"description": "Memory subplugin for dsh-foxy: local JSONL archive plus optional cross-platform Foxy Memory API, recall and search.",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "lib/index.js",
|
|
7
|
-
"exports": {
|
|
8
|
-
".": "./lib/index.js",
|
|
9
|
-
"./client": "./lib/client.js"
|
|
10
|
-
},
|
|
11
|
-
"files": [
|
|
12
|
-
"lib",
|
|
13
|
-
"cordis.patch.yml",
|
|
14
|
-
"README.md"
|
|
15
|
-
],
|
|
16
|
-
"engines": {
|
|
17
|
-
"node": ">=20"
|
|
18
|
-
},
|
|
19
|
-
"author": "Kun-Fox",
|
|
20
|
-
"repository": {
|
|
21
|
-
"type": "git",
|
|
22
|
-
"url": "git+https://github.com/Kun-Fox/dsh-foxy-memory.git"
|
|
23
|
-
},
|
|
24
|
-
"homepage": "https://github.com/Kun-Fox/dsh-foxy-memory#readme",
|
|
25
|
-
"bugs": {
|
|
26
|
-
"url": "https://github.com/Kun-Fox/dsh-foxy-memory/issues"
|
|
27
|
-
},
|
|
28
|
-
"dsh": {
|
|
29
|
-
"bundle": {
|
|
30
|
-
"patch": "./cordis.patch.yml"
|
|
31
|
-
},
|
|
32
|
-
"client": {
|
|
33
|
-
"platform": "web",
|
|
34
|
-
"inject": [
|
|
35
|
-
"@deepseek-ai/dsh-client-ui-slots"
|
|
36
|
-
]
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
"keywords": [
|
|
40
|
-
"dsh",
|
|
41
|
-
"deepseek-harness",
|
|
42
|
-
"foxy",
|
|
43
|
-
"memory",
|
|
44
|
-
"livingmemory"
|
|
45
|
-
],
|
|
46
|
-
"license": "MIT"
|
|
47
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-foxy-memory",
|
|
3
|
+
"version": "0.4.5",
|
|
4
|
+
"description": "Memory subplugin for dsh-foxy: local JSONL archive plus optional cross-platform Foxy Memory API, recall and search.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./lib/index.js",
|
|
9
|
+
"./client": "./lib/client.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"lib",
|
|
13
|
+
"cordis.patch.yml",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=20"
|
|
18
|
+
},
|
|
19
|
+
"author": "Kun-Fox",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/Kun-Fox/dsh-foxy-memory.git"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/Kun-Fox/dsh-foxy-memory#readme",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/Kun-Fox/dsh-foxy-memory/issues"
|
|
27
|
+
},
|
|
28
|
+
"dsh": {
|
|
29
|
+
"bundle": {
|
|
30
|
+
"patch": "./cordis.patch.yml"
|
|
31
|
+
},
|
|
32
|
+
"client": {
|
|
33
|
+
"platform": "web",
|
|
34
|
+
"inject": [
|
|
35
|
+
"@deepseek-ai/dsh-client-ui-slots"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"dsh",
|
|
41
|
+
"deepseek-harness",
|
|
42
|
+
"foxy",
|
|
43
|
+
"memory",
|
|
44
|
+
"livingmemory"
|
|
45
|
+
],
|
|
46
|
+
"license": "MIT"
|
|
47
|
+
}
|