@53ai/53ai-openclaw 1.0.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,26 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6
+
7
+ ## [1.0.0] - 2025-03-17
8
+
9
+ ### Added
10
+ - Initial release
11
+ - WebSocket real-time communication support
12
+ - Direct message (DM) mode support
13
+ - Multi-modal message support (images, files)
14
+ - "Thinking" message support for user feedback
15
+ - Access policy control (open, allowlist, pairing)
16
+ - Persistent request ID storage
17
+
18
+ ### Changed
19
+ - Security fix: Removed credentials from URL query parameters
20
+ - Fixed empty catch blocks with proper logging
21
+ - Fixed potential WebSocket memory leak with cleanup on all error paths
22
+ - Fixed message race condition with sequential queue processing
23
+ - Reduced max reconnect attempts from 100 to 10
24
+
25
+ ### Fixed
26
+ - Type safety improvements: replaced `any` types with proper interfaces
package/README.md ADDED
@@ -0,0 +1,424 @@
1
+ # 53AI OpenClaw 插件
2
+
3
+ 53AIHub (AgentHub) 智能机器人接入 OpenClaw 的通道插件。
4
+
5
+ ## 功能
6
+
7
+ - 将 53AIHub/AgentHub 智能体接入 OpenClaw
8
+ - 支持直接消息 (DM) 模式
9
+ - 支持 WebSocket 实时通信
10
+ - **支持多模态消息**(图片、文件)
11
+ - 支持 AI 生成的图片/文件发送给用户
12
+ - **支持"思考中"消息** - 用户发送消息后立即收到反馈
13
+
14
+ ## 安装方式
15
+
16
+ ### 方式一:从 npm 安装(推荐)
17
+
18
+ ```bash
19
+ # 使用 npm 安装
20
+ npm install @53ai/53ai-openclaw
21
+
22
+ # 或使用 openclaw CLI
23
+ openclaw plugins install @53ai/53ai-openclaw
24
+
25
+ # 指定版本
26
+ openclaw plugins install @53ai/53ai-openclaw@1.0.0
27
+ ```
28
+
29
+ ### 方式二:本地开发调试安装
30
+
31
+ 适用于插件开发阶段,支持热更新。
32
+
33
+ ```bash
34
+ # 在插件目录下构建
35
+ cd 53ai-openclaw
36
+ npm install
37
+ npm run build
38
+
39
+ # 方式 A: 链式安装 (推荐开发时使用,修改后只需重启 gateway)
40
+ openclaw plugins install -l /path/to/53ai-openclaw
41
+
42
+ # 方式 B: 复制到扩展目录
43
+ mkdir -p ~/.openclaw/extensions/53aihub
44
+ cp -r dist openclaw.plugin.json package.json ~/.openclaw/extensions/53aihub/
45
+ cd ~/.openclaw/extensions/53aihub && npm install --production
46
+ ```
47
+
48
+ ### 方式三:npm pack 打包安装
49
+
50
+ 适用于分发 tarball 文件,无需 npm 发布。
51
+
52
+ **打包:**
53
+ ```bash
54
+ cd 53ai-openclaw
55
+ npm run clean && npm install && npm run build
56
+ npm pack
57
+ # 生成: 53ai-openclaw-1.0.0.tgz
58
+ ```
59
+
60
+ **安装:**
61
+ ```bash
62
+ # 从本地 tarball 安装
63
+ openclaw plugins install ./53ai-openclaw-1.0.0.tgz
64
+
65
+ # 或从远程 URL 安装
66
+ openclaw plugins install https://your-server.com/53ai-openclaw-1.0.0.tgz
67
+ ```
68
+
69
+ ### 方式四:从 Git 仓库安装
70
+
71
+ ```bash
72
+ openclaw plugins install git@github.com:53ai/53ai-openclaw.git
73
+ ```
74
+
75
+ ## 配置
76
+
77
+ 安装插件后,重启 Gateway 并配置通道:
78
+
79
+ ```bash
80
+ # 重启 Gateway
81
+ openclaw gateway restart
82
+ # 或 systemd 服务
83
+ sudo systemctl restart openclaw-gateway
84
+
85
+ # 配置必要参数
86
+ openclaw config set channels.53aihub.botId "智能体详情的botId"
87
+ openclaw config set channels.53aihub.secret "智能体详情的botId对应的secret"
88
+ openclaw config set channels.53aihub.websocketUrl "ws://域名/api/v1/openclaw/ws/connect"
89
+
90
+ # 启用通道
91
+ openclaw config set channels.53aihub.enabled true
92
+ ```
93
+
94
+ ### 配置参数说明
95
+
96
+ | 参数 | 必填 | 默认值 | 说明 |
97
+ |------|------|--------|------|
98
+ | `botId` | 是 | - | AgentHub 智能体 ID (HashID) |
99
+ | `secret` | 是 | - | AgentHub App Secret / Token |
100
+ | `websocketUrl` | 是 | - | AgentHub WebSocket 连接地址 |
101
+ | `token` | 否 | - | secret 的别名,与 secret 二选一 |
102
+ | `enabled` | 否 | false | 是否启用通道 |
103
+ | `accessPolicy` | 否 | `open` | 访问策略: `open`=开放所有用户, `allowlist`=仅白名单用户, `pairing`=首次使用需审批, `disabled`=禁用 |
104
+ | `allowFrom` | 否 | - | 访问控制白名单,配合 accessPolicy=allowlist 或 pairing 使用 |
105
+ | `sendThinkingMessage` | 否 | true | 是否发送"思考中"提示消息 |
106
+
107
+ ### 访问控制配置示例
108
+
109
+ **白名单模式** - 仅允许指定用户访问:
110
+ ```bash
111
+ openclaw config set channels.53aihub.accessPolicy "allowlist"
112
+ openclaw config set channels.53aihub.allowFrom '["user-123", "user-456"]'
113
+ ```
114
+
115
+ **配对审批模式** - 首次使用需管理员审批:
116
+ ```bash
117
+ openclaw config set channels.53aihub.accessPolicy "pairing"
118
+ openclaw config set channels.53aihub.allowFrom '["user-789"]'
119
+ ```
120
+
121
+ **开放模式** - 允许所有用户访问(默认):
122
+ ```bash
123
+ openclaw config set channels.53aihub.accessPolicy "open"
124
+ ```
125
+
126
+ ### 查看配置状态
127
+
128
+ ```bash
129
+ # 查看通道状态
130
+ openclaw channels status
131
+
132
+ # 查看插件详情
133
+ openclaw plugins info 53aihub
134
+ ```
135
+
136
+ ## 验证安装
137
+
138
+ ```bash
139
+ # 检查插件是否加载
140
+ openclaw plugins list | grep 53aihub
141
+
142
+ # 检查通道配置
143
+ openclaw config get channels.53aihub
144
+
145
+ # 检查 Gateway 日志
146
+ openclaw gateway logs | grep -i 53aihub
147
+ ```
148
+
149
+ ## 多模态消息支持
150
+
151
+ 插件支持接收和发送多模态消息(图片、文件)。
152
+
153
+ ### 接收多模态消息
154
+
155
+ 当用户发送包含图片或文件的消息时,插件会自动解析并处理:
156
+
157
+ **用户发送图片** → 插件接收 `AgentHubIncomingMessage`:
158
+ ```typescript
159
+ {
160
+ type: "message",
161
+ msgId: "msg-xxx",
162
+ chatId: "user-123",
163
+ text: "这张图片是什么?",
164
+ imageUrls: ["https://example.com/image.png"],
165
+ contentItems: [
166
+ { type: "text", text: "这张图片是什么?" },
167
+ { type: "image", image: { url: "https://example.com/image.png" } }
168
+ ]
169
+ }
170
+ ```
171
+
172
+ **用户发送文件**:
173
+ ```typescript
174
+ {
175
+ type: "message",
176
+ msgId: "msg-xxx",
177
+ text: "请分析这个文档",
178
+ fileUrls: ["https://example.com/document.pdf"],
179
+ contentItems: [
180
+ { type: "text", text: "请分析这个文档" },
181
+ { type: "file", file: { url: "https://example.com/document.pdf", filename: "document.pdf" } }
182
+ ]
183
+ }
184
+ ```
185
+
186
+ ### 发送媒体消息给用户
187
+
188
+ AI 可以主动发送图片或文件给用户:
189
+
190
+ **发送图片**:
191
+ ```typescript
192
+ import { sendMediaMessage } from "./message-sender.js";
193
+
194
+ await sendMediaMessage(wsClient, "user-123", {
195
+ type: "image",
196
+ url: "https://example.com/generated-image.png",
197
+ mimeType: "image/png"
198
+ }, "这是生成的图片");
199
+ ```
200
+
201
+ **发送文件**:
202
+ ```typescript
203
+ await sendMediaMessage(wsClient, "user-123", {
204
+ type: "file",
205
+ url: "https://example.com/report.pdf",
206
+ filename: "report.pdf",
207
+ mimeType: "application/pdf"
208
+ }, "分析报告已生成");
209
+ ```
210
+
211
+ **发送 Base64 图片**:
212
+ ```typescript
213
+ await sendMediaMessage(wsClient, "user-123", {
214
+ type: "image",
215
+ base64: "iVBORw0KGgoAAAANS...",
216
+ mimeType: "image/png"
217
+ }, "图片已生成");
218
+ ```
219
+
220
+ ### 媒体消息格式
221
+
222
+ **发送格式** (`action: "message"`):
223
+ ```json
224
+ {
225
+ "req_id": "msg-xxx",
226
+ "action": "message",
227
+ "status": "final",
228
+ "data": {
229
+ "toChatId": "user-123",
230
+ "text": "这是图片描述",
231
+ "media": {
232
+ "type": "image",
233
+ "url": "https://example.com/image.png",
234
+ "mimeType": "image/png"
235
+ }
236
+ }
237
+ }
238
+ ```
239
+
240
+ **Media 字段说明**:
241
+
242
+ | 字段 | 类型 | 说明 |
243
+ |------|------|------|
244
+ | `type` | string | `"image"` 或 `"file"` |
245
+ | `url` | string | 媒体文件 URL(与 base64 二选一) |
246
+ | `base64` | string | Base64 编码数据(与 url 二选一) |
247
+ | `mimeType` | string | MIME 类型,如 `image/png`、`application/pdf` |
248
+ | `filename` | string | 文件名(仅 file 类型需要) |
249
+
250
+ ---
251
+
252
+ ## 发布到 NPM
253
+
254
+ 本插件已发布到 npmjs.com,包名为 `@53ai/53ai-openclaw`。
255
+
256
+ ### 开发者发布流程
257
+
258
+ #### 前置条件
259
+
260
+ 1. 拥有 npmjs.com 账号并登录:
261
+ ```bash
262
+ npm login --registry=https://registry.npmjs.org/
263
+ ```
264
+
265
+ 2. 确认登录状态:
266
+ ```bash
267
+ npm whoami
268
+ ```
269
+
270
+ #### 发布新版本
271
+
272
+ ```bash
273
+ # 方式一:使用 npm scripts(推荐)
274
+ npm run release # 发布当前版本(不升级版本号)
275
+ npm run release:patch # 升级补丁版本 (1.0.0 -> 1.0.1)
276
+ npm run release:minor # 升级次版本 (1.0.0 -> 1.1.0)
277
+ npm run release:major # 升级主版本 (1.0.0 -> 2.0.0)
278
+
279
+ # 方式二:直接使用脚本
280
+ bash scripts/publish.sh # 发布当前版本
281
+ bash scripts/publish.sh patch # 升级补丁版本
282
+ bash scripts/publish.sh 2.0.0 # 指定版本号发布
283
+ ```
284
+
285
+ #### 发布脚本功能
286
+
287
+ `scripts/publish.sh` 会自动执行以下步骤:
288
+
289
+ | 步骤 | 说明 |
290
+ |------|------|
291
+ | 1. 检查 npm 登录 | 验证是否已登录 npm |
292
+ | 2. 检查 git 状态 | 提示未提交的更改 |
293
+ | 3. 运行测试 | 如有测试配置则执行 |
294
+ | 4. 升级版本号 | 可选,根据参数决定 |
295
+ | 5. 构建项目 | 执行 `npm run build` |
296
+ | 6. 预览发布文件 | 显示将要发布的文件列表 |
297
+ | 7. 确认发布 | 交互式确认后发布 |
298
+ | 8. 创建 git 标签 | 自动创建版本标签 |
299
+
300
+ #### 发布后验证
301
+
302
+ ```bash
303
+ # 查看包信息
304
+ npm info @53ai/53ai-openclaw
305
+
306
+ # 查看所有版本
307
+ npm view @53ai/53ai-openclaw versions
308
+
309
+ # 访问 npm 页面
310
+ # https://www.npmjs.com/package/@53ai/53ai-openclaw
311
+ ```
312
+
313
+ ### 版本更新策略
314
+
315
+ | 命令 | 版本变化 | 适用场景 |
316
+ |------|----------|----------|
317
+ | `npm run release:patch` | 1.0.0 → 1.0.1 | Bug 修复 |
318
+ | `npm run release:minor` | 1.0.0 → 1.1.0 | 新功能添加(向后兼容) |
319
+ | `npm run release:major` | 1.0.0 → 2.0.0 | 破坏性变更 |
320
+
321
+ ### 自动化发布(CI/CD)
322
+
323
+ 如需在 CI/CD 环境中自动发布,可配置 npm token:
324
+
325
+ ```bash
326
+ # 设置 npm token(在 CI 环境中)
327
+ echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> ~/.npmrc
328
+
329
+ # 非交互式发布
330
+ npm publish --access public
331
+ ```
332
+
333
+ **GitHub Actions 示例**:
334
+
335
+ ```yaml
336
+ # .github/workflows/publish.yml
337
+ name: Publish to npm
338
+
339
+ on:
340
+ release:
341
+ types: [created]
342
+
343
+ jobs:
344
+ publish:
345
+ runs-on: ubuntu-latest
346
+ steps:
347
+ - uses: actions/checkout@v4
348
+ - uses: actions/setup-node@v4
349
+ with:
350
+ node-version: '20'
351
+ registry-url: 'https://registry.npmjs.org'
352
+ - run: npm ci
353
+ - run: npm run build
354
+ - run: npm publish --access public
355
+ env:
356
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
357
+ ```
358
+
359
+ ---
360
+
361
+ ## 卸载
362
+
363
+ ```bash
364
+ # 清理配置
365
+ openclaw config delete channels.53aihub
366
+
367
+ # 移除插件
368
+ openclaw plugins uninstall 53ai-openclaw --force
369
+ ```
370
+
371
+ ---
372
+
373
+ ## 开发
374
+
375
+ ```bash
376
+ # 安装依赖
377
+ npm install
378
+
379
+ # 构建
380
+ npm run build
381
+
382
+ # 监听模式 (开发时)
383
+ npm run dev
384
+
385
+ # 清理构建产物
386
+ npm run clean
387
+
388
+ # 运行测试
389
+ npm test
390
+ ```
391
+
392
+ ---
393
+
394
+ ## 故障排查
395
+
396
+ ### 插件未加载
397
+
398
+ 1. 确认 `openclaw.plugin.json` 存在于插件根目录
399
+ 2. 确认 `dist/` 目录包含编译后的文件
400
+ 3. 检查 Gateway 日志: `openclaw gateway logs`
401
+
402
+ ### 通道未生效
403
+
404
+ 1. 确认 `channels.53aihub.enabled` 为 `true`
405
+ 2. 确认必填配置项已设置
406
+ 3. 重启 Gateway: `openclaw gateway restart`
407
+
408
+ ### WebSocket 连接失败
409
+
410
+ 1. 检查 `websocketUrl` 格式是否正确
411
+ 2. 确认网络可达性
412
+ 3. 检查 `botId` 和 `secret` 是否正确
413
+
414
+ ### 发布失败
415
+
416
+ 1. 确认已登录 npm: `npm whoami`
417
+ 2. 确认有权限发布 `@53ai` 作用域的包
418
+ 3. 检查版本号是否已存在: `npm view @53ai/53ai-openclaw versions`
419
+
420
+ ---
421
+
422
+ ## License
423
+
424
+ MIT