-
-
Notifications
You must be signed in to change notification settings - Fork 41
[Feature] Add tool listing command and refactor reactive chain management #588
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 tool.list command to display all available tools - Support pagination with -p (page) and -l (limit) options, default limit is 5 - Implement alphabetical sorting for consistent tool ordering - Add comprehensive i18n support for Chinese and English locales - Add null safety check in tool creation to prevent runtime errors - Follow the same design pattern as model.list command The new command allows users to view all registered tools in the system with proper pagination and sorting, enhancing tool discoverability.
- Refactor ChatInterface to use ComputedRef for chain wrapper - Remove manual watchers in favor of computed-based reactivity - Simplify chain initialization logic and lifecycle management - Update embeddings property to return ComputedRef for consistency - Remove unnecessary debug logging in request_model middleware - Improve memory extraction validation in long-memory extension This change reduces complexity by leveraging Vue's computed properties instead of manual watch subscriptions, making the code more maintainable and reducing potential memory leaks from untracked watchers.
Update koishi-plugin-chatluna-storage-service peer dependency from ^0.0.9 to ^0.0.10 across all packages.
|
Caution Review failedThe pull request is closed. 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在命令链与全局中间件序列中接入工具相关功能(命令与中间件);新增并注册 Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant U as 用户
participant K as Koishi
participant CMD as chatluna.tool.list
participant CH as ChatChain
participant MW as list_all_tool 中间件
participant P as Pagination
U->>K: 输入 `chatluna.tool.list` [--page --limit]
K->>CMD: 解析命令并执行
CMD->>CH: chain.receiveCommand(action: "list_tool", page, limit)
CH->>MW: 触发中间件 `list_all_tool`
MW->>MW: 收集并按自然数/不区分大小写排序工具列表
MW->>P: 填充分页、格式化页眉/页脚/页码
P-->>MW: 返回当前页文本
MW->>CH: 设置 `context.message` 并结束后续中间件(stop)
CH-->>K: 返回格式化工具列表消息
K-->>U: 输出工具列表
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro ⛔ Files ignored due to path filters (26)
📒 Files selected for processing (1)
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 introduces a new user-facing command for listing available tools with pagination, enhancing the discoverability and management of functionalities within the system. Concurrently, it significantly refactors the internal reactive chain management, transitioning from manual watcher subscriptions to Vue's Highlights
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 a useful tool listing command and significantly refactors the reactive chain management, which is a great improvement for maintainability and stability. The implementation of the new feature is solid, and the bug fixes are correct. I've found a couple of potential issues: one is a possible race condition in the new tool listing middleware due to a shared object, and the other is a potential runtime error in the refactored chain management logic where a function might not adhere to its return type. My comments include suggestions to address these points.
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: 4
🧹 Nitpick comments (1)
packages/core/src/middlewares/model/list_all_tool.ts (1)
42-49: LGTM!建议添加错误处理。分页逻辑正确,中间件定位合理(在
lifecycle-handle_command之后,lifecycle-request_model之前)。但建议为分页操作添加错误处理以提高健壮性。可选改进 - 添加错误处理:
await pagination.push(tools) - context.message = await pagination.getFormattedPage(page, limit) + try { + context.message = await pagination.getFormattedPage(page, limit) + } catch (error) { + context.message = session.text('.pagination_error') + logger.error('Failed to format tool list:', error) + } return ChainMiddlewareRunStatus.STOP
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (7)
package.jsonis excluded by!**/*.jsonpackages/adapter-gemini/package.jsonis excluded by!**/*.jsonpackages/core/package.jsonis excluded by!**/*.jsonpackages/core/src/locales/en-US.ymlis excluded by!**/*.ymlpackages/core/src/locales/zh-CN.ymlis excluded by!**/*.ymlpackages/extension-mcp/package.jsonis excluded by!**/*.jsonpackages/extension-tools/package.jsonis excluded by!**/*.json
📒 Files selected for processing (8)
packages/core/src/command.ts(2 hunks)packages/core/src/commands/tool.ts(1 hunks)packages/core/src/llm-core/chat/app.ts(7 hunks)packages/core/src/llm-core/platform/service.ts(1 hunks)packages/core/src/middleware.ts(2 hunks)packages/core/src/middlewares/model/list_all_tool.ts(1 hunks)packages/core/src/middlewares/model/request_model.ts(0 hunks)packages/extension-long-memory/src/utils/chat-history.ts(1 hunks)
💤 Files with no reviewable changes (1)
- packages/core/src/middlewares/model/request_model.ts
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-17T00:25:27.195Z
Learnt from: dingyi222666
PR: ChatLunaLab/chatluna#548
File: packages/core/src/llm-core/chat/app.ts:0-0
Timestamp: 2025-09-17T00:25:27.195Z
Learning: 在 ChatInterface 类中,响应式 watch 调用已经通过 ctx.effect() 包装来自动处理清理工作,避免内存泄漏。字段 _chain 和 _embeddings 的类型已更新为可空类型。
Applied to files:
packages/core/src/llm-core/chat/app.ts
🧬 Code graph analysis (3)
packages/core/src/commands/tool.ts (3)
packages/core/src/middlewares/model/list_all_tool.ts (1)
apply(7-50)packages/core/src/llm-core/platform/client.ts (1)
config(91-93)packages/core/src/chains/chain.ts (1)
ChatChain(14-366)
packages/core/src/middlewares/model/list_all_tool.ts (4)
packages/core/src/commands/tool.ts (1)
apply(5-19)packages/core/src/chains/chain.ts (1)
ChatChain(14-366)packages/core/src/utils/pagination.ts (1)
Pagination(1-103)packages/core/src/command.ts (1)
command(14-28)
packages/core/src/llm-core/chat/app.ts (3)
packages/core/src/llm-core/memory/message/database_history.ts (1)
KoishiChatMessageHistory(20-405)packages/core/src/llm-core/utils/count_tokens.ts (1)
parseRawModelName(195-205)packages/core/src/llm-core/memory/langchain/buffer_memory.ts (1)
BufferMemory(50-97)
🪛 ESLint
packages/core/src/middlewares/model/list_all_tool.ts
[error] 26-27: Delete ⏎···············
(prettier/prettier)
🪛 GitHub Check: CodeFactor
packages/core/src/middlewares/model/list_all_tool.ts
[warning] 26-26: packages/core/src/middlewares/model/list_all_tool.ts#L26
Delete ⏎··············· (prettier/prettier)
⏰ 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 (13)
packages/core/src/llm-core/platform/service.ts (1)
316-327: 改进了错误处理,增加了工具存在性检查在调用
createTool之前现在会先检查工具是否存在,这样可以避免潜在的空指针异常并提供明确的错误信息。packages/core/src/llm-core/chat/app.ts (5)
37-38: 已将链和嵌入封装为响应式 ComputedRef重构将
_chain和_embeddings从直接状态改为 Vue 的ComputedRef包装器,这与 Vue 的响应式模式更一致,并简化了生命周期管理。基于 learnings 提供的上下文,
ctx.effect()包装确保了正确的清理工作。
332-334: 嵌入属性现在返回 ComputedRef
embeddingsgetter 现在返回ComputedRef<Embeddings>而不是直接的Embeddings实例,与_chain的重构保持一致。调用者现在需要通过
.value访问嵌入实例。
381-381: 清理上下文时正确访问链的值
clearChatHistory方法现在使用this._chain?.value?.model来访问链,与新的ComputedRef类型一致。
384-424: 嵌入初始化返回计算属性
_initEmbeddings现在返回computed(() => {...})包装的嵌入实例,实现了响应式的客户端状态跟踪。当客户端引用更新时,嵌入会自动重新计算。
235-322: 确认所有 ComputedRef 实例的.value访问
脚本扫描出 13 处this._chain/this._embeddings直接访问,多数为非 ComputedRef 字段,仅需在packages/core/src/llm-core/chat/app.ts(48、236、248、306、333、343)和packages/service-search/src/provide.ts对应行验证已使用.value。packages/core/src/command.ts (1)
11-23: 已添加工具命令到中间件链新的
tool中间件已正确导入并添加到执行链中,与现有模式保持一致。packages/core/src/middleware.ts (1)
27-93: 已添加工具列表中间件到执行链新的
list_all_tool中间件已正确导入并插入到中间件数组中,位于list_all_model和list_all_vectorstore之间,与相关功能逻辑上保持一致。packages/extension-long-memory/src/utils/chat-history.ts (1)
141-151: 验证空数组重试逻辑循环从
extractMemory()返回的任何数组(包括空数组)时即停止重试,旧逻辑可能只对非空数组停止。请确认:
- 空数组是否应视为“成功但无内容”直接停止
- 还是空数组可能是暂时性失败,需要继续重试
packages/core/src/commands/tool.ts (2)
1-4: LGTM!导入语句正确且必要。
6-8: LGTM!父命令注册正确,权限级别设置合理。
packages/core/src/middlewares/model/list_all_tool.ts (2)
7-17: LGTM!Pagination 实例的初始化合理,空的格式字符串稍后在中间件中动态更新。
52-56: LGTM!模块扩展声明正确,遵循 TypeScript 标准模式。
Update core package version to 1.3.0-alpha.61 and update peer dependencies across all adapter, extension, and service packages to reference the new core version. Updated packages: - core: 1.3.0-alpha.60 -> 1.3.0-alpha.61 - extension-long-memory: 1.3.0-alpha.3 -> 1.3.0-alpha.4 - extension-mcp: 1.3.0-alpha.7 -> 1.3.0-alpha.8 - extension-tools: 1.3.0-alpha.17 -> 1.3.0-alpha.18 - adapter-gemini: 1.3.0-alpha.18 -> 1.3.0-alpha.19 This release includes the new tool listing command and reactive chain management refactoring.
This PR adds a new tool listing command with pagination support and refactors the reactive chain management system to improve code maintainability and reduce potential memory leaks.
New Features
chatluna.tool.listcommand with pagination support (--pageand--limitoptions) to display all available toolslist_all_toolfor handling tool list requests with paginationBug Fixes
Other Changes
Technical improvements: The reactive refactoring reduces complexity by leveraging Vue's computed properties instead of manual watch subscriptions, making the code more maintainable and reducing potential memory leaks from untracked watchers.