claw-subagent-service 0.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/README.md +44 -0
- package/cli.js +254 -0
- package/command/linux/restart.sh +98 -0
- package/command/linux/start.sh +101 -0
- package/command/linux/status.sh +140 -0
- package/command/linux/stop.sh +112 -0
- package/command/win/restart.bat +39 -0
- package/command/win/start.bat +65 -0
- package/command/win/status.bat +52 -0
- package/command/win/stop.bat +55 -0
- package/command/win/windows/345/220/257/345/212/250/350/204/232/346/234/254 +0 -0
- package/package.json +37 -0
- package/scripts/install-silent.js +167 -0
- package/scripts/uninstall.js +61 -0
- package/service/daemon.js +189 -0
- package/service/logger.js +31 -0
- package/service/modules/auth.js +17 -0
- package/service/modules/business-message-handler.js +118 -0
- package/service/modules/command-handler.js +152 -0
- package/service/modules/config.js +44 -0
- package/service/modules/dashboard-collector.js +588 -0
- package/service/modules/heartbeat-dashboard.js +153 -0
- package/service/modules/mac-address.js +15 -0
- package/service/modules/message-processor-example.js +72 -0
- package/service/modules/message-processor.js +62 -0
- package/service/modules/normal-message-handler.js +60 -0
- package/service/modules/openclaw-control.js +128 -0
- package/service/modules/openclaw-enum.js +48 -0
- package/service/modules/opencode-service.js +199 -0
- package/service/modules/opencode-starter.js +194 -0
- package/service/modules/port-checker.js +31 -0
- package/service/modules/rongyun-message-handler.js +250 -0
- package/service/modules/rongyun-message-sender.js +157 -0
- package/service/modules/rongyun-message-types.js +28 -0
- package/service/modules/script-executor.js +550 -0
- package/service/modules/service-manager.js +319 -0
- package/service/modules/structured-message-router.js +118 -0
- package/service/rongcloud/env-polyfill.js +95 -0
- package/service/rongcloud/index.js +19 -0
- package/service/rongcloud/message-handler.js +147 -0
- package/service/rongcloud/message-types.js +22 -0
- package/service/rongcloud/openclaw-client.js +98 -0
- package/service/rongcloud/openclaw-config.js +108 -0
- package/service/rongcloud/rongcloud-client.js +273 -0
- package/service/rongcloud/types.js +9 -0
- package/service/updater.js +348 -0
- package/service/worker.js +376 -0
- package/version.json +4 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 融云消息发送工具
|
|
3
|
+
*
|
|
4
|
+
* 封装与融云 guardserver 的消息交互
|
|
5
|
+
* 服务端融云账号: guardserver
|
|
6
|
+
*/
|
|
7
|
+
const { RongyunMessageTypeEnum } = require('./rongyun-message-types');
|
|
8
|
+
const { getMacAddress } = require('./mac-address');
|
|
9
|
+
const { generateSecret } = require('./auth');
|
|
10
|
+
|
|
11
|
+
class RongyunMessageSender {
|
|
12
|
+
constructor(rongcloudClient, config, log) {
|
|
13
|
+
this.rongcloudClient = rongcloudClient;
|
|
14
|
+
this.config = config;
|
|
15
|
+
this.log = log;
|
|
16
|
+
this.serverImId = 'guardserver';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 构建标准协议消息
|
|
21
|
+
*/
|
|
22
|
+
buildMessage(msgType, content, requestId) {
|
|
23
|
+
const mac = getMacAddress();
|
|
24
|
+
const secret = generateSecret(mac, this.config.secretKey || 'secret_key');
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
msg_type: msgType,
|
|
28
|
+
source_im_id: this.config.accountId || '',
|
|
29
|
+
destination_im_id: this.serverImId,
|
|
30
|
+
mac: mac,
|
|
31
|
+
secret: secret,
|
|
32
|
+
content: typeof content === 'string' ? content : JSON.stringify(content),
|
|
33
|
+
request_id: requestId || '',
|
|
34
|
+
timestamp: Math.floor(Date.now() / 1000),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 发送协议消息到 guardserver
|
|
40
|
+
*/
|
|
41
|
+
async sendProtocolMessage(msgType, content, requestId) {
|
|
42
|
+
if (!this.rongcloudClient?.isConnected) {
|
|
43
|
+
this.log?.error('[RongyunMessageSender] 未连接,无法发送消息');
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const messagePayload = this.buildMessage(msgType, content, requestId);
|
|
49
|
+
|
|
50
|
+
this.log?.info(`[RongyunMessageSender] 发送协议消息 -> ${this.serverImId}, type=${msgType}`);
|
|
51
|
+
|
|
52
|
+
const result = await this.rongcloudClient.sendMessage(
|
|
53
|
+
this.serverImId,
|
|
54
|
+
JSON.stringify(messagePayload),
|
|
55
|
+
1 // PRIVATE
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
if (result) {
|
|
59
|
+
this.log?.info(`[RongyunMessageSender] ${msgType} 发送成功`);
|
|
60
|
+
} else {
|
|
61
|
+
this.log?.warn(`[RongyunMessageSender] ${msgType} 发送失败`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return result;
|
|
65
|
+
} catch (err) {
|
|
66
|
+
this.log?.error(`[RongyunMessageSender] 发送异常: ${err.message}`);
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 发送 CLIENT_CONNECTED
|
|
73
|
+
*/
|
|
74
|
+
async sendClientConnected() {
|
|
75
|
+
return await this.sendProtocolMessage(
|
|
76
|
+
RongyunMessageTypeEnum.CLIENT_CONNECTED,
|
|
77
|
+
{
|
|
78
|
+
mac_address: getMacAddress(),
|
|
79
|
+
nickname: this.config.nodeName || 'CLI客户端',
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 发送 CLIENT_DISCONNECTED
|
|
86
|
+
*/
|
|
87
|
+
async sendClientDisconnected() {
|
|
88
|
+
return await this.sendProtocolMessage(
|
|
89
|
+
RongyunMessageTypeEnum.CLIENT_DISCONNECTED,
|
|
90
|
+
{
|
|
91
|
+
mac_address: getMacAddress(),
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 发送心跳
|
|
98
|
+
*/
|
|
99
|
+
async sendHeartbeat(openClawStatus) {
|
|
100
|
+
return await this.sendProtocolMessage(
|
|
101
|
+
RongyunMessageTypeEnum.HEARTBEAT,
|
|
102
|
+
{
|
|
103
|
+
mac_address: getMacAddress(),
|
|
104
|
+
nickname: this.config.nodeName || 'CLI客户端',
|
|
105
|
+
open_claw_status: openClawStatus,
|
|
106
|
+
client_status: 1,
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 发送命令结果
|
|
113
|
+
*/
|
|
114
|
+
async sendCommandResult(command, commandId, status, message, requestId) {
|
|
115
|
+
return await this.sendProtocolMessage(
|
|
116
|
+
RongyunMessageTypeEnum.COMMAND_RESULT,
|
|
117
|
+
{
|
|
118
|
+
command,
|
|
119
|
+
command_id: commandId,
|
|
120
|
+
status,
|
|
121
|
+
message,
|
|
122
|
+
},
|
|
123
|
+
requestId
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 发送聊天消息回复
|
|
129
|
+
*/
|
|
130
|
+
async sendChatMessage(content, requestId) {
|
|
131
|
+
return await this.sendProtocolMessage(
|
|
132
|
+
RongyunMessageTypeEnum.CHAT_MESSAGE,
|
|
133
|
+
{
|
|
134
|
+
status: 'success',
|
|
135
|
+
message: 'Response received',
|
|
136
|
+
content: content,
|
|
137
|
+
metadata: {}
|
|
138
|
+
},
|
|
139
|
+
requestId
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 发送仪表盘数据
|
|
145
|
+
*/
|
|
146
|
+
async sendDashboardData(msgType, data) {
|
|
147
|
+
return await this.sendProtocolMessage(msgType, {
|
|
148
|
+
mac_address: getMacAddress(),
|
|
149
|
+
timestamp: new Date().toISOString(),
|
|
150
|
+
...data,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
module.exports = {
|
|
156
|
+
RongyunMessageSender
|
|
157
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 融云交互消息类型枚举
|
|
3
|
+
* 服务端和客户端必须保持完全一致
|
|
4
|
+
* 服务端路径: src/enum/rongyun_message_type_enum.py
|
|
5
|
+
* 桌面客户端路径: nodejs_client/src/main/enum/rongyunMessageTypeEnum.ts
|
|
6
|
+
*/
|
|
7
|
+
const RongyunMessageTypeEnum = {
|
|
8
|
+
CLIENT_CONNECTED: "client_connected",
|
|
9
|
+
CLIENT_DISCONNECTED: "client_disconnected",
|
|
10
|
+
HEARTBEAT: "heartbeat",
|
|
11
|
+
HEARTBEAT_ACK: "heartbeat_ack",
|
|
12
|
+
DASHBOARD_REPORT: "dashboard_report",
|
|
13
|
+
DASHBOARD_REPORT_ACK: "dashboard_report_ack",
|
|
14
|
+
DASHBOARD_SESSIONS: "dashboard_sessions",
|
|
15
|
+
DASHBOARD_JOBS: "dashboard_jobs",
|
|
16
|
+
DASHBOARD_PROJECTS: "dashboard_projects",
|
|
17
|
+
DASHBOARD_SUMMARIES: "dashboard_summaries",
|
|
18
|
+
DASHBOARD_SESSIONS_CONTEXTS: "dashboard_sessions_contexts",
|
|
19
|
+
DASHBOARD_USAGE_EVENTS: "dashboard_usage_events",
|
|
20
|
+
COMMAND: "command",
|
|
21
|
+
COMMAND_RESULT: "command_result",
|
|
22
|
+
CHAT_MESSAGE: "chat_message",
|
|
23
|
+
CREATE_OPENCODE_SESSION: "create_opencode_session",
|
|
24
|
+
OPENCODE_SESSION_CREATED: "opencode_session_created",
|
|
25
|
+
DELETE_OPENCODE_SESSION: "delete_opencode_session"
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
module.exports = { RongyunMessageTypeEnum };
|