Conversation
在OneBot API params类型中添加可选的外显参数字段 在NodeCustomMessage中添加news字段支持嵌套转发外显 在core适配器中正确传递和处理外显参数 确保外显参数同时存在于API请求顶层和node数据内
将jsonwebtoken从devDependencies移至dependencies 升级jsonwebtoken到9.0.3(原版,修复SlowBuffer兼容性) 添加@types/jsonwebtoken到开发依赖提供类型支持 防止jsonwebtoken被tsup打包,使用系统安装版本 修复: #615
Reviewer's Guide在所有 OneBot API 和适配器中,为合并转发消息增加 Napcat 扩展展示参数支持,并更新围绕 jsonwebtoken 使用的核心包依赖。 携带 Napcat 展示选项发送转发消息的时序图sequenceDiagram
actor User
participant AdapterOneBot
participant OneBotCore
participant OneBotApiServer
User->>AdapterOneBot: triggerForwardMessage(elements, options)
AdapterOneBot->>AdapterOneBot: forwardKarinConvertAdapter(elements, options)
AdapterOneBot->>OneBotCore: sendGroupForwardMsg(group_id, messages, options)
OneBotCore->>OneBotCore: sendApi(sendGroupForwardMsg, payload_with_messages_and_options)
OneBotCore->>OneBotApiServer: send_group_forward_msg(payload_with_messages_and_options)
OneBotApiServer-->>OneBotCore: message_id
OneBotCore-->>AdapterOneBot: message_id
AdapterOneBot-->>User: message_id
更新后的 OneBot 转发消息 Napcat 展示选项类图classDiagram
class OneBotCore {
<<abstract>>
+sendForwardMsg(messages: NodeMessage[], options: ForwardOptions)
+sendGroupForwardMsg(group_id: number, messages: NodeMessage[], options: ForwardOptions)
+sendPrivateForwardMsg(user_id: number, messages: NodeMessage[], options: ForwardOptions)
}
class ForwardOptions {
+news: NewsItem[]?
+prompt: string?
+summary: string?
+source: string?
}
class NewsItem {
+text: string
}
class OneBotMessageApiSendForwardMsgParams {
+messages: NodeMessage[]
+news: NewsItem[]?
+prompt: string?
+summary: string?
+source: string?
}
class OneBotMessageApiSendGroupForwardMsgParams {
+group_id: number
+messages: NodeMessage[]
+news: NewsItem[]?
+prompt: string?
+summary: string?
+source: string?
}
class OneBotMessageApiSendPrivateForwardMsgParams {
+user_id: number
+messages: NodeMessage[]
+news: NewsItem[]?
+prompt: string?
+summary: string?
+source: string?
}
class NodeCustomMessage {
+user_id: string
+nickname: string
+content: OneBotMessage[]
+news: NewsItem[]?
+prompt: string?
+summary: string?
+source: string?
}
class AdapterOneBot {
+_onebot: OneBotCore
+forwardKarinConvertAdapter(elements: ForwardElement[], options: ForwardOptions)
}
class ForwardElement {
+options: ForwardOptions?
}
OneBotCore ..> ForwardOptions
OneBotMessageApiSendForwardMsgParams ..> NewsItem
OneBotMessageApiSendGroupForwardMsgParams ..> NewsItem
OneBotMessageApiSendPrivateForwardMsgParams ..> NewsItem
NodeCustomMessage ..> NewsItem
AdapterOneBot --> OneBotCore
AdapterOneBot ..> ForwardElement
ForwardElement ..> ForwardOptions
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your Experience访问你的 dashboard 以:
Getting HelpOriginal review guide in EnglishReviewer's GuideAdds support for Napcat extended display parameters on merged forward messages across OneBot APIs and adapter, and updates core package dependencies around jsonwebtoken usage. Sequence diagram for sending forward message with Napcat display optionssequenceDiagram
actor User
participant AdapterOneBot
participant OneBotCore
participant OneBotApiServer
User->>AdapterOneBot: triggerForwardMessage(elements, options)
AdapterOneBot->>AdapterOneBot: forwardKarinConvertAdapter(elements, options)
AdapterOneBot->>OneBotCore: sendGroupForwardMsg(group_id, messages, options)
OneBotCore->>OneBotCore: sendApi(sendGroupForwardMsg, payload_with_messages_and_options)
OneBotCore->>OneBotApiServer: send_group_forward_msg(payload_with_messages_and_options)
OneBotApiServer-->>OneBotCore: message_id
OneBotCore-->>AdapterOneBot: message_id
AdapterOneBot-->>User: message_id
Updated class diagram for OneBot forward message Napcat display optionsclassDiagram
class OneBotCore {
<<abstract>>
+sendForwardMsg(messages: NodeMessage[], options: ForwardOptions)
+sendGroupForwardMsg(group_id: number, messages: NodeMessage[], options: ForwardOptions)
+sendPrivateForwardMsg(user_id: number, messages: NodeMessage[], options: ForwardOptions)
}
class ForwardOptions {
+news: NewsItem[]?
+prompt: string?
+summary: string?
+source: string?
}
class NewsItem {
+text: string
}
class OneBotMessageApiSendForwardMsgParams {
+messages: NodeMessage[]
+news: NewsItem[]?
+prompt: string?
+summary: string?
+source: string?
}
class OneBotMessageApiSendGroupForwardMsgParams {
+group_id: number
+messages: NodeMessage[]
+news: NewsItem[]?
+prompt: string?
+summary: string?
+source: string?
}
class OneBotMessageApiSendPrivateForwardMsgParams {
+user_id: number
+messages: NodeMessage[]
+news: NewsItem[]?
+prompt: string?
+summary: string?
+source: string?
}
class NodeCustomMessage {
+user_id: string
+nickname: string
+content: OneBotMessage[]
+news: NewsItem[]?
+prompt: string?
+summary: string?
+source: string?
}
class AdapterOneBot {
+_onebot: OneBotCore
+forwardKarinConvertAdapter(elements: ForwardElement[], options: ForwardOptions)
}
class ForwardElement {
+options: ForwardOptions?
}
OneBotCore ..> ForwardOptions
OneBotMessageApiSendForwardMsgParams ..> NewsItem
OneBotMessageApiSendGroupForwardMsgParams ..> NewsItem
OneBotMessageApiSendPrivateForwardMsgParams ..> NewsItem
NodeCustomMessage ..> NewsItem
AdapterOneBot --> OneBotCore
AdapterOneBot ..> ForwardElement
ForwardElement ..> ForwardOptions
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Summary of ChangesHello @sj817, 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 introduces significant improvements to the OneBot message forwarding mechanism by enabling the inclusion of various external display parameters. These changes allow for more detailed and customizable presentation of forwarded messages, enhancing the user experience. The update also includes routine dependency management and a minor adjustment to the TypeScript compilation settings. 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
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
|
📝 WalkthroughWalkthroughThis PR extends OneBot's forward messaging APIs to support additional optional metadata fields (news, prompt, summary, source) across message construction and API calls. Dependencies are updated to use standard jsonwebtoken instead of a custom fork, and TypeScript's skipLibCheck is enabled. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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 |
There was a problem hiding this comment.
Hey - 我在这里给出了一些整体性的反馈:
- 用于转发消息的
options对象(news/prompt/summary/source)目前在多个地方单独定义类型(OneBotMessageApi、OneBotCore 方法、Adapter、NodeCustomMessage);建议抽取一个共享的ForwardMsgOptions/ForwardCardMeta接口并复用,以保持这些方法签名的一致性并减少重复。
给 AI 代理的提示词
Please address the comments from this code review:
## Overall Comments
- 用于转发消息的 `options` 对象(`news/prompt/summary/source`)目前在多个地方单独定义类型(OneBotMessageApi、OneBotCore 方法、Adapter、NodeCustomMessage);建议抽取一个共享的 `ForwardMsgOptions`/`ForwardCardMeta` 接口并复用,以保持这些方法签名的一致性并减少重复。帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English
Hey - I've left some high level feedback:
- The
optionsobject for forward messages (news/prompt/summary/source) is currently typed in multiple places (OneBotMessageApi, OneBotCore methods, Adapter, NodeCustomMessage); consider extracting a sharedForwardMsgOptions/ForwardCardMetainterface and reusing it to keep these signatures in sync and reduce duplication.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `options` object for forward messages (`news/prompt/summary/source`) is currently typed in multiple places (OneBotMessageApi, OneBotCore methods, Adapter, NodeCustomMessage); consider extracting a shared `ForwardMsgOptions`/`ForwardCardMeta` interface and reusing it to keep these signatures in sync and reduce duplication.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
本次 PR 主要为合并转发消息增加了外显参数的支持,并更新了核心依赖。代码改动清晰地实现了预期功能。
我的审查意见主要集中在以下几点:
- 在
core.ts中,对转发消息选项的处理存在不一致,可能导致 bug,建议统一处理逻辑。 - 在多个文件中,新增加的转发选项类型定义存在重复,建议提取为共享类型以提高代码可维护性。
tsconfig.base.json中开启了skipLibCheck,这可能会隐藏依赖库中的类型错误,建议说明原因或寻找替代方案。
整体来看,这是一个不错的功能增强,修复建议中的问题后代码质量会更高。
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/adapter/onebot/core/core.ts (1)
1092-1104:⚠️ Potential issue | 🟠 MajorTop-level
optionsblock unconditionally overwrites per-elementelem.optionsfields withundefined.Block at lines 1092–1097 guards each field with a truthy check before assigning it from
elem.options. However, block at lines 1099–1104 assigns all four fields unconditionally from the top-leveloptions, which means ifoptionsdoesn't includenews(i.e.,options.news === undefined), thenode.data.newsthat was already set fromelem.options.newsgets silently cleared.Minimal repro:
// First element carries its own news elements[0].options = { news: [{ text: 'foo' }] } // Top-level options omits news sendForwardMsg(contact, elements, { summary: 'baz' }) // ⟹ node.data.news is undefined after the merge — elem.options.news lostApply the same guard used in the
elem.optionsblock:🐛 Proposed fix
if (options && messages.length === 0) { - node.data.news = options.news - node.data.prompt = options.prompt - node.data.summary = options.summary - node.data.source = options.source + if (options.news !== undefined) node.data.news = options.news + if (options.prompt !== undefined) node.data.prompt = options.prompt + if (options.summary !== undefined) node.data.summary = options.summary + if (options.source !== undefined) node.data.source = options.source }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/core/src/adapter/onebot/core/core.ts` around lines 1092 - 1104, The top-level options block unconditionally overwrites per-element fields on node.data (e.g., news/prompt/summary/source) even when options.* is undefined; update the conditional to mirror the elem.options guard: within the if (options && messages.length === 0) block only assign node.data.news = options.news (and similarly prompt, summary, source) when options.news/prompt/summary/source are present (truthy or !== undefined) so existing values set from elem.options are not clobbered.
🧹 Nitpick comments (2)
packages/onebot/src/core/core.ts (1)
550-596: Extract the repeated inline options type to a named type.The
{ news?: Array<{ text: string }>, prompt?: string, summary?: string, source?: string }shape is written identically in all three forward-message methods. Extracting it makes changes (e.g., adding a new field) atomic and makes it reusable by external callers.♻️ Proposed refactor
Add near the top of the file (or in a shared types file):
/** NapCat扩展: 合并转发消息外显参数 */ export interface ForwardMsgOptions { /** 小卡片中间的外显 */ news?: Array<{ text: string }> /** 消息列表的外显 */ prompt?: string /** 小卡片底下文本: 查看1条转发消息 */ summary?: string /** 小卡片标题 */ source?: string }Then reference it in all three methods:
async sendForwardMsg ( messages: NodeMessage[], - options?: { news?: Array<{ text: string }>, prompt?: string, summary?: string, source?: string } + options?: ForwardMsgOptions ) { async sendGroupForwardMsg ( group_id: number, messages: NodeMessage[], - options?: { news?: Array<{ text: string }>, prompt?: string, summary?: string, source?: string } + options?: ForwardMsgOptions ) { async sendPrivateForwardMsg ( user_id: number, messages: NodeMessage[], - options?: { news?: Array<{ text: string }>, prompt?: string, summary?: string, source?: string } + options?: ForwardMsgOptions ) {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/onebot/src/core/core.ts` around lines 550 - 596, The three methods sendForwardMsg, sendGroupForwardMsg, and sendPrivateForwardMsg repeat the same inline options shape; extract that shape into a named exported interface (e.g., ForwardMsgOptions) and replace the inline type in each method signature with that interface so callers can reuse and updates become atomic; add the interface near the top of the file (or a shared types file) and update the options?: ... types in sendForwardMsg, sendGroupForwardMsg, and sendPrivateForwardMsg to use ForwardMsgOptions.tsconfig.base.json (1)
19-19:skipLibCheck: trueapplies project-wide — consider scoping if possible.This silences type errors in all third-party declaration files across the monorepo, not just the new
@types/jsonwebtokenpackage. While it's a common pragmatic choice, it can mask legitimate type mismatches introduced by other@types/*upgrades in the future.If the driver was a specific conflict in
@types/jsonwebtoken, a narrower workaround (e.g., a local*.d.tsoverride orpathsalias) could preserve full type coverage elsewhere. If the project-wide suppression is accepted, leaving a comment here explaining the rationale would aid future maintenance.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tsconfig.base.json` at line 19, The tsconfig flag skipLibCheck is currently set to true and applies repo-wide, which can hide third-party declaration issues; instead either scope the suppression by removing skipLibCheck from the base config and adding it to the specific package tsconfig (e.g., the package that added `@types/jsonwebtoken`), or revert and implement a targeted fix such as a local declaration override (a small *.d.ts augmenting or declaring the problematic module) or a paths alias for `@types/jsonwebtoken`; if you intentionally keep skipLibCheck: true at the base level, add a concise comment next to skipLibCheck explaining that it was enabled specifically to work around a known `@types/jsonwebtoken` conflict and reference the related issue/PR for future maintainers.
🤖 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/adapter/onebot/core/core.ts`:
- Around line 1092-1104: The top-level options block unconditionally overwrites
per-element fields on node.data (e.g., news/prompt/summary/source) even when
options.* is undefined; update the conditional to mirror the elem.options guard:
within the if (options && messages.length === 0) block only assign
node.data.news = options.news (and similarly prompt, summary, source) when
options.news/prompt/summary/source are present (truthy or !== undefined) so
existing values set from elem.options are not clobbered.
---
Nitpick comments:
In `@packages/onebot/src/core/core.ts`:
- Around line 550-596: The three methods sendForwardMsg, sendGroupForwardMsg,
and sendPrivateForwardMsg repeat the same inline options shape; extract that
shape into a named exported interface (e.g., ForwardMsgOptions) and replace the
inline type in each method signature with that interface so callers can reuse
and updates become atomic; add the interface near the top of the file (or a
shared types file) and update the options?: ... types in sendForwardMsg,
sendGroupForwardMsg, and sendPrivateForwardMsg to use ForwardMsgOptions.
In `@tsconfig.base.json`:
- Line 19: The tsconfig flag skipLibCheck is currently set to true and applies
repo-wide, which can hide third-party declaration issues; instead either scope
the suppression by removing skipLibCheck from the base config and adding it to
the specific package tsconfig (e.g., the package that added
`@types/jsonwebtoken`), or revert and implement a targeted fix such as a local
declaration override (a small *.d.ts augmenting or declaring the problematic
module) or a paths alias for `@types/jsonwebtoken`; if you intentionally keep
skipLibCheck: true at the base level, add a concise comment next to skipLibCheck
explaining that it was enabled specifically to work around a known
`@types/jsonwebtoken` conflict and reference the related issue/PR for future
maintainers.
ℹ️ Review info
Configuration used: defaults
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (6)
packages/core/package.jsonpackages/core/src/adapter/onebot/core/core.tspackages/onebot/src/api/message.tspackages/onebot/src/core/core.tspackages/onebot/src/message/index.tstsconfig.base.json
Summary by Sourcery
为合并转发消息提供外部展示选项支持,并更新核心依赖。
新功能:
NodeCustomMessage新增可选的外部展示字段(news、prompt、summary、source)。options对象。增强:
AdapterOneBot流程中传递转发消息的外部展示选项,以便在发送群组和私聊转发消息时一并包含这些信息。jsonwebtoken库及其对应的类型定义,并调整开发依赖(devDependencies)。构建:
jsonwebtoken及其 TypeScript 类型,并移除之前使用的带作用域的jsonwebtoken依赖。Original summary in English
Summary by Sourcery
Support external display options for merged forward messages and update core dependencies.
New Features:
Enhancements:
Build:
Summary by CodeRabbit
New Features
Chores