Skip to content

fix: close #615; 适配合并转发的外显参数#616

Merged
sj817 merged 2 commits intomainfrom
fix/forward-options-and-jsonwebtoken
Feb 23, 2026
Merged

fix: close #615; 适配合并转发的外显参数#616
sj817 merged 2 commits intomainfrom
fix/forward-options-and-jsonwebtoken

Conversation

@sj817
Copy link
Member

@sj817 sj817 commented Feb 23, 2026

Summary by Sourcery

为合并转发消息提供外部展示选项支持,并更新核心依赖。

新功能:

  • 为 Napcat 扩展中的 OneBot 转发消息 API 和 NodeCustomMessage 新增可选的外部展示字段(newspromptsummarysource)。
  • 允许 OneBotCore 的转发消息方法接受携带外部展示元数据的 options 对象。

增强:

  • AdapterOneBot 流程中传递转发消息的外部展示选项,以便在发送群组和私聊转发消息时一并包含这些信息。
  • 将核心包切换为使用上游的 jsonwebtoken 库及其对应的类型定义,并调整开发依赖(devDependencies)。

构建:

  • 更新核心包的 dependencies 和 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:

  • Add optional external display fields (news, prompt, summary, source) to OneBot forward message APIs and NodeCustomMessage for Napcat extensions.
  • Allow OneBotCore forward message methods to accept an options object carrying external display metadata.

Enhancements:

  • Propagate forward message external display options through the AdapterOneBot flow so they are included when sending group and private forward messages.
  • Switch core package to use the upstream jsonwebtoken library with corresponding type definitions and adjust devDependencies.

Build:

  • Update core package dependencies and devDependencies to include jsonwebtoken and its TypeScript types and remove the previous scoped jsonwebtoken dependency.

Summary by CodeRabbit

  • New Features

    • Forward message functionality now supports optional customization fields including news, prompt, summary, and source for enhanced message composition.
  • Chores

    • Updated core library dependencies and TypeScript build configuration.

在OneBot API params类型中添加可选的外显参数字段
在NodeCustomMessage中添加news字段支持嵌套转发外显
在core适配器中正确传递和处理外显参数
确保外显参数同时存在于API请求顶层和node数据内
将jsonwebtoken从devDependencies移至dependencies
升级jsonwebtoken到9.0.3(原版,修复SlowBuffer兼容性)
添加@types/jsonwebtoken到开发依赖提供类型支持
防止jsonwebtoken被tsup打包,使用系统安装版本

修复: #615
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 23, 2026

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
Loading

更新后的 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
Loading

File-Level Changes

Change Details Files
在 OneBot 消息 API 和核心辅助方法中暴露 Napcat 转发消息展示选项。
  • 在 OneBotMessageApi 的 send_forward_msgsend_group_forward_msgsend_private_forward_msg 的参数中,新增可选字段 newspromptsummarysource
  • 扩展 OneBotCore.sendForwardMsgsendGroupForwardMsgsendPrivateForwardMsg,使其接受一个可选的 options 对象来携带这些展示字段,并将其展开到发送给 API 的 payload 中。
packages/onebot/src/api/message.ts
packages/onebot/src/core/core.ts
将转发消息的展示选项从 Karin 适配器传播到 OneBot 节点,覆盖元素级与全局级的选项。
  • elem.options 是一个对象时,将其 newspromptsummarysource 字段(包括新增的 news 字段)映射到 node.data
  • 当顶层提供了转发选项但没有消息时,从 options 中设置 node.data.newspromptsummarysource
  • 在调用时除了传入转换后的消息列表外,还将 options 对象一并透传给 sendGroupForwardMsgsendPrivateForwardMsg
packages/core/src/adapter/onebot/core/core.ts
对 jsonwebtoken 及其类型支持相关的核心包依赖进行统一调整。
  • jsonwebtoken 从带 karinjS 前缀的 devDependency 移动为版本为 ^9.0.3 的直接运行时依赖。
  • 新增 @types/jsonwebtoken 作为 devDependency,并移除之前对带作用域 jsonwebtoken 包的 devDependency。
  • 相应更新 pnpm-lock.yamltsconfig.base.json(具体细节可在 diff 中确认)。
packages/core/package.json
pnpm-lock.yaml
tsconfig.base.json
扩展 NodeCustomMessage,以在合并转发卡片上支持 Napcat 的 news 字段。
  • NodeCustomMessage 中新增可选的 news 数组字段(元素为 text 对象),用于表示 Napcat 合并转发的中部卡片展示内容。
packages/onebot/src/message/index.ts

Tips and commands

Interacting with Sourcery

  • 触发新评审: 在 pull request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的评审评论。
  • 从评审评论生成 GitHub issue: 在某条评审评论下回复,要求 Sourcery 根据该评论创建 issue。你也可以直接回复 @sourcery-ai issue 来从该评论生成 issue。
  • 生成 pull request 标题: 在 pull request 标题的任意位置写上 @sourcery-ai,即可随时生成标题。也可以在 pull request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 pull request 概要: 在 pull request body 的任意位置写上 @sourcery-ai summary,即可在对应位置生成 PR 概要。也可以在 pull request 中评论 @sourcery-ai summary 来(重新)生成概要。
  • 生成评审者指南: 在 pull request 中评论 @sourcery-ai guide,即可(重新)生成评审者指南。
  • 一次性解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve,即可将所有 Sourcery 评论标记为已解决。如果你已经处理完这些评论,又不想继续看到它们,会很有用。
  • 忽略所有 Sourcery 评审: 在 pull request 中评论 @sourcery-ai dismiss,即可忽略所有现有的 Sourcery 评审。特别适合在你希望基于一次全新的评审重新开始时使用——别忘了再评论 @sourcery-ai review 来触发新评审!

Customizing Your Experience

访问你的 dashboard 以:

  • 启用或禁用评审功能,例如 Sourcery 自动生成的 pull request 概要、评审者指南等。
  • 更改评审语言。
  • 添加、删除或编辑自定义评审说明。
  • 调整其他评审相关设置。

Getting Help

Original review guide in English

Reviewer's Guide

Adds 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 options

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
Loading

Updated class diagram for OneBot forward message Napcat display options

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
Loading

File-Level Changes

Change Details Files
Expose Napcat forward-message display options in OneBot message APIs and core helpers.
  • Add optional news, prompt, summary, and source fields to send_forward_msg, send_group_forward_msg, and send_private_forward_msg params in the OneBotMessageApi typing.
  • Extend OneBotCore.sendForwardMsg, sendGroupForwardMsg, and sendPrivateForwardMsg to accept an optional options object carrying these display fields and spread them into the API payloads.
packages/onebot/src/api/message.ts
packages/onebot/src/core/core.ts
Propagate forward-message display options from Karin adapter into OneBot nodes, including element-level and global options.
  • When elem.options is an object, map its news, prompt, summary, and source fields into node.data, including the new news field.
  • When forwarding options are provided at the top level and no messages exist, set node.data.news, prompt, summary, and source from options.
  • Pass the options object through to sendGroupForwardMsg and sendPrivateForwardMsg in addition to the converted message list.
packages/core/src/adapter/onebot/core/core.ts
Align core package dependencies for jsonwebtoken and typing support.
  • Move jsonwebtoken from a karinjS-scoped devDependency to a direct runtime dependency at version ^9.0.3.
  • Add @types/jsonwebtoken as a devDependency and remove the previous devDependency on the scoped jsonwebtoken package.
  • Leave pnpm-lock.yaml and tsconfig.base.json adjusted accordingly (details to verify in the diff).
packages/core/package.json
pnpm-lock.yaml
tsconfig.base.json
Extend NodeCustomMessage to support Napcat news field on merged forward cards.
  • Add an optional news array field (with text objects) to NodeCustomMessage to represent the mid-card display for Napcat merged forwards.
packages/onebot/src/message/index.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • OneBot Message Forwarding Enhancements: Added support for new external display parameters (news, prompt, summary, source) when forwarding messages through the OneBot adapter, allowing for richer presentation of forwarded content.
  • Dependency Updates: The jsonwebtoken package was updated and moved to runtime dependencies, along with its type definitions. Several other transitive dependencies were also updated or added.
  • TypeScript Configuration Adjustment: The TypeScript configuration was updated to skip library type checking, which can improve build performance and reduce type-related issues with third-party libraries.

🧠 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
    • Updated jsonwebtoken dependency to version ^9.0.3 and moved it from devDependencies to dependencies.
    • Added @types/jsonwebtoken to devDependencies.
  • packages/core/src/adapter/onebot/core/core.ts
    • Implemented handling for the new news option within elem.options and options when converting forward messages.
    • Modified sendGroupForwardMsg and sendPrivateForwardMsg to accept an additional options parameter for external display.
  • packages/onebot/src/api/message.ts
    • Extended the send_forward_msg, send_group_forward_msg, and send_private_forward_msg API interfaces to include optional news, prompt, summary, and source parameters.
  • packages/onebot/src/core/core.ts
    • Updated sendForwardMsg, sendGroupForwardMsg, and sendPrivateForwardMsg methods to accept and pass through the new options parameter to the underlying API calls.
  • packages/onebot/src/message/index.ts
    • Added an optional news property to the NodeCustomMessage interface.
  • pnpm-lock.yaml
    • Synchronized the pnpm lockfile to reflect changes in package.json, including the jsonwebtoken update and new transitive dependencies.
    • Removed libc specifications from various platform-specific native module entries.
    • Updated the postcss dependency version within autoprefixer.
  • tsconfig.base.json
    • Changed skipLibCheck from false to true in the base TypeScript configuration.
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

coderabbitai bot commented Feb 23, 2026

📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
Dependency Management
packages/core/package.json
Replaced custom karinjs jsonwebtoken with standard jsonwebtoken (^9.0.3) runtime dependency and added corresponding type definitions (^9.0.10).
OneBot Message API Extensions
packages/onebot/src/api/message.ts, packages/onebot/src/message/index.ts
Extended forward message API payload structures and NodeCustomMessage interface with optional fields: news, prompt, summary, and source.
OneBot Core Method Signatures
packages/onebot/src/core/core.ts
Updated sendForwardMsg, sendGroupForwardMsg, and sendPrivateForwardMsg methods to accept optional options parameter containing metadata fields, which are spread into the API request payload.
Core Adapter Implementation
packages/core/src/adapter/onebot/core/core.ts
Modified forward message construction to merge optional news payload from element options or call-level options into node data.
TypeScript Configuration
tsconfig.base.json
Enabled skipLibCheck to skip type checking for library declaration files in node_modules.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A message hops with metadata wings,
News and summaries—oh, the things!
Options flow like clover sweet,
From source to prompt, the path complete,
Dependencies bundled, types align,
Forward with joy, the APIs shine! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title references issue #615 and describes adding support for forward message display parameters in Chinese. It accurately represents the main changes across multiple packages involving forward message API extensions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/forward-options-and-jsonwebtoken

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.

❤️ Share

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

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

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` 接口并复用,以保持这些方法签名的一致性并减少重复。

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享给更多人 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@github-actions
Copy link
Contributor

你可以通过以下命令安装该版本:

pnpm add https://pkg.pr.new/node-karin@035eb00 -w

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

本次 PR 主要为合并转发消息增加了外显参数的支持,并更新了核心依赖。代码改动清晰地实现了预期功能。
我的审查意见主要集中在以下几点:

  1. core.ts 中,对转发消息选项的处理存在不一致,可能导致 bug,建议统一处理逻辑。
  2. 在多个文件中,新增加的转发选项类型定义存在重复,建议提取为共享类型以提高代码可维护性。
  3. tsconfig.base.json 中开启了 skipLibCheck,这可能会隐藏依赖库中的类型错误,建议说明原因或寻找替代方案。
    整体来看,这是一个不错的功能增强,修复建议中的问题后代码质量会更高。

@sj817 sj817 merged commit f1129c9 into main Feb 23, 2026
4 of 5 checks passed
@sj817 sj817 deleted the fix/forward-options-and-jsonwebtoken branch February 23, 2026 08:21
@github-actions github-actions bot mentioned this pull request Feb 23, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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 | 🟠 Major

Top-level options block unconditionally overwrites per-element elem.options fields with undefined.

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-level options, which means if options doesn't include news (i.e., options.news === undefined), the node.data.news that was already set from elem.options.news gets 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 lost

Apply the same guard used in the elem.options block:

🐛 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: true applies project-wide — consider scoping if possible.

This silences type errors in all third-party declaration files across the monorepo, not just the new @types/jsonwebtoken package. 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.ts override or paths alias) 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

📥 Commits

Reviewing files that changed from the base of the PR and between c281d40 and 035eb00.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • packages/core/package.json
  • packages/core/src/adapter/onebot/core/core.ts
  • packages/onebot/src/api/message.ts
  • packages/onebot/src/core/core.ts
  • packages/onebot/src/message/index.ts
  • tsconfig.base.json

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