@modusensus/dsh-mneme 0.7.11 → 0.7.12
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.en.md +69 -0
- package/README.md +69 -0
- package/bin/cli.mjs +603 -0
- package/lib/api-standalone.js +264 -0
- package/lib/api.js +91 -2
- package/lib/client.js +243 -1
- package/lib/config.js +49 -0
- package/lib/index.js +43 -12
- package/lib/settings.js +40 -0
- package/lib/store.js +4 -1
- package/package.json +5 -1
- package/src/api-standalone.js +264 -0
- package/src/api.js +91 -2
- package/src/config.js +49 -0
- package/src/index.js +43 -12
- package/src/settings.js +40 -0
- package/src/store.js +4 -1
- package/test/api.test.js +44 -0
- package/test/settings.test.js +24 -0
- package/test/standalone-api.test.js +326 -0
package/README.en.md
CHANGED
|
@@ -297,6 +297,75 @@ It works out of the box with the defaults. To adjust, override in `~/.dsh/profil
|
|
|
297
297
|
|
|
298
298
|
> 🔐 **API security**: DSH has no built-in authentication and by default listens only on `127.0.0.1`. The plugin API is open by default (so the web panel works out of the box). For protection (e.g. when exposed to a LAN), set `apiToken` in the configuration: write operations (profile/rules/commands) and key endpoints (`vector-config`, `vector-reindex`) require `Authorization: Bearer <token>` (the frontend settings panel accepts the same token), while the read-only `list` / `search` / `semantic` endpoints remain open. The `apiKey` returned by `/api/dsh-mneme/vector-config` is masked (`sk-***…`), while the stored plaintext is kept for actual calls; the frontend sending back an empty or masked value means "do not change the key".
|
|
299
299
|
|
|
300
|
+
## External API & CLI
|
|
301
|
+
|
|
302
|
+
Besides DSH's internal port, the plugin can also run a **standalone HTTP external API** (default `http://127.0.0.1:8790`, Bearer token auth) so other plugins, CLI scripts, or desktop tools can read and write memories without depending on DSH's internal port.
|
|
303
|
+
|
|
304
|
+
### Enabling & Authentication
|
|
305
|
+
|
|
306
|
+
- Enable the external API in the plugin settings (it listens on `127.0.0.1:8790` by default, local machine only);
|
|
307
|
+
- The access token can be found in the plugin settings / the panel under "Settings → External Access";
|
|
308
|
+
- Except for `GET /health` (no auth), all routes require an `Authorization: Bearer <token>` header; an invalid token returns `401 {"error":"unauthorized"}`.
|
|
309
|
+
|
|
310
|
+
Main routes:
|
|
311
|
+
|
|
312
|
+
| Method | Route | Description |
|
|
313
|
+
|--------|-------|-------------|
|
|
314
|
+
| `GET` | `/health` | Health check (no auth), returns `{ok:true}` |
|
|
315
|
+
| `GET` | `/status` | Version, memory stats, entity count, uptime |
|
|
316
|
+
| `GET` | `/memories?limit&offset&type&minImportance&source&order=chrono` | List memories with pagination |
|
|
317
|
+
| `GET` | `/memories/:id` | A single memory |
|
|
318
|
+
| `POST` | `/memories` | Create a memory `{type,title,content,importance?,tags?,source?}` |
|
|
319
|
+
| `DELETE` | `/memories/:id` | Delete a memory |
|
|
320
|
+
| `GET` | `/search?q&mode=keyword\|vector\|auto&topK` | Search (keyword / vector / auto) |
|
|
321
|
+
|
|
322
|
+
### curl Examples
|
|
323
|
+
|
|
324
|
+
```bash
|
|
325
|
+
# Service status
|
|
326
|
+
curl -s -H "Authorization: Bearer $DSH_MNEME_TOKEN" http://127.0.0.1:8790/status
|
|
327
|
+
|
|
328
|
+
# List the 5 most recent memories
|
|
329
|
+
curl -s -H "Authorization: Bearer $DSH_MNEME_TOKEN" \
|
|
330
|
+
"http://127.0.0.1:8790/memories?limit=5"
|
|
331
|
+
|
|
332
|
+
# Add a decision memory
|
|
333
|
+
curl -s -X POST http://127.0.0.1:8790/memories \
|
|
334
|
+
-H "Authorization: Bearer $DSH_MNEME_TOKEN" \
|
|
335
|
+
-H "Content-Type: application/json" \
|
|
336
|
+
-d '{"type":"decision","title":"Adopt SQLite","content":"Storage layer uses node:sqlite","importance":4,"tags":["storage"]}'
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
### Installing the CLI
|
|
340
|
+
|
|
341
|
+
The plugin ships a zero-dependency CLI (published with the npm package):
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
npm i -g @modusensus/dsh-mneme
|
|
345
|
+
dsh-mneme --help
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
On first use, configure the server URL and token (you can also use the `DSH_MNEME_URL` / `DSH_MNEME_TOKEN` environment variables, or override temporarily with `--url` / `--token`):
|
|
349
|
+
|
|
350
|
+
```bash
|
|
351
|
+
dsh-mneme config set http://127.0.0.1:8790 <your-token>
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### Common CLI Commands
|
|
355
|
+
|
|
356
|
+
```bash
|
|
357
|
+
dsh-mneme status # Service status
|
|
358
|
+
dsh-mneme list --type project --limit 10 # List memories
|
|
359
|
+
dsh-mneme search "deploy pipeline" --mode vector --topk 5 # Semantic search
|
|
360
|
+
dsh-mneme add --type decision --title "Adopt SQLite" \
|
|
361
|
+
--content "Storage layer uses node:sqlite" --importance 4 --tags storage
|
|
362
|
+
dsh-mneme get 42 # Show one memory
|
|
363
|
+
dsh-mneme delete 42 # Delete
|
|
364
|
+
dsh-mneme config show # Show current config (token masked)
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
> All read/write commands support `--json` for raw JSON output; `config path` prints the config file location (`~/.dsh-mneme/cli.json`).
|
|
368
|
+
|
|
300
369
|
## 🏗️ Architecture
|
|
301
370
|
|
|
302
371
|
```
|
package/README.md
CHANGED
|
@@ -297,6 +297,75 @@ dsh web
|
|
|
297
297
|
|
|
298
298
|
> 🔐 **API 安全**:DSH 无内置鉴权且默认仅监听 `127.0.0.1`。插件 API 默认开放(便于 Web 面板即装即用)。如需防护(如局域网暴露),在配置中设置 `apiToken`:写操作(画像/规则/命令)与密钥端点(`vector-config`、`vector-reindex`)需携带 `Authorization: Bearer <token>`(前端设置面板可填入同一 token),只读的 `list` / `search` / `semantic` 保持开放。`/api/dsh-mneme/vector-config` 返回的 `apiKey` 已掩码(`sk-***…`),存储仍保留明文供调用;前端回传空或掩码值表示"不改 key"。
|
|
299
299
|
|
|
300
|
+
## 外部 API 与 CLI
|
|
301
|
+
|
|
302
|
+
除 DSH 内部端口外,插件还可以开启一个**独立的 HTTP 外部 API**(默认 `http://127.0.0.1:8790`,Bearer token 鉴权),供其他插件、CLI 脚本或桌面工具读写记忆,不依赖 DSH 内部端口。
|
|
303
|
+
|
|
304
|
+
### 启用与鉴权
|
|
305
|
+
|
|
306
|
+
- 在插件设置中开启外部 API(默认监听 `127.0.0.1:8790`,仅本机可访问);
|
|
307
|
+
- 访问 token 在插件设置 / 面板「设置 → 外部访问」中查看;
|
|
308
|
+
- 除 `GET /health`(免鉴权)外,所有路由需携带 `Authorization: Bearer <token>`,无效 token 返回 `401 {"error":"unauthorized"}`。
|
|
309
|
+
|
|
310
|
+
主要路由:
|
|
311
|
+
|
|
312
|
+
| 方法 | 路由 | 说明 |
|
|
313
|
+
|------|------|------|
|
|
314
|
+
| `GET` | `/health` | 健康检查(免鉴权),返回 `{ok:true}` |
|
|
315
|
+
| `GET` | `/status` | 版本、记忆统计、实体数、运行时长 |
|
|
316
|
+
| `GET` | `/memories?limit&offset&type&minImportance&source&order=chrono` | 分页列出记忆 |
|
|
317
|
+
| `GET` | `/memories/:id` | 单条记忆 |
|
|
318
|
+
| `POST` | `/memories` | 新增记忆 `{type,title,content,importance?,tags?,source?}` |
|
|
319
|
+
| `DELETE` | `/memories/:id` | 删除记忆 |
|
|
320
|
+
| `GET` | `/search?q&mode=keyword\|vector\|auto&topK` | 搜索(关键词 / 向量 / 自动) |
|
|
321
|
+
|
|
322
|
+
### curl 示例
|
|
323
|
+
|
|
324
|
+
```bash
|
|
325
|
+
# 服务状态
|
|
326
|
+
curl -s -H "Authorization: Bearer $DSH_MNEME_TOKEN" http://127.0.0.1:8790/status
|
|
327
|
+
|
|
328
|
+
# 列出最近 5 条记忆
|
|
329
|
+
curl -s -H "Authorization: Bearer $DSH_MNEME_TOKEN" \
|
|
330
|
+
"http://127.0.0.1:8790/memories?limit=5"
|
|
331
|
+
|
|
332
|
+
# 新增一条决策记忆
|
|
333
|
+
curl -s -X POST http://127.0.0.1:8790/memories \
|
|
334
|
+
-H "Authorization: Bearer $DSH_MNEME_TOKEN" \
|
|
335
|
+
-H "Content-Type: application/json" \
|
|
336
|
+
-d '{"type":"decision","title":"采用 SQLite","content":"存储层使用 node:sqlite","importance":4,"tags":["存储"]}'
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
### CLI 安装
|
|
340
|
+
|
|
341
|
+
插件自带零依赖 CLI(随 npm 包一起发布):
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
npm i -g @modusensus/dsh-mneme
|
|
345
|
+
dsh-mneme --help
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
首次使用先配置服务地址与 token(也可用环境变量 `DSH_MNEME_URL` / `DSH_MNEME_TOKEN`,或 `--url` / `--token` 参数临时覆盖):
|
|
349
|
+
|
|
350
|
+
```bash
|
|
351
|
+
dsh-mneme config set http://127.0.0.1:8790 <你的token>
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### CLI 常用命令
|
|
355
|
+
|
|
356
|
+
```bash
|
|
357
|
+
dsh-mneme status # 服务状态
|
|
358
|
+
dsh-mneme list --type project --limit 10 # 列出记忆
|
|
359
|
+
dsh-mneme search "部署流程" --mode vector --topk 5 # 语义搜索
|
|
360
|
+
dsh-mneme add --type decision --title "采用 SQLite" \
|
|
361
|
+
--content "存储层使用 node:sqlite" --importance 4 --tags 存储,决策
|
|
362
|
+
dsh-mneme get 42 # 查看单条
|
|
363
|
+
dsh-mneme delete 42 # 删除
|
|
364
|
+
dsh-mneme config show # 查看当前配置(token 打码)
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
> 所有读取/写入命令支持 `--json` 输出原始 JSON;`config path` 打印配置文件路径(`~/.dsh-mneme/cli.json`)。
|
|
368
|
+
|
|
300
369
|
## 🏗️ 架构
|
|
301
370
|
|
|
302
371
|
```
|