claw-subagent-service 0.0.70 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claw-subagent-service",
3
- "version": "0.0.70",
3
+ "version": "0.0.72",
4
4
  "description": "虾说智能助手",
5
5
  "main": "cli.js",
6
6
  "bin": {
@@ -37,4 +37,4 @@
37
37
  "node": ">=14.0.0"
38
38
  },
39
39
  "license": "MIT"
40
- }
40
+ }
@@ -42,7 +42,7 @@ class MessageHandler {
42
42
  return false;
43
43
  }
44
44
 
45
- const allowedTypes = ['RC:TxtMsg', 'claw'];
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
- if (msg.messageType === 'claw') {
98
- this.log?.info(`收到龙虾消息,交由 OpenClawClient 处理`);
99
- await this.handleClaw(msg);
100
- } else {
101
- // 如果配置了代理地址,使用流式处理
102
- if (this.isStreamingEnabled) {
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
  */
@@ -234,19 +185,21 @@ class MessageHandler {
234
185
  buffer += delta;
235
186
  seq += 1;
236
187
  this.log?.info(`[MessageHandler] onDelta: seq=${seq}, delta_len=${delta.length}, buffer_len=${buffer.length}`);
237
- await this._sendStreamChunk(fromUserId, targetId, conversationType, buffer, streamId, seq === 1, false, seq);
188
+ // 发送增量(delta),让前端做增量拼接,避免内容重复
189
+ await this._sendStreamChunk(fromUserId, targetId, conversationType, delta, streamId, seq === 1, false, seq);
238
190
  hasSentChunk = true;
239
191
  },
240
192
  async (fullText) => {
241
193
  this.log?.info(`[MessageHandler] onDone 触发, fullText.length=${fullText.length}, buffer.length=${buffer.length}, hasSentChunk=${hasSentChunk}`);
242
194
  if (buffer.trim()) {
195
+ // 发送尾流:空字符串表示流结束,前端保留已拼接的完整内容
243
196
  seq += 1;
244
- await this._sendStreamChunk(fromUserId, targetId, conversationType, buffer, streamId, seq === 1, true, seq);
197
+ await this._sendStreamChunk(fromUserId, targetId, conversationType, '', streamId, false, true, seq);
245
198
  hasSentChunk = true;
246
199
  } else if (hasSentChunk) {
247
200
  // 已经发送过内容,单独发送结束标记
248
201
  seq += 1;
249
- await this._sendStreamChunk(fromUserId, targetId, conversationType, buffer, streamId, false, true, seq);
202
+ await this._sendStreamChunk(fromUserId, targetId, conversationType, '', streamId, false, true, seq);
250
203
  } else {
251
204
  // 完全没有收到内容,发送错误提示
252
205
  await this._sendStreamChunk(fromUserId, targetId, conversationType, '抱歉,AI 暂时没有回复内容。', streamId, true, true, 1);
@@ -1,7 +1,6 @@
1
1
  const MessageType = {
2
2
  COMMAND: 'command',
3
- NORMAL: 'normal',
4
- CLAW: 'claw'
3
+ NORMAL: 'normal'
5
4
  };
6
5
 
7
6
  module.exports = {