claw-subagent-service 0.0.118 → 0.0.120

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.118",
3
+ "version": "0.0.120",
4
4
  "description": "虾说智能助手",
5
5
  "main": "cli.js",
6
6
  "bin": {
@@ -294,14 +294,20 @@ class MessageHandler {
294
294
  }
295
295
  } catch (err) {
296
296
  this.log?.error(`[MessageHandler] 流式处理失败,回退到非流式: ${err.message}`);
297
- const reply = await this.handleNormalMessage(msg);
298
- if (reply) {
299
- const targetId = this.getReplyTarget(msg);
300
- await this.sendFn(targetId, reply, msg.conversationType);
301
- // 非流式回退成功,群聊轮数 +1
302
- if (msg.conversationType === 3) {
303
- this._incrementGroupRoundCount(msg.targetId, maxRounds);
297
+
298
+ // 只有非取消错误才回退到非流式处理
299
+ if (err.message !== 'canceled') {
300
+ const reply = await this.handleNormalMessage(msg);
301
+ if (reply) {
302
+ const targetId = this.getReplyTarget(msg);
303
+ await this.sendFn(targetId, reply, msg.conversationType);
304
+ // 非流式回退成功,群聊轮数 +1
305
+ if (msg.conversationType === 3) {
306
+ this._incrementGroupRoundCount(msg.targetId, maxRounds);
307
+ }
304
308
  }
309
+ } else {
310
+ this.log?.info(`[MessageHandler] 请求被取消,不回退到非流式处理`);
305
311
  }
306
312
  }
307
313
  } else {
@@ -627,11 +633,37 @@ class MessageHandler {
627
633
  sightUrl = content.sightUrl || content.url || '';
628
634
  name = content.name || '未知视频';
629
635
  duration = content.duration || 0;
636
+ } else if (typeof content === 'string') {
637
+ // 尝试解析 content 是否为 JSON(包含 sightUrl)
638
+ try {
639
+ const contentObj = JSON.parse(content);
640
+ if (contentObj.sightUrl) {
641
+ sightUrl = contentObj.sightUrl;
642
+ }
643
+ } catch (e) {
644
+ // content 不是 JSON,可能是 base64 缩略图
645
+ sightUrl = msg.sightUrl || msg.url || msg.localPath || '';
646
+ }
630
647
  } else {
631
648
  sightUrl = msg.sightUrl || msg.url || msg.localPath || '';
632
649
  }
633
650
 
651
+ // 如果还是没有找到 URL,尝试从 extra 字段获取
652
+ if (!sightUrl && msg.extra) {
653
+ try {
654
+ const extraData = JSON.parse(msg.extra);
655
+ sightUrl = extraData.videoUrl || extraData.sightUrl || '';
656
+ } catch (e) {
657
+ // extra 不是 JSON,忽略
658
+ }
659
+ }
660
+
634
661
  this.log?.info(`[_extractMessageContent] 视频消息: sightUrl=${sightUrl}`);
662
+
663
+ if (!sightUrl) {
664
+ return '[视频](无法获取视频地址)';
665
+ }
666
+
635
667
  return `[视频] ${sightUrl} ${name} ${duration}秒`;
636
668
  }
637
669
 
@@ -645,11 +677,37 @@ class MessageHandler {
645
677
  fileUrl = content.fileUrl || content.fileUri || content.url || '';
646
678
  name = content.name || '未知文件';
647
679
  size = content.size || 0;
680
+ } else if (typeof content === 'string') {
681
+ // 尝试解析 content 是否为 JSON(包含 fileUrl)
682
+ try {
683
+ const contentObj = JSON.parse(content);
684
+ if (contentObj.fileUrl) {
685
+ fileUrl = contentObj.fileUrl;
686
+ }
687
+ } catch (e) {
688
+ // content 不是 JSON
689
+ fileUrl = msg.fileUrl || msg.fileUri || msg.url || msg.localPath || '';
690
+ }
648
691
  } else {
649
692
  fileUrl = msg.fileUrl || msg.fileUri || msg.url || msg.localPath || '';
650
693
  }
651
694
 
695
+ // 如果还是没有找到 URL,尝试从 extra 字段获取
696
+ if (!fileUrl && msg.extra) {
697
+ try {
698
+ const extraData = JSON.parse(msg.extra);
699
+ fileUrl = extraData.fileUrl || extraData.fileUri || '';
700
+ } catch (e) {
701
+ // extra 不是 JSON,忽略
702
+ }
703
+ }
704
+
652
705
  this.log?.info(`[_extractMessageContent] 文件消息: fileUrl=${fileUrl}`);
706
+
707
+ if (!fileUrl) {
708
+ return '[文件](无法获取文件地址)';
709
+ }
710
+
653
711
  return `[文件] ${fileUrl} ${name} ${size}`;
654
712
  }
655
713