Skip to content

Conversation

@dingyi222666
Copy link
Member

This PR refactors the platform client registration system by removing the unused ctx parameter from the CreateClientFunction type and all adapter implementations.

Summary of Changes

This PR simplifies the platform client registration API by removing redundant context parameter passing. The context is already accessible within client constructors, making the parameter in registerClient unnecessary.

Other Changes

  • Core refactoring:

    • Updated CreateClientFunction type signature from (ctx: Context) => BasePlatformClient to () => BasePlatformClient
    • Modified PlatformService to call createClientFunction() without passing context
    • Updated ChatLunaPlugin.registerClient() method signature
  • Adapter updates: Removed unused ctx parameter from registerClient calls in all 15 adapters:

    • adapter-azure-openai
    • adapter-claude
    • adapter-deepseek
    • adapter-dify
    • adapter-doubao
    • adapter-gemini
    • adapter-hunyuan
    • adapter-ollama
    • adapter-openai-like
    • adapter-openai
    • adapter-qwen
    • adapter-rwkv
    • adapter-spark
    • adapter-wenxin
    • adapter-zhipu
  • Service updates: Updated embeddings service (huggingface) to use new signature

  • Version bumps: Bumped all package versions to align with core v1.3.0-alpha.58

Technical Details

The refactoring improves code clarity by:

  1. Removing unnecessary parameter passing
  2. Making the API more intuitive (context is already available in constructors)
  3. Reducing cognitive overhead for plugin developers

All clients already receive the context through their constructor parameters, making the additional context parameter in the factory function redundant.

…ent function

- Update CreateClientFunction type signature to remove Context parameter
- Remove unused ctx parameter from all adapter registerClient calls
- Update platform service to call createClientFunction without context
- Simplify client registration across all adapters:
  - adapter-azure-openai
  - adapter-claude
  - adapter-deepseek
  - adapter-dify
  - adapter-doubao
  - adapter-gemini
  - adapter-hunyuan
  - adapter-ollama
  - adapter-openai-like
  - adapter-openai
  - adapter-qwen
  - adapter-rwkv
  - adapter-spark
  - adapter-wenxin
  - adapter-zhipu
  - service-embeddings (huggingface)

The context is already available in the client constructors, making the
parameter in registerClient redundant.
- Bump core package to v1.3.0-alpha.58
- Update all adapter packages to reference new core version:
  - adapter-azure-openai: 1.3.0-alpha.11 → 1.3.0-alpha.12
  - adapter-claude: 1.3.0-alpha.11 → 1.3.0-alpha.12
  - adapter-deepseek: 1.3.0-alpha.11 → 1.3.0-alpha.12
  - adapter-dify: 1.3.0-alpha.9 → 1.3.0-alpha.10
  - adapter-doubao: 1.3.0-alpha.11 → 1.3.0-alpha.12
  - adapter-gemini: 1.3.0-alpha.16 → 1.3.0-alpha.17
  - adapter-hunyuan: 1.3.0-alpha.9 → 1.3.0-alpha.10
  - adapter-ollama: 1.3.0-alpha.9 → 1.3.0-alpha.10
  - adapter-openai-like: 1.3.0-alpha.12 → 1.3.0-alpha.13
  - adapter-openai: 1.3.0-alpha.11 → 1.3.0-alpha.12
  - adapter-qwen: 1.3.0-alpha.12 → 1.3.0-alpha.13
  - adapter-rwkv: 1.3.0-alpha.9 → 1.3.0-alpha.10
  - adapter-spark: 1.3.0-alpha.9 → 1.3.0-alpha.10
  - adapter-wenxin: 1.3.0-alpha.9 → 1.3.0-alpha.10
  - adapter-zhipu: 1.3.0-alpha.11 → 1.3.0-alpha.12
- Update extension packages peer dependencies
- Update service packages including embeddings (1.2.7 → 1.3.0-alpha.1)
- Update shared-adapter peer dependency

All packages now reference koishi-plugin-chatluna ^1.3.0-alpha.58
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 11, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

将 registerClient 的工厂函数从接收 Context 参数改为零参数闭包:核心类型与服务调用相应调整,所有适配器与 Huggingface 注册改为捕获外层 ctx;平台服务调用由 createClientFunction(ctx) 改为 createClientFunction()。未改动公开导出接口除类型签名外无变化。

Changes

Cohort / File(s) Change Summary
Core 类型与服务调用
packages/core/src/llm-core/platform/types.ts, packages/core/src/llm-core/platform/service.ts, packages/core/src/services/chat.ts
CreateClientFunction 签名由 (ctx: Context) => BasePlatformClient 改为 () => BasePlatformClient;平台服务由 createClientFunction(this.ctx) 改为 createClientFunction()ChatLunaPlugin.registerClient 相应改为接收零参工厂。
适配器注册工厂统一改为零参闭包
packages/adapter-*/src/index.ts(含:azure-openai, claude, deepseek, dify, doubao, gemini, hunyuan, ollama, openai-like, openai, qwen, rwkv, spark, wenxin, zhipu
所有适配器的 plugin.registerClient((ctx) => new ...Client(ctx, config, plugin)) 改为 plugin.registerClient(() => new ...Client(ctx, config, plugin)),由外层 apply 作用域捕获 ctx
Embeddings – Huggingface
packages/service-embeddings/src/embeddings/huggingface.ts
将注册回调改为零参工厂,使用外层 ctx 构造 HuggingfaceClient
配置模式微调
packages/core/src/config.ts
blackList 字段由先调用 .computed() 再设 number() 的链式写法调整为先 number().computed(),保持约束和值不变但改变了 schema 构造顺序。

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Host as Host/App
  participant Plugin as ChatLunaPlugin
  participant Core as PlatformService
  participant Factory as createClientFunction()
  participant Client as PlatformClient

  Host->>Plugin: apply(ctx, config)
  Plugin->>Plugin: registerClient(() => new Client(ctx, config, plugin))
  Note right of Plugin #DFF2E1: 工厂函数不再接收 ctx 参数\n改为闭包捕获外层 ctx

  Host->>Core: 请求获取/创建客户端
  Core->>Factory: 调用零参工厂:createClientFunction()
  Factory-->>Core: 返回 Client 实例
  Core-->>Host: 提供已创建/缓存的 Client
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

小兔把工厂改成闭包,
ctx 静静藏在外层坡。
适配器排队不再收参,
客户端一按便来到我窝。
代码田里跳跃的脚步声,🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed 标题简洁明了地指出了核心变更:从平台客户端注册中移除未使用的 ctx 参数,精确反映了 PR 的主要内容。
Description Check ✅ Passed PR 描述清楚说明了移除 ctx 参数的重构目的和具体更改范围,包括核心类型签名更新、服务调用变更及所有适配器的改动,内容完全与变更集相关且详实。

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dd5461e and 3504735.

⛔ Files ignored due to path filters (28)
  • packages/adapter-azure-openai/package.json is excluded by !**/*.json
  • packages/adapter-claude/package.json is excluded by !**/*.json
  • packages/adapter-deepseek/package.json is excluded by !**/*.json
  • packages/adapter-dify/package.json is excluded by !**/*.json
  • packages/adapter-doubao/package.json is excluded by !**/*.json
  • packages/adapter-gemini/package.json is excluded by !**/*.json
  • packages/adapter-hunyuan/package.json is excluded by !**/*.json
  • packages/adapter-ollama/package.json is excluded by !**/*.json
  • packages/adapter-openai-like/package.json is excluded by !**/*.json
  • packages/adapter-openai/package.json is excluded by !**/*.json
  • packages/adapter-qwen/package.json is excluded by !**/*.json
  • packages/adapter-rwkv/package.json is excluded by !**/*.json
  • packages/adapter-spark/package.json is excluded by !**/*.json
  • packages/adapter-wenxin/package.json is excluded by !**/*.json
  • packages/adapter-zhipu/package.json is excluded by !**/*.json
  • packages/core/package.json is excluded by !**/*.json
  • packages/core/src/locales/en-US.yml is excluded by !**/*.yml
  • packages/core/src/locales/zh-CN.yml is excluded by !**/*.yml
  • packages/extension-long-memory/package.json is excluded by !**/*.json
  • packages/extension-mcp/package.json is excluded by !**/*.json
  • packages/extension-tools/package.json is excluded by !**/*.json
  • packages/extension-variable/package.json is excluded by !**/*.json
  • packages/renderer-image/package.json is excluded by !**/*.json
  • packages/service-embeddings/package.json is excluded by !**/*.json
  • packages/service-image/package.json is excluded by !**/*.json
  • packages/service-search/package.json is excluded by !**/*.json
  • packages/service-vector-store/package.json is excluded by !**/*.json
  • packages/shared-adapter/package.json is excluded by !**/*.json
📒 Files selected for processing (1)
  • packages/core/src/config.ts (1 hunks)

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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 implements a significant refactoring to simplify the platform client registration system by eliminating a redundant 'ctx' parameter. The change improves code clarity and reduces cognitive overhead for developers by ensuring that the context is accessed directly within client constructors where it's already available, rather than being passed explicitly through the factory function. This leads to a cleaner and more intuitive API for client registration across the system.

Highlights

  • API Simplification: The 'ctx' parameter has been removed from the 'CreateClientFunction' type and its implementations, as the context is already available within client constructors, streamlining the API.
  • Core Refactoring: The core 'PlatformService' and 'ChatLunaPlugin.registerClient' methods have been updated to reflect the new client registration signature, no longer requiring the explicit passing of the 'ctx' parameter.
  • Adapter Updates: All 15 platform adapters (e.g., Azure OpenAI, Claude, Gemini) have been updated to align with the simplified client registration, removing the now-unused 'ctx' parameter from their 'registerClient' calls.
  • Version Bumps: All affected packages have had their versions incremented to align with the core 'koishi-plugin-chatluna' version '1.3.0-alpha.58'.
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.

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

This pull request introduces a well-executed refactoring across multiple packages to simplify the platform client registration. By removing the now-redundant ctx parameter from the CreateClientFunction and all its implementations, the API is cleaner and more intuitive. The changes correctly leverage closures to capture the plugin-specific context, which is a good improvement. The modifications are consistent and correctly applied throughout the codebase, including all adapters and the core services. Overall, this is a solid improvement to the codebase's clarity and maintainability.

- Bump core package to v1.3.0-alpha.59
- Update all packages to reference new core version dependency
- Fix config schema: improve blackList field definition with proper chaining
- Fix locale files: correct quote usage in test result messages

All packages now reference koishi-plugin-chatluna ^1.3.0-alpha.59
Add @koishijs/plugin-notifier ^1.2.1 as a dependency to fix missing
package error. This dependency is required for the notification feature
added in the previous release.
@dingyi222666 dingyi222666 merged commit b4bcc4f into v1-dev Oct 11, 2025
2 of 3 checks passed
@dingyi222666 dingyi222666 deleted the fix/platform-client branch October 11, 2025 19:25
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.

2 participants