feat(core): refine config schema and fix emgas lint#782
feat(core): refine config schema and fix emgas lint#782dingyi222666 merged 2 commits intoChatLunaLab:v1-devfrom
Conversation
|
Caution Review failedPull request was closed or merged during review Walkthrough将聊天链的上下文(含 options.startedAt)在线程中传递到发送器与碎片构建逻辑中;基于该时间戳和新增配置 replyQuoteThreshold 决定引用前缀;配置校验重构为条件交叉模式;以及将 ASCII 检查改为逐字符判断以兼容非 ASCII 内容。 Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant User as Client (User)
participant Chain as ChatChain
participant Sender as DefaultChatChainSender
participant Fragment as MessageFragmentBuilder
User->>Chain: receiveMessage / receiveCommand(...)
Note right of Chain: context = { options: { startedAt: Date.now() }, send: bound }
Chain->>Sender: sendMessage(session, messages, context)
Sender->>Fragment: buildMessageFragment(session, message, context)
Fragment-->>Sender: fragment (uses context.options.startedAt)
Sender->>Chain: send/dispatch(fragment, context)
Chain-->>User: delivered
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
诗
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
Summary of ChangesHello, 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! 此拉取请求旨在通过引入基于阈值的条件逻辑来增强消息回复和转发功能,从而优化核心配置架构。它将 Highlights
🧠 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
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
本次 PR 主要重构了配置项 isReplyWithAt 和 isForwardMsg 的 schema,使其支持条件化配置,并引入了 replyQuoteThreshold 以根据响应耗时决定是否引用原消息。相关的函数签名和调用都已更新,以传递 context 对象来计算耗时。同时,中英文 locale 文案也得到了同步更新,使其描述更准确。代码中还修复了一个 lint 问题。
整体来看,代码实现清晰,符合预期功能。我只在 emgas/extractor.ts 中发现一个可以改进的地方,即使用 codePointAt() 来更健壮地处理 Unicode 字符。具体建议请见行内评论。
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/core/src/config.ts (1)
8-9:⚠️ Potential issue | 🟡 Minor类型定义与 Schema 不一致
forwardMsgMinLength在接口中定义为必填 (number),但在 Schema 中仅当isForwardMsg为true时才存在。当isForwardMsg为false时,运行时该字段为undefined,与类型定义冲突。建议将其改为可选类型以保持一致:
建议修复
isForwardMsg: boolean - forwardMsgMinLength: number + forwardMsgMinLength?: number🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/core/src/config.ts` around lines 8 - 9, The interface in config.ts declares forwardMsgMinLength as a required number while the runtime Schema only provides it when isForwardMsg is true; update the interface where isForwardMsg and forwardMsgMinLength are declared so forwardMsgMinLength is optional (change to forwardMsgMinLength?: number) and adjust any related type usages/call sites or casts to handle undefined accordingly to keep types consistent with the Schema.
🧹 Nitpick comments (1)
packages/core/src/chains/chain.ts (1)
742-748: 验证forwardMsgMinLength在isForwardMsg为false时的行为根据新的 Schema 配置,当
isForwardMsg为false时,forwardMsgMinLength将为undefined。虽然运行时短路求值 (&&) 可以保护此访问,但建议添加空值合并以增强健壮性,与replyQuoteThreshold的处理方式保持一致。建议修复
if ( this.config.isForwardMsg && this.getMessageText(messages).length > - this.config.forwardMsgMinLength + (this.config.forwardMsgMinLength ?? 0) ) {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/core/src/chains/chain.ts` around lines 742 - 748, The guard uses this.config.isForwardMsg && this.getMessageText(messages).length > this.config.forwardMsgMinLength which relies on short-circuiting but should mirror replyQuoteThreshold handling; update the comparison to use a nullish-coalescing default for forwardMsgMinLength (e.g., this.config.forwardMsgMinLength ?? 0) so when isForwardMsg is false or forwardMsgMinLength is undefined it behaves safely, keeping the overall condition and calls to getMessageText(messages) and sendAsForward(session, messages) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@packages/core/src/config.ts`:
- Around line 8-9: The interface in config.ts declares forwardMsgMinLength as a
required number while the runtime Schema only provides it when isForwardMsg is
true; update the interface where isForwardMsg and forwardMsgMinLength are
declared so forwardMsgMinLength is optional (change to forwardMsgMinLength?:
number) and adjust any related type usages/call sites or casts to handle
undefined accordingly to keep types consistent with the Schema.
---
Nitpick comments:
In `@packages/core/src/chains/chain.ts`:
- Around line 742-748: The guard uses this.config.isForwardMsg &&
this.getMessageText(messages).length > this.config.forwardMsgMinLength which
relies on short-circuiting but should mirror replyQuoteThreshold handling;
update the comparison to use a nullish-coalescing default for
forwardMsgMinLength (e.g., this.config.forwardMsgMinLength ?? 0) so when
isForwardMsg is false or forwardMsgMinLength is undefined it behaves safely,
keeping the overall condition and calls to getMessageText(messages) and
sendAsForward(session, messages) unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 4cd3bfd7-7c49-4bb8-8352-0a32138c10be
⛔ Files ignored due to path filters (2)
packages/core/src/locales/en-US.schema.ymlis excluded by!**/*.ymlpackages/core/src/locales/zh-CN.schema.ymlis excluded by!**/*.yml
📒 Files selected for processing (3)
packages/core/src/chains/chain.tspackages/core/src/config.tspackages/extension-long-memory/src/layers/emgas/extractor.ts
将 isReplyWithAt 从单纯布尔开关改为“开关 + 阈值分支”配置
新增 replyQuoteThreshold,用于按响应耗时决定是否引用原消息
将 isForwardMsg 同样改为“开关 + 阈值分支”配置
forwardMsgMinLength 仅在启用合并消息时显示
调整 schema 结构,使两个分支配置分别紧跟各自开关显示
同步更新中英文 locales 文案
优化 includeQuoteReply 与 replyQuoteThreshold 的中文描述,使其语义更准确、表达更统一
修复了lint问题