feat(session_waiter): allow session_waiter handler to return MessageEventResult - #9551
Open
Hiraeth-Wave wants to merge 2 commits into
Open
feat(session_waiter): allow session_waiter handler to return MessageEventResult#9551Hiraeth-Wave wants to merge 2 commits into
Hiraeth-Wave wants to merge 2 commits into
Conversation
Let session_waiter handlers return a MessageEventResult instead of forcing them to call event.send(). The returned result is yielded back into the pipeline by handle_session_control_agent, so it goes through the full ResultDecorateStage (reply-with-mention, reply-with-quote, segmented reply, TTS, text-to-image, etc.) and RespondStage like any normal reply. Backward compatible: handlers that return None keep the original stop_event behavior.
📄 Knowledge reviewDosu skipped reviewing this PR because your organization has used its |
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.
fix #9548
Modifications / 改动点
核心改动(2 文件,约 10 行):
astrbot/core/utils/session_waiter.py:SessionWaiter.trigger返回 handler 的返回值(原为丢弃),返回类型None→Any。astrbot/builtin_stars/astrbot/main.py:handle_session_control_agent改为 async generator——当 trigger 返回MessageEventResult时yield它,借助 scheduler 的洋葱模型自动执行ResultDecorateStage和RespondStage(发送);否则保持原stop_event行为。测试(2 文件,7 个用例):
tests/unit/test_session_waiter.py:覆盖 trigger 在 handler 返回MessageEventResult/None/ 抛异常 / 无对应 session 四种情况下的返回值。tests/unit/test_session_control_agent.py:覆盖handle_session_control_agent在 trigger 返回MessageEventResult(yield + stop)/None(无 yield + stop)/ 无匹配 session(无操作)三种分支。工作机制:
call_handler检测到 handler 是 async generator 且yield出MessageEventResult时,会自动event.set_result(ret)再向上yield,触发 scheduler 递归执行后续 stage。因此 waiter handler 只需return event.plain_result(...),回复即走完整装饰流程。向后兼容:老插件在 waiter 内用
event.send()且不 return 的,handler 返回None,走原stop_event路径,行为完全不变。新插件改为return event.plain_result(...)即可享受完整装饰流程。文档更新:更新会话控制文档,使用新调用方法,增加相关提示。此外顺带更新了过时的
import。插件侧用法示例
改前(装饰功能失效):
改后(装饰功能生效):
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
requirements.txt和pyproject.toml文件相应位置。Summary by Sourcery
Propagate session waiter handler return values so session-controlled replies can go through the normal message decoration and sending pipeline, while preserving existing behavior when handlers return None.
New Features:
Enhancements:
Documentation:
Tests: