Skip to content

[Fix] simplify message splitting logic and cleanup voice renderers#712

Merged
dingyi222666 merged 2 commits intov1-devfrom
fix/voice-render
Feb 6, 2026
Merged

[Fix] simplify message splitting logic and cleanup voice renderers#712
dingyi222666 merged 2 commits intov1-devfrom
fix/voice-render

Conversation

@dingyi222666
Copy link
Member

This pr simplifies the message splitting logic in voice renderers by using message.toString() and removes unused dependencies and helper functions.

New Features

None

Bug fixes

  • Simplified and improved the reliability of message splitting in VoiceRenderer and MixedVoiceRenderer.

Other Changes

  • Removed unused marked and Token imports and related helper functions (renderToken, renderTokens).
  • Cleaned up formatting in TextRenderer, VoiceRenderer, and MixedVoiceRenderer.
  • Bumped koishi-plugin-chatluna (core) version to 1.3.18.

- Replace manual text parsing and token rendering with message.toString()
- Improve reliability and consistency of message splitting in VoiceRenderer and MixedVoiceRenderer
- Bump version to 1.3.18
- Remove unused marked imports and helper functions in voice renderers
- Minor formatting improvements in text and voice renderers
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @dingyi222666, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on refining the internal message processing within the voice rendering components, leading to more robust and maintainable code. It streamlines how messages are prepared for voice output and removes unnecessary external dependencies, contributing to a leaner and more efficient codebase.

Highlights

  • Message Splitting Logic Simplification: The message splitting logic in VoiceRenderer and MixedVoiceRenderer has been significantly simplified and improved for reliability by directly utilizing the message.toString() method.
  • Dependency and Helper Function Cleanup: Unused marked and Token imports, along with their associated helper functions (renderToken, renderTokens), have been removed from VoiceRenderer and MixedVoiceRenderer, reducing code bloat.
  • Code Formatting Improvements: Minor formatting adjustments were applied across TextRenderer, VoiceRenderer, and MixedVoiceRenderer to enhance code readability and consistency.
  • Package Version Update: The koishi-plugin-chatluna core package version has been bumped from 1.3.16 to 1.3.18.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • packages/core/package.json
    • Bumped koishi-plugin-chatluna core version from 1.3.16 to 1.3.18.
  • packages/core/src/renders/mixed-voice.ts
    • Removed unused marked and Token imports.
    • Simplified the _splitMessage method to use message.toString() for improved reliability.
    • Removed unused helper functions renderToken and renderTokens.
  • packages/core/src/renders/text.ts
    • Applied minor formatting cleanup for the transformed array mapping.
  • packages/core/src/renders/voice.ts
    • Removed unused marked and Token imports.
    • Simplified the _splitMessage method to use message.toString() for improved reliability.
    • Removed unused helper functions renderToken and renderTokens.
Activity
  • No specific activity (comments, reviews) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 6, 2026

Caution

Review failed

The pull request is closed.

功能概述

本次变更从 mixed-voice.tstext.tsvoice.ts 三个渲染模块中移除了 marked 库和 Token 类型的依赖,将基于令牌的消息分割逻辑替换为更简洁的字符串转换方式,同时删除了相关的辅助函数,未改变公开 API。

变更详情

内聚组 / 文件 变更摘要
渲染模块简化
packages/core/src/renders/mixed-voice.ts, packages/core/src/renders/voice.ts
移除 marked 库和 Token 类型导入,删除 renderToken 和 renderTokens 辅助函数,将 _splitMessage 方法从复杂的令牌解析简化为 toString() 和布尔值过滤。
文本渲染箭头函数简化
packages/core/src/renders/text.ts
将 options.split 代码路径中的显式函数体简化为单行箭头函数 (element) => h('message', element),保留相同语义。

估算代码审查工作量

🎯 2 (简单) | ⏱️ ~10 分钟

相关的拉取请求

诗歌

🐰 消息不用标记词,
toString 让逻辑清晰;
冗余函数全删去,
简洁优雅真欢欣。

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/voice-render

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dingyi222666 dingyi222666 merged commit aba5051 into v1-dev Feb 6, 2026
2 of 3 checks passed
@dingyi222666 dingyi222666 deleted the fix/voice-render branch February 6, 2026 04:31
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request does a great job of simplifying the message splitting logic in the voice renderers and cleaning up the code by removing unused dependencies. The changes make the code more concise and easier to understand.

However, I've identified a critical issue in the new implementation of _splitMessage in both VoiceRenderer and MixedVoiceRenderer. The use of Array.prototype.flatMap() with a callback that returns a string will cause the string to be treated as an array of characters, which is not the intended behavior. This would lead to the voice renderer receiving individual characters instead of whole sentences. I've left comments with suggestions to fix this by using map() instead.

Once this is addressed, the PR will be in great shape.

return tokens
})
.filter(Boolean)
return messages.flatMap((message) => message.toString()).filter(Boolean)
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

Using flatMap with a function that returns a string will iterate over the characters of the string, effectively splitting the message strings into individual characters. This is likely not the intended behavior, as it will cause the voice renderer to process single characters instead of full strings. You should use map instead to transform each message element into a string.

Suggested change
return messages.flatMap((message) => message.toString()).filter(Boolean)
return messages.map((message) => message.toString()).filter(Boolean)

return tokens
})
.filter(Boolean)
return messages.flatMap((message) => message.toString()).filter(Boolean)
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

Using flatMap with a function that returns a string will iterate over the characters of the string, effectively splitting the message strings into individual characters. This is likely not the intended behavior, as it will cause the voice renderer to process single characters instead of full strings. You should use map instead to transform each message element into a string.

Suggested change
return messages.flatMap((message) => message.toString()).filter(Boolean)
return messages.map((message) => message.toString()).filter(Boolean)

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