feat: support DingTalk streaming AI cards#8890
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for DingTalk streaming interactive cards by adding configuration options, implementing card creation and update methods in the DingTalk adapter, and updating the event handler to stream message updates. The review feedback highlights a potential memory leak if the streaming generator raises an exception, which can be resolved by wrapping the loop in a try...finally block, and a bug where a configured update interval of 0.0 is overridden due to a falsy check.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
11b0ca7 to
9b36e52
Compare
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
DingtalkMessageEvent._send_streaming_as_plain_text, the previous call tosuper().send_streaming(...)has been removed and theuse_fallbackparameter is now ignored; if you intended to preserve the base-class streaming/fallback behavior, consider still delegating tosuper()after buffering or dropping the unused parameter. - The card streaming path repeatedly sends the full accumulated
full_contenton each update; if payload size or rate limits become a concern, consider tracking and sending only the newly appended text (e.g., via a diff or slice) instead of the entire history each time.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `DingtalkMessageEvent._send_streaming_as_plain_text`, the previous call to `super().send_streaming(...)` has been removed and the `use_fallback` parameter is now ignored; if you intended to preserve the base-class streaming/fallback behavior, consider still delegating to `super()` after buffering or dropping the unused parameter.
- The card streaming path repeatedly sends the full accumulated `full_content` on each update; if payload size or rate limits become a concern, consider tracking and sending only the newly appended text (e.g., via a diff or slice) instead of the entire history each time.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
中文说明
这个 PR 为 AstrBot 内置钉钉平台适配器增加原生“互动 AI 卡片流式回复”支持。
目前 WebUI 里的钉钉设置已经有
card_template_id配置项,并提示“启用后将使用互动卡片进行流式回复”,但实际DingtalkMessageEvent.send_streaming()仍然会把模型输出缓冲到结束后再作为普通消息发送。用户在钉钉里提问后需要等待完整生成结束才看到回复,体验上不是流式输出。本 PR 基于已经在外部插件中验证通过的适配逻辑迁移到官方钉钉 adapter:填写钉钉互动卡片模板 ID 后,流式回复会创建钉钉 AI 卡片,并把模型生成的文本持续更新到卡片内容变量中;未配置模板或创建卡片失败时,会自动回退到原来的普通消息发送方式。
改动内容
card_template_id作为钉钉流式卡片开关。dingtalk_stream.AICardReplier创建并投递钉钉互动 AI 卡片。card_content_key,用于指定卡片模板中的内容变量名,默认content。card_update_interval,用于控制卡片更新最小间隔,默认0.35秒。验证情况
git diff --check。card_template_id,卡片内容变量为content,开启流式输出后可以正常以互动 AI 卡片形式流式更新。本地环境的
python3是 3.9.6,而当前项目要求 Python>=3.12,因此没有在本地运行 Python 语法检查或完整测试。English Summary
This PR adds native DingTalk interactive AI card streaming support to the built-in DingTalk platform adapter. When
card_template_idis configured, streaming text chunks are delivered through a DingTalk AI card viadingtalk_stream.AICardReplier; otherwise the adapter falls back to the existing buffered normal-message behavior.Summary by Sourcery
Add native streaming reply support for DingTalk using interactive AI cards, with configurable card content field and update interval, while preserving fallback to buffered plain messages.
New Features:
Enhancements: