Skip to content

fix(hsr): 兼容 Config V2 宿主契约 - #4

Merged
qiyinxi merged 2 commits into
mainfrom
agent/v2p-host-compat
Aug 9, 2026
Merged

qiyinxi merged 2 commits into
mainfrom
agent/v2p-host-compat

Conversation

@qiyinxi

@qiyinxi qiyinxi commented Aug 9, 2026 •

Copy link
Copy Markdown
Member

将 HSR 错误通知从已移除的 Config.send_websocket_message 切到 Publisher/task.notice;通知配置优先读取 Config V2,保留旧宿主回退。核心包版本升级到 0.1.9,适配器与 aggregate 保持 0.1.9,最低依赖仍兼容 core >=0.1.8。验证:全量 unittest 268/268;metadata 6/6;changed modules compileall;git diff --check。构建上传由合并后的官方发布工作流执行。

Summary by Sourcery

适配 HSR 通知处理逻辑以支持 Config V2 主机契约以及新的任务通知 WebSocket 渠道。

新功能:

  • 支持从 Config V2 中读取 HSR 通知设置和自定义 webhook,并在需要时自动回退到旧版配置。

缺陷修复:

  • 确保 HSR 配置检查、通知错误以及崩溃事件通过新的 TASK_NOTICE WebSocket 渠道上报,而不是使用已移除的 Config.send_websocket_message API。

改进:

  • 引入共享辅助方法,用于解析全局通知设置和自定义 webhook,将 Config V2 与旧版配置的查找逻辑集中管理。
  • 将 automas-script-hsr 包版本提升至 0.1.9,同时保持适配器的核心最低依赖与 core 0.1.8 兼容。

文档:

  • 更新变更日志,记录 automas-script-hsr 0.1.9 的发布以及相关适配器/核心版本信息。

测试:

  • 更新包元数据测试以反映新的 automas-script-hsr 版本,并明确适配器与核心的兼容性预期。
Original summary in English

Summary by Sourcery

Adapt HSR notification handling to Config V2 host contracts and new task notice WebSocket channel.

New Features:

  • Support reading HSR notification settings and custom webhooks from Config V2 with automatic fallback to legacy configuration.

Bug Fixes:

  • Ensure HSR configuration check, notification errors, and crash events are reported via the new TASK_NOTICE WebSocket channel instead of the removed Config.send_websocket_message API.

Enhancements:

  • Introduce shared helpers for resolving global notification settings and custom webhooks to centralize Config V2 and legacy lookups.
  • Bump automas-script-hsr package version to 0.1.9 while keeping adapter minimum core dependency compatible with core 0.1.8.

Documentation:

  • Update changelog to document the automas-script-hsr 0.1.9 release and related adapter/core versioning.

Tests:

  • Update package metadata tests to reflect the new automas-script-hsr version and clarify adapter/core compatibility expectations.

@sourcery-ai

sourcery-ai Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

HSR 脚本的通知处理已更新,以支持 Config V2 合约,同时保留旧版回退机制;基于 websocket 的错误通知从已移除的 Config.send_websocket_message 辅助方法迁移到新的 Publisher / task.notice 流水线;同时将 HSR 包的版本号小幅升级到 0.1.9,并使元数据与测试保持一致。

通过 Publisher/task_notice 发送 HSR 错误通知的序列图

sequenceDiagram
    participant HSRManager as HSRManager
    participant Publisher as Publisher
    participant Protocol as protocol
    participant Schema as WSTaskNoticeData

    HSRManager->>Schema: WSTaskNoticeData(level="error", message)
    HSRManager->>Publisher: send(id, Protocol.TASK_NOTICE, WSTaskNoticeData)
    note over HSRManager,Publisher: Replaces Config.send_websocket_message for error notifications
Loading

文件级变更

Change Details Files
为 HSR 邮件/统计/Webhook/Koishi 通知引入支持 Config V2 的通知访问器,同时保留对旧版 Config 的回退。
  • 为 Config V2 的通知配置字段添加到内部键名的映射。
  • 实现辅助方法,优先从 Config.setting.notify 读取通知设置,若不存在则回退到 Config.get("Notify", key)。
  • 实现辅助方法,从 Config.setting.custom_webhooks.values() 解析自定义 webhook,若不存在则回退到 Config.Notify_CustomWebhooks.values()。
  • 重构 push_notification 逻辑,使其对 SendTaskResultTime、IfSendMail、ToAddress、IfServerChan、ServerChanKey、IfKoishiSupport 和 IfSendStatistic 使用上述新辅助方法。
packages/automas_script_hsr/src/automas_script_hsr/runtime/notify.py
使用基于 Publisher 的 TASK_NOTICE 消息携带结构化的 WSTaskNoticeData,替换已废弃的 Config.send_websocket_message 错误上报。
  • 在之前使用 Config.send_websocket_message 的调用点导入 Publisher、protocol 和 WSTaskNoticeData。
  • 在配置检查失败、通知错误以及任务/用户崩溃时,发送 TASK_NOTICE 类型的 websocket 事件,而不是通用的 Info 类型消息。
  • 将错误负载标准化为 WSTaskNoticeData(level="error", message=...),以便前端可以一致地消费新的宿主端合约。
packages/automas_script_hsr/src/automas_script_hsr/runtime/manager.py
packages/automas_script_hsr/src/automas_script_hsr/runtime/autoproxy.py
将 HSR 包的版本管理和测试与 0.1.9 核心版本对齐,同时保留适配器的最低依赖兼容性。
  • 在 pyproject 和元数据测试中,将 automas-script-hsr 项目版本从 0.1.8 提升到 0.1.9。
  • 在 CHANGELOG 中记录版本提升和依赖下限,说明 automas-script-hsr 0.1.9 与 core >=0.1.8 的兼容性。
  • 调整 test_package_metadata,断言已发布版本为 0.1.9,同时明确将 automas-script-hsr 的适配器最低要求保持在 0.1.8。
  • 更新 uv.lock 以匹配新的版本和依赖关系图。
packages/automas_script_hsr/pyproject.toml
tests/test_package_metadata.py
CHANGELOG.md
uv.lock

Tips and commands

与 Sourcery 交互

  • 触发新评审: 在 Pull Request 中评论 @sourcery-ai review。
  • 继续讨论: 直接回复 Sourcery 的评审评论。
  • 从评审评论生成 GitHub Issue: 通过回复某条评审评论,让 Sourcery 从该评论创建一个 Issue。你也可以在评审评论中回复 @sourcery-ai issue 来创建对应的 Issue。
  • 生成 Pull Request 标题: 在 Pull Request 标题的任意位置写上 @sourcery-ai,即可在任何时候生成标题。你也可以在 Pull Request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 Pull Request 摘要: 在 Pull Request 描述正文中任意位置写上 @sourcery-ai summary,即可在你期望的位置生成 PR 摘要。你也可以在 Pull Request 中评论 @sourcery-ai summary 来在任何时候(重新)生成摘要。
  • 生成评审者指南: 在 Pull Request 中评论 @sourcery-ai guide,即可在任何时候(重新)生成评审者指南。
  • 一次性解决所有 Sourcery 评论: 在 Pull Request 中评论 @sourcery-ai resolve,即可将所有 Sourcery 评论标记为已解决。如果你已经处理完所有评论且不想再看到它们,这会非常方便。
  • 一次性关闭所有 Sourcery 评审: 在 Pull Request 中评论 @sourcery-ai dismiss,即可关闭所有现有的 Sourcery 评审。如果你想以一次全新的评审开始,这会特别有用——别忘了再评论 @sourcery-ai review 来触发新的评审!

自定义你的体验

访问你的 dashboard 以:

  • 启用或禁用评审功能,例如 Sourcery 自动生成的 Pull Request 摘要、评审者指南等。
  • 更改评审使用的语言。
  • 添加、移除或编辑自定义评审说明。
  • 调整其他评审设置。

获取帮助

Original review guide in English

Reviewer's Guide

HSR script notification handling is updated to support Config V2 contracts while retaining legacy fallbacks, and websocket-based error notices are migrated from the removed Config.send_websocket_message helper to the new Publisher/task.notice pipeline, alongside a minor version bump to 0.1.9 for the HSR package and metadata/tests alignment.

Sequence diagram for HSR error notices via Publisher/task_notice

sequenceDiagram
    participant HSRManager as HSRManager
    participant Publisher as Publisher
    participant Protocol as protocol
    participant Schema as WSTaskNoticeData

    HSRManager->>Schema: WSTaskNoticeData(level="error", message)
    HSRManager->>Publisher: send(id, Protocol.TASK_NOTICE, WSTaskNoticeData)
    note over HSRManager,Publisher: Replaces Config.send_websocket_message for error notifications
Loading

File-Level Changes

Change Details Files
Introduce Config V2-aware notification accessors with legacy Config fallbacks for HSR mail/statistics/webhook/Koishi notifications.
  • Add a field name mapping for Config V2 notify settings to internal keys.
  • Implement helper to read notification settings from Config.setting.notify first, then fall back to Config.get("Notify", key).
  • Implement helper to resolve custom webhooks from Config.setting.custom_webhooks.values() with fallback to Config.Notify_CustomWebhooks.values().
  • Refactor push_notification logic to use the new helpers for SendTaskResultTime, IfSendMail, ToAddress, IfServerChan, ServerChanKey, IfKoishiSupport, and IfSendStatistic.
packages/automas_script_hsr/src/automas_script_hsr/runtime/notify.py
Replace deprecated Config.send_websocket_message error reporting with Publisher-based TASK_NOTICE messages carrying structured WSTaskNoticeData.
  • Import Publisher, protocol, and WSTaskNoticeData at call sites that previously used Config.send_websocket_message.
  • Send TASK_NOTICE websocket events instead of generic Info type messages for configuration check failures, notification errors, and task/user crashes.
  • Standardize error payloads to WSTaskNoticeData(level="error", message=...) so frontend consumes the new host contract consistently.
packages/automas_script_hsr/src/automas_script_hsr/runtime/manager.py
packages/automas_script_hsr/src/automas_script_hsr/runtime/autoproxy.py
Align HSR package versioning and tests with the 0.1.9 core release while preserving adapter minimum dependency compatibility.
  • Bump automas-script-hsr project version from 0.1.8 to 0.1.9 in pyproject and metadata tests.
  • Document the version bump and dependency floors in CHANGELOG to reflect automas-script-hsr 0.1.9 and core >=0.1.8 compatibility.
  • Adjust test_package_metadata to assert a 0.1.9 published version while explicitly keeping the adapter minimum requirement at 0.1.8 for automas-script-hsr.
  • Update uv.lock to match the new versions and dependency graph.
packages/automas_script_hsr/pyproject.toml
tests/test_package_metadata.py
CHANGELOG.md
uv.lock

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我发现了 1 个问题,并留下了一些总体反馈:

  • 建议将新的 Config V2 辅助函数(_global_notify_value, _global_custom_webhooks)移动到一个共享的 config/notify 工具模块中,这样其他脚本可以复用它们,而不是以后再次添加类似逻辑。
  • 在多个异步方法中重复进行内联导入 Publisher、protocol 和 WSTaskNoticeData,可以考虑提升到模块级别,这样可读性更好,也能避免重复的导入逻辑,除非有充足理由必须保持惰性导入。
  • 在 _global_custom_webhooks 中,你可能需要返回一个元组或更具体的类型化集合,而不是 list[Any],以更好地反映预期的 webhook 对象结构,并帮助下游的静态分析。
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider moving the new Config V2 helper functions (`_global_notify_value`, `_global_custom_webhooks`) into a shared config/notify utility module so other scripts can reuse them instead of re-adding similar logic later.
- The repeated inline imports of `Publisher`, `protocol`, and `WSTaskNoticeData` inside multiple async methods could be hoisted to the module level for readability and to avoid duplicated import logic unless there is a strong reason to keep them lazy.
- In `_global_custom_webhooks`, you might want to return a tuple or a more specific typed collection instead of `list[Any]` to better reflect the expected webhook object shape and help downstream static analysis.

## Individual Comments

### Comment 1
<location path="packages/automas_script_hsr/src/automas_script_hsr/runtime/notify.py" line_range="138" />
<code_context>
+        if _global_notify_value("IfSendMail"):
             await Notify.send_mail(
-                "网页", title, message_html, Config.get("Notify", "ToAddress")
+                "网页", title, message_html, _global_notify_value("ToAddress", "")
             )

</code_context>
<issue_to_address>
**suggestion (bug_risk):** Using an empty string as default for `ToAddress`/`ServerChanKey` changes behavior when config is missing.

The previous behavior relied on `Config.get` returning `None` (or another sentinel) when a key was missing; this change now substitutes `""`. If notifications are enabled but `ToAddress`/`ServerChanKey` are unset, the code may attempt to send using empty values instead of failing. Please either keep a `None` default and let downstream logic handle it, or add validation to ensure these values are non-empty before sending.

Suggested implementation:

```python
        to_address = _global_notify_value("ToAddress")
        if _global_notify_value("IfSendMail") and to_address:
            await Notify.send_mail(

```

```python
                "网页", title, message_html, to_address

```

1. Apply the same pattern for ServerChan (and any other notification channels): fetch the value once, check that it is truthy/non-empty before sending, and pass the validated value to the send function.
2. If `_global_notify_value` currently uses `""` as a default for missing keys, consider changing its default to `None` so downstream code can reliably distinguish between “unset” and “empty string”.
3. Review other call sites where `_global_notify_value("ToAddress", "")` or `_global_notify_value("ServerChanKey", "")` are used and update them to avoid substituting empty strings when configuration values are missing.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Original comment in English

Hey - I've found 1 issue, and left some high level feedback:

  • Consider moving the new Config V2 helper functions (_global_notify_value, _global_custom_webhooks) into a shared config/notify utility module so other scripts can reuse them instead of re-adding similar logic later.
  • The repeated inline imports of Publisher, protocol, and WSTaskNoticeData inside multiple async methods could be hoisted to the module level for readability and to avoid duplicated import logic unless there is a strong reason to keep them lazy.
  • In _global_custom_webhooks, you might want to return a tuple or a more specific typed collection instead of list[Any] to better reflect the expected webhook object shape and help downstream static analysis.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider moving the new Config V2 helper functions (`_global_notify_value`, `_global_custom_webhooks`) into a shared config/notify utility module so other scripts can reuse them instead of re-adding similar logic later.
- The repeated inline imports of `Publisher`, `protocol`, and `WSTaskNoticeData` inside multiple async methods could be hoisted to the module level for readability and to avoid duplicated import logic unless there is a strong reason to keep them lazy.
- In `_global_custom_webhooks`, you might want to return a tuple or a more specific typed collection instead of `list[Any]` to better reflect the expected webhook object shape and help downstream static analysis.

## Individual Comments

### Comment 1
<location path="packages/automas_script_hsr/src/automas_script_hsr/runtime/notify.py" line_range="138" />
<code_context>
+        if _global_notify_value("IfSendMail"):
             await Notify.send_mail(
-                "网页", title, message_html, Config.get("Notify", "ToAddress")
+                "网页", title, message_html, _global_notify_value("ToAddress", "")
             )

</code_context>
<issue_to_address>
**suggestion (bug_risk):** Using an empty string as default for `ToAddress`/`ServerChanKey` changes behavior when config is missing.

The previous behavior relied on `Config.get` returning `None` (or another sentinel) when a key was missing; this change now substitutes `""`. If notifications are enabled but `ToAddress`/`ServerChanKey` are unset, the code may attempt to send using empty values instead of failing. Please either keep a `None` default and let downstream logic handle it, or add validation to ensure these values are non-empty before sending.

Suggested implementation:

```python
        to_address = _global_notify_value("ToAddress")
        if _global_notify_value("IfSendMail") and to_address:
            await Notify.send_mail(

```

```python
                "网页", title, message_html, to_address

```

1. Apply the same pattern for ServerChan (and any other notification channels): fetch the value once, check that it is truthy/non-empty before sending, and pass the validated value to the send function.
2. If `_global_notify_value` currently uses `""` as a default for missing keys, consider changing its default to `None` so downstream code can reliably distinguish between “unset” and “empty string”.
3. Review other call sites where `_global_notify_value("ToAddress", "")` or `_global_notify_value("ServerChanKey", "")` are used and update them to avoid substituting empty strings when configuration values are missing.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread packages/automas_script_hsr/src/automas_script_hsr/runtime/notify.py Outdated
@qiyinxi
qiyinxi merged commit 6a8580e into main Aug 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant