claw-subagent-service 0.0.71 → 0.0.72
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/package.json
CHANGED
|
@@ -42,7 +42,7 @@ class MessageHandler {
|
|
|
42
42
|
return false;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
const allowedTypes = ['RC:TxtMsg'
|
|
45
|
+
const allowedTypes = ['RC:TxtMsg'];
|
|
46
46
|
if (!allowedTypes.includes(msg.messageType)) {
|
|
47
47
|
this.log?.info(`[MessageHandler] 忽略非文本消息: ${msg.messageType}`);
|
|
48
48
|
return false;
|
|
@@ -94,30 +94,25 @@ class MessageHandler {
|
|
|
94
94
|
const logContent = typeof msg.content === 'string' ? msg.content : (msg.content?.content || '');
|
|
95
95
|
this.log?.info(`[MessageHandler] 收到消息 from=${msg.senderUserId}, type=${type}, content=${logContent.substring(0, 50)}`);
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
try {
|
|
104
|
-
await this.handleNormalMessageStream(msg);
|
|
105
|
-
} catch (err) {
|
|
106
|
-
this.log?.error(`[MessageHandler] 流式处理失败,回退到非流式: ${err.message}`);
|
|
107
|
-
const reply = await this.handleNormalMessage(msg);
|
|
108
|
-
if (reply) {
|
|
109
|
-
const targetId = this.getReplyTarget(msg);
|
|
110
|
-
await this.sendFn(targetId, reply, msg.conversationType);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
} else {
|
|
114
|
-
// 降级到非流式处理
|
|
97
|
+
// 如果配置了代理地址,使用流式处理
|
|
98
|
+
if (this.isStreamingEnabled) {
|
|
99
|
+
try {
|
|
100
|
+
await this.handleNormalMessageStream(msg);
|
|
101
|
+
} catch (err) {
|
|
102
|
+
this.log?.error(`[MessageHandler] 流式处理失败,回退到非流式: ${err.message}`);
|
|
115
103
|
const reply = await this.handleNormalMessage(msg);
|
|
116
104
|
if (reply) {
|
|
117
105
|
const targetId = this.getReplyTarget(msg);
|
|
118
106
|
await this.sendFn(targetId, reply, msg.conversationType);
|
|
119
107
|
}
|
|
120
108
|
}
|
|
109
|
+
} else {
|
|
110
|
+
// 降级到非流式处理
|
|
111
|
+
const reply = await this.handleNormalMessage(msg);
|
|
112
|
+
if (reply) {
|
|
113
|
+
const targetId = this.getReplyTarget(msg);
|
|
114
|
+
await this.sendFn(targetId, reply, msg.conversationType);
|
|
115
|
+
}
|
|
121
116
|
}
|
|
122
117
|
} catch (err) {
|
|
123
118
|
this.log?.error(`[MessageHandler] 处理消息异常: ${err.message}`);
|
|
@@ -127,9 +122,6 @@ class MessageHandler {
|
|
|
127
122
|
}
|
|
128
123
|
|
|
129
124
|
getMessageType(msg) {
|
|
130
|
-
if (msg.messageType === 'claw') {
|
|
131
|
-
return MessageType.CLAW;
|
|
132
|
-
}
|
|
133
125
|
const text = typeof msg.content === 'string' ? msg.content : (msg.content?.content || '');
|
|
134
126
|
if (text.startsWith('/')) {
|
|
135
127
|
return MessageType.COMMAND;
|
|
@@ -164,47 +156,6 @@ class MessageHandler {
|
|
|
164
156
|
await this.sendFn(targetId, reply, msg.conversationType);
|
|
165
157
|
}
|
|
166
158
|
|
|
167
|
-
async handleClaw(msg) {
|
|
168
|
-
const targetId = this.getReplyTarget(msg);
|
|
169
|
-
|
|
170
|
-
// 发送已读回执(fire-and-forget,不阻塞)
|
|
171
|
-
if (this.sendReadReceiptFn) {
|
|
172
|
-
this.sendReadReceiptFn(msg).catch(() => {});
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// 如果配置了代理地址,使用流式处理
|
|
176
|
-
if (this.isStreamingEnabled) {
|
|
177
|
-
try {
|
|
178
|
-
await this.handleNormalMessageStream(msg);
|
|
179
|
-
} catch (err) {
|
|
180
|
-
this.log?.error(`[MessageHandler] 流式处理失败,回退到 CLI: ${err.message}`);
|
|
181
|
-
// 回退到非流式 CLI 调用
|
|
182
|
-
try {
|
|
183
|
-
const reply = await this.openclawClient.chat(msg.content, msg.senderUserId);
|
|
184
|
-
if (reply) {
|
|
185
|
-
this.log?.info(`[MessageHandler] AI 回复: ${reply.substring(0, 50)}...`);
|
|
186
|
-
await this.sendFn(targetId, reply, msg.conversationType);
|
|
187
|
-
}
|
|
188
|
-
} catch (cliErr) {
|
|
189
|
-
this.log?.error(`[MessageHandler] CLI 回退也失败: ${cliErr.message}`);
|
|
190
|
-
await this.sendFn(targetId, `❌ 处理失败: ${cliErr.message}`, msg.conversationType);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// 降级:后台执行 openclaw CLI,不阻塞消息队列
|
|
197
|
-
this.openclawClient.chat(msg.content, msg.senderUserId)
|
|
198
|
-
.then(reply => {
|
|
199
|
-
this.log?.info(`[MessageHandler] AI 回复: ${reply.substring(0, 50)}...`);
|
|
200
|
-
this.sendFn(targetId, reply, msg.conversationType).catch(() => {});
|
|
201
|
-
})
|
|
202
|
-
.catch(err => {
|
|
203
|
-
this.log?.error(`[MessageHandler] OpenClaw 调用失败: ${err.message}`);
|
|
204
|
-
this.sendFn(targetId, `❌ 处理失败: ${err.message}`, msg.conversationType).catch(() => {});
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
|
|
208
159
|
/**
|
|
209
160
|
* 流式处理普通消息
|
|
210
161
|
*/
|