dsh-foxy-memory 0.3.0 → 0.4.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/README.md +42 -19
- package/lib/client.js +288 -0
- package/lib/index.js +127 -4
- package/package.json +12 -10
package/README.md
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
`dsh-foxy-memory` 是 [`dsh-foxy`](../dsh-foxy) 的可选记忆子插件。它把 Foxy 会话写成本地 JSONL,并在下一轮把最近记忆注入 Foxy 的 persona。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
它本身不依赖 ChatLuna/LivingMemory;只装 `dsh-foxy` + `dsh-foxy-memory` 就能得到能记住对话的 Foxy。
|
|
6
|
+
|
|
7
|
+
## 依赖关系
|
|
8
|
+
|
|
9
|
+
- 必需:`dsh-foxy`(提供 `foxyMemory` 扩展契约)。
|
|
10
|
+
- 可选:`koishi-plugin-chatluna-foxy-memory`(QQ 侧/跨平台记忆中枢)。把 provider 设为 `livingmemory`,`bridgeUrl` 指向新插件的 `/foxy-memory`;它直接读写 Koishi 数据库与向量索引,不再需要旧 `koishi-plugin-foxy-memory-bridge` 进程。
|
|
11
|
+
- 平台子插件 `dsh-foxy-bili` / `dsh-foxy-weibo` 会把事件写入本插件暴露的 `foxyMemory` provider。
|
|
6
12
|
|
|
7
13
|
## 记录格式
|
|
8
14
|
|
|
@@ -17,11 +23,11 @@
|
|
|
17
23
|
```json
|
|
18
24
|
{
|
|
19
25
|
"id": "uuid",
|
|
20
|
-
"presetId": "
|
|
26
|
+
"presetId": "preset",
|
|
21
27
|
"sessionId": "session-id",
|
|
22
28
|
"platform": "dsh",
|
|
23
29
|
"sourceLabel": "DSH",
|
|
24
|
-
"speaker": "
|
|
30
|
+
"speaker": "用户",
|
|
25
31
|
"role": "user",
|
|
26
32
|
"type": "conversation",
|
|
27
33
|
"status": "active",
|
|
@@ -37,7 +43,7 @@
|
|
|
37
43
|
注入时会格式化成:
|
|
38
44
|
|
|
39
45
|
```text
|
|
40
|
-
- [2026-11-06 20:00] [DSH]
|
|
46
|
+
- [2026-11-06 20:00] [DSH] 用户: 今天在 DSH 做了……
|
|
41
47
|
- [2026-11-06 20:00] [DSH] Foxy: 记住啦。
|
|
42
48
|
```
|
|
43
49
|
|
|
@@ -53,12 +59,12 @@
|
|
|
53
59
|
| `maxContentChars` | `4000` | 单条内容截断 |
|
|
54
60
|
| `maxContextEntries` | `20` | 最多注入条数 |
|
|
55
61
|
| `maxContextChars` | `6000` | 注入内容总字符上限 |
|
|
56
|
-
| `userLabel` |
|
|
62
|
+
| `userLabel` | `用户` | 用户显示名 |
|
|
57
63
|
| `assistantLabel` | `Foxy` | 助手显示名 |
|
|
58
64
|
| `provider` | `livingmemory`(配置 bridgeUrl 时)/ `local` | 记忆写到哪个 provider |
|
|
59
|
-
| `bridgeUrl` | 空 |
|
|
60
|
-
| `bridgeToken` | 空 |
|
|
61
|
-
| `bridgePresetId` | `
|
|
65
|
+
| `bridgeUrl` | 空 | 新插件地址,如 `http://127.0.0.1:5140/foxy-memory` |
|
|
66
|
+
| `bridgeToken` | 空 | 与新插件 `foxyApiToken` 一致;公网部署必须设置 |
|
|
67
|
+
| `bridgePresetId` | `preset(Character)` | 写入 LivingMemory 的 preset |
|
|
62
68
|
| `bridgeTimeoutMs` | `15000` | 桥请求超时 |
|
|
63
69
|
| `batchSize` | `8` | 累积多少条消息后调用 `/ingest` |
|
|
64
70
|
| `flushIntervalMs` | `30000` | 未满一批时的定时冲刷间隔 |
|
|
@@ -68,6 +74,27 @@ DSH 侧不再逐条写记忆:`record` 只把消息放进 pending,满 `batchS
|
|
|
68
74
|
|
|
69
75
|
Foxy 面板的「记忆桥设置」可以修改这些值,保存到 `$DSH_HOME/foxy/settings.json`;插件启动时读取,保存后尝试热重载。`/api/dsh-foxy/settings` 在 DSH host 内提供。
|
|
70
76
|
|
|
77
|
+
## 记忆浏览界面
|
|
78
|
+
|
|
79
|
+
安装并重启 DSH 后,左侧栏出现 **Foxy Memory**。页面提供:
|
|
80
|
+
|
|
81
|
+
- 记忆总数、待写入数、来源平台数和当前 provider;
|
|
82
|
+
- 按平台(QQ / 微博 / B站 / DSH)、状态筛选;
|
|
83
|
+
- 按内容、说话人、关键词搜索;
|
|
84
|
+
- 单条归档,默认只显示活跃记忆。
|
|
85
|
+
|
|
86
|
+
Host 路由:
|
|
87
|
+
|
|
88
|
+
```text
|
|
89
|
+
GET /api/dsh-foxy-memory/stats
|
|
90
|
+
GET /api/dsh-foxy-memory/list?platform=weibo&status=active&pageSize=50
|
|
91
|
+
GET /api/dsh-foxy-memory/search?q=关键词
|
|
92
|
+
POST /api/dsh-foxy-memory/archive {"id":"..."}
|
|
93
|
+
POST /api/dsh-foxy-memory/reload
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`/list` 和 `/search` 在 `provider: "livingmemory"` 时走新记忆插件的 `/foxy-memory/list|search`,失败自动回退本地 JSONL。
|
|
97
|
+
|
|
71
98
|
## 服务
|
|
72
99
|
|
|
73
100
|
加载后提供:
|
|
@@ -83,27 +110,23 @@ ctx.foxyMemory.stats()
|
|
|
83
110
|
|
|
84
111
|
同时通过 `ctx.foxy.registerMemoryProvider('local', ...)` 和(配置了桥时)`registerMemoryProvider('livingmemory', ...)` 注册到 Foxy 的 provider 注册表。
|
|
85
112
|
|
|
86
|
-
## 与
|
|
113
|
+
## 与 Foxy Memory 的关系
|
|
87
114
|
|
|
88
|
-
本地 JSONL
|
|
115
|
+
本地 JSONL 是默认实现,适合只装 DSH、不接 QQ 的场景。它不会自动写入 Koishi 的 `koishi.db` 或 PGlite 向量索引。
|
|
89
116
|
|
|
90
|
-
|
|
117
|
+
如果需要 DSH 与 QQ 共用同一套跨平台记忆,安装并配置 [`koishi-plugin-chatluna-foxy-memory`](../koishi-plugin-chatluna-foxy-memory):
|
|
91
118
|
|
|
92
119
|
```yaml
|
|
93
120
|
# DSH 侧 dsh-foxy-memory 配置
|
|
94
121
|
provider: livingmemory
|
|
95
122
|
bridgeUrl: http://127.0.0.1:5140/foxy-memory
|
|
96
|
-
bridgeToken:
|
|
97
|
-
bridgePresetId:
|
|
123
|
+
bridgeToken: 与新插件 foxyApiToken 一致的随机串
|
|
124
|
+
bridgePresetId: preset(Character)
|
|
98
125
|
```
|
|
99
126
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
```js
|
|
103
|
-
ctx.chatluna_living_memory.createMemory(scope, input, speakerKeys)
|
|
104
|
-
```
|
|
127
|
+
新插件的 `/foxy-memory/record|ingest|context|list|search|health` 直接操作 Koishi 数据库、用户画像与向量索引。DSH 侧只发 HTTP 请求,不再启动旧 `koishi-plugin-foxy-memory-bridge`。
|
|
105
128
|
|
|
106
|
-
|
|
129
|
+
迁移时保留原 `living_memory_*` 表与 PGlite 目录;新插件就是同一套表结构的兼容 fork,不需要导出/导入 JSONL。切换前先备份 `koishi.db` 与向量目录,再开启 `foxyApiEnabled`。桥不可用时会自动回退本地 JSONL,不会丢消息。
|
|
107
130
|
|
|
108
131
|
## 安装
|
|
109
132
|
|
package/lib/client.js
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'dsh-foxy-memory',
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
const React = require('react')
|
|
5
|
+
const h = React.createElement
|
|
6
|
+
const { useCallback, useEffect, useState } = React
|
|
7
|
+
|
|
8
|
+
const API = '/api/dsh-foxy-memory'
|
|
9
|
+
const PANEL_ID = 'dsh-foxy-memory'
|
|
10
|
+
const LABEL = 'Foxy Memory'
|
|
11
|
+
|
|
12
|
+
async function request(path, options = {}) {
|
|
13
|
+
const response = await fetch(API + path, {
|
|
14
|
+
...options,
|
|
15
|
+
headers: { 'content-type': 'application/json', ...(options.headers || {}) },
|
|
16
|
+
})
|
|
17
|
+
let body = {}
|
|
18
|
+
try {
|
|
19
|
+
body = await response.json()
|
|
20
|
+
} catch {}
|
|
21
|
+
if (!response.ok || body.ok === false) throw new Error(body.error || `HTTP ${response.status}`)
|
|
22
|
+
return body
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function formatTime(value) {
|
|
26
|
+
if (!value) return '未知时间'
|
|
27
|
+
const date = new Date(value)
|
|
28
|
+
if (Number.isNaN(date.getTime())) return String(value)
|
|
29
|
+
return date.toLocaleString('zh-CN', { hour12: false })
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function platformLabel(value) {
|
|
33
|
+
const platform = String(value || 'dsh').toLowerCase()
|
|
34
|
+
if (platform === 'qq') return 'QQ'
|
|
35
|
+
if (platform === 'weibo') return '微博'
|
|
36
|
+
if (platform === 'bilibili') return 'B站'
|
|
37
|
+
if (platform === 'dsh') return 'DSH'
|
|
38
|
+
return platform || '未知'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function MemoryIcon({ size = 18 }) {
|
|
42
|
+
return h(
|
|
43
|
+
'svg',
|
|
44
|
+
{
|
|
45
|
+
width: size,
|
|
46
|
+
height: size,
|
|
47
|
+
viewBox: '0 0 24 24',
|
|
48
|
+
fill: 'none',
|
|
49
|
+
stroke: 'currentColor',
|
|
50
|
+
strokeWidth: 1.8,
|
|
51
|
+
strokeLinecap: 'round',
|
|
52
|
+
strokeLinejoin: 'round',
|
|
53
|
+
'aria-hidden': true,
|
|
54
|
+
},
|
|
55
|
+
h('path', { d: 'M9 4.5a3 3 0 0 0-3 3v1a3 3 0 0 0-1 5.7A3 3 0 0 0 8 19a3 3 0 0 0 4 1V4.5A3 3 0 0 0 9 4.5Z' }),
|
|
56
|
+
h('path', { d: 'M15 4.5a3 3 0 0 1 3 3v1a3 3 0 0 1 1 5.7A3 3 0 0 1 16 19a3 3 0 0 1-4 1' }),
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function Badge({ children }) {
|
|
61
|
+
return h('span', { className: 'fm-badge' }, children)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function Panel() {
|
|
65
|
+
const [items, setItems] = useState([])
|
|
66
|
+
const [stats, setStats] = useState({})
|
|
67
|
+
const [query, setQuery] = useState('')
|
|
68
|
+
const [platform, setPlatform] = useState('')
|
|
69
|
+
const [status, setStatus] = useState('active')
|
|
70
|
+
const [loading, setLoading] = useState(false)
|
|
71
|
+
const [error, setError] = useState('')
|
|
72
|
+
const [notice, setNotice] = useState('')
|
|
73
|
+
|
|
74
|
+
const load = useCallback(async () => {
|
|
75
|
+
setLoading(true)
|
|
76
|
+
setError('')
|
|
77
|
+
try {
|
|
78
|
+
const params = new URLSearchParams({
|
|
79
|
+
status,
|
|
80
|
+
pageSize: '100',
|
|
81
|
+
})
|
|
82
|
+
if (platform) params.set('platform', platform)
|
|
83
|
+
if (query.trim()) {
|
|
84
|
+
params.set('q', query.trim())
|
|
85
|
+
const result = await request(`/search?${params.toString()}`)
|
|
86
|
+
setItems(result.items || [])
|
|
87
|
+
setStats(result.stats || stats)
|
|
88
|
+
} else {
|
|
89
|
+
const result = await request(`/list?${params.toString()}`)
|
|
90
|
+
setItems(result.items || [])
|
|
91
|
+
setStats(result.stats || {})
|
|
92
|
+
}
|
|
93
|
+
} catch (cause) {
|
|
94
|
+
setError(cause instanceof Error ? cause.message : String(cause))
|
|
95
|
+
} finally {
|
|
96
|
+
setLoading(false)
|
|
97
|
+
}
|
|
98
|
+
}, [platform, query, status])
|
|
99
|
+
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
void load()
|
|
102
|
+
}, [])
|
|
103
|
+
|
|
104
|
+
const archive = async (item) => {
|
|
105
|
+
if (!item?.id) return
|
|
106
|
+
if (!window.confirm('归档这条记忆?归档后默认列表不再显示。')) return
|
|
107
|
+
try {
|
|
108
|
+
await request('/archive', {
|
|
109
|
+
method: 'POST',
|
|
110
|
+
body: JSON.stringify({ id: item.id }),
|
|
111
|
+
})
|
|
112
|
+
setNotice('已归档')
|
|
113
|
+
await load()
|
|
114
|
+
} catch (cause) {
|
|
115
|
+
setError(cause instanceof Error ? cause.message : String(cause))
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const platforms = stats.platforms || {}
|
|
120
|
+
const total = stats.total ?? stats.count ?? items.length
|
|
121
|
+
|
|
122
|
+
return h(
|
|
123
|
+
'div',
|
|
124
|
+
{ className: 'fm-page' },
|
|
125
|
+
h(
|
|
126
|
+
'header',
|
|
127
|
+
{ className: 'fm-header' },
|
|
128
|
+
h(
|
|
129
|
+
'div',
|
|
130
|
+
null,
|
|
131
|
+
h('p', { className: 'fm-eyebrow' }, 'FOXY EXTENSION'),
|
|
132
|
+
h('h1', null, 'Foxy Memory'),
|
|
133
|
+
h('p', { className: 'fm-subtitle' }, '跨平台记忆浏览、检索与归档。QQ、微博、B站与 DSH 共用同一套 Foxy 记忆。'),
|
|
134
|
+
),
|
|
135
|
+
h(
|
|
136
|
+
'div',
|
|
137
|
+
{ className: 'fm-header-actions' },
|
|
138
|
+
h('button', { type: 'button', className: 'fm-button', onClick: load, disabled: loading }, loading ? '刷新中…' : '刷新'),
|
|
139
|
+
),
|
|
140
|
+
),
|
|
141
|
+
error ? h('div', { className: 'fm-alert fm-alert-error' }, error) : null,
|
|
142
|
+
notice ? h('div', { className: 'fm-alert' }, notice) : null,
|
|
143
|
+
h(
|
|
144
|
+
'section',
|
|
145
|
+
{ className: 'fm-stats' },
|
|
146
|
+
h('div', { className: 'fm-stat' }, h('span', null, '记忆总数'), h('strong', null, total)),
|
|
147
|
+
h('div', { className: 'fm-stat' }, h('span', null, '待写入'), h('strong', null, stats.pending || 0)),
|
|
148
|
+
h('div', { className: 'fm-stat' }, h('span', null, '来源平台'), h('strong', null, Object.keys(platforms).length || '—')),
|
|
149
|
+
h('div', { className: 'fm-stat' }, h('span', null, 'Provider'), h('strong', null, stats.provider || 'local')),
|
|
150
|
+
),
|
|
151
|
+
h(
|
|
152
|
+
'section',
|
|
153
|
+
{ className: 'fm-toolbar' },
|
|
154
|
+
h('input', {
|
|
155
|
+
className: 'fm-input fm-search',
|
|
156
|
+
value: query,
|
|
157
|
+
placeholder: '搜索内容、说话人或关键词…',
|
|
158
|
+
onChange: (event) => setQuery(event.target.value),
|
|
159
|
+
onKeyDown: (event) => {
|
|
160
|
+
if (event.key === 'Enter') void load()
|
|
161
|
+
},
|
|
162
|
+
}),
|
|
163
|
+
h(
|
|
164
|
+
'select',
|
|
165
|
+
{
|
|
166
|
+
className: 'fm-input',
|
|
167
|
+
value: platform,
|
|
168
|
+
onChange: (event) => setPlatform(event.target.value),
|
|
169
|
+
},
|
|
170
|
+
h('option', { value: '' }, '全部平台'),
|
|
171
|
+
...['qq', 'weibo', 'bilibili', 'dsh'].map((key) =>
|
|
172
|
+
h('option', { key, value: key }, platformLabel(key)),
|
|
173
|
+
),
|
|
174
|
+
),
|
|
175
|
+
h(
|
|
176
|
+
'select',
|
|
177
|
+
{
|
|
178
|
+
className: 'fm-input',
|
|
179
|
+
value: status,
|
|
180
|
+
onChange: (event) => setStatus(event.target.value),
|
|
181
|
+
},
|
|
182
|
+
h('option', { value: 'active' }, '活跃'),
|
|
183
|
+
h('option', { value: '*' }, '全部状态'),
|
|
184
|
+
h('option', { value: 'archived' }, '已归档'),
|
|
185
|
+
),
|
|
186
|
+
h('button', { type: 'button', className: 'fm-button', onClick: load, disabled: loading }, '查询'),
|
|
187
|
+
),
|
|
188
|
+
h(
|
|
189
|
+
'section',
|
|
190
|
+
{ className: 'fm-list' },
|
|
191
|
+
items.length === 0
|
|
192
|
+
? h('div', { className: 'fm-empty' }, loading ? '读取中…' : '没有匹配的记忆。')
|
|
193
|
+
: items.slice().reverse().map((item) =>
|
|
194
|
+
h(
|
|
195
|
+
'article',
|
|
196
|
+
{ className: 'fm-card', key: String(item.id || `${item.createdAt}-${item.content}`) },
|
|
197
|
+
h(
|
|
198
|
+
'div',
|
|
199
|
+
{ className: 'fm-card-head' },
|
|
200
|
+
h('div', null, h('strong', null, item.speaker || item.role || 'Foxy'), h('span', { className: 'fm-time' }, formatTime(item.createdAt))),
|
|
201
|
+
h('div', { className: 'fm-card-badges' }, h(Badge, null, platformLabel(item.platform || item.sourceLabel)), item.status ? h(Badge, null, item.status) : null),
|
|
202
|
+
),
|
|
203
|
+
h('p', { className: 'fm-content' }, item.content || item.summary || '(无内容)'),
|
|
204
|
+
item.keywords?.length ? h('div', { className: 'fm-keywords' }, item.keywords.map((word) => h('span', { key: word }, word))) : null,
|
|
205
|
+
h(
|
|
206
|
+
'div',
|
|
207
|
+
{ className: 'fm-card-foot' },
|
|
208
|
+
h('span', null, item.presetId || 'foxy3'),
|
|
209
|
+
item.id ? h('button', { type: 'button', className: 'fm-link', onClick: () => archive(item) }, '归档') : null,
|
|
210
|
+
),
|
|
211
|
+
),
|
|
212
|
+
),
|
|
213
|
+
),
|
|
214
|
+
)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const CSS = `
|
|
218
|
+
.fm-page { height: 100%; overflow: auto; box-sizing: border-box; padding: 28px clamp(20px, 4vw, 56px) 48px; color: var(--dsw-alias-label-primary, #111827); background: var(--dsw-alias-bg-base, #fff); }
|
|
219
|
+
.fm-header { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; margin-bottom: 20px; }
|
|
220
|
+
.fm-eyebrow { margin: 0 0 8px; color: var(--dsw-alias-label-tertiary, #6b7280); font-size: 10px; font-weight: 700; letter-spacing: .16em; }
|
|
221
|
+
.fm-header h1 { margin: 0; font-size: 24px; line-height: 1.25; letter-spacing: -.02em; }
|
|
222
|
+
.fm-subtitle { max-width: 660px; margin: 7px 0 0; color: var(--dsw-alias-label-secondary, #6b7280); font-size: 12px; line-height: 1.65; }
|
|
223
|
+
.fm-header-actions { display: flex; gap: 8px; }
|
|
224
|
+
.fm-button { border: 1px solid var(--dsw-alias-bg-layer-3, #e5e7eb); background: var(--dsw-alias-bg-layer-2, #f8fafc); color: inherit; border-radius: 7px; padding: 8px 13px; font-size: 12px; cursor: pointer; }
|
|
225
|
+
.fm-button:hover { background: var(--dsw-alias-interactive-bg-hover, #f1f5f9); }
|
|
226
|
+
.fm-button:disabled { opacity: .55; cursor: default; }
|
|
227
|
+
.fm-alert { margin: 0 0 14px; padding: 9px 12px; border-radius: 7px; border: 1px solid #b7d7c0; background: rgba(47,125,74,.08); color: #2f6b42; font-size: 12px; }
|
|
228
|
+
.fm-alert-error { border-color: #e6b8b5; background: rgba(180,50,40,.06); color: #a33; }
|
|
229
|
+
.fm-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
|
|
230
|
+
.fm-stat { border: 1px solid var(--dsw-alias-bg-layer-3, #e5e7eb); border-radius: 10px; padding: 12px 14px; background: var(--dsw-alias-bg-layer-2, #f8fafc); }
|
|
231
|
+
.fm-stat span { display: block; color: var(--dsw-alias-label-tertiary, #6b7280); font-size: 10px; }
|
|
232
|
+
.fm-stat strong { display: block; margin-top: 5px; font-size: 18px; }
|
|
233
|
+
.fm-toolbar { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
|
|
234
|
+
.fm-input { min-height: 34px; border: 1px solid var(--dsw-alias-bg-layer-3, #e5e7eb); border-radius: 7px; background: var(--dsw-alias-bg-layer-2, #f8fafc); color: inherit; padding: 7px 10px; font-size: 12px; box-sizing: border-box; }
|
|
235
|
+
.fm-search { flex: 1 1 280px; }
|
|
236
|
+
.fm-list { display: flex; flex-direction: column; gap: 9px; }
|
|
237
|
+
.fm-card { border: 1px solid var(--dsw-alias-bg-layer-3, #e5e7eb); border-radius: 10px; padding: 13px 15px; background: var(--dsw-alias-bg-layer-2, #f8fafc); }
|
|
238
|
+
.fm-card-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
|
|
239
|
+
.fm-card-head strong { font-size: 12px; }
|
|
240
|
+
.fm-time { margin-left: 8px; color: var(--dsw-alias-label-tertiary, #6b7280); font-size: 10px; }
|
|
241
|
+
.fm-card-badges { display: flex; gap: 5px; flex-wrap: wrap; }
|
|
242
|
+
.fm-badge { border-radius: 999px; padding: 2px 8px; background: var(--dsw-alias-bg-layer-4, rgba(128,128,128,.12)); color: var(--dsw-alias-label-secondary, #6b7280); font-size: 10px; white-space: nowrap; }
|
|
243
|
+
.fm-content { margin: 9px 0 0; color: var(--dsw-alias-label-primary, #111827); font-size: 12px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
|
|
244
|
+
.fm-keywords { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 8px; }
|
|
245
|
+
.fm-keywords span { color: var(--dsw-alias-label-tertiary, #6b7280); font-size: 10px; }
|
|
246
|
+
.fm-card-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; padding-top: 9px; border-top: 1px dashed var(--dsw-alias-bg-layer-3, #e5e7eb); color: var(--dsw-alias-label-tertiary, #6b7280); font-size: 10px; }
|
|
247
|
+
.fm-link { border: 0; background: transparent; color: #a33; cursor: pointer; font-size: 10px; padding: 0; }
|
|
248
|
+
.fm-empty { padding: 42px 16px; text-align: center; color: var(--dsw-alias-label-tertiary, #6b7280); font-size: 12px; border: 1px dashed var(--dsw-alias-bg-layer-3, #e5e7eb); border-radius: 10px; }
|
|
249
|
+
@media (max-width: 720px) { .fm-page { padding: 20px 16px 32px; } .fm-header { flex-direction: column; } .fm-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
|
|
250
|
+
`
|
|
251
|
+
|
|
252
|
+
const name = 'dsh-foxy-memory'
|
|
253
|
+
const inject = ['slots']
|
|
254
|
+
|
|
255
|
+
function apply(ctx) {
|
|
256
|
+
const style = document.createElement('style')
|
|
257
|
+
style.setAttribute('data-plugin-css', 'dsh-foxy-memory')
|
|
258
|
+
style.textContent = CSS
|
|
259
|
+
document.head.appendChild(style)
|
|
260
|
+
ctx.effect(() => () => style.remove(), 'dsh-foxy-memory: style')
|
|
261
|
+
|
|
262
|
+
ctx.slots.inject('main', () =>
|
|
263
|
+
ctx.slots.register(
|
|
264
|
+
{ name: 'main', key: PANEL_ID, inject: () => ({ workbench: true }) },
|
|
265
|
+
() => h(Panel),
|
|
266
|
+
),
|
|
267
|
+
)
|
|
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
|
+
ctx.slots.inject('settings.section', () =>
|
|
275
|
+
ctx.slots.register(
|
|
276
|
+
{ name: 'settings.section', id: 'foxy-memory', order: 33, label: LABEL },
|
|
277
|
+
() => h(Panel),
|
|
278
|
+
),
|
|
279
|
+
)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const module = { exports: {} }
|
|
283
|
+
module.exports.name = name
|
|
284
|
+
module.exports.inject = inject
|
|
285
|
+
module.exports.apply = apply
|
|
286
|
+
return module.exports
|
|
287
|
+
},
|
|
288
|
+
})
|
package/lib/index.js
CHANGED
|
@@ -30,6 +30,32 @@ function normalizePlatform(value) {
|
|
|
30
30
|
return platform || 'dsh'
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
function json(body, status = 200) {
|
|
34
|
+
return new Response(JSON.stringify(body), {
|
|
35
|
+
status,
|
|
36
|
+
headers: { 'content-type': 'application/json; charset=utf-8' },
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function readJsonBody(request) {
|
|
41
|
+
if (typeof request?.json === 'function') {
|
|
42
|
+
try {
|
|
43
|
+
return await request.json()
|
|
44
|
+
} catch {}
|
|
45
|
+
}
|
|
46
|
+
const raw = request?.body
|
|
47
|
+
if (raw && typeof raw.getReader === 'function') {
|
|
48
|
+
const text = await new Response(raw).text()
|
|
49
|
+
return text ? JSON.parse(text) : {}
|
|
50
|
+
}
|
|
51
|
+
if (typeof raw === 'string') return raw ? JSON.parse(raw) : {}
|
|
52
|
+
if (raw && (Buffer.isBuffer(raw) || raw instanceof Uint8Array)) {
|
|
53
|
+
const text = Buffer.from(raw).toString('utf8')
|
|
54
|
+
return text ? JSON.parse(text) : {}
|
|
55
|
+
}
|
|
56
|
+
return {}
|
|
57
|
+
}
|
|
58
|
+
|
|
33
59
|
function formatEntry(entry, config) {
|
|
34
60
|
const date = new Date(entry.createdAt).toISOString().slice(0, 16).replace('T', ' ')
|
|
35
61
|
const platform = entry.sourceLabel || (entry.platform === 'dsh' ? 'DSH' : entry.platform) || 'DSH'
|
|
@@ -103,6 +129,11 @@ export function apply(ctx, config = {}) {
|
|
|
103
129
|
ctx.logger?.warn?.(`[dsh-foxy-memory] failed to load ${entriesFile}: ${error instanceof Error ? error.message : String(error)}`)
|
|
104
130
|
})
|
|
105
131
|
|
|
132
|
+
async function reload() {
|
|
133
|
+
entries.clear()
|
|
134
|
+
await init()
|
|
135
|
+
}
|
|
136
|
+
|
|
106
137
|
async function record(input = {}) {
|
|
107
138
|
await ready
|
|
108
139
|
const role = input.role === 'assistant' ? 'assistant' : input.role === 'user' ? 'user' : ''
|
|
@@ -347,7 +378,7 @@ export function apply(ctx, config = {}) {
|
|
|
347
378
|
async context(input = {}) {
|
|
348
379
|
try {
|
|
349
380
|
const result = await bridgePost('/context', {
|
|
350
|
-
presetId: bridgePresetId,
|
|
381
|
+
presetId: input.presetId || bridgePresetId,
|
|
351
382
|
sessionId: input.sessionId,
|
|
352
383
|
query: input.query || 'DSH',
|
|
353
384
|
limit: input.limit,
|
|
@@ -358,8 +389,36 @@ export function apply(ctx, config = {}) {
|
|
|
358
389
|
}
|
|
359
390
|
return context(input)
|
|
360
391
|
},
|
|
361
|
-
list
|
|
362
|
-
|
|
392
|
+
async list(input = {}) {
|
|
393
|
+
try {
|
|
394
|
+
const result = await bridgePost('/list', {
|
|
395
|
+
presetId: input.presetId || bridgePresetId,
|
|
396
|
+
platform: input.platform,
|
|
397
|
+
status: input.status || 'active',
|
|
398
|
+
keyword: input.keyword,
|
|
399
|
+
page: input.page || 1,
|
|
400
|
+
pageSize: input.limit || input.pageSize || 50,
|
|
401
|
+
})
|
|
402
|
+
return Array.isArray(result.items) ? result.items : []
|
|
403
|
+
} catch (error) {
|
|
404
|
+
ctx.logger?.warn?.(`[dsh-foxy-memory] bridge list failed, falling back to local: ${error instanceof Error ? error.message : String(error)}`)
|
|
405
|
+
return list(input)
|
|
406
|
+
}
|
|
407
|
+
},
|
|
408
|
+
async search(query, input = {}) {
|
|
409
|
+
try {
|
|
410
|
+
const result = await bridgePost('/search', {
|
|
411
|
+
presetId: input.presetId || bridgePresetId,
|
|
412
|
+
query,
|
|
413
|
+
platform: input.platform,
|
|
414
|
+
limit: input.limit || 20,
|
|
415
|
+
})
|
|
416
|
+
return Array.isArray(result.memories) ? result.memories : []
|
|
417
|
+
} catch (error) {
|
|
418
|
+
ctx.logger?.warn?.(`[dsh-foxy-memory] bridge search failed, falling back to local: ${error instanceof Error ? error.message : String(error)}`)
|
|
419
|
+
return search(query, input)
|
|
420
|
+
}
|
|
421
|
+
},
|
|
363
422
|
archive,
|
|
364
423
|
stats() {
|
|
365
424
|
const pending = [...pendingBySession.values()].reduce((sum, list) => sum + list.length, 0)
|
|
@@ -381,6 +440,70 @@ export function apply(ctx, config = {}) {
|
|
|
381
440
|
if (typeof ctx.provide === 'function') ctx.provide('foxyMemory', active)
|
|
382
441
|
ctx.logger?.info?.(`[dsh-foxy-memory] ready; provider=${active.name}; file=${entriesFile}${bridgeUrl ? `; bridge=${bridgeUrl}` : ''}`)
|
|
383
442
|
|
|
443
|
+
ctx.inject?.(['connection'], (host) => {
|
|
444
|
+
const register = host?.connection?.fetch?.register
|
|
445
|
+
if (typeof register !== 'function') return
|
|
446
|
+
const route = (path, methods, handler) =>
|
|
447
|
+
register({
|
|
448
|
+
path,
|
|
449
|
+
methods,
|
|
450
|
+
requestBody: 'buffered',
|
|
451
|
+
fetch: async (request) => {
|
|
452
|
+
try {
|
|
453
|
+
return await handler(request)
|
|
454
|
+
} catch (error) {
|
|
455
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
456
|
+
ctx.logger?.warn?.(`[dsh-foxy-memory] ${path} failed: ${message}`)
|
|
457
|
+
return json({ ok: false, error: message }, 500)
|
|
458
|
+
}
|
|
459
|
+
},
|
|
460
|
+
})
|
|
461
|
+
|
|
462
|
+
route('/api/dsh-foxy-memory/stats', ['GET'], async () =>
|
|
463
|
+
json({ ok: true, stats: typeof active.stats === 'function' ? active.stats() : {} }),
|
|
464
|
+
)
|
|
465
|
+
|
|
466
|
+
route('/api/dsh-foxy-memory/list', ['GET'], async (request) => {
|
|
467
|
+
const url = new URL(request.url, 'http://dsh.local')
|
|
468
|
+
const input = {
|
|
469
|
+
presetId: url.searchParams.get('presetId') || undefined,
|
|
470
|
+
platform: url.searchParams.get('platform') || undefined,
|
|
471
|
+
status: url.searchParams.get('status') || 'active',
|
|
472
|
+
keyword: url.searchParams.get('keyword') || undefined,
|
|
473
|
+
page: Number(url.searchParams.get('page')) || 1,
|
|
474
|
+
limit: Number(url.searchParams.get('pageSize')) || 50,
|
|
475
|
+
}
|
|
476
|
+
const items = await active.list(input)
|
|
477
|
+
return json({ ok: true, items, total: items.length, stats: typeof active.stats === 'function' ? active.stats() : {} })
|
|
478
|
+
})
|
|
479
|
+
|
|
480
|
+
route('/api/dsh-foxy-memory/search', ['GET'], async (request) => {
|
|
481
|
+
const url = new URL(request.url, 'http://dsh.local')
|
|
482
|
+
const query = url.searchParams.get('q') || ''
|
|
483
|
+
const input = {
|
|
484
|
+
presetId: url.searchParams.get('presetId') || undefined,
|
|
485
|
+
platform: url.searchParams.get('platform') || undefined,
|
|
486
|
+
limit: Number(url.searchParams.get('limit')) || 20,
|
|
487
|
+
}
|
|
488
|
+
const items = query ? await active.search(query, input) : []
|
|
489
|
+
return json({ ok: true, items, total: items.length })
|
|
490
|
+
})
|
|
491
|
+
|
|
492
|
+
route('/api/dsh-foxy-memory/archive', ['POST'], async (request) => {
|
|
493
|
+
const body = await readJsonBody(request)
|
|
494
|
+
const id = String(body.id || '').trim()
|
|
495
|
+
if (!id) return json({ ok: false, error: '缺少记忆 ID' }, 400)
|
|
496
|
+
const item = await active.archive(id)
|
|
497
|
+
if (!item) return json({ ok: false, error: '记忆不存在' }, 404)
|
|
498
|
+
return json({ ok: true, item })
|
|
499
|
+
})
|
|
500
|
+
|
|
501
|
+
route('/api/dsh-foxy-memory/reload', ['POST'], async () => {
|
|
502
|
+
if (active.name === 'local') await reload()
|
|
503
|
+
return json({ ok: true })
|
|
504
|
+
})
|
|
505
|
+
})
|
|
506
|
+
|
|
384
507
|
return {
|
|
385
508
|
provider: active,
|
|
386
509
|
dispose: () => {
|
|
@@ -389,7 +512,7 @@ export function apply(ctx, config = {}) {
|
|
|
389
512
|
disposeLocal()
|
|
390
513
|
disposeBridge?.()
|
|
391
514
|
},
|
|
392
|
-
reload
|
|
515
|
+
reload,
|
|
393
516
|
}
|
|
394
517
|
}
|
|
395
518
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-foxy-memory",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Memory subplugin for dsh-foxy: local JSONL archive plus optional
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"description": "Memory subplugin for dsh-foxy: local JSONL archive plus optional cross-platform Foxy Memory API, recall and search.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./lib/index.js",
|
|
9
|
+
"./client": "./lib/client.js"
|
|
10
|
+
},
|
|
7
11
|
"files": [
|
|
8
12
|
"lib",
|
|
9
13
|
"cordis.patch.yml",
|
|
@@ -24,6 +28,12 @@
|
|
|
24
28
|
"dsh": {
|
|
25
29
|
"bundle": {
|
|
26
30
|
"patch": "./cordis.patch.yml"
|
|
31
|
+
},
|
|
32
|
+
"client": {
|
|
33
|
+
"platform": "web",
|
|
34
|
+
"inject": [
|
|
35
|
+
"@deepseek-ai/dsh-client-ui-slots"
|
|
36
|
+
]
|
|
27
37
|
}
|
|
28
38
|
},
|
|
29
39
|
"keywords": [
|
|
@@ -35,11 +45,3 @@
|
|
|
35
45
|
],
|
|
36
46
|
"license": "MIT"
|
|
37
47
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|