foliko 2.0.14 → 2.0.17

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": "foliko",
3
- "version": "2.0.14",
3
+ "version": "2.0.17",
4
4
  "description": "简约的插件化 Agent 框架",
5
5
  "main": "src/index.js",
6
6
  "type": "commonjs",
@@ -68,8 +68,6 @@ class WeixinPlugin extends Plugin {
68
68
  // 当前活跃 agent 用 _currentAgent 跟踪
69
69
  this._currentAgent = null
70
70
  this.sessionId=null
71
- // 防止重复处理的标志
72
- this._processingMessages = new Set()
73
71
  }
74
72
 
75
73
  install(framework) {
@@ -519,23 +517,12 @@ class WeixinPlugin extends Plugin {
519
517
  * 处理消息
520
518
  */
521
519
  async _handleMessage(msg) {
522
- if (!msg || !msg.userId) return
523
-
524
- // 防止重复处理同一消息
525
- const msgKey = msg.msgId || `${msg.userId}-${msg.createTime}-${msg.type}`
526
- if (this._processingMessages.has(msgKey)) {
527
- log.debug(` 跳过重复消息: ${msgKey}`)
520
+ if (!msg || !msg.userId) {
521
+ log.debug(` [WeChat] 消息无 userId,跳过`)
528
522
  return
529
523
  }
530
- this._processingMessages.add(msgKey)
531
- // 5秒后清理,避免内存泄漏
532
- setTimeout(() => this._processingMessages.delete(msgKey), 5000)
533
524
 
534
- // 忽略机器人自己发送的消息(防止回音室效应)
535
- if (this._myUserId && msg.userId === this._myUserId) {
536
- log.debug(` 忽略机器人自己的消息: ${msgKey}`)
537
- return
538
- }
525
+ log.info(` [WeChat] 收到消息: userId=${msg.userId} type=${msg.type} text=${msg.text?.slice(0, 50) || ''}`)
539
526
 
540
527
  const userId = msg.userId
541
528
  // 从 SessionPlugin 获取历史消息数量
@@ -617,14 +604,6 @@ class WeixinPlugin extends Plugin {
617
604
  * 处理对话
618
605
  */
619
606
  async _processChat(userId, text, originalMsg) {
620
- // 防止并发处理同一个用户的消息
621
- const userKey = `process:${userId}`
622
- if (this._processingMessages.has(userKey)) {
623
- log.debug(` 用户 ${userId} 正在处理中,跳过新消息`)
624
- return
625
- }
626
- this._processingMessages.add(userKey)
627
-
628
607
  try {
629
608
  // 处理命令
630
609
  if (text.startsWith('/')) {
@@ -656,8 +635,8 @@ class WeixinPlugin extends Plugin {
656
635
  } finally {
657
636
  this.stopTypingInterval()
658
637
  }
659
- } finally {
660
- this._processingMessages.delete(userKey)
638
+ } catch (err) {
639
+ log.error(' [_processChat] Error:', err.message)
661
640
  }
662
641
  }
663
642