fix(extension-variable): migrate lunar variables to before-chat and renderer providers#807
fix(extension-variable): migrate lunar variables to before-chat and renderer providers#807Juvwxyz wants to merge 1 commit intoChatLunaLab:v1-devfrom
Conversation
…enderer providers
There was a problem hiding this comment.
Code Review
This pull request refactors the registration of function and variable providers by wrapping them in ctx.effect to ensure proper lifecycle management. In lunar.ts, the event listener was updated to chatluna/before-chat, and lunar variable generation was extracted into a dedicated function. Feedback was provided regarding the latest_message provider to include a safety check for the session object and to validate that messageCount is a positive integer to prevent runtime errors.
| async (args, _, configurable) => { | ||
| const session = configurable.session as Session | ||
| const messageCount = parseInt(args[0]) || 4 | ||
| const messages = collector.getMessages( | ||
| session.guildId || session.userId, | ||
| session.userId | ||
| ) | ||
| return messages.slice(-messageCount).join('\n\n') | ||
| } |
There was a problem hiding this comment.
The latest_message function provider lacks a safety check for the session object within the configurable parameter. If the renderer is invoked without a session (e.g., in some automated or template-testing contexts), this will cause a runtime error when accessing session.guildId. Additionally, it's safer to ensure messageCount is a positive integer to avoid unexpected behavior with slice when negative values are provided.
async (args, _, configurable) => {
const session = configurable?.session as Session
if (!session) {
return ''
}
const messageCount = Math.max(1, parseInt(args[0]) || 4)
const messages = collector.getMessages(
session.guildId || session.userId,
session.userId
)
return messages.slice(-messageCount).join('\n\n')
}|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
概览修改了extension-variable插件中的提示词渲染器和变量提供者的注册机制。 变化
代码审查工作量估算🎯 3 (中等) | ⏱️ ~20 分钟 可能相关的 PR
推荐审查者
诗歌
🚥 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)
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
This PR fixes variable injection in koishi-plugin-chatluna-variable-extension so lunar/holiday variables work in both the main ChatLuna
flow and chatluna-character preset rendering.
Changes
Behavior
After this change:
Verification