-
-
Notifications
You must be signed in to change notification settings - Fork 41
[Feature] support file message transformation for OneBot platform #679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add file interceptor to message transformer - Support downloading files from OneBot platform (group and private) - Integrate with chatluna_storage for temporary file handling - Add koishi-plugin-adapter-onebot to devDependencies
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Walkthrough在聊天消息读取中间件中新增对文件元素的拦截与处理:根据元素确定文件名,使用平台适配器(OneBot)获取文件 URL 或直接读取 URL,通过 HTTP 拉取并转为 Buffer 与 Base64,存为临时文件并在消息内容中追加 File 引用。 Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Msg as 消息处理器
participant Detect as 元素检测器
participant Platform as 平台适配器\n(OneBot)
participant HTTP as HTTP 客户端
participant Storage as 临时存储
participant Output as 消息输出
Msg->>Detect: 遍历消息元素
Detect->>Detect: 识别到文件元素
Detect->>Platform: readPlatformFile(ctx, session, element)
Note right of Platform: 根据 session/element\n决定 OneBot 直连或群组 URL
Platform->>HTTP: 请求文件 URL(若需通过 HTTP)
HTTP-->>Platform: 返回文件数据/流
Platform->>Detect: 返回 { buffer, base64Source } 或 null
alt 成功读取
Detect->>Storage: 写入临时文件
Storage-->>Detect: 返回临时路径
Detect->>Output: 在消息内容追加 `File: <path>` 引用
Output-->>Msg: 返回更新后的消息
else 读取失败
Detect-->>Msg: 记录警告并跳过该元素
end
代码审查工作量🎯 3 (Moderate) | ⏱️ ~20 分钟 Possibly related PRs
庆祝诗
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Repository UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧠 Learnings (1)📚 Learning: 2025-12-04T20:25:49.237ZApplied to files:
🧬 Code graph analysis (1)packages/core/src/middlewares/chat/read_chat_message.ts (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (3)
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 @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 enhances the system's capability to process file messages originating from the OneBot platform. It establishes a mechanism to intercept file elements within chat messages, retrieve their URLs from OneBot, download the files, store them using the 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. 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.
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 introduces file message transformation for the OneBot platform, which is a great feature. The implementation correctly adds a file interceptor to download and process files. However, I've identified a couple of critical issues that could lead to runtime errors. Specifically, there's a missing null check for the file buffer after a download attempt, and an uninitialized variable in readPlatformFile that would cause a crash for non-OneBot platforms. I've provided suggestions to fix these issues and improve code robustness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/core/src/middlewares/chat/read_chat_message.ts (1)
283-309:readFile函数实现基本正确,但有一点建议。当前
base64Source被计算但在调用处并未使用(只用了buffer)。考虑移除未使用的返回值以减少不必要的计算,或者确认后续是否会用到。🔎 如果确认不需要 base64Source,可以简化为
async function readFile(ctx: Context, url: string) { try { const response = await ctx.http(url, { responseType: 'arraybuffer', method: 'get', headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36' } }) const buffer = Buffer.from(response.data) - const base64 = buffer.toString('base64') - return { - base64Source: base64, buffer } } catch (error) { logger.error(`Failed to read file from ${url}:`, error) return { - base64Source: null, buffer: null } } }
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
packages/core/package.jsonis excluded by!**/*.json
📒 Files selected for processing (1)
packages/core/src/middlewares/chat/read_chat_message.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/core/src/middlewares/chat/read_chat_message.ts (1)
packages/core/src/index.ts (1)
logger(38-38)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build
- GitHub Check: lint
🔇 Additional comments (1)
packages/core/src/middlewares/chat/read_chat_message.ts (1)
1-6: 导入更改看起来没问题。新增的
Session和OneBotBot类型导入是新功能所必需的。
- Add validation for file buffer and URL existence - Add warning logs when file reading or URL retrieval fails
This PR introduces file message transformation support specifically for the OneBot platform, allowing the system to handle file elements in chat messages.
New Features
readPlatformFileto fetch file URLs from OneBot (both private and group chats).chatluna_storage.Bug fixes
None
Other Changes
koishi-plugin-adapter-onebottopackages/coredevDependencies for type support.