claw-subagent-service 0.0.68 → 0.0.69

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.68",
3
+ "version": "0.0.69",
4
4
  "description": "虾说智能助手",
5
5
  "main": "cli.js",
6
6
  "bin": {
@@ -13,6 +13,7 @@ class MessageHandler {
13
13
  this.openclawClient = new OpenClawClient(log);
14
14
  this.nodeId = config.accountId || '';
15
15
  this.handleNormalMessage = handleNormalMessage;
16
+ this._streamQueue = Promise.resolve();
16
17
  }
17
18
 
18
19
  /**
@@ -293,27 +294,33 @@ class MessageHandler {
293
294
  this.log?.warn('[MessageHandler] _sendStreamChunk skipped: isStreamingEnabled=false');
294
295
  return;
295
296
  }
296
- try {
297
- const resp = await axios.post(
298
- `${this.config.apiBaseUrl}/im/api/proxy/stream/publish`,
299
- {
300
- fromUserId,
301
- targetId,
302
- content,
303
- streamId,
304
- isFirstChunk,
305
- isLastChunk,
306
- conversationType,
307
- seq
308
- },
309
- { timeout: 10000 }
310
- );
311
- this.log?.info(`[MessageHandler] _sendStreamChunk 成功: status=${resp.status}, seq=${seq}`);
312
- } catch (err) {
313
- const url = `${this.config.apiBaseUrl}/im/api/proxy/stream/publish`;
314
- const status = err.response?.status;
315
- this.log?.warn(`[MessageHandler] 发送流式消息失败: ${err.message}, url=${url}, status=${status || 'N/A'}, seq=${seq}`);
316
- }
297
+
298
+ // 使用队列确保流式消息片段串行发送,避免并发导致后端处理错乱
299
+ this._streamQueue = this._streamQueue.then(async () => {
300
+ try {
301
+ const resp = await axios.post(
302
+ `${this.config.apiBaseUrl}/im/api/proxy/stream/publish`,
303
+ {
304
+ fromUserId,
305
+ targetId,
306
+ content,
307
+ streamId,
308
+ isFirstChunk,
309
+ isLastChunk,
310
+ conversationType,
311
+ seq
312
+ },
313
+ { timeout: 10000 }
314
+ );
315
+ this.log?.info(`[MessageHandler] _sendStreamChunk 成功: status=${resp.status}, seq=${seq}`);
316
+ } catch (err) {
317
+ const url = `${this.config.apiBaseUrl}/im/api/proxy/stream/publish`;
318
+ const status = err.response?.status;
319
+ this.log?.warn(`[MessageHandler] 发送流式消息失败: ${err.message}, url=${url}, status=${status || 'N/A'}, seq=${seq}`);
320
+ }
321
+ });
322
+
323
+ await this._streamQueue;
317
324
  }
318
325
 
319
326
  parseCommand(raw, senderId) {