feat(lark): add Lark streaming card footer status#7766
feat(lark): add Lark streaming card footer status#7766catDforD wants to merge 1 commit intoAstrBotDevs:masterfrom
Conversation
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The footer status strings ("生成中...", "已完成", "耗时 {x.x}s") are currently hard-coded in Chinese inside
_build_streaming_footer_text; consider sourcing these from the existing i18n infrastructure or configuration so they respect the user's language settings. - In
_update_streaming_footeryou early-return whennot content, which means you can’t clear an existing footer; if you ever need to support hiding/resetting the footer dynamically, you may want to distinguish betweenNone(no-op) and an empty string (explicitly clear).
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The footer status strings ("生成中...", "已完成", "耗时 {x.x}s") are currently hard-coded in Chinese inside `_build_streaming_footer_text`; consider sourcing these from the existing i18n infrastructure or configuration so they respect the user's language settings.
- In `_update_streaming_footer` you early-return when `not content`, which means you can’t clear an existing footer; if you ever need to support hiding/resetting the footer dynamically, you may want to distinguish between `None` (no-op) and an empty string (explicitly clear).Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request introduces a footer for Lark streaming cards, allowing users to see the generation status and elapsed time. Changes include new configuration options in the default config, updates to the Lark event handler to manage footer elements, and localization support in the dashboard. Review feedback suggests localizing hardcoded strings in the footer generation logic to support internationalization and refactoring duplicated code for updating card elements into a shared helper function to improve maintainability.
| parts.append("已完成" if completed else "生成中...") | ||
| if elapsed_enabled and completed and elapsed_seconds is not None: | ||
| parts.append(f"耗时 {elapsed_seconds:.1f}s") |
There was a problem hiding this comment.
| async def _update_streaming_footer( | ||
| self, | ||
| card_id: str, | ||
| content: str, | ||
| sequence: int, | ||
| ) -> bool: | ||
| """更新 CardKit 流式卡片底部状态文本。""" | ||
| if not content: | ||
| return True | ||
| if self.bot.cardkit is None: | ||
| logger.error("[Lark] API Client cardkit 模块未初始化") | ||
| return False | ||
|
|
||
| request = ( | ||
| ContentCardElementRequest.builder() | ||
| .card_id(card_id) | ||
| .element_id(self.STREAMING_FOOTER_ELEMENT_ID) | ||
| .request_body( | ||
| ContentCardElementRequestBody.builder() | ||
| .content(content) | ||
| .sequence(sequence) | ||
| .uuid(str(uuid.uuid4())) | ||
| .build() | ||
| ) | ||
| .build() | ||
| ) | ||
|
|
||
| try: | ||
| response = await self.bot.cardkit.v1.card_element.acontent(request) | ||
| except Exception as e: | ||
| logger.debug(f"[Lark] 流式更新 footer 失败 (ignored): {e}") | ||
| return False | ||
|
|
||
| if not response.success(): | ||
| logger.debug( | ||
| f"[Lark] 流式更新 footer 失败({response.code}): {response.msg}" | ||
| ) | ||
| return False | ||
|
|
||
| return True |
There was a problem hiding this comment.
This method is almost identical to _update_streaming_text. Following the general rules of this repository, consider refactoring the common logic into a shared helper function (e.g., _update_streaming_element(card_id, element_id, content, sequence)) to improve maintainability and reduce code duplication.
References
- When implementing similar functionality for different cases (e.g., direct vs. quoted attachments), refactor the logic into a shared helper function to avoid code duplication.
Closes #7743
Modifications / 改动点
新增飞书流式卡片底部提示配置项:
platform_specific.lark.footer.statusplatform_specific.lark.footer.elapsed为飞书 CardKit 流式回复卡片增加底部状态展示:
status后,生成中显示生成中...,完成后显示已完成elapsed后,完成后显示耗时 x.xs已完成 · 耗时 x.xs补充 WebUI 配置项文案的国际化翻译,覆盖
zh-CN、en-US、ru-RU增加单元测试,覆盖 footer 文案生成和 CardKit footer 元素渲染逻辑
This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Add configurable footer status information to Lark streaming cards, including generation state and elapsed time, and wire it through config, event handling, and rendering.
New Features:
Enhancements:
Tests: