fix(zulip): 弃用,重新PR#477
Closed
wedone wants to merge 8 commits into
Closed
Conversation
Zulip Python 客户端的 call_endpoint 方法期望 files 参数接收文件对象列表(有 .name 属性),但代码错误地传入了文件路径字符串列表,导致附件上传时触发 AttributeError。 修复方案:在调用 call_endpoint 前使用 open() 打开文件,传递文件对象给 Zulip 客户端,确保 with 语句在使用完毕后正确关闭文件。 Closes #附件上传失败问题
LLM 回复时可能使用消息内容中的 Zulip 上传路径(如 /user_uploads/...) 作为 media 参数,而非本地已下载的文件路径,导致 open() 报错 No such file or directory。 添加 _resolve_media_path 方法,在上传前将 Zulip 路径解析为本地文件: - 本地路径直接存在则原样返回 - Zulip 上传路径(/user_uploads/...)或完整 URL 先查找已下载的本地副本 - 若本地不存在则从 Zulip 服务器重新下载 - 无法解析时记录错误并跳过
…cipients MessageTool 创建的 OutboundMessage 只包含 message_id,缺少 msg_type/stream/topic/recipient_user_id 等 Zulip 路由字段,导致 _build_send_request 生成空收件人列表。 _recipient_map 在收到消息时已存储了完整的路由元数据,但从未被用于补全发送消息的元数据。 修复:在 send() 中,当 metadata 缺少 msg_type 时,从 _recipient_map 查找对应 chat_id 的路由信息并合并,确保发送消息时始终有正确的收件人。
LLM 调用 message 工具时,agent loop 会先发送一条 _tool_hint 进度消息,然后 MessageTool 才发送真正的消息。配置中 send_tool_hints 默认为 False,但 _outbound_router 未检查该标志,导致 Zulip 通道将工具提示当作普通消息发送,产生重复且格式错误的文本。修复:在 send() 入口处过滤 _tool_hint 消息,直接返回不发送。
Contributor
Author
|
关闭此 PR,将基于 upstream/dev 创建新的干净 PR,仅包含修复 commit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
修复 Zulip 通道在处理附件上传和发送时存在的四个 BUG,涉及文件对象传递、路径解析、路由元数据补全和进度消息过滤。
BUG 1: 附件上传报错
'str' object has no attribute 'name'_upload_and_send将文件路径字符串直接传入client.call_endpoint(files=...),但 Zulip Python 客户端期望文件对象列表(内部执行f.name),导致AttributeErroropen(media_path, "rb")打开文件后传入文件对象BUG 2: 附件重发时 Zulip 上传路径被当作本地文件路径
/user_uploads/...)作为media参数,而非本地已下载的文件路径,导致open()报错No such file or directory_resolve_media_path方法,将 Zulip 上传路径解析为本地文件路径(优先查找已下载副本,否则重新下载)BUG 3: 附件发送报错
Message must have recipientsMessageTool创建的OutboundMessage只包含{"message_id": ...},缺少msg_type/stream/topic/recipient_user_id等 Zulip 路由字段,导致_build_send_request生成空收件人列表。_recipient_map在收到消息时已存储完整路由元数据,但从未被读取使用send()中,当 metadata 缺少msg_type时,从_recipient_map查找对应chat_id的路由信息并合并BUG 4: 附件发送时产生重复的
message("...")格式文本message工具时,agent loop 先发送_tool_hint进度消息(如message("内容")),然后MessageTool才发送真正的消息。配置中send_tool_hints默认为False,但_outbound_router未检查该标志send()入口处过滤_tool_hint消息,直接返回不发送Related Issues
Module(s) Affected
agentsapiconfigcoreknowledgeloggingservicestoolsutilsweb(Frontend)docs(Documentation)scriptstestschannelsChecklist
pre-commit run --all-filesand fixed any issues.Additional Notes
所有修复仅涉及
deeptutor/tutorbot/channels/zulip.py一个文件,改动最小化,不影响其他通道(Matrix、飞书等)的行为。