claw_messenger 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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +577 -0
  3. package/bin/auto-init.js +104 -0
  4. package/bin/cli.js +5 -0
  5. package/bin/diagnose-plugin.js +174 -0
  6. package/bin/dm-bridge.cjs +12 -0
  7. package/bin/install.js +452 -0
  8. package/bin/postinstall.js +23 -0
  9. package/bin/qr-crypto-node.js +186 -0
  10. package/bin/setup.js +262 -0
  11. package/dist/auto-register.d.ts +49 -0
  12. package/dist/auto-register.js +328 -0
  13. package/dist/bridge-runner.d.ts +1 -0
  14. package/dist/bridge-runner.js +107 -0
  15. package/dist/cli.d.ts +2 -0
  16. package/dist/cli.js +164 -0
  17. package/dist/device-status.d.ts +30 -0
  18. package/dist/device-status.js +109 -0
  19. package/dist/env-polyfill.d.ts +3 -0
  20. package/dist/env-polyfill.js +166 -0
  21. package/dist/group-config-manager.d.ts +22 -0
  22. package/dist/group-config-manager.js +130 -0
  23. package/dist/index.d.ts +17 -0
  24. package/dist/index.js +36 -0
  25. package/dist/logger.d.ts +14 -0
  26. package/dist/logger.js +103 -0
  27. package/dist/mac-address.d.ts +1 -0
  28. package/dist/mac-address.js +46 -0
  29. package/dist/openclaw-client.d.ts +41 -0
  30. package/dist/openclaw-client.js +530 -0
  31. package/dist/openclaw-config.d.ts +41 -0
  32. package/dist/openclaw-config.js +359 -0
  33. package/dist/openclaw.plugin.json +40 -0
  34. package/dist/package.json +112 -0
  35. package/dist/plugin-entry.d.ts +54 -0
  36. package/dist/plugin-entry.js +772 -0
  37. package/dist/postinstall.js +23 -0
  38. package/dist/rongcloud-client.d.ts +16 -0
  39. package/dist/rongcloud-client.js +274 -0
  40. package/dist/rongcloud-server-api.d.ts +53 -0
  41. package/dist/rongcloud-server-api.js +221 -0
  42. package/dist/utils.d.ts +9 -0
  43. package/dist/utils.js +97 -0
  44. package/openclaw.plugin.json +40 -0
  45. package/package.json +112 -0
package/dist/utils.js ADDED
@@ -0,0 +1,97 @@
1
+ import { spawn } from 'child_process';
2
+ import { getOpenClawEnv } from './openclaw-client.js';
3
+ const OPENCLAW_TIMEOUT_MS = 120000;
4
+ const MAX_OUTPUT_BYTES = 1024 * 1024;
5
+ /**
6
+ * 清洗 OpenClaw CLI 输出:去除 ANSI 转义码、过滤配置/插件日志噪音
7
+ */
8
+ export function cleanOpenClawOutput(output) {
9
+ return output
10
+ .split('\n')
11
+ .map(line => line.replace(/\x1B\[[0-9;]*m/g, '').trim())
12
+ .filter(line => {
13
+ if (!line)
14
+ return false;
15
+ if (line.startsWith('[OpenClawConfig]'))
16
+ return false;
17
+ if (line.startsWith('[plugins]'))
18
+ return false;
19
+ if (line.includes('虾说 IM 插件已注册'))
20
+ return false;
21
+ if (line.includes('虾说 IM'))
22
+ return false;
23
+ if (line.includes('龙虾信使插件已注册'))
24
+ return false;
25
+ if (line.includes('龙虾信使'))
26
+ return false;
27
+ if (line.includes('已加载配置文件'))
28
+ return false;
29
+ if (line.includes('plugins.allow'))
30
+ return false;
31
+ if (line.includes('Config warnings'))
32
+ return false;
33
+ if (line.includes('stale config'))
34
+ return false;
35
+ if (line.includes('plugin not found'))
36
+ return false;
37
+ return true;
38
+ })
39
+ .join('\n')
40
+ .trim();
41
+ }
42
+ /**
43
+ * 使用 spawn + 参数数组调用 openclaw CLI,避免 shell 注入风险
44
+ * @returns 清洗后的输出字符串;出错时返回可读错误信息,不会抛异常
45
+ */
46
+ export function spawnOpenClaw(args, timeoutMs = OPENCLAW_TIMEOUT_MS) {
47
+ return new Promise((resolve) => {
48
+ var _a, _b;
49
+ const isWindows = process.platform === 'win32';
50
+ const child = spawn('openclaw', args, {
51
+ shell: isWindows,
52
+ env: getOpenClawEnv(),
53
+ windowsHide: true,
54
+ });
55
+ let stdoutChunks = [];
56
+ let stderrChunks = [];
57
+ let killed = false;
58
+ let outputBytes = 0;
59
+ const timer = setTimeout(() => {
60
+ killed = true;
61
+ child.kill();
62
+ }, timeoutMs);
63
+ const accumulate = (data, chunks) => {
64
+ const chunk = data.toString();
65
+ outputBytes += Buffer.byteLength(chunk, 'utf8');
66
+ if (outputBytes > MAX_OUTPUT_BYTES) {
67
+ killed = true;
68
+ child.kill();
69
+ return;
70
+ }
71
+ chunks.push(chunk);
72
+ };
73
+ (_a = child.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => accumulate(data, stdoutChunks));
74
+ (_b = child.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (data) => accumulate(data, stderrChunks));
75
+ child.on('error', (err) => {
76
+ clearTimeout(timer);
77
+ if (err.code === 'ENOENT') {
78
+ resolve('找不到 openclaw 命令');
79
+ }
80
+ else {
81
+ resolve(`OpenClaw 调用失败: ${err.message}`);
82
+ }
83
+ });
84
+ child.on('close', () => {
85
+ clearTimeout(timer);
86
+ if (killed) {
87
+ resolve('OpenClaw 响应超时');
88
+ return;
89
+ }
90
+ const stdout = stdoutChunks.join('');
91
+ const stderr = stderrChunks.join('');
92
+ const output = stdout || stderr || '';
93
+ const clean = cleanOpenClawOutput(output);
94
+ resolve(clean || 'OpenClaw 未返回有效响应');
95
+ });
96
+ });
97
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "id": "claw_messenger",
3
+ "name": "claw_messenger",
4
+ "description": "虾说 IM 直连通道插件,支持私聊、群聊、流式消息",
5
+ "version": "2.1.2",
6
+ "author": "",
7
+ "license": "MIT",
8
+ "repository": "https://github.com/quukk/clawmessenger",
9
+ "keywords": ["claw-messenger", "im", "chat", "channel"],
10
+ "entry": "./dist/plugin-entry.js",
11
+ "channels": ["claw_messenger"],
12
+ "channelConfigs": {
13
+ "claw_messenger": {
14
+ "schema": {
15
+ "type": "object",
16
+ "additionalProperties": true,
17
+ "properties": {
18
+ "nodeName": {
19
+ "type": "string",
20
+ "label": "节点昵称",
21
+ "description": "在虾说 IM 中显示的节点名称"
22
+ }
23
+ }
24
+ },
25
+ "label": "虾说 IM",
26
+ "description": "通过融云 IM 连接虾说消息系统",
27
+ "preferOver": []
28
+ }
29
+ },
30
+ "configSchema": {
31
+ "type": "object",
32
+ "additionalProperties": true,
33
+ "properties": {
34
+ "nodeName": {
35
+ "type": "string",
36
+ "label": "节点昵称"
37
+ }
38
+ }
39
+ }
40
+ }
package/package.json ADDED
@@ -0,0 +1,112 @@
1
+ {
2
+ "name": "claw_messenger",
3
+ "version": "1.0.0",
4
+ "description": "OpenClaw 插件 - 虾说应用桥接",
5
+ "type": "module",
6
+ "main": "dist/plugin-entry.js",
7
+ "types": "dist/index.d.ts",
8
+ "bin": {
9
+ "claw_messenger": "bin/install.js",
10
+ "claw-messenger": "bin/install.js",
11
+ "claw-messenger-bridge": "bin/install.js",
12
+ "claw-bridge": "dist/bridge-runner.js",
13
+ "claw-bridge-setup": "bin/setup.js",
14
+ "clawmessenger": "bin/cli.js"
15
+ },
16
+ "files": [
17
+ "bin",
18
+ "dist",
19
+ "package.json",
20
+ "openclaw.plugin.json",
21
+ "README.md"
22
+ ],
23
+ "openclaw": {
24
+ "extensions": [
25
+ "./dist/plugin-entry.js"
26
+ ],
27
+ "channel": {
28
+ "id": "claw_messenger",
29
+ "label": "claw_messenger",
30
+ "selectionLabel": "虾说 IM",
31
+ "docsPath": "/channels/claw_messenger",
32
+ "blurb": "claw_messenger IM channel for OpenClaw",
33
+ "order": 80
34
+ },
35
+ "compat": {
36
+ "pluginApi": ">=2.0.0"
37
+ },
38
+ "install": {
39
+ "npmSpec": "claw_messenger",
40
+ "defaultChoice": "npx",
41
+ "minHostVersion": ">=2026.3.24"
42
+ }
43
+ },
44
+ "scripts": {
45
+ "build": "node ./node_modules/typescript/bin/tsc && copy /Y package.json dist\\ && copy /Y openclaw.plugin.json dist\\ && copy /Y bin\\postinstall.js dist\\postinstall.js",
46
+ "setup": "npm run build && node bin/install.js",
47
+ "install-local": "node bin/install.js",
48
+ "start": "node bin/dm-bridge.cjs",
49
+ "bridge": "ts-node bridge-runner.ts",
50
+ "test": "vitest run",
51
+ "test:watch": "vitest",
52
+ "test:coverage": "vitest run --coverage",
53
+ "prepublishOnly": "npm run build",
54
+ "postinstall": "node dist/postinstall.js",
55
+ "publish:patch": "npm version patch && npm publish",
56
+ "publish:minor": "npm version minor && npm publish",
57
+ "publish:major": "npm version major && npm publish",
58
+ "unpublish:last": "node scripts/unpublish.js",
59
+ "unpublish:version": "node scripts/unpublish.js",
60
+ "deprecate:last": "npm deprecate $(node -p \"require('./package.json').name\")@$(node -p \"require('./package.json').version\") \"This version is deprecated. Please upgrade.\"",
61
+ "deprecate:version": "npm deprecate"
62
+ },
63
+ "keywords": [
64
+ "openclaw",
65
+ "claw-messenger",
66
+ "im",
67
+ "chat",
68
+ "bridge",
69
+ "ai"
70
+ ],
71
+ "author": "",
72
+ "license": "MIT",
73
+ "repository": {
74
+ "type": "git",
75
+ "url": "git+https://github.com/quukk/clawmessenger.git"
76
+ },
77
+ "bugs": {
78
+ "url": "https://github.com/quukk/clawmessenger/issues"
79
+ },
80
+ "homepage": "https://github.com/quukk/clawmessenger#readme",
81
+ "dependencies": {
82
+ "@rongcloud/engine": "^5.36.6",
83
+ "@rongcloud/imlib-next": "^5.36.6",
84
+ "axios": "^1.15.0",
85
+ "fake-indexeddb": "^6.2.5",
86
+ "jsdom": "^24.0.0",
87
+ "qrcode-terminal": "^0.12.0",
88
+ "ws": "^8.16.0"
89
+ },
90
+ "peerDependencies": {
91
+ "openclaw": ">=2026.3.24"
92
+ },
93
+ "peerDependenciesMeta": {
94
+ "openclaw": {
95
+ "optional": true
96
+ }
97
+ },
98
+ "devDependencies": {
99
+ "@types/jsdom": "^21.1.6",
100
+ "@types/node": "^20.11.0",
101
+ "@types/qrcode-terminal": "^0.12.2",
102
+ "@types/ws": "^8.5.10",
103
+ "@vitest/coverage-v8": "^1.6.1",
104
+ "ts-node": "^10.9.2",
105
+ "tsx": "^4.7.0",
106
+ "typescript": "^5.3.3",
107
+ "vitest": "^1.6.1"
108
+ },
109
+ "engines": {
110
+ "node": ">=16.0.0"
111
+ }
112
+ }