@xgjktech/xg_cwork_im 1.0.0 → 1.0.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/README.md +87 -27
- package/index.ts +3 -2
- package/package.json +2 -3
- package/src/channel.ts +536 -471
- package/src/connection.ts +150 -11
- package/src/group-history-tool.ts +57 -16
- package/src/send-group-message-tool.ts +20 -8
- package/src/send-service.ts +6 -0
- package/src/types.ts +38 -2
package/README.md
CHANGED
|
@@ -24,6 +24,8 @@ IM 系统 → WebSocket → 插件(本项目) → OpenClaw AI → IM
|
|
|
24
24
|
|
|
25
25
|
## 安装
|
|
26
26
|
|
|
27
|
+
推荐同事通过 **npm** 安装,无需访问内部 Git;需要改源码时再从内部仓库克隆(方法 B)。
|
|
28
|
+
|
|
27
29
|
### 方法 A:通过 npm 包安装(推荐)
|
|
28
30
|
|
|
29
31
|
一条命令完成安装,依赖由 OpenClaw 自动处理:
|
|
@@ -36,10 +38,10 @@ openclaw plugins install @xgjktech/xg_cwork_im
|
|
|
36
38
|
|
|
37
39
|
### 方法 B:通过本地源码安装
|
|
38
40
|
|
|
39
|
-
如需二次开发或无法使用 npm
|
|
41
|
+
如需二次开发或无法使用 npm 安装时,可从内部 Git 克隆后以链接模式安装:
|
|
40
42
|
|
|
41
43
|
```bash
|
|
42
|
-
git clone
|
|
44
|
+
git clone http://192.168.3.200/openclaw/openclaw-channel-xg-cwork-im.git
|
|
43
45
|
cd openclaw-channel-xg-cwork-im
|
|
44
46
|
npm install
|
|
45
47
|
openclaw plugins install -l .
|
|
@@ -71,6 +73,43 @@ NPM_CONFIG_REGISTRY=https://registry.npmmirror.com npm install
|
|
|
71
73
|
|
|
72
74
|
---
|
|
73
75
|
|
|
76
|
+
## 更新已安装的插件
|
|
77
|
+
|
|
78
|
+
当插件发布新版本后,已安装的用户可按以下方式更新。
|
|
79
|
+
|
|
80
|
+
### 通过 npm 安装的(方法 A)
|
|
81
|
+
|
|
82
|
+
使用**插件 id**(不是 npm 包名)执行更新:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
openclaw plugins update xg_cwork_im
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
更新完成后执行 `openclaw gateway restart` 使新版本生效。
|
|
89
|
+
|
|
90
|
+
国内网络可临时指定镜像源后再更新:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
NPM_CONFIG_REGISTRY=https://registry.npmmirror.com openclaw plugins update xg_cwork_im
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### 通过本地源码 / 链接安装的(方法 B)
|
|
97
|
+
|
|
98
|
+
在插件目录拉取最新代码后重启网关:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
cd openclaw-channel-xg-cwork-im # 进入当时克隆的目录
|
|
102
|
+
git pull
|
|
103
|
+
npm install
|
|
104
|
+
openclaw gateway restart
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### 手动安装的(方法 C)
|
|
108
|
+
|
|
109
|
+
重新从内部 Git 下载或复制最新代码到 `~/.openclaw/extensions/xg_cwork_im`,在该目录执行 `npm install --omit=dev` 或 `npm run install:prod`,再执行 `openclaw gateway restart`。
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
74
113
|
## 配置
|
|
75
114
|
|
|
76
115
|
### 步骤 1:启用并信任插件
|
|
@@ -214,6 +253,7 @@ openclaw-channel-xg-cwork-im/
|
|
|
214
253
|
│ ├── connection.ts # WebSocket 连接管理
|
|
215
254
|
│ ├── send-service.ts # IM 消息发送
|
|
216
255
|
│ ├── group-history-tool.ts # 拉取群消息历史的 Agent Tool
|
|
256
|
+
│ ├── send-group-message-tool.ts # 发送群消息的 Agent Tool
|
|
217
257
|
│ └── channel.ts # Channel Plugin 主定义
|
|
218
258
|
├── package.json
|
|
219
259
|
├── tsconfig.json
|
|
@@ -223,62 +263,82 @@ openclaw-channel-xg-cwork-im/
|
|
|
223
263
|
|
|
224
264
|
---
|
|
225
265
|
|
|
226
|
-
##
|
|
266
|
+
## 代码仓库与发布流程说明
|
|
227
267
|
|
|
228
|
-
|
|
268
|
+
- **代码仓库**:本项目在**内部 Git** 管理,地址:`http://192.168.3.200/openclaw/openclaw-channel-xg-cwork-im`,不推送到 GitHub。
|
|
269
|
+
- **安装方式**:同事安装请优先使用 **npm**(方法 A);需要改源码时从内部 Git 克隆(方法 B)。
|
|
270
|
+
- **发布流程**:在内部 Git 上开发、提交后,由维护者**发布到 npm**;同事通过 `openclaw plugins install @xgjktech/xg_cwork_im` 安装,无需访问 Git。
|
|
229
271
|
|
|
230
|
-
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## 维护者:如何发布到 npm(详细步骤)
|
|
275
|
+
|
|
276
|
+
代码在内部 Git 上维护,发布到 npm 后同事即可一条命令安装。按下列步骤操作。
|
|
277
|
+
|
|
278
|
+
### 步骤 1:在 npm 注册 / 登录
|
|
231
279
|
|
|
232
|
-
|
|
233
|
-
|
|
280
|
+
1. 无 npm 账号:打开 [https://www.npmjs.com/signup](https://www.npmjs.com/signup) 注册。
|
|
281
|
+
2. 在项目根目录执行:
|
|
234
282
|
|
|
235
283
|
```bash
|
|
236
284
|
npm login
|
|
237
285
|
```
|
|
238
286
|
|
|
239
|
-
按提示输入 Username
|
|
287
|
+
3. 按提示输入 **Username**、**Password**、**Email**。
|
|
288
|
+
4. 若账号开启了**双因素认证(2FA)**,发布时必须使用:
|
|
289
|
+
- 在 npm 网站 **Access Tokens** 里创建 **Granular Access Token**,勾选 **Publish packages**,并勾选 **Bypass 2FA**;或
|
|
290
|
+
- 在命令行登录时使用 **OTP**(一次性密码)。
|
|
291
|
+
否则会报错:`Two-factor authentication or granular access token with bypass 2fa enabled is required to publish packages`。
|
|
240
292
|
|
|
241
|
-
### 2
|
|
293
|
+
### 步骤 2:确认 scope 与权限
|
|
242
294
|
|
|
243
|
-
|
|
295
|
+
- 包名为 `@xgjktech/xg_cwork_im`,属于 **scope** `@xgjktech`。
|
|
296
|
+
- 在 [npm 官网](https://www.npmjs.com/) 登录 → **Organizations** → **Create**,创建组织名为 **xgjktech**,确保你的账号有该组织的发布权限。
|
|
297
|
+
- 若改用个人 scope(如 `@你的用户名/xg_cwork_im`),需修改 `package.json` 的 `"name"` 并同步改 README 中的安装命令。
|
|
244
298
|
|
|
245
|
-
|
|
246
|
-
- **使用个人 scope**:若你希望包名是个人 scope(如 `@你的用户名/xg_cwork_im`),需把 `package.json` 里的 `"name"` 改成 `@你的用户名/xg_cwork_im`,并同步修改 README 中的安装命令。
|
|
299
|
+
### 步骤 3:发布前检查
|
|
247
300
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
在仓库根目录执行:
|
|
301
|
+
在项目根目录执行:
|
|
251
302
|
|
|
252
303
|
```bash
|
|
253
|
-
# 查看将要随包发布的文件(与 package.json 的 "files" 一致)
|
|
254
304
|
npm pack --dry-run
|
|
255
305
|
```
|
|
256
306
|
|
|
257
|
-
|
|
307
|
+
确认列出的文件无敏感内容(如 `.env`、密钥)。发布内容由 `package.json` 的 `"files"` 控制。
|
|
258
308
|
|
|
259
|
-
### 4
|
|
309
|
+
### 步骤 4:执行发布
|
|
260
310
|
|
|
261
|
-
**scoped
|
|
311
|
+
**scoped 包必须加 `--access public`**,否则会按私有包计费并可能报 402:
|
|
262
312
|
|
|
263
313
|
```bash
|
|
264
314
|
npm publish --access public
|
|
265
315
|
```
|
|
266
316
|
|
|
267
|
-
|
|
317
|
+
成功后可在此查看:
|
|
318
|
+
[https://www.npmjs.com/package/@xgjktech/xg_cwork_im](https://www.npmjs.com/package/@xgjktech/xg_cwork_im)
|
|
319
|
+
|
|
320
|
+
### 步骤 5:后续更新(重新推送到 npm)
|
|
268
321
|
|
|
269
|
-
|
|
322
|
+
每次发新版本都按下面做一遍即可:
|
|
270
323
|
|
|
271
|
-
|
|
324
|
+
1. 在内部 Git 上改代码、提交、推送。
|
|
325
|
+
2. 在 **package.json** 里把 **version** 升高(如 `1.0.0` → `1.0.1`),保存。
|
|
326
|
+
3. 在项目根目录执行:
|
|
272
327
|
|
|
273
328
|
```bash
|
|
274
329
|
npm publish --access public
|
|
275
330
|
```
|
|
276
331
|
|
|
277
|
-
|
|
332
|
+
4. 通知同事执行 **更新已安装的插件**(见上文「更新已安装的插件」),例如:
|
|
333
|
+
`openclaw plugins update xg_cwork_im` → `openclaw gateway restart`。
|
|
334
|
+
|
|
335
|
+
(若该 scope 已发过公开包,有时可只执行 `npm publish`,建议仍带 `--access public` 避免误发成私有。)
|
|
278
336
|
|
|
279
337
|
### 常见问题
|
|
280
338
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
339
|
+
| 报错或现象 | 原因 | 处理 |
|
|
340
|
+
|-----------|------|------|
|
|
341
|
+
| **403 Forbidden**,且提示需 2FA 或 token | 账号开启 2FA 后,普通登录无法发布 | 使用 **Granular Access Token**(勾选 Publish + Bypass 2FA),或在发布时提供 OTP |
|
|
342
|
+
| **403 Forbidden**,无 2FA 提示 | 当前账号无 `@xgjktech` 发布权限 | 在 npm 创建/加入组织 `xgjktech`,或将包名改为个人 scope |
|
|
343
|
+
| **402 Payment Required** | 未加 `--access public`,scoped 包被视为私有 | 执行 `npm publish --access public` |
|
|
344
|
+
| 国内网络登录/发布慢或超时 | 默认 registry 在国外 | 登录:`npm login --registry=https://registry.npmjs.org/`;发布时也可加 `--registry=https://registry.npmjs.org/`,不推荐长期用第三方镜像发布 |
|
package/index.ts
CHANGED
|
@@ -22,8 +22,9 @@ const plugin: XgCworkImPluginModule = {
|
|
|
22
22
|
// 注册 AI 工具(静态工具对象,确保 toolNames 正确注册)
|
|
23
23
|
const cworkConfig = extractXgCworkImConfig(api.config);
|
|
24
24
|
if (cworkConfig) {
|
|
25
|
-
|
|
26
|
-
api.registerTool(
|
|
25
|
+
// 工具涉及网络请求 / 副作用,按文档要求标记为 optional,由用户在 Agent 的 tools.allow 中显式启用
|
|
26
|
+
api.registerTool(buildGroupHistoryTool(cworkConfig), { optional: true });
|
|
27
|
+
api.registerTool(buildSendGroupMessageTool(cworkConfig), { optional: true });
|
|
27
28
|
} else {
|
|
28
29
|
console.warn("[xg_cwork_im] channel config not found, skipping tool registration");
|
|
29
30
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xgjktech/xg_cwork_im",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "XG CWork IM channel plugin for OpenClaw",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bot",
|
|
7
7
|
"channel",
|
|
8
8
|
"openclaw",
|
|
9
|
-
"
|
|
9
|
+
"xg_cwork_im",
|
|
10
10
|
"im"
|
|
11
11
|
],
|
|
12
12
|
"license": "MIT",
|
|
@@ -51,7 +51,6 @@
|
|
|
51
51
|
"blurb": "小橙工作台 IM 机器人 Channel 插件,通过 WebSocket 长连接接收消息。",
|
|
52
52
|
"aliases": [
|
|
53
53
|
"xg_cwork_im",
|
|
54
|
-
"xgim",
|
|
55
54
|
"im"
|
|
56
55
|
]
|
|
57
56
|
},
|