openclaw-memory-alibaba-local 0.1.2 → 0.1.3
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/API.md +917 -0
- package/package.json +5 -15
package/API.md
ADDED
|
@@ -0,0 +1,917 @@
|
|
|
1
|
+
# openclaw-memory-alibaba-local — 接口说明
|
|
2
|
+
|
|
3
|
+
本文说明**记忆管理面板**与 **Agent 工具**相关接口。管理面板的**数据接口**已改为 **Gateway WebSocket RPC**(与 OpenClaw 网关协议一致);仅 **HTML 壳**仍通过 HTTP 提供。
|
|
4
|
+
|
|
5
|
+
- **网关根 URL**:以部署为准,例如 `http://127.0.0.1:12345`,下文记为 `{GATEWAY}`。
|
|
6
|
+
- **WebSocket**:`ws://` 或 `wss://` + 与 HTTP 相同的 `host`(同端口)。
|
|
7
|
+
- **HTML 壳**:`{GATEWAY}/plugins/memory`(前缀匹配)。
|
|
8
|
+
|
|
9
|
+
**类型约定**
|
|
10
|
+
|
|
11
|
+
| 文档中的类型 | 含义 |
|
|
12
|
+
|--------------|------|
|
|
13
|
+
| `string` / `number` / `boolean` | JSON 基本类型 |
|
|
14
|
+
| `object` | JSON **对象**(键值对;与语言里的 Map 类似,但是标准 JSON) |
|
|
15
|
+
| `T[]` / `array` | JSON **数组**;若元素为对象,文档在下方单独给出「数组元素结构」表 |
|
|
16
|
+
| `—` | 不适用(如响应头说明) |
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 一、Gateway WebSocket RPC(管理面板数据)
|
|
21
|
+
|
|
22
|
+
### 1.1 连接与鉴权
|
|
23
|
+
|
|
24
|
+
1. 浏览器建立 `WebSocket` 到 `{WS_GATEWAY}`(与页面同源:`location` 的 host + `ws:`/`wss:`)。
|
|
25
|
+
2. 服务端先推送事件 `connect.challenge`(`payload.nonce`)。
|
|
26
|
+
3. 客户端发送首帧请求(OpenClaw 协议)。**内嵌面板**按页面 hostname 选择 `client`(与网关 `isLocalClient`、是否清空 `scopes` 一致):
|
|
27
|
+
|
|
28
|
+
- **回环**:`localhost` / `127.0.0.1` / `::1` → `id: "openclaw-control-ui"`,`mode: "ui"`。
|
|
29
|
+
- **非回环**(如局域网 IP、自定义域名):`id: "openclaw-probe"`,`mode: "probe"`(避免 Control UI 在非本机 HTTP 下直接握手失败)。
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"type": "req",
|
|
34
|
+
"id": "<任意唯一字符串>",
|
|
35
|
+
"method": "connect",
|
|
36
|
+
"params": {
|
|
37
|
+
"minProtocol": 3,
|
|
38
|
+
"maxProtocol": 3,
|
|
39
|
+
"client": {
|
|
40
|
+
"id": "openclaw-control-ui",
|
|
41
|
+
"version": "memory-panel",
|
|
42
|
+
"platform": "<navigator.platform 或 web>",
|
|
43
|
+
"mode": "ui"
|
|
44
|
+
},
|
|
45
|
+
"role": "operator",
|
|
46
|
+
"scopes": ["operator.admin"],
|
|
47
|
+
"auth": { "token": "<与 openclaw.json gateway.auth.token 一致>" }
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
4. 成功时收到 `type: "res"` 且 `ok: true`,`payload` 内含 `hello-ok` 等网关握手信息。浏览器连接会校验来源(`gateway.controlUi.allowedOrigins` 等),与官方 Control UI 一致。
|
|
53
|
+
|
|
54
|
+
**HTTP + `?token=` 时的 `openclaw.json`(`gateway.controlUi`)**:
|
|
55
|
+
|
|
56
|
+
| 访问方式 | 典型配置 |
|
|
57
|
+
|----------|----------|
|
|
58
|
+
| 本机 `http://127.0.0.1` / `localhost` + Control UI 客户端 | **`allowInsecureAuth: true`**(否则握手报错 *control ui requires device identity*) |
|
|
59
|
+
| 局域网 IP / 非回环 hostname + Probe 客户端 | 除 token 外通常需 **`dangerouslyDisableDeviceAuth: true`**,否则握手可成功但网关会**清空 `scopes`**,`memory.admin.*` 报 *missing scope*(面板 403/502) |
|
|
60
|
+
| 生产/跨机更稳妥 | **HTTPS** + 设备配对,或 SSH 转发到本机后用 `127.0.0.1` + `allowInsecureAuth` |
|
|
61
|
+
|
|
62
|
+
示例(本机开发常见):
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
"gateway": {
|
|
66
|
+
"controlUi": {
|
|
67
|
+
"allowInsecureAuth": true
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
局域网浏览器直连网关时(面板已用 probe 客户端)示例:
|
|
73
|
+
|
|
74
|
+
```json
|
|
75
|
+
"gateway": {
|
|
76
|
+
"controlUi": {
|
|
77
|
+
"dangerouslyDisableDeviceAuth": true
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
5. 后续业务请求均为:
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
{ "type": "req", "id": "<唯一>", "method": "<下表 method>", "params": { } }
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
成功:`{ "type": "res", "id": "…", "ok": true, "payload": <与原先 HTTP JSON 响应体相同> }`
|
|
89
|
+
失败:`ok: false`,`error.message` 为人类可读原因;部分失败同时带 `payload`(如 `{ "error": "…", "status": 400 }`)。
|
|
90
|
+
|
|
91
|
+
### 1.2 管理方法一览
|
|
92
|
+
|
|
93
|
+
| `method` | 说明 | `params`(JSON object) | 成功时 `payload` |
|
|
94
|
+
|----------|------|---------------------------|------------------|
|
|
95
|
+
| `memory.admin.config` | 面板配置 | 无必填字段 | 同原 `GET …/api/config` 响应 |
|
|
96
|
+
| `memory.admin.facets` | 下拉去重值 | 可选 `tab`(保留字段,服务端可忽略) | 同原 `GET …/api/facets` |
|
|
97
|
+
| `memory.admin.dashboard` | 大盘统计 | `timeFrom`, `timeTo`(ISO 8601)、`agentId`;可选 `sessionId` | 同原 `GET …/api/dashboard` |
|
|
98
|
+
| `memory.admin.list` | 分页列表 | `tab`, `agentId`;可选 `sessionId`, `timeFrom`, `timeTo`, `category`, `page`, `limit`, `sortDesc`(布尔,默认 true) | 同原 `GET …/api/list` |
|
|
99
|
+
| `memory.admin.delete` | 批量删除 | `items`: `{ agentId, id }[]` | 同原 `POST …/api/delete` |
|
|
100
|
+
| `memory.admin.add` | 手工插入 | `agentId`, `text`, `category` | 同原 `POST …/api/add` |
|
|
101
|
+
|
|
102
|
+
### 1.3 废弃的 HTTP JSON
|
|
103
|
+
|
|
104
|
+
| 路径 | 行为 |
|
|
105
|
+
|------|------|
|
|
106
|
+
| `GET/POST {GATEWAY}/plugins/memory/api/*` | 若配置了 gateway token,仍校验 `?token=` 或 `Authorization: Bearer`;校验通过后返回 **`410 Gone`**,body 提示改用 WebSocket `memory.admin.*`。 |
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## 二、HTTP(仅 HTML 壳)
|
|
111
|
+
|
|
112
|
+
### 2.1 `GET /plugins/memory`
|
|
113
|
+
|
|
114
|
+
| 项目 | 说明 |
|
|
115
|
+
|------|------|
|
|
116
|
+
| **功能** | 返回记忆管理端单页 HTML(壳页面;数据由 `/api/*` 拉取) |
|
|
117
|
+
| **URI** | `{GATEWAY}/plugins/memory` |
|
|
118
|
+
|
|
119
|
+
**入参**
|
|
120
|
+
|
|
121
|
+
| 参数 | 位置 | 类型 | 必须 | 合法值 / 说明 | 默认值 |
|
|
122
|
+
|------|------|------|------|----------------|--------|
|
|
123
|
+
| — | — | — | — | 无查询参数 | — |
|
|
124
|
+
|
|
125
|
+
**出参**(成功 `200`)
|
|
126
|
+
|
|
127
|
+
| 字段 / 项 | 类型 | 说明 |
|
|
128
|
+
|-----------|------|------|
|
|
129
|
+
| 响应体 | `string` | HTML 文档 |
|
|
130
|
+
| 响应头 `Content-Type` | — | `text/html; charset=utf-8` |
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
### 2.2 参考:`memory.admin.config`(原 `GET …/api/config`)
|
|
135
|
+
|
|
136
|
+
| 项目 | 说明 |
|
|
137
|
+
|------|------|
|
|
138
|
+
| **功能** | 返回面板开关、Tab 类别、中文标签、列表筛选项等 |
|
|
139
|
+
| **URI** | `{GATEWAY}/plugins/memory/api/config` |
|
|
140
|
+
|
|
141
|
+
**入参**
|
|
142
|
+
|
|
143
|
+
| 参数 | 位置 | 类型 | 必须 | 合法值 / 说明 | 默认值 |
|
|
144
|
+
|------|------|------|------|----------------|--------|
|
|
145
|
+
| — | — | — | — | 无 | — |
|
|
146
|
+
|
|
147
|
+
**出参**(成功 `200`,`application/json`)
|
|
148
|
+
|
|
149
|
+
| 字段 | 类型 | 说明 |
|
|
150
|
+
|------|------|------|
|
|
151
|
+
| `enableFullContextMemory` | `boolean` | 是否开启全文类记忆 |
|
|
152
|
+
| `enableSelfImprovingMemory` | `boolean` | 是否开启自进化类记忆 |
|
|
153
|
+
| `categoryLabelsZh` | `object` | 键:记忆类型代码 `string` → 值:中文展示名 `string`(动态键,无固定子字段表) |
|
|
154
|
+
| `tabCategories` | `object` | 固定三键,见下表「`tabCategories` 对象结构」 |
|
|
155
|
+
| `memoryTypeFilterOptions` | `object` | 固定三键,见下表「`memoryTypeFilterOptions` 对象结构」 |
|
|
156
|
+
|
|
157
|
+
**`tabCategories` 对象结构**(键固定)
|
|
158
|
+
|
|
159
|
+
| 键 | 类型 | 说明 |
|
|
160
|
+
|----|------|------|
|
|
161
|
+
| `user` | `string[]` | 用户 Tab 下的类型代码列表 |
|
|
162
|
+
| `self` | `string[]` | 自进化 Tab;功能关闭时可能为 `[]` |
|
|
163
|
+
| `full` | `string[]` | 全文 Tab;功能关闭时可能为 `[]` |
|
|
164
|
+
|
|
165
|
+
**`memoryTypeFilterOptions` 对象结构**(键固定)
|
|
166
|
+
|
|
167
|
+
| 键 | 类型 | 说明 |
|
|
168
|
+
|----|------|------|
|
|
169
|
+
| `user` | `object[]` | 筛选项列表,元素结构见下表 |
|
|
170
|
+
| `self` | `object[]` | 同上 |
|
|
171
|
+
| `full` | `object[]` | 同上 |
|
|
172
|
+
|
|
173
|
+
**`memoryTypeFilterOptions.*` 数组元素(object)**
|
|
174
|
+
|
|
175
|
+
| 字段 | 类型 | 说明 |
|
|
176
|
+
|------|------|------|
|
|
177
|
+
| `category` | `string` | 记忆类型代码 |
|
|
178
|
+
| `labelZh` | `string` | 界面展示用中文 |
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
### 2.3 参考:`memory.admin.facets`(原 `GET …/api/facets`)
|
|
183
|
+
|
|
184
|
+
| 项目 | 说明 |
|
|
185
|
+
|------|------|
|
|
186
|
+
| **功能** | 返回库中出现过的去重 `agentId`、`sessionId`(供下拉框) |
|
|
187
|
+
| **URI** | `{GATEWAY}/plugins/memory/api/facets` |
|
|
188
|
+
|
|
189
|
+
**入参**
|
|
190
|
+
|
|
191
|
+
| 参数 | 位置 | 类型 | 必须 | 合法值 / 说明 | 默认值 |
|
|
192
|
+
|------|------|------|------|----------------|--------|
|
|
193
|
+
| — | — | — | — | 无 | — |
|
|
194
|
+
|
|
195
|
+
**出参**(成功 `200`,`application/json`)
|
|
196
|
+
|
|
197
|
+
| 字段 | 类型 | 说明 |
|
|
198
|
+
|------|------|------|
|
|
199
|
+
| `agents` | `string[]` | 已排序的去重 Agent ID |
|
|
200
|
+
| `sessions` | `string[]` | 已排序的去重会话 ID |
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
### 2.4 参考:`memory.admin.dashboard`(原 `GET …/api/dashboard`)
|
|
205
|
+
|
|
206
|
+
| 项目 | 说明 |
|
|
207
|
+
|------|------|
|
|
208
|
+
| **功能** | 指定时间范围 + Agent(可选会话)下的记忆大盘统计 |
|
|
209
|
+
| **URI** | `{GATEWAY}/plugins/memory/api/dashboard` |
|
|
210
|
+
|
|
211
|
+
**入参**
|
|
212
|
+
|
|
213
|
+
| 参数 | 位置 | 类型 | 必须 | 合法值 / 说明 | 默认值 |
|
|
214
|
+
|------|------|------|------|----------------|--------|
|
|
215
|
+
| `timeFrom` | query | `string` | **是** | ISO 8601,须可被 `Date.parse` 解析 | 无 |
|
|
216
|
+
| `timeTo` | query | `string` | **是** | 同上 | 无 |
|
|
217
|
+
| `agentId` | query | `string` | **是** | 非空(trim 后) | 无 |
|
|
218
|
+
| `sessionId` | query | `string` | 否 | 非空则仅统计该会话;空表示不限 | 空 |
|
|
219
|
+
|
|
220
|
+
**出参**(成功 `200`,`application/json`)
|
|
221
|
+
|
|
222
|
+
| 字段 | 类型 | 说明 |
|
|
223
|
+
|------|------|------|
|
|
224
|
+
| `total` | `number` | 满足条件的记忆条数 |
|
|
225
|
+
| `timeFromMs` | `number` | 起始时间毫秒时间戳 |
|
|
226
|
+
| `timeToMs` | `number` | 结束时间毫秒时间戳 |
|
|
227
|
+
| `byKind` | `object` | 四大类条数,子结构见下表 |
|
|
228
|
+
| `byCategory` | `object` | 键:类型代码 `string` → 值:条数 `number`(动态键) |
|
|
229
|
+
| `byBucket` | `object[]` | 时间趋势桶,元素结构见下表 |
|
|
230
|
+
| `topAgents` | `object[]` | 条数 Top Agent,**最多 10 条**,元素结构见下表 |
|
|
231
|
+
| `topSessions` | `object[]` | 条数 Top 会话,**最多 10 条**,元素结构见下表 |
|
|
232
|
+
| `importance` | `object` | 重要程度分档,子结构见下表 |
|
|
233
|
+
| `uniqueAgents` | `number` | 去重 Agent 数 |
|
|
234
|
+
| `uniqueSessions` | `number` | 去重会话数 |
|
|
235
|
+
|
|
236
|
+
**`byKind` 对象结构**
|
|
237
|
+
|
|
238
|
+
| 字段 | 类型 | 说明 |
|
|
239
|
+
|------|------|------|
|
|
240
|
+
| `user` | `number` | 用户记忆类(`user_memory_*`) |
|
|
241
|
+
| `self` | `number` | 自进化类(`self_improving_*`) |
|
|
242
|
+
| `full` | `number` | 全文相关(含 `full_context_memory` 与 `full_context_*`) |
|
|
243
|
+
| `other` | `number` | 其余类型 |
|
|
244
|
+
|
|
245
|
+
**`byBucket` 数组元素(object)**
|
|
246
|
+
|
|
247
|
+
| 字段 | 类型 | 说明 |
|
|
248
|
+
|------|------|------|
|
|
249
|
+
| `key` | `string` | 桶标识(如月份 `YYYY-MM` 或序号) |
|
|
250
|
+
| `label` | `string` | 展示用标签 |
|
|
251
|
+
| `count` | `number` | 该桶内条数 |
|
|
252
|
+
|
|
253
|
+
说明:跨度 ≤48 小时按**小时**桶;跨度大于 60 天按**本地自然月**桶;否则按**日**桶。
|
|
254
|
+
|
|
255
|
+
**`topAgents` 数组元素(object)**
|
|
256
|
+
|
|
257
|
+
| 字段 | 类型 | 说明 |
|
|
258
|
+
|------|------|------|
|
|
259
|
+
| `agentId` | `string` | Agent ID |
|
|
260
|
+
| `count` | `number` | 条数 |
|
|
261
|
+
|
|
262
|
+
**`topSessions` 数组元素(object)**
|
|
263
|
+
|
|
264
|
+
| 字段 | 类型 | 说明 |
|
|
265
|
+
|------|------|------|
|
|
266
|
+
| `sessionId` | `string` | 会话 ID |
|
|
267
|
+
| `count` | `number` | 条数 |
|
|
268
|
+
|
|
269
|
+
**`importance` 对象结构**
|
|
270
|
+
|
|
271
|
+
| 字段 | 类型 | 说明 |
|
|
272
|
+
|------|------|------|
|
|
273
|
+
| `low` | `number` | 重要度小于 0.34 的条数 |
|
|
274
|
+
| `mid` | `number` | 重要度大于等于 0.34 且小于 0.67 |
|
|
275
|
+
| `high` | `number` | 重要度不小于 0.67 |
|
|
276
|
+
| `avg` | `number` | 有效重要度的平均值;无有效值时为 `0` |
|
|
277
|
+
|
|
278
|
+
**失败** `400`:缺少/非法时间、缺少 `agentId`、或命中行数超过约 5 万等,body 多为 `{ "error": string }`。
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
### 2.5 参考:`memory.admin.list`(原 `GET …/api/list`;RPC 中 `sortDesc` 为 **boolean**,`page`/`limit` 为 **number**)
|
|
283
|
+
|
|
284
|
+
| 项目 | 说明 |
|
|
285
|
+
|------|------|
|
|
286
|
+
| **功能** | 分页列出记忆行(Tab 对应类别集合;全文 Tab 按 `batchId` 分组排序) |
|
|
287
|
+
| **URI** | `{GATEWAY}/plugins/memory/api/list` |
|
|
288
|
+
|
|
289
|
+
**入参**
|
|
290
|
+
|
|
291
|
+
| 参数 | 位置 | 类型 | 必须 | 合法值 / 说明 | 默认值 |
|
|
292
|
+
|------|------|------|------|----------------|--------|
|
|
293
|
+
| `agentId` | query | `string` | **是** | 非空 | 无 |
|
|
294
|
+
| `tab` | query | `string` | 否 | `user` \| `self` \| `full`,决定基础类别集合 | `user` |
|
|
295
|
+
| `sessionId` | query | `string` | 否 | 仅该会话 | 空(不限) |
|
|
296
|
+
| `timeFrom` | query | `string` | 否 | ISO 8601,过滤创建时间下限 | 不限 |
|
|
297
|
+
| `timeTo` | query | `string` | 否 | ISO 8601,过滤创建时间上限 | 不限 |
|
|
298
|
+
| `category` | query | `string` | 否 | 须属当前 Tab 类别且出现在该 Tab 的 `memoryTypeFilterOptions` 中 | 不按子类型过滤 |
|
|
299
|
+
| `page` | query | `number` | 否 | 正整数页码 | `1` |
|
|
300
|
+
| `limit` | query | `number` | 否 | 每页 1~500 | `100` |
|
|
301
|
+
| `sortDesc` | query | `string` | 否 | 传 `"false"` 时部分 Tab 改为时间升序;否则降序 | 降序 |
|
|
302
|
+
|
|
303
|
+
**出参**(成功 `200`,`application/json`)
|
|
304
|
+
|
|
305
|
+
| 字段 | 类型 | 说明 |
|
|
306
|
+
|------|------|------|
|
|
307
|
+
| `items` | `object[]` | 当前页记忆行,元素结构见下表 |
|
|
308
|
+
| `total` | `number` | 符合条件的总条数(分页前) |
|
|
309
|
+
| `page` | `number` | 当前页码 |
|
|
310
|
+
| `pageSize` | `number` | 本页条数(对应请求中的 `limit`) |
|
|
311
|
+
|
|
312
|
+
**`items` 数组元素(object)**
|
|
313
|
+
|
|
314
|
+
| 字段 | 类型 | 必填(于对象内) | 说明 |
|
|
315
|
+
|------|------|------------------|------|
|
|
316
|
+
| `id` | `string` | 是 | 行 UUID,删除时与 `agentId` 一起提交 |
|
|
317
|
+
| `agentId` | `string` | 是 | Agent ID |
|
|
318
|
+
| `sessionId` | `string` | 是 | 会话 ID,可能为空字符串 `""` |
|
|
319
|
+
| `text` | `string` | 是 | 正文 |
|
|
320
|
+
| `importance` | `number` | 是 | 重要程度 |
|
|
321
|
+
| `category` | `string` | 是 | 类型代码 |
|
|
322
|
+
| `createdAt` | `number` | 是 | 创建时间(毫秒时间戳) |
|
|
323
|
+
| `isDeleted` | `number` | 是 | 列表一般为未删除数据,常见 `0` |
|
|
324
|
+
| `batchId` | `string` | 否 | 全文快照批次 ID,用于成组展示 |
|
|
325
|
+
| `seqInBatch` | `number` | 否 | 批次内顺序 |
|
|
326
|
+
| `chunkIndex` | `number` | 否 | 多向量段时序号 |
|
|
327
|
+
|
|
328
|
+
**失败** `400`:`agentId` 缺失、`category` 与 Tab 不匹配、匹配过多等。
|
|
329
|
+
|
|
330
|
+
**特例**(功能关闭的 Tab):`items` 为 `[]`,`total` 为 `0`,`page` 为 `1`,`pageSize` 为 `100`。
|
|
331
|
+
|
|
332
|
+
---
|
|
333
|
+
|
|
334
|
+
### 2.6 参考:`memory.admin.delete`(原 `POST …/api/delete`)
|
|
335
|
+
|
|
336
|
+
| 项目 | 说明 |
|
|
337
|
+
|------|------|
|
|
338
|
+
| **功能** | 按行 ID 批量硬删除 |
|
|
339
|
+
| **URI** | `{GATEWAY}/plugins/memory/api/delete` |
|
|
340
|
+
| **Content-Type** | `application/json`(请求) |
|
|
341
|
+
| **Body 上限** | 约 64KB |
|
|
342
|
+
|
|
343
|
+
**入参(Body JSON)**
|
|
344
|
+
|
|
345
|
+
| 参数 | 位置 | 类型 | 必须 | 合法值 / 说明 | 默认值 |
|
|
346
|
+
|------|------|------|------|----------------|--------|
|
|
347
|
+
| `items` | body | `object[]` | **是** | 至少 1 个元素;元素结构见下表 | 无 |
|
|
348
|
+
|
|
349
|
+
**`items` 数组元素(object)**
|
|
350
|
+
|
|
351
|
+
| 字段 | 类型 | 必须 | 说明 |
|
|
352
|
+
|------|------|------|------|
|
|
353
|
+
| `agentId` | `string` | **是** | 非空 |
|
|
354
|
+
| `id` | `string` | **是** | 行 UUID |
|
|
355
|
+
|
|
356
|
+
**出参**(成功 `200`,`application/json`)
|
|
357
|
+
|
|
358
|
+
| 字段 | 类型 | 说明 |
|
|
359
|
+
|------|------|------|
|
|
360
|
+
| `deleted` | `number` | 实际删除条数 |
|
|
361
|
+
|
|
362
|
+
说明:缺 `agentId` 或 `id` 的项会被跳过;若有效项为 0,返回 `400`,`error` 为 `items required`。
|
|
363
|
+
|
|
364
|
+
---
|
|
365
|
+
|
|
366
|
+
### 2.7 参考:`memory.admin.add`(原 `POST …/api/add`)
|
|
367
|
+
|
|
368
|
+
| 项目 | 说明 |
|
|
369
|
+
|------|------|
|
|
370
|
+
| **功能** | 管理端手工写入一条逻辑记忆(可对应多段向量行) |
|
|
371
|
+
| **URI** | `{GATEWAY}/plugins/memory/api/add` |
|
|
372
|
+
| **Content-Type** | `application/json` |
|
|
373
|
+
| **Body 上限** | 约 64KB |
|
|
374
|
+
|
|
375
|
+
**入参(Body JSON)**
|
|
376
|
+
|
|
377
|
+
| 参数 | 位置 | 类型 | 必须 | 合法值 / 说明 | 默认值 |
|
|
378
|
+
|------|------|------|------|----------------|--------|
|
|
379
|
+
| `agentId` | body | `string` | **是** | 非空(trim) | 无 |
|
|
380
|
+
| `text` | body | `string` | **是** | trim 后非空;超长按约 8000 字符截断 | 无 |
|
|
381
|
+
| `category` | body | `string` | **是** | 见附录 A 与 config 开关;本接口不使用 `full_context_memory` 字面量 | 无 |
|
|
382
|
+
|
|
383
|
+
写入行的 `sessionId` 固定为 `manual_insert`。
|
|
384
|
+
|
|
385
|
+
**出参**(成功 `200`,`application/json`)
|
|
386
|
+
|
|
387
|
+
| 字段 | 类型 | 说明 |
|
|
388
|
+
|------|------|------|
|
|
389
|
+
| `id` | `string` | 首段向量行的 UUID |
|
|
390
|
+
| `createdAt` | `number` | 首行创建时间(毫秒时间戳) |
|
|
391
|
+
| `chunkRows` | `number` | 写入的向量行数(段数) |
|
|
392
|
+
|
|
393
|
+
**失败**:`400` / `502` / `503` 等,body 多为 `{ "error": string }`(见源码与运行时文案)。
|
|
394
|
+
|
|
395
|
+
---
|
|
396
|
+
|
|
397
|
+
### 2.8 HTTP 调用示例(curl;**`/api/*` 已返回 410**,仅作 HTML 与历史对照)
|
|
398
|
+
|
|
399
|
+
**环境**:`http://127.0.0.1:12345`,已配置 `gateway.auth.token`;下列 curl 中 **`GET/POST …/plugins/memory/api/*` 现已为 `410 Gone`**,请改用 **WebSocket `memory.admin.*`**。库内数据变化后,实测 JSON 会与下文摘录不同。
|
|
400
|
+
|
|
401
|
+
```bash
|
|
402
|
+
export GATEWAY="http://127.0.0.1:12345"
|
|
403
|
+
export TOKEN="你的 gateway.auth.token"
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
鉴权:**请求头** `Authorization: Bearer $TOKEN`,或 **Query** `?token=$TOKEN`。
|
|
407
|
+
|
|
408
|
+
**实测状态码一览**
|
|
409
|
+
|
|
410
|
+
| 请求 | HTTP |
|
|
411
|
+
|------|------|
|
|
412
|
+
| `GET …/plugins/memory` | `200` |
|
|
413
|
+
| `GET …/api/config`(Bearer) | **`410`**(已废弃) |
|
|
414
|
+
| `GET …/api/config?token=` | **`410`** |
|
|
415
|
+
| `GET …/api/facets` | **`410`** |
|
|
416
|
+
| `GET …/api/dashboard`(带 timeFrom/timeTo/agentId) | **`410`** |
|
|
417
|
+
| `GET …/api/list` | **`410`** |
|
|
418
|
+
| `POST …/api/delete`,body `{"items":[]}` | **`410`** |
|
|
419
|
+
| `POST …/api/add`(示例 body) | **`410`** |
|
|
420
|
+
| `POST …/api/delete`(删掉刚插入的 id) | **`410`** |
|
|
421
|
+
| `GET …/api/config`,错误 Bearer | **`410`** 或 `401`(先鉴权再 410) |
|
|
422
|
+
|
|
423
|
+
---
|
|
424
|
+
|
|
425
|
+
**1)`GET /plugins/memory`(无 token)**
|
|
426
|
+
|
|
427
|
+
```bash
|
|
428
|
+
curl -sS -D - -o /tmp/memory_panel.html "$GATEWAY/plugins/memory" | head -n 12
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
**响应头(实测前若干行)**
|
|
432
|
+
|
|
433
|
+
```http
|
|
434
|
+
HTTP/1.1 200 OK
|
|
435
|
+
X-Content-Type-Options: nosniff
|
|
436
|
+
Referrer-Policy: no-referrer
|
|
437
|
+
Permissions-Policy: camera=(), microphone=(), geolocation=()
|
|
438
|
+
Content-Type: text/html; charset=utf-8
|
|
439
|
+
Cache-Control: no-store, no-cache, must-revalidate
|
|
440
|
+
Pragma: no-cache
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
**响应体**:HTML 单页(实测整页约 65KB)。正文开头如下,余下为内联样式与脚本。
|
|
444
|
+
|
|
445
|
+
```html
|
|
446
|
+
<!DOCTYPE html>
|
|
447
|
+
<html lang="zh-CN">
|
|
448
|
+
<head>
|
|
449
|
+
<meta charset="utf-8"/>
|
|
450
|
+
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
451
|
+
<title>RDSClaw 记忆管理</title>
|
|
452
|
+
<style>
|
|
453
|
+
/* 与 OpenClaw Observability 面板一致的浅色卡片 + 红色主色 */
|
|
454
|
+
:root {
|
|
455
|
+
font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
456
|
+
color: #212121;
|
|
457
|
+
background: #f5f5f5;
|
|
458
|
+
--oc-accent: #d32f2f;
|
|
459
|
+
--oc-accent-hover: #b71c1c;
|
|
460
|
+
--oc-secondary: #7e57c2;
|
|
461
|
+
--oc-border: #e0e0e0;
|
|
462
|
+
--oc-muted: #757575;
|
|
463
|
+
--oc-card: #ffffff;
|
|
464
|
+
--oc-page: #f5f5f5;
|
|
465
|
+
}
|
|
466
|
+
* { box-sizing: border-box; }
|
|
467
|
+
input[type="checkbox"] { accent-color: var(--oc-accent); }
|
|
468
|
+
body {
|
|
469
|
+
margin: 0;
|
|
470
|
+
padding: 20px 20px 32px;
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
---
|
|
474
|
+
|
|
475
|
+
**2)`GET /plugins/memory/api/config`**
|
|
476
|
+
|
|
477
|
+
```bash
|
|
478
|
+
curl -sS -H "Authorization: Bearer $TOKEN" \
|
|
479
|
+
"$GATEWAY/plugins/memory/api/config"
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
**响应体 `200`(实测 JSON,已格式化)**
|
|
483
|
+
|
|
484
|
+
```json
|
|
485
|
+
{
|
|
486
|
+
"enableFullContextMemory": true,
|
|
487
|
+
"enableSelfImprovingMemory": true,
|
|
488
|
+
"categoryLabelsZh": {
|
|
489
|
+
"user_memory_fact": "用户事实",
|
|
490
|
+
"user_memory_preference": "用户偏好",
|
|
491
|
+
"user_memory_decision": "用户决策",
|
|
492
|
+
"full_context_memory": "全文记忆",
|
|
493
|
+
"full_context_user": "全文 · 用户消息",
|
|
494
|
+
"full_context_assistant": "全文 · AI助手消息",
|
|
495
|
+
"full_context_system": "全文 · 系统消息",
|
|
496
|
+
"full_context_tool": "全文 · 工具调用",
|
|
497
|
+
"full_context_tool_result": "全文 · 工具结果",
|
|
498
|
+
"full_context_others": "全文 · 其他消息",
|
|
499
|
+
"self_improving_learnings": "最佳实践",
|
|
500
|
+
"self_improving_errors": "错误经验",
|
|
501
|
+
"self_improving_feature_requests": "行为诉求"
|
|
502
|
+
},
|
|
503
|
+
"tabCategories": {
|
|
504
|
+
"user": [
|
|
505
|
+
"user_memory_fact",
|
|
506
|
+
"user_memory_preference",
|
|
507
|
+
"user_memory_decision"
|
|
508
|
+
],
|
|
509
|
+
"self": [
|
|
510
|
+
"self_improving_learnings",
|
|
511
|
+
"self_improving_errors",
|
|
512
|
+
"self_improving_feature_requests"
|
|
513
|
+
],
|
|
514
|
+
"full": [
|
|
515
|
+
"full_context_user",
|
|
516
|
+
"full_context_assistant",
|
|
517
|
+
"full_context_system",
|
|
518
|
+
"full_context_tool",
|
|
519
|
+
"full_context_tool_result",
|
|
520
|
+
"full_context_others"
|
|
521
|
+
]
|
|
522
|
+
},
|
|
523
|
+
"memoryTypeFilterOptions": {
|
|
524
|
+
"user": [
|
|
525
|
+
{ "category": "user_memory_fact", "labelZh": "用户事实" },
|
|
526
|
+
{ "category": "user_memory_preference", "labelZh": "用户偏好" },
|
|
527
|
+
{ "category": "user_memory_decision", "labelZh": "用户决策" }
|
|
528
|
+
],
|
|
529
|
+
"self": [
|
|
530
|
+
{ "category": "self_improving_learnings", "labelZh": "最佳实践" },
|
|
531
|
+
{ "category": "self_improving_errors", "labelZh": "错误经验" },
|
|
532
|
+
{ "category": "self_improving_feature_requests", "labelZh": "行为诉求" }
|
|
533
|
+
],
|
|
534
|
+
"full": [
|
|
535
|
+
{ "category": "full_context_user", "labelZh": "全文 · 用户消息" },
|
|
536
|
+
{ "category": "full_context_assistant", "labelZh": "全文 · AI助手消息" },
|
|
537
|
+
{ "category": "full_context_system", "labelZh": "全文 · 系统消息" },
|
|
538
|
+
{ "category": "full_context_tool", "labelZh": "全文 · 工具调用" },
|
|
539
|
+
{ "category": "full_context_tool_result", "labelZh": "全文 · 工具结果" },
|
|
540
|
+
{ "category": "full_context_others", "labelZh": "全文 · 其他消息" }
|
|
541
|
+
]
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
---
|
|
547
|
+
|
|
548
|
+
**3)Query 传 token(与 Bearer 等价,实测 body 与上条一致)**
|
|
549
|
+
|
|
550
|
+
```bash
|
|
551
|
+
curl -sS "$GATEWAY/plugins/memory/api/config?token=$TOKEN"
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
**响应体**:与 **2)** 相同(实测与 Bearer 返回同一 JSON)。
|
|
555
|
+
|
|
556
|
+
---
|
|
557
|
+
|
|
558
|
+
**4)`GET /plugins/memory/api/facets`**
|
|
559
|
+
|
|
560
|
+
```bash
|
|
561
|
+
curl -sS -H "Authorization: Bearer $TOKEN" \
|
|
562
|
+
"$GATEWAY/plugins/memory/api/facets"
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
**响应体 `200`(实测)**
|
|
566
|
+
|
|
567
|
+
```json
|
|
568
|
+
{
|
|
569
|
+
"agents": ["main"],
|
|
570
|
+
"sessions": [
|
|
571
|
+
"agent:main:main",
|
|
572
|
+
"session:67505b88-3019-4c5a-88e2-53fe10abc8da",
|
|
573
|
+
"session:7e4de4fd-153c-4d14-a558-898486323f32",
|
|
574
|
+
"session:8b8fcf30-df6c-4361-85e1-007cf3390f9f",
|
|
575
|
+
"session:97dab399-a12b-409d-a4a7-52ab04c16085",
|
|
576
|
+
"session:afca0e5d-0de8-48a2-885e-c6494d988849",
|
|
577
|
+
"session:ca4f769f-ab45-40b9-8e7c-6c16e830dd99",
|
|
578
|
+
"session:cfdce68f-9a35-4e80-aae4-90501f31538e",
|
|
579
|
+
"session:e2e-1774361036",
|
|
580
|
+
"session:e7693a60-62de-4783-ab6b-a532b8995594",
|
|
581
|
+
"session:mem-empty-1774359591"
|
|
582
|
+
]
|
|
583
|
+
}
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
---
|
|
587
|
+
|
|
588
|
+
**5)`GET /plugins/memory/api/dashboard`**
|
|
589
|
+
|
|
590
|
+
```bash
|
|
591
|
+
curl -sS -G -H "Authorization: Bearer $TOKEN" \
|
|
592
|
+
--data-urlencode "timeFrom=2025-01-01T00:00:00.000Z" \
|
|
593
|
+
--data-urlencode "timeTo=2026-12-31T23:59:59.999Z" \
|
|
594
|
+
--data-urlencode "agentId=main" \
|
|
595
|
+
"$GATEWAY/plugins/memory/api/dashboard"
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
**响应体 `200`(实测,已格式化)**
|
|
599
|
+
|
|
600
|
+
```json
|
|
601
|
+
{
|
|
602
|
+
"total": 1520,
|
|
603
|
+
"timeFromMs": 1735689600000,
|
|
604
|
+
"timeToMs": 1798761599999,
|
|
605
|
+
"byKind": { "user": 20, "self": 30, "full": 1470, "other": 0 },
|
|
606
|
+
"byCategory": {
|
|
607
|
+
"full_context_user": 135,
|
|
608
|
+
"full_context_tool_result": 1095,
|
|
609
|
+
"full_context_assistant": 240,
|
|
610
|
+
"user_memory_preference": 5,
|
|
611
|
+
"user_memory_fact": 15,
|
|
612
|
+
"self_improving_errors": 2,
|
|
613
|
+
"self_improving_learnings": 26,
|
|
614
|
+
"self_improving_feature_requests": 2
|
|
615
|
+
},
|
|
616
|
+
"byBucket": [
|
|
617
|
+
{ "key": "2025-01", "label": "2025-01", "count": 0 },
|
|
618
|
+
{ "key": "2025-02", "label": "2025-02", "count": 0 },
|
|
619
|
+
{ "key": "2025-03", "label": "2025-03", "count": 0 },
|
|
620
|
+
{ "key": "2025-04", "label": "2025-04", "count": 0 },
|
|
621
|
+
{ "key": "2025-05", "label": "2025-05", "count": 0 },
|
|
622
|
+
{ "key": "2025-06", "label": "2025-06", "count": 0 },
|
|
623
|
+
{ "key": "2025-07", "label": "2025-07", "count": 0 },
|
|
624
|
+
{ "key": "2025-08", "label": "2025-08", "count": 0 },
|
|
625
|
+
{ "key": "2025-09", "label": "2025-09", "count": 0 },
|
|
626
|
+
{ "key": "2025-10", "label": "2025-10", "count": 0 },
|
|
627
|
+
{ "key": "2025-11", "label": "2025-11", "count": 0 },
|
|
628
|
+
{ "key": "2025-12", "label": "2025-12", "count": 0 },
|
|
629
|
+
{ "key": "2026-01", "label": "2026-01", "count": 0 },
|
|
630
|
+
{ "key": "2026-02", "label": "2026-02", "count": 0 },
|
|
631
|
+
{ "key": "2026-03", "label": "2026-03", "count": 1520 },
|
|
632
|
+
{ "key": "2026-04", "label": "2026-04", "count": 0 },
|
|
633
|
+
{ "key": "2026-05", "label": "2026-05", "count": 0 },
|
|
634
|
+
{ "key": "2026-06", "label": "2026-06", "count": 0 },
|
|
635
|
+
{ "key": "2026-07", "label": "2026-07", "count": 0 },
|
|
636
|
+
{ "key": "2026-08", "label": "2026-08", "count": 0 },
|
|
637
|
+
{ "key": "2026-09", "label": "2026-09", "count": 0 },
|
|
638
|
+
{ "key": "2026-10", "label": "2026-10", "count": 0 },
|
|
639
|
+
{ "key": "2026-11", "label": "2026-11", "count": 0 },
|
|
640
|
+
{ "key": "2026-12", "label": "2026-12", "count": 0 },
|
|
641
|
+
{ "key": "2027-01", "label": "2027-01", "count": 0 }
|
|
642
|
+
],
|
|
643
|
+
"topAgents": [{ "agentId": "main", "count": 1520 }],
|
|
644
|
+
"topSessions": [
|
|
645
|
+
{ "sessionId": "session:e7693a60-62de-4783-ab6b-a532b8995594", "count": 871 },
|
|
646
|
+
{ "sessionId": "agent:main:main", "count": 305 },
|
|
647
|
+
{ "sessionId": "session:8b8fcf30-df6c-4361-85e1-007cf3390f9f", "count": 113 },
|
|
648
|
+
{ "sessionId": "session:67505b88-3019-4c5a-88e2-53fe10abc8da", "count": 104 },
|
|
649
|
+
{ "sessionId": "session:7e4de4fd-153c-4d14-a558-898486323f32", "count": 29 },
|
|
650
|
+
{ "sessionId": "session:mem-empty-1774359591", "count": 28 },
|
|
651
|
+
{ "sessionId": "session:afca0e5d-0de8-48a2-885e-c6494d988849", "count": 28 },
|
|
652
|
+
{ "sessionId": "session:cfdce68f-9a35-4e80-aae4-90501f31538e", "count": 21 },
|
|
653
|
+
{ "sessionId": "session:97dab399-a12b-409d-a4a7-52ab04c16085", "count": 8 },
|
|
654
|
+
{ "sessionId": "session:ca4f769f-ab45-40b9-8e7c-6c16e830dd99", "count": 7 }
|
|
655
|
+
],
|
|
656
|
+
"importance": {
|
|
657
|
+
"low": 0,
|
|
658
|
+
"mid": 17,
|
|
659
|
+
"high": 1503,
|
|
660
|
+
"avg": 0.6994736842105452
|
|
661
|
+
},
|
|
662
|
+
"uniqueAgents": 1,
|
|
663
|
+
"uniqueSessions": 11
|
|
664
|
+
}
|
|
665
|
+
```
|
|
666
|
+
|
|
667
|
+
---
|
|
668
|
+
|
|
669
|
+
**6)`GET /plugins/memory/api/list`**
|
|
670
|
+
|
|
671
|
+
```bash
|
|
672
|
+
curl -sS -G -H "Authorization: Bearer $TOKEN" \
|
|
673
|
+
--data-urlencode "agentId=main" \
|
|
674
|
+
--data-urlencode "tab=user" \
|
|
675
|
+
--data-urlencode "page=1" \
|
|
676
|
+
--data-urlencode "limit=2" \
|
|
677
|
+
"$GATEWAY/plugins/memory/api/list"
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
**响应体 `200`(实测)**
|
|
681
|
+
|
|
682
|
+
```json
|
|
683
|
+
{
|
|
684
|
+
"items": [
|
|
685
|
+
{
|
|
686
|
+
"id": "861dcc43-66be-4a55-8157-bad77fc60e17",
|
|
687
|
+
"agentId": "main",
|
|
688
|
+
"sessionId": "session:8b8fcf30-df6c-4361-85e1-007cf3390f9f",
|
|
689
|
+
"text": "用户偏好使用中文进行交流。",
|
|
690
|
+
"importance": 0.5,
|
|
691
|
+
"category": "user_memory_fact",
|
|
692
|
+
"createdAt": 1774378304727,
|
|
693
|
+
"isDeleted": 0,
|
|
694
|
+
"seqInBatch": 0,
|
|
695
|
+
"chunkIndex": 0
|
|
696
|
+
},
|
|
697
|
+
{
|
|
698
|
+
"id": "1231e4e7-6a81-4216-b4c9-f4755e3825d0",
|
|
699
|
+
"agentId": "main",
|
|
700
|
+
"sessionId": "session:8b8fcf30-df6c-4361-85e1-007cf3390f9f",
|
|
701
|
+
"text": "用户为 RDS 记忆插件增加了 BM25 支持。",
|
|
702
|
+
"importance": 0.7,
|
|
703
|
+
"category": "user_memory_fact",
|
|
704
|
+
"createdAt": 1774378281971,
|
|
705
|
+
"isDeleted": 0,
|
|
706
|
+
"seqInBatch": 0,
|
|
707
|
+
"chunkIndex": 0
|
|
708
|
+
}
|
|
709
|
+
],
|
|
710
|
+
"total": 20,
|
|
711
|
+
"page": 1,
|
|
712
|
+
"pageSize": 2
|
|
713
|
+
}
|
|
714
|
+
```
|
|
715
|
+
|
|
716
|
+
---
|
|
717
|
+
|
|
718
|
+
**7)`POST /plugins/memory/api/delete`(空 `items`)**
|
|
719
|
+
|
|
720
|
+
```bash
|
|
721
|
+
curl -sS -H "Authorization: Bearer $TOKEN" \
|
|
722
|
+
-H "Content-Type: application/json" \
|
|
723
|
+
-d '{"items":[]}' \
|
|
724
|
+
"$GATEWAY/plugins/memory/api/delete"
|
|
725
|
+
```
|
|
726
|
+
|
|
727
|
+
**响应体 `400`(实测)**
|
|
728
|
+
|
|
729
|
+
```json
|
|
730
|
+
{ "error": "items required" }
|
|
731
|
+
```
|
|
732
|
+
|
|
733
|
+
---
|
|
734
|
+
|
|
735
|
+
**8)`POST /plugins/memory/api/add` → 再 `delete`(同一条 id)**
|
|
736
|
+
|
|
737
|
+
```bash
|
|
738
|
+
curl -sS -H "Authorization: Bearer $TOKEN" \
|
|
739
|
+
-H "Content-Type: application/json" \
|
|
740
|
+
-d '{"agentId":"main","text":"API doc embedded real response sample","category":"user_memory_fact"}' \
|
|
741
|
+
"$GATEWAY/plugins/memory/api/add"
|
|
742
|
+
```
|
|
743
|
+
|
|
744
|
+
**`add` 响应体 `200`(实测;该行已在后续 delete 中删掉)**
|
|
745
|
+
|
|
746
|
+
```json
|
|
747
|
+
{
|
|
748
|
+
"id": "a8ae8460-40ea-4878-baf8-f6fb48e5f79e",
|
|
749
|
+
"createdAt": 1774412491204,
|
|
750
|
+
"chunkRows": 1
|
|
751
|
+
}
|
|
752
|
+
```
|
|
753
|
+
|
|
754
|
+
```bash
|
|
755
|
+
curl -sS -H "Authorization: Bearer $TOKEN" \
|
|
756
|
+
-H "Content-Type: application/json" \
|
|
757
|
+
-d '{"items":[{"agentId":"main","id":"a8ae8460-40ea-4878-baf8-f6fb48e5f79e"}]}' \
|
|
758
|
+
"$GATEWAY/plugins/memory/api/delete"
|
|
759
|
+
```
|
|
760
|
+
|
|
761
|
+
**`delete` 响应体 `200`(实测)**
|
|
762
|
+
|
|
763
|
+
```json
|
|
764
|
+
{ "deleted": 1 }
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
---
|
|
768
|
+
|
|
769
|
+
**9)错误 token**
|
|
770
|
+
|
|
771
|
+
```bash
|
|
772
|
+
curl -sS -H "Authorization: Bearer wrong-token" \
|
|
773
|
+
"$GATEWAY/plugins/memory/api/config"
|
|
774
|
+
```
|
|
775
|
+
|
|
776
|
+
**响应体 `401`(实测)**
|
|
777
|
+
|
|
778
|
+
```json
|
|
779
|
+
{
|
|
780
|
+
"error": {
|
|
781
|
+
"message": "Unauthorized",
|
|
782
|
+
"type": "unauthorized"
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
```
|
|
786
|
+
|
|
787
|
+
---
|
|
788
|
+
|
|
789
|
+
## 三、Agent 工具(非 HTTP)
|
|
790
|
+
|
|
791
|
+
由网关注册为 **tool**;入参为工具调用 JSON,**不是**浏览器地址栏请求。
|
|
792
|
+
|
|
793
|
+
### 2.1 `memory_recall`
|
|
794
|
+
|
|
795
|
+
**入参**
|
|
796
|
+
|
|
797
|
+
| 参数 | 位置 | 类型 | 必须 | 合法值 / 说明 | 默认值 |
|
|
798
|
+
|------|------|------|------|----------------|--------|
|
|
799
|
+
| `query` | tool 参数 | `string` | **是** | 检索语句 | 无 |
|
|
800
|
+
| `limit` | tool 参数 | `number` | 否 | 正整数;实际上限受插件约束 | 约 `30` |
|
|
801
|
+
|
|
802
|
+
**出参**(工具返回值,OpenClaw 惯例)
|
|
803
|
+
|
|
804
|
+
| 字段 | 类型 | 说明 |
|
|
805
|
+
|------|------|------|
|
|
806
|
+
| `content` | `object[]` | 常为 `[{ "type": "text", "text": string }]`,给人/模型阅读 |
|
|
807
|
+
| `details` | `object` | 机器可读;子结构见下表(依场景不同) |
|
|
808
|
+
|
|
809
|
+
**`details` 常见形态**
|
|
810
|
+
|
|
811
|
+
| 场景 | `details` 类型 | 字段说明 |
|
|
812
|
+
|------|----------------|----------|
|
|
813
|
+
| 未配置插件 | `object` | `error`:`string`,如 `"not_configured"` |
|
|
814
|
+
| 无结果 | `object` | `count`:`number`,`0` |
|
|
815
|
+
| 有结果 | `object` | `count`:`number`;`memories`:`object[]`,元素见下表 |
|
|
816
|
+
|
|
817
|
+
**`details.memories` 数组元素(object)**
|
|
818
|
+
|
|
819
|
+
| 字段 | 类型 | 说明 |
|
|
820
|
+
|------|------|------|
|
|
821
|
+
| `id` | `string` | 记忆行 ID |
|
|
822
|
+
| `text` | `string` | 正文 |
|
|
823
|
+
| `category` | `string` | 类型代码 |
|
|
824
|
+
| `importance` | `number` | 重要程度 |
|
|
825
|
+
| `score` | `number` | 相关度分数 |
|
|
826
|
+
| `createdAt` | `number` | 毫秒时间戳 |
|
|
827
|
+
|
|
828
|
+
---
|
|
829
|
+
|
|
830
|
+
### 2.2 `memory_store`
|
|
831
|
+
|
|
832
|
+
**入参**
|
|
833
|
+
|
|
834
|
+
| 参数 | 位置 | 类型 | 必须 | 合法值 / 说明 | 默认值 |
|
|
835
|
+
|------|------|------|------|----------------|--------|
|
|
836
|
+
| `text` | tool 参数 | `string` | **是** | 待存储正文 | 无 |
|
|
837
|
+
| `importance` | tool 参数 | `number` | 否 | 建议 0~1 | `0.7` |
|
|
838
|
+
| `category` | tool 参数 | `string` | 否 | 枚举随配置;默认用户事实类 | `user_memory_fact` |
|
|
839
|
+
|
|
840
|
+
**出参**
|
|
841
|
+
|
|
842
|
+
| 字段 | 类型 | 说明 |
|
|
843
|
+
|------|------|------|
|
|
844
|
+
| `content` | `object[]` | 文本摘要(`type: text`) |
|
|
845
|
+
| `details` | `object` | 成功时见下表;失败时常含 `error`:`string` |
|
|
846
|
+
|
|
847
|
+
**`details` 成功时(object)**
|
|
848
|
+
|
|
849
|
+
| 字段 | 类型 | 说明 |
|
|
850
|
+
|------|------|------|
|
|
851
|
+
| `action` | `string` | `"created"` 或 `"updated"` |
|
|
852
|
+
| `id` | `string` | 记忆行 ID |
|
|
853
|
+
|
|
854
|
+
---
|
|
855
|
+
|
|
856
|
+
### 2.3 `memory_forget`
|
|
857
|
+
|
|
858
|
+
**入参**
|
|
859
|
+
|
|
860
|
+
| 参数 | 位置 | 类型 | 必须 | 合法值 / 说明 | 默认值 |
|
|
861
|
+
|------|------|------|------|----------------|--------|
|
|
862
|
+
| `memoryId` | tool 参数 | `string` | 否 | 行 UUID;与 `query` 二选一 | 无 |
|
|
863
|
+
| `query` | tool 参数 | `string` | 否 | 检索语句;与 `memoryId` 二选一 | 无 |
|
|
864
|
+
|
|
865
|
+
**出参**
|
|
866
|
+
|
|
867
|
+
| 字段 | 类型 | 说明 |
|
|
868
|
+
|------|------|------|
|
|
869
|
+
| `content` | `object[]` | 文本说明 |
|
|
870
|
+
| `details` | `object` | 依场景不同,见下表 |
|
|
871
|
+
|
|
872
|
+
**`details` 常见形态**
|
|
873
|
+
|
|
874
|
+
| 场景 | 字段 | 类型 | 说明 |
|
|
875
|
+
|------|------|------|------|
|
|
876
|
+
| 未配置 | `error` | `string` | 如 `not_configured` |
|
|
877
|
+
| 缺参 | `error` | `string` | `missing_param` |
|
|
878
|
+
| 按 ID 删除成功 | `action` | `string` | `deleted` |
|
|
879
|
+
| 按 ID 删除成功 | `id` | `string` | 被删 ID |
|
|
880
|
+
| 按 ID 未找到 | `action` | `string` | `not_found` |
|
|
881
|
+
| 按 ID 未找到 | `id` | `string` | 请求的 ID |
|
|
882
|
+
| 按 query 无匹配 | `found` | `number` | `0` |
|
|
883
|
+
| 按 query 自动删除 | `action` | `string` | `deleted` |
|
|
884
|
+
| 按 query 自动删除 | `rows` | `number` | 删除行数 |
|
|
885
|
+
| 按 query 自动删除 | `id` | `string` | 代表行 ID |
|
|
886
|
+
| 按 query 仅候选 | `action` | `string` | `candidates` |
|
|
887
|
+
| 按 query 仅候选 | `candidates` | `object[]` | 元素含 `id`、`text`、`category`、`score` |
|
|
888
|
+
|
|
889
|
+
**`details.candidates` 数组元素(object)**
|
|
890
|
+
|
|
891
|
+
| 字段 | 类型 | 说明 |
|
|
892
|
+
|------|------|------|
|
|
893
|
+
| `id` | `string` | 记忆 ID |
|
|
894
|
+
| `text` | `string` | 正文 |
|
|
895
|
+
| `category` | `string` | 类型 |
|
|
896
|
+
| `score` | `number` | 分数 |
|
|
897
|
+
|
|
898
|
+
---
|
|
899
|
+
|
|
900
|
+
## 四、附录
|
|
901
|
+
|
|
902
|
+
### A. `POST /api/add` 与工具可用的类型代码(随配置增减)
|
|
903
|
+
|
|
904
|
+
| 场景 | 允许的 `category` 示例 |
|
|
905
|
+
|------|-------------------------|
|
|
906
|
+
| 始终 | `user_memory_fact`、`user_memory_preference`、`user_memory_decision` |
|
|
907
|
+
| 全文开启 | `full_context_user`、`full_context_assistant`、`full_context_system`、`full_context_tool`、`full_context_tool_result`、`full_context_others` |
|
|
908
|
+
| 自进化开启 | `self_improving_learnings`、`self_improving_errors`、`self_improving_feature_requests` |
|
|
909
|
+
|
|
910
|
+
### B. 运维备注
|
|
911
|
+
|
|
912
|
+
- Service id:`openclaw-memory-alibaba-local`;无额外对外 HTTP。
|
|
913
|
+
- `autoRecall`、`autoCapture` 等为行为开关,无独立 URL。
|
|
914
|
+
|
|
915
|
+
---
|
|
916
|
+
|
|
917
|
+
*若与实现不一致,以仓库当前源码为准。*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openclaw-memory-alibaba-local",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "OpenClaw memory plugin: local LanceDB + DashScope-compatible embeddings",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,21 +17,11 @@
|
|
|
17
17
|
"vector-search"
|
|
18
18
|
],
|
|
19
19
|
"files": [
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"bm25-recall.ts",
|
|
23
|
-
"capture-state.ts",
|
|
24
|
-
"config.ts",
|
|
25
|
-
"db.ts",
|
|
26
|
-
"embed-chunks.ts",
|
|
27
|
-
"embedding-backend.ts",
|
|
28
|
-
"categories.ts",
|
|
29
|
-
"prompts.ts",
|
|
30
|
-
"web/memory-admin-ops.ts",
|
|
31
|
-
"web/memory-routes.ts",
|
|
32
|
-
"web/memory-ui.ts",
|
|
20
|
+
"*.ts",
|
|
21
|
+
"web/**/*.ts",
|
|
33
22
|
"openclaw.plugin.json",
|
|
34
|
-
"README.md"
|
|
23
|
+
"README.md",
|
|
24
|
+
"API.md"
|
|
35
25
|
],
|
|
36
26
|
"dependencies": {
|
|
37
27
|
"@lancedb/lancedb": "^0.27.1",
|