Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix:在 IM(微信) 输入 /skills list,无返回。/skills 可以有返回

openJiuwen-bot211b89b824bc
diff --git a/jiuwenswarm/gateway/channel_manager/im_platforms/wechat/wechat_connect.py b/jiuwenswarm/gateway/channel_manager/im_platforms/wechat/wechat_connect.py
index 8f9a3c1836..d7e5338026 100644
--- a/jiuwenswarm/gateway/channel_manager/im_platforms/wechat/wechat_connect.py
+++ b/jiuwenswarm/gateway/channel_manager/im_platforms/wechat/wechat_connect.py
@@ -841,7 +841,19 @@ class WechatChannel(BaseChannel):
payload = getattr(msg, "payload", None) or {}
if not isinstance(payload, dict):
return False
- return payload.get("is_complete") is True
+ if payload.get("is_complete") is not True:
+ return False
+ # 仅当是「纯哨兵」帧才视作流结束标记:AgentServer 流式终帧 payload 正是
+ # ``{"is_complete": True}``(见 interface.py:2129),正文已由前置 chat.delta 下发。
+ # 但 /skills list 等非流式通知经 _send_channel_notice 也会带 is_complete=True,
+ # 且其正文在 payload.content 里——若不在此排除,整段技能列表会被当哨兵丢弃。
+ if payload.get("content") not in (None, ""):
+ return False
+ if payload.get("error") not in (None, ""):
+ return False
+ if payload.get("event_type"):
+ return False
+ return set(payload.keys()) <= {"is_complete"}
@staticmethod
def _is_stream_accept_ack_only(msg: Message) -> bool:
diff --git a/jiuwenswarm/gateway/message_handler/message_handler.py b/jiuwenswarm/gateway/message_handler/message_handler.py
index 2532efb46a..e791db90b0 100644
--- a/jiuwenswarm/gateway/message_handler/message_handler.py
+++ b/jiuwenswarm/gateway/message_handler/message_handler.py
@@ -1250,8 +1250,20 @@ class MessageHandler(ABC):
reply_session_id: str | None,
msg: "Message",
) -> None:
- """受控通道整行 /skills list:请求 skills.list 并以 CHAT_FINAL 通知透传。"""
+ """受控通道整行 /skills list:请求 skills.list 并以 CHAT_FINAL 通知透传。
+
+ skills.list 响应载荷形如 ``{"skills": [...]}`` / ``{"error": "..."}``,
+ 不含 ``content`` 字段。多数 IM 通道(微信/钉钉/企微/WhatsApp 等)的 ``send``
+ 仅从 ``payload.content`` / ``params.content`` 取文本,缺 ``content`` 即被当作
+ 空消息丢弃,导致 /skills list 无返回(/skills 本身不经此分支故不受影响)。
+ 因此这里用 ``format_skills_list_for_notice`` 把载荷渲染成纯文本放入 ``content``,
+ 同时保留原始字段:飞书仍可经 ``_build_skills_list_card_content`` 识别 ``skills``
+ 键渲染为卡片,其它 IM 通道则回退到读取 ``content`` 文本。
+ """
from jiuwenswarm.common.schema.message import Message, ReqMethod
+ from jiuwenswarm.gateway.message_handler.command_parser.slash_command import (
+ format_skills_list_for_notice,
+ )
req_id = f"skills_slash_{int(time.time() * 1000):x}_{secrets.token_hex(3)}"
skills_req = Message(
@@ -1285,6 +1297,10 @@ class MessageHandler(ABC):
notice_payload = {
"error": f"获取技能列表失败{(': ' + err) if err else ''}",
}
+ # 渲染纯文本 content,供只读 content 的 IM 通道(微信等)下发。
+ notice_payload["content"] = format_skills_list_for_notice(
+ notice_payload if isinstance(notice_payload, dict) else None
+ )
await self._send_channel_notice(
user_infos, channel_id, reply_session_id, notice_payload
)
@@ -1294,7 +1310,7 @@ class MessageHandler(ABC):
user_infos,
channel_id,
reply_session_id,
- {"error": f"获取技能列表失败:{exc}"},
+ {"content": f"获取技能列表失败:{exc}", "error": f"获取技能列表失败:{exc}"},
)
async def _branch_slash_notice(
diff --git a/tests/unit_tests/gateway/test_slash_command.py b/tests/unit_tests/gateway/test_slash_command.py
index f118b56f28..35bea953a3 100644
--- a/tests/unit_tests/gateway/test_slash_command.py
+++ b/tests/unit_tests/gateway/test_slash_command.py
@@ -200,6 +200,34 @@ def test_format_skills_list_for_notice() -> None:
assert "b" in out
+def test_format_skills_list_for_notice_im_invariants() -> None:
+ """IM 通道(微信等)仅从 payload.content 取文本,skills.list 载荷必须能渲染出非空 content。
+
+ /skills list 在 IM 端无返回的根因:skills.list 响应 ``{"skills": [...]}`` 不含
+ ``content``,被通道当作空消息丢弃。这里锁定 _skills_slash_notice 依赖的渲染入口
+ 在成功/空/错误三态下都产出可下发文本。
+ """
+ # 成功:有技能
+ ok_text = format_skills_list_for_notice(
+ {"skills": [{"name": "a", "description": "d", "source": "local"}]}
+ )
+ assert ok_text and ok_text.strip()
+ assert "【技能列表】" in ok_text
+
+ # 空:无技能
+ empty_text = format_skills_list_for_notice({"skills": []})
+ assert empty_text and empty_text.strip()
+
+ # 错误:上游返回 error 字段
+ err_text = format_skills_list_for_notice({"error": "boom"})
+ assert err_text and err_text.strip()
+ assert "boom" in err_text
+
+ # 异常:载荷为 None / 非 dict
+ assert format_skills_list_for_notice(None).strip()
+ assert format_skills_list_for_notice({}).strip()
+
+
def test_first_batch_registry_ids() -> None:
ids = {e.id for e in FIRST_BATCH_REGISTRY}
expected = {