Skip to content

Conversation

@dingyi222666
Copy link
Member

This PR adds a notification system to improve the user onboarding experience by providing real-time feedback about model configuration status.

New Features

  • Model Configuration Notifications: Added a dynamic notification system that informs users about their model configuration status
    • Displays warning notification with documentation link when no models are configured
    • Shows success notification with model count when models are loaded
    • Notifications update automatically as models are added or removed
  • Optional API Keys: Made API key configuration optional across all adapter packages, allowing users to install adapters before configuring credentials
  • Improved Resource Cleanup: Fixed watcher disposal in ChatInterface to properly clean up reactive watchers on effect disposal

Bug fixes

  • Fixed memory leak in ChatInterface where Vue watchers were not properly disposed when effects were cleaned up (packages/core/src/llm-core/chat/app.ts:312-336)

Other Changes

  • Updated default factory to enable notification feature
  • Added @koishijs/plugin-notifier dependency type import
  • Standardized API key schema across 11 adapter packages (azure-openai, claude, deepseek, doubao, gemini, hunyuan, openai, openai-like, qwen, wenxin, zhipu)

- Add notification system to warn users when no models are configured
- Display success notification showing total loaded models count
- Include helpful link to model configuration documentation
- Fix watcher cleanup in ChatInterface to properly dispose watchers on effect cleanup
- Enable notification feature in default factory configuration

The notification updates dynamically as models are added or removed, providing
real-time feedback to users about their model configuration status.
Remove required() constraint from API key schema definitions across all adapters,
allowing users to install and configure adapters without immediate API key setup.
This change enables:
- Better onboarding experience with notification guidance
- Deferred API key configuration until users are ready
- Compatibility with the new notification system for model configuration status

Affected adapters:
- azure-openai, claude, deepseek, doubao, gemini
- hunyuan, openai, openai-like, qwen, wenxin, zhipu
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 11, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (26)
  • 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/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

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

放宽多适配器配置中 apiKeys 元组首项的必填约束(改为默认空串),核心层在聊天模块中重构了对 llm/embeddings 的 watcher 管理并新增 modelSchema 的通知支持与调用参数变更。

Changes

Cohort / File(s) Change Summary
Adapters: 放宽 apiKeys 首项必填约束
packages/adapter-azure-openai/src/index.ts, packages/adapter-claude/src/index.ts, packages/adapter-deepseek/src/index.ts, packages/adapter-doubao/src/index.ts, packages/adapter-gemini/src/index.ts, packages/adapter-hunyuan/src/index.ts, packages/adapter-openai-like/src/index.ts, packages/adapter-openai/src/index.ts, packages/adapter-qwen/src/index.ts, packages/adapter-wenxin/src/index.ts, packages/adapter-zhipu/src/index.ts, packages/adapter-rwkv/src/index.ts, packages/adapter-dify/src/index.ts
将各适配器 ConfigapiKeys 元组的第一个元素从 Schema.string().role('secret').required(...) 调整为 Schema.string().role('secret').default('')(对少数项为 additionalModels.apiKey 的也设置默认空串),仅放宽校验/默认值,不改变元组结构或 role 标注。
Core Chat: 响应式 watcher 拆分与清理
packages/core/src/llm-core/chat/app.ts
ctx.effect 内显式创建针对 llmembeddings 的独立 watcher;llm 变为 null 时清空 chain,否则重建;embeddings 变更时更新引用并重建 chain;每个 watcher 返回清理函数以在 dispose 时停止监听。
Core Default: 调用签名变更
packages/core/src/llm-core/chat/default.ts
defaultFactory 中对 modelSchema 的调用由 modelSchema(ctx) 改为 modelSchema(ctx, true)(传入 createNotification = true)。
Core Utils: modelSchema 增参与通知
packages/core/src/utils/schema.ts
modelSchema(ctx)modelSchema(ctx, createNotification: boolean = false);当启用时通过 ctx.notifier 创建/更新通知(无模型提示警告;有多个模型更新为成功信息);保留 watcher 的即时触发与清理逻辑。

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant UI as 调用者
  participant Chat as ChatApp(ctx)
  participant LLM as llm
  participant EMB as embeddings
  participant CH as chain

  UI->>Chat: init()
  Note over Chat: 在 ctx.effect 内注册两个独立 watcher(llm, embeddings)

  par Watch llm
    LLM-->>Chat: change(newValue)
    alt newValue == null
      Chat->>CH: set undefined
    else
      Chat->>Chat: createChain()
      Chat->>CH: replace with new chain
    end
  and Watch embeddings
    EMB-->>Chat: change(newEmb)
    Chat->>Chat: _embeddings = newEmb
    Chat->>Chat: recreate chain
  end

  UI-->>Chat: dispose()
  Chat->>Chat: 调用各 watcher 的 cleanup(停止监听)
  Chat->>CH: 释放链路
Loading
sequenceDiagram
  autonumber
  participant Ctx as Context
  participant MS as modelSchema(ctx, createNotification)
  participant Noti as notifier
  participant Sch as schema(model)

  Ctx->>MS: call with createNotification = true
  opt createNotification
    MS->>Noti: create warning "未配置模型"
  end

  loop watch modelNames (immediate)
    MS->>Sch: 更新选项基于 modelNames
    alt count > 1 and notification exists
      MS->>Noti: update 成功信息(模型数量)
    else
      opt notification exists
        MS->>Noti: update 警告,提示配置模型
      end
    end
  end

  Ctx-->>MS: dispose
  MS->>Noti: 清理通知(如存在)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45–60 minutes

Possibly related PRs

Poem

小兔改了 schema,密钥不再强求填。
链路看守拆两路,变更销毁清干净。
提示轻声来报话,模型配置别忘记。
我蹦我跳提交去,仓库又见新春晖! 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed 标题清晰地聚焦于本次 PR 的核心功能——为模型配置添加通知支持,简洁明了且与实际变更内容高度一致,不包含无关噪音或过度宽泛的叙述。
Description Check ✅ Passed 描述详尽地阐述了新增通知系统、可选 API 密钥配置、资源清理改进及 Bug 修复等内容,与实际代码更改紧密对应,且未偏离主题。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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 significantly enhances the user onboarding and system stability by introducing a dynamic notification system for model configuration, making API key setup optional across numerous adapter packages, and resolving a critical memory leak in the ChatInterface component. These changes aim to provide a smoother user experience and improve the overall robustness of the application.

Highlights

  • Model Configuration Notifications: A new dynamic notification system has been implemented to provide real-time feedback on model configuration status, guiding users with warnings for unconfigured models and success messages when models are loaded.
  • Optional API Keys: API key configuration has been made optional across 11 adapter packages, allowing users to install adapters without immediate credential setup.
  • Improved Resource Cleanup: A memory leak in ChatInterface related to Vue watchers not being properly disposed has been fixed, enhancing resource management.
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 valuable notification system for model configuration, makes API keys optional across various adapters to improve user onboarding, and fixes a memory leak by correctly managing watcher disposal. The changes are well-structured and align with the stated goals. I've identified a couple of issues in the new notification logic within packages/core/src/utils/schema.ts where the notification link is broken and the model count is incorrect. I've provided a single suggestion to address both. Overall, this is a solid improvement to the project.

Copy link
Contributor

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

Actionable comments posted: 5

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b8406fb and 3c89e49.

📒 Files selected for processing (14)
  • packages/adapter-azure-openai/src/index.ts (1 hunks)
  • packages/adapter-claude/src/index.ts (1 hunks)
  • packages/adapter-deepseek/src/index.ts (1 hunks)
  • packages/adapter-doubao/src/index.ts (1 hunks)
  • packages/adapter-gemini/src/index.ts (1 hunks)
  • packages/adapter-hunyuan/src/index.ts (1 hunks)
  • packages/adapter-openai-like/src/index.ts (1 hunks)
  • packages/adapter-openai/src/index.ts (1 hunks)
  • packages/adapter-qwen/src/index.ts (1 hunks)
  • packages/adapter-wenxin/src/index.ts (1 hunks)
  • packages/adapter-zhipu/src/index.ts (1 hunks)
  • packages/core/src/llm-core/chat/app.ts (1 hunks)
  • packages/core/src/llm-core/chat/default.ts (1 hunks)
  • packages/core/src/utils/schema.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 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
📚 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 的类型已更新为可空类型 (| undefined),并添加 ctx.on('dispose') 处理器提供额外的清理保障。这种使用 Koishi effect 系统的方式比手动管理 stop 句柄更优雅。

Applied to files:

  • packages/core/src/llm-core/chat/app.ts
🧬 Code graph analysis (1)
packages/core/src/llm-core/chat/default.ts (1)
packages/core/src/utils/schema.ts (1)
  • modelSchema (15-53)
⏰ 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: lint
  • GitHub Check: build
🔇 Additional comments (5)
packages/adapter-hunyuan/src/index.ts (1)

55-55: API 密钥可选化符合 PR 目标。

在 11 个适配器包中统一将 apiKeys 元组的第一个元素从必需改为可选,允许用户在配置凭据之前安装适配器。运行时过滤逻辑(第 16-17 行)仍然确保只有非空密钥被使用。

packages/core/src/utils/schema.ts (3)

1-1: LGTM!

添加 h 导入以支持通知内容的 HTML 解析。


7-7: LGTM!

添加 @koishijs/plugin-notifier 的类型导入以支持通知系统。


27-48: 确认通知对象在上下文销毁时被正确清理
请验证 @koishijs/plugin-notifier 是否在 ctx.stop 时自动释放通知实例;如无,请在 stop 回调中添加 notification?.dispose() 以避免内存泄漏。

packages/adapter-qwen/src/index.ts (1)

52-52: 所有适配器均已移除 .required(),变更符合预期
已验证包括 qwen 在内的 11 个适配器中的 API 密钥模式已统一更新,安全且兼容。

…ification URL

- Add .default('') to API key schema definitions across all adapters to prevent
  undefined values when fields are left empty
- Fix malformed URL in notification message (remove stray "> characters)
- Ensure consistent schema behavior across all adapter packages

Affected adapters:
- azure-openai, claude, deepseek, dify, doubao, gemini, hunyuan
- openai, openai-like, qwen, rwkv, wenxin, zhipu

This complements the previous commits by providing proper default values for
optional API keys, improving the user experience when configuring adapters.
Copy link
Contributor

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

Actionable comments posted: 4

♻️ Duplicate comments (1)
packages/adapter-openai-like/src/index.ts (1)

102-102: 此问题在先前评审中已标记

先前的评审已经指出:移除 .required() 后,元组首项可能为 undefined,但 parseConfig(第 31 行)的过滤逻辑仍直接访问 apiKey.length。当默认值是 [[]] 或用户新增行但尚未填写时,这里会得到 undefined,在 ready 钩子里立即抛出 TypeError: Cannot read properties of undefined (reading 'length'),插件无法启动。

请在过滤时为解构项提供默认值或显式判断类型,避免访问空值。建议的修复方案:

-            return config.apiKeys
-                .filter(([apiKey, _, enabled]) => {
-                    return apiKey.length > 0 && enabled
-                })
-                .map(([apiKey, apiEndpoint]) => {
+            return config.apiKeys
+                .filter(([apiKey = '', , enabled = true]) => {
+                    return apiKey.length > 0 && enabled
+                })
+                .map(([apiKey = '', apiEndpoint]) => {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3c89e49 and a644bf4.

📒 Files selected for processing (14)
  • packages/adapter-azure-openai/src/index.ts (1 hunks)
  • packages/adapter-claude/src/index.ts (1 hunks)
  • packages/adapter-deepseek/src/index.ts (1 hunks)
  • packages/adapter-dify/src/index.ts (1 hunks)
  • packages/adapter-doubao/src/index.ts (1 hunks)
  • packages/adapter-gemini/src/index.ts (1 hunks)
  • packages/adapter-hunyuan/src/index.ts (1 hunks)
  • packages/adapter-openai-like/src/index.ts (1 hunks)
  • packages/adapter-openai/src/index.ts (1 hunks)
  • packages/adapter-qwen/src/index.ts (1 hunks)
  • packages/adapter-rwkv/src/index.ts (1 hunks)
  • packages/adapter-wenxin/src/index.ts (1 hunks)
  • packages/adapter-zhipu/src/index.ts (1 hunks)
  • packages/core/src/utils/schema.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (8)
  • packages/adapter-hunyuan/src/index.ts
  • packages/adapter-claude/src/index.ts
  • packages/adapter-azure-openai/src/index.ts
  • packages/adapter-wenxin/src/index.ts
  • packages/adapter-openai/src/index.ts
  • packages/adapter-zhipu/src/index.ts
  • packages/adapter-deepseek/src/index.ts
  • packages/core/src/utils/schema.ts
⏰ 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: lint
  • GitHub Check: build
🔇 Additional comments (1)
packages/adapter-dify/src/index.ts (1)

59-59: 变更安全

additionalModels 中的 apiKey 添加默认值是安全的。此文件的 parseConfig 逻辑不涉及元组解构和长度访问,不存在运行时错误风险。

Update core package version and synchronize peer dependency versions across
all adapter, extension, and service packages to 1.3.0-alpha.57.

Updated packages:
- Core: 1.3.0-alpha.56 → 1.3.0-alpha.57
- Adapters: azure-openai, claude, deepseek, dify, doubao, gemini, hunyuan,
  ollama, openai, openai-like, qwen, rwkv, spark, wenxin, zhipu (peer deps)
- Extensions: long-memory, mcp, tools, variable (peer deps)
- Services: embeddings, image, search, vector-store (peer deps)
- Renderers: image (peer deps)
- Shared: adapter (peer deps)

This release includes the notification system for model configuration guidance.
@dingyi222666 dingyi222666 merged commit e3539a0 into v1-dev Oct 11, 2025
4 of 5 checks passed
@dingyi222666 dingyi222666 deleted the feat/notification branch October 11, 2025 14:27
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