Skip to content

feat: improve LLM context service enhance logic#4527

Merged
erha19 merged 16 commits intomainfrom
fix/llm-context-service
May 8, 2025
Merged

feat: improve LLM context service enhance logic#4527
erha19 merged 16 commits intomainfrom
fix/llm-context-service

Conversation

@erha19
Copy link
Copy Markdown
Member

@erha19 erha19 commented May 7, 2025

Types

  • 🎉 New Features

Background or solution

优化 LLM 上下文管理,当用户指定文件时,不再引入当前打开的文档内容

Changelog

improve LLM context service enhance logic

Summary by CodeRabbit

  • 新功能

    • 当模型选择器被禁用时,新增悬浮提示,指引用户需清空或新建会话以切换模型。
    • 聊天界面模型选择器提示语支持中英文本地化。
  • 优化

    • 优化文件引用逻辑:手动添加文件后暂停自动收集,避免重复添加不同选择范围的同一文件。
    • 上下文提示内容调整:当已附加文件或文件夹时,不再获取当前文件信息,附加文件不再过滤最近浏览文件,全部展示。
    • 进度条组件及相关视图增加空值安全检查,防止因缺少进度模型导致的渲染错误。
    • 服务器配置保存流程调整,优化服务器添加和移除的调用顺序及异步处理。
    • 提升模态框及遮罩层的层级,确保其显示优先级更高。

@erha19 erha19 requested review from Aaaaash, ensorrow and life2015 May 7, 2025 09:18
@erha19
Copy link
Copy Markdown
Member Author

erha19 commented May 7, 2025

/next

@opensumi opensumi Bot added the 🎨 feature feature required label May 7, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2025

## Walkthrough

本次更改主要涉及 AI 聊天界面模型选择器的禁用提示优化、文件上下文管理逻辑调整、上下文提示生成逻辑的简化,以及中英文本地化字符串的新增。具体包括:为模型选择器添加禁用时的提示气泡,优化文件手动/自动引用的判断与去重,以及调整上下文提示中附件文件的处理逻辑。同时对进度条相关组件增加空值判断,防止运行时错误。服务器配置保存逻辑也做了调用顺序调整。

## Changes

| 文件路径/分组 | 变更摘要 |
|---|---|
| packages/ai-native/src/browser/components/mention-input/mention-input.tsx | 新增 `renderModelSelectorTip` 回调,模型选择器被禁用时包裹 Popover 提示,提示内容本地化。 |
| packages/ai-native/src/browser/context/llm-context.service.ts | 新增 `hasUserManualReference` 标志,手动添加文件时设置,清理上下文时重置。自动收集文件受此标志控制。文件去重逻辑增加 selection 范围判断,序列化附件时文本提取范围优化。 |
| packages/ai-native/src/common/prompts/context-prompt-provider.ts | `provideContextPrompt` 方法优化:如有附件则跳过当前文件信息获取。`buildAttachedFilesSection` 方法签名变更,移除 recentlyViewFiles 参数及相关过滤逻辑。 |
| packages/i18n/src/common/en-US.lang.ts<br>packages/i18n/src/common/zh-CN.lang.ts | 新增本地化字符串 `aiNative.chat.modelSelector.disableTip`,分别为英文和中文提示。 |
| packages/core-browser/src/progress/progress-bar.tsx<br>packages/main-layout/src/browser/accordion/section.view.tsx<br>packages/main-layout/src/browser/tabbar/bar.view.tsx<br>packages/quick-open/src/browser/quick-open.view.tsx | ProgressBar 及相关组件中对 `progressModel``indicator` 的访问增加了可选链或空值判断,防止未定义时的运行时错误。 |
| packages/ai-native/src/browser/mcp/config/mcp-config.service.ts | 调整 `saveServer` 方法中服务器配置保存与调用顺序,取消部分 await,先更新偏好设置再异步调用服务端接口。 |
| packages/ai-native/src/browser/mcp/mcp-preferences-contribution.ts | 移除未使用的导入 `CodeSchemaId``IJSONSchema`,简化导入语句。 |
| packages/components/src/style/variable.less | 提升 `@zindex-modal``@zindex-modal-mask` 的 z-index 值,从 1000 增加到 10000,调整模态框及遮罩层的层级关系。 |
| packages/ai-native/src/node/mcp-server.stdio.ts | 构造函数中针对 `command` 参数为 `'node'` 时,改为使用环境变量 `NODE_BINARY_PATH` 指定的路径或默认 `'node'`,否则直接赋值。更新方法中同样处理。 |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant User as 用户
    participant MentionInput as MentionInput组件
    participant Popover as Popover提示
    participant Select as 模型选择器

    User->>MentionInput: 打开模型选择器
    MentionInput->>MentionInput: 判断是否禁用
    alt 被禁用
        MentionInput->>Popover: 显示禁用提示
        Popover->>Select: 包裹模型选择器
    else 可用
        MentionInput->>Select: 直接渲染模型选择器
    end
sequenceDiagram
    participant User as 用户
    participant LLMContextService as 上下文服务
    participant Editor as 编辑器

    User->>LLMContextService: 手动添加文件引用
    LLMContextService->>LLMContextService: 设置 hasUserManualReference = true

    Editor->>LLMContextService: 触发自动收集文件
    LLMContextService->>LLMContextService: 检查 hasUserManualReference
    alt 已手动引用
        LLMContextService-->>Editor: 跳过自动添加
    else 未手动引用
        LLMContextService->>LLMContextService: 自动添加文件
    end

    User->>LLMContextService: 清理上下文
    LLMContextService->>LLMContextService: 重置 hasUserManualReference = false
Loading

Suggested reviewers

  • ensorrow
  • Aaaaash
  • life2015
  • Ricbet

<!-- walkthrough_end -->
<!-- This is an auto-generated comment: all tool run failures by coderabbit.ai -->

> [!WARNING]
> There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.
> 
> <details>
> <summary>🔧 ESLint</summary>
> 
> > If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.
> 
> yarn install v1.22.22
> [1/4] Resolving packages...
> warning eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options.
> warning eslint > @humanwhocodes/config-array@0.13.0: Use @eslint/config-array instead
> warning eslint > file-entry-cache > flat-cache > rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
> warning eslint > file-entry-cache > flat-cache > rimraf > glob@7.2.3: Glob versions prior to v9 are no longer supported
> warning eslint > file-entry-cache > flat-cache > rimraf > glob > inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
> warning eslint > @humanwhocodes/config-array > @humanwhocodes/object-schema@2.0.3: Use @eslint/object-schema instead
> warning eslint-import-resolver-typescript > glob@7.2.3: Glob versions prior to v9 are no longer supported
> error Couldn't find any versions for "@opensumi/ide-dev-tool" that matches "workspace:*"
> info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
> 
> 
> 
> </details>

<!-- end of auto-generated comment: all tool run failures by coderabbit.ai -->


---

<details>
<summary>📜 Recent review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 12a9683635ddb3d75c2ad643b4565d01027603c2 and 22e2db2161e066257170956b449ccef8b1c8909b.

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `packages/ai-native/src/node/mcp-server.stdio.ts` (2 hunks)

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary>

* packages/ai-native/src/node/mcp-server.stdio.ts

</details>

<details>
<summary>⏰ Context from checks skipped due to timeout of 90000ms (9)</summary>

* GitHub Check: 🚀🚀🚀 Next Version for pull request
* GitHub Check: unittest (macos-latest, 18.x, jsdom)
* GitHub Check: ubuntu-latest, Node.js 20.x
* GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
* GitHub Check: unittest (ubuntu-latest, 18.x, node)
* GitHub Check: unittest (macos-latest, 18.x, node)
* GitHub Check: build-windows
* GitHub Check: build (macos-latest, 20.x)
* GitHub Check: build (ubuntu-latest, 20.x)

</details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKNwSPbABsvkCiQBHbGlcSHFcLzpIACIAMxJqLnhmXnwpSAAZDIBZBQwaAA9QxEoJeAYPMlhMCsgvfCJy6MgAdzRkBwFmdRp6OUhsEr5KaoBGAE50ZFtIDEcBSkgAFgBWACYAdg0YWA9mbSxY/AZB/liwhGm7VAJ+bnFugC8PXF3IfYw0UjZ8s7zC0ItdQILCvDwZZykTKYIjYL4ebKKEi+AAUWWyAEp7KVyiRtgBlbiieCxcpoHyyAA0Fw82G4tGoHgY1QwpGQYMgC2qZXwfEQ+Au1FauywaAGQ3sRIYJPg0nQPGc4h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CJPJ94tQZLGliIwfIPFVmNYOoF8RuYfgKQvU3bpCwkQlMNQGLFpjzT6YdUdQEOJmSIAhxk0CCHQCHGH04YBgE6eMFcwMBYgowWgCsBWAABmWIGOg2C0AGAowTYOsFiACAVgGwNAEsFoDjA0AawAAGzjBQZcMhMmsFcxgyJYhgE6bQATIJlRgcM1zIGjBlrAvp4wcYGqlGAMBwZowVYHDJUCbBiZCQUYLEA2AMA1gJABMisAxmPSEY6AL6U1HGCJkUZn0kgPjJemjAgZRkNYJDITIkYIZSwcYAmTQCuYVgzUNYOcDpg8yGASwVmcLIYAbBxgAgL6a9JWAJkPpaAOGaoFUBLBmZtAOGbQFiAoylgawJYCQCWDKyuZJ0vGXDKWACBVgtstYGsFNkkZ1ggcr6QmVWCAyvptAAQLEHtkrA0AsMtACsC1lrAPZPMgQHDLHTJzDZtAJYAmVUBKB64aAEgFHPDmvSY5aAU2VHKTmsyvpawegBrIgCQAJZ4wZGV9LhlfSVgVUHORsGTlSzbZSwL6b7JWBwyu5rmD4ZsHxlGzU5jcqAAHJID1yBAawPGaMBICuY4ZcMtYFTI2CuZxgI832fLM2YOyBAFMhMs9INlczuZTcnGGdIulXTBCN02gEOICz6AgAA== -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

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.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=opensumi/core&utm_content=4527):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Generate unit testing code for this file.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai generate unit testing code for this file.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and generate unit testing code.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json`

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

Copy link
Copy Markdown
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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bb36783 and 90cf1d5.

📒 Files selected for processing (5)
  • packages/ai-native/src/browser/components/mention-input/mention-input.tsx (2 hunks)
  • packages/ai-native/src/browser/context/llm-context.service.ts (5 hunks)
  • packages/ai-native/src/common/prompts/context-prompt-provider.ts (2 hunks)
  • packages/i18n/src/common/en-US.lang.ts (1 hunks)
  • packages/i18n/src/common/zh-CN.lang.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/ai-native/src/browser/context/llm-context.service.ts (1)
packages/ai-native/src/common/llm-context.ts (1)
  • FileContext (49-52)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: 🚀🚀🚀 Next Version for pull request
  • GitHub Check: build-windows
  • GitHub Check: build (ubuntu-latest, 20.x)
  • GitHub Check: build (macos-latest, 20.x)
  • GitHub Check: ubuntu-latest, Node.js 20.x
🔇 Additional comments (7)
packages/ai-native/src/browser/context/llm-context.service.ts (1)

55-60: 去重逻辑细化 👍

比较条件加入了 selection 起止行,能有效避免“同文件不同选区”产生的重复条目,值得肯定。

packages/ai-native/src/common/prompts/context-prompt-provider.ts (2)

26-28: 当存在附加文件/文件夹时忽略当前文件信息——请确认符合预期

如果用户手动附加了文件,但仍希望模型同时获得当前文件上下文,新的逻辑将不再满足需求。
建议评估业务场景:是否需要通过设置项或参数保留旧行为。


95-112: buildAttachedFilesSection 精简入参 👍

移除了对 recentlyViewFiles 的过滤,逻辑更直观、实现更简洁。

packages/i18n/src/common/zh-CN.lang.ts (1)

1237-1237: 新增模型选择器禁用提示已就绪

文案贴切,键名也保持了命名一致性,无其他问题。

packages/i18n/src/common/en-US.lang.ts (1)

1469-1470: 本地化字符串已添加,确保中文版本也同步更新

新增的本地化字符串为模型选择器被禁用时提供了清晰的提示信息,告诉用户需要清除或创建新会话才能更改模型。

packages/ai-native/src/browser/components/mention-input/mention-input.tsx (2)

1022-1038: 实现良好的气泡提示功能

renderModelSelectorTip 函数实现了条件性地为禁用状态的模型选择器添加气泡提示,代码结构清晰。使用 React.useCallback 进行了适当的性能优化,依赖项设置正确,确保只在 footerConfig.disableModelSelector 变化时重新创建函数。


1069-1079: 模型选择器渲染逻辑优化

渲染代码已适当更新,使用新的 renderModelSelectorTip 函数来条件性地添加提示气泡。这种实现提升了用户体验,当模型选择器被禁用时,用户能够看到明确的提示信息。

Comment thread packages/ai-native/src/browser/context/llm-context.service.ts
Comment thread packages/ai-native/src/browser/context/llm-context.service.ts
Comment thread packages/ai-native/src/browser/context/llm-context.service.ts Outdated
Comment on lines 293 to 294
file.selection && new Range(file.selection[0], 0, file.selection[1] + 1, Infinity),
),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Range 起始列应从 1 开始,且不宜多加一行

Monaco 的列号从 1 开始,传入 0 可能触发异常;
同时把 endLineNumber 设为 selection[1] + 1 会越界,进而导致取文本失败。

-          file.selection && new Range(file.selection[0], 0, file.selection[1] + 1, Infinity),
+          file.selection && new Range(file.selection[0], 1, file.selection[1], Infinity),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
file.selection && new Range(file.selection[0], 0, file.selection[1] + 1, Infinity),
),
file.selection && new Range(file.selection[0], 1, file.selection[1], Infinity),
),
🤖 Prompt for AI Agents (early access)
In packages/ai-native/src/browser/context/llm-context.service.ts at lines
293-294, the Range constructor uses a start column of 0 and an end line number
of selection[1] + 1, which is incorrect. Change the start column to 1 since
Monaco columns start at 1, and set the end line number to selection[1] without
adding 1 to avoid out-of-bounds errors.

@opensumi
Copy link
Copy Markdown
Contributor

opensumi Bot commented May 7, 2025

🎉 PR Next publish successful!

3.8.3-next-1746609719.0

@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2025

Codecov Report

Attention: Patch coverage is 8.00000% with 23 lines in your changes missing coverage. Please review.

Project coverage is 53.02%. Comparing base (bb36783) to head (22e2db2).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...-native/src/browser/context/llm-context.service.ts 0.00% 13 Missing and 5 partials ⚠️
...ative/src/browser/mcp/config/mcp-config.service.ts 0.00% 3 Missing ⚠️
...tive/src/common/prompts/context-prompt-provider.ts 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4527      +/-   ##
==========================================
- Coverage   53.02%   53.02%   -0.01%     
==========================================
  Files        1669     1669              
  Lines      102941   102951      +10     
  Branches    22299    22308       +9     
==========================================
+ Hits        54583    54588       +5     
  Misses      40228    40228              
- Partials     8130     8135       +5     
Flag Coverage Δ
jsdom 48.51% <0.00%> (+<0.01%) ⬆️
node 12.10% <8.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@erha19
Copy link
Copy Markdown
Member Author

erha19 commented May 7, 2025

/next

@opensumi
Copy link
Copy Markdown
Contributor

opensumi Bot commented May 7, 2025

🎉 PR Next publish successful!

3.8.3-next-1746611266.0

@erha19
Copy link
Copy Markdown
Member Author

erha19 commented May 7, 2025

/next

@opensumi
Copy link
Copy Markdown
Contributor

opensumi Bot commented May 7, 2025

🎉 PR Next publish successful!

3.8.3-next-1746617857.0

@erha19
Copy link
Copy Markdown
Member Author

erha19 commented May 7, 2025

/next

Copy link
Copy Markdown
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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a3edb91 and c4c255e.

📒 Files selected for processing (1)
  • packages/ai-native/src/browser/mcp/config/mcp-config.service.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/ai-native/src/browser/mcp/config/mcp-config.service.ts (1)
packages/ai-native/src/common/mcp-server-manager.ts (1)
  • MCPServerDescription (95-98)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: 🚀🚀🚀 Next Version for pull request
  • GitHub Check: build (ubuntu-latest, 20.x)
  • GitHub Check: build (macos-latest, 20.x)
  • GitHub Check: build-windows
  • GitHub Check: unittest (ubuntu-latest, 18.x, node)
  • GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
  • GitHub Check: unittest (macos-latest, 18.x, jsdom)
  • GitHub Check: unittest (macos-latest, 18.x, node)
  • GitHub Check: ubuntu-latest, Node.js 20.x

Comment on lines +207 to +211
await this.preferenceService.set('mcp', { mcpServers: servers });
if (prev?.enabled) {
await this.sumiMCPServerBackendProxy.$removeServer(prev.name);
this.sumiMCPServerBackendProxy.$removeServer(prev.name);
}
await this.preferenceService.set('mcp', { mcpServers: servers });
this.sumiMCPServerBackendProxy.$addOrUpdateServer(data as MCPServerDescription);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

调整了保存服务器配置的操作顺序和异步行为

代码改动将首先更新偏好设置,然后异步执行后端服务器操作而不等待完成。这种变更有以下影响:

  1. 用户界面会立即反映新配置,提升了感知响应速度
  2. 由于不再等待后端操作完成,方法会更快返回
  3. 后端操作失败时用户不会立即收到通知

建议添加错误处理机制以捕获后端操作可能出现的错误:

 await this.preferenceService.set('mcp', { mcpServers: servers });
 if (prev?.enabled) {
-  this.sumiMCPServerBackendProxy.$removeServer(prev.name);
+  this.sumiMCPServerBackendProxy.$removeServer(prev.name).catch(error => {
+    this.logger.error(`无法移除服务器 ${prev.name}:`, error);
+    this.messageService.error(localize('ai.native.mcp.error.remove.server', '无法移除服务器: {0}', error.message || error));
+  });
 }
-this.sumiMCPServerBackendProxy.$addOrUpdateServer(data as MCPServerDescription);
+this.sumiMCPServerBackendProxy.$addOrUpdateServer(data as MCPServerDescription).catch(error => {
+  this.logger.error(`无法添加或更新服务器 ${data.name}:`, error);
+  this.messageService.error(localize('ai.native.mcp.error.add.server', '无法添加或更新服务器: {0}', error.message || error));
+});
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
await this.preferenceService.set('mcp', { mcpServers: servers });
if (prev?.enabled) {
await this.sumiMCPServerBackendProxy.$removeServer(prev.name);
this.sumiMCPServerBackendProxy.$removeServer(prev.name);
}
await this.preferenceService.set('mcp', { mcpServers: servers });
this.sumiMCPServerBackendProxy.$addOrUpdateServer(data as MCPServerDescription);
await this.preferenceService.set('mcp', { mcpServers: servers });
if (prev?.enabled) {
this.sumiMCPServerBackendProxy.$removeServer(prev.name).catch(error => {
this.logger.error(`无法移除服务器 ${prev.name}:`, error);
this.messageService.error(
localize('ai.native.mcp.error.remove.server', '无法移除服务器: {0}', error.message || error)
);
});
}
this.sumiMCPServerBackendProxy.$addOrUpdateServer(data as MCPServerDescription).catch(error => {
this.logger.error(`无法添加或更新服务器 ${data.name}:`, error);
this.messageService.error(
localize('ai.native.mcp.error.add.server', '无法添加或更新服务器: {0}', error.message || error)
);
});
🤖 Prompt for AI Agents (early access)
In packages/ai-native/src/browser/mcp/config/mcp-config.service.ts around lines
207 to 211, the code updates preferences first and then calls backend server
operations asynchronously without awaiting them, which improves UI
responsiveness but loses error handling for backend failures. Modify the code to
add try-catch blocks around the backend calls to $removeServer and
$addOrUpdateServer, and handle or log any errors to ensure backend operation
failures are captured and can be addressed.

@opensumi
Copy link
Copy Markdown
Contributor

opensumi Bot commented May 7, 2025

🎉 PR Next publish successful!

3.8.3-next-1746621593.0

@erha19
Copy link
Copy Markdown
Member Author

erha19 commented May 7, 2025

/next

@opensumi
Copy link
Copy Markdown
Contributor

opensumi Bot commented May 7, 2025

🎉 PR Next publish successful!

3.8.3-next-1746625865.0

@erha19
Copy link
Copy Markdown
Member Author

erha19 commented May 7, 2025

/next

Copy link
Copy Markdown
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: 1

🧹 Nitpick comments (1)
packages/ai-native/src/node/mcp-server.stdio.ts (1)

27-27: 建议增加环境变量路径验证

当使用 NODE_BINARY_PATH 环境变量时,目前没有验证该路径是否指向有效的可执行文件。如果环境变量设置了无效路径,可能会导致服务器启动失败,而错误信息可能不够明确。

建议添加一个辅助方法来验证可执行文件路径的有效性:

+ import { existsSync, accessSync, constants } from 'fs';
+ import { resolve } from 'path';

constructor(
  name: string,
  command: string,
  args?: string[],
  env?: Record<string, string>,
  private readonly logger?: ILogger,
) {
  this.name = name;
-  this.command = command === 'node' ? process.env.NODE_BINARY_PATH || 'node' : command;
+  if (command === 'node' && process.env.NODE_BINARY_PATH) {
+    const nodePath = process.env.NODE_BINARY_PATH;
+    try {
+      // 验证路径是否存在且可执行
+      const fullPath = resolve(nodePath);
+      if (existsSync(fullPath)) {
+        accessSync(fullPath, constants.X_OK);
+        this.command = nodePath;
+      } else {
+        this.logger?.warn(`环境变量 NODE_BINARY_PATH 设置的路径 "${nodePath}" 不存在,将使用默认的 "node" 命令`);
+        this.command = 'node';
+      }
+    } catch (error) {
+      this.logger?.warn(`环境变量 NODE_BINARY_PATH 设置的路径 "${nodePath}" 不可执行,将使用默认的 "node" 命令`, error);
+      this.command = 'node';
+    }
+  } else {
+    this.command = command;
+  }
  this.args = args;
  this.env = env;
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b6cc5cb and 12a9683.

📒 Files selected for processing (1)
  • packages/ai-native/src/node/mcp-server.stdio.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: unittest (macos-latest, 18.x, jsdom)
  • GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
  • GitHub Check: unittest (ubuntu-latest, 18.x, node)
  • GitHub Check: unittest (macos-latest, 18.x, node)
  • GitHub Check: 🚀🚀🚀 Next Version for pull request
  • GitHub Check: ubuntu-latest, Node.js 20.x
  • GitHub Check: build-windows
  • GitHub Check: build (ubuntu-latest, 20.x)
  • GitHub Check: build (macos-latest, 20.x)

Comment thread packages/ai-native/src/node/mcp-server.stdio.ts
@opensumi
Copy link
Copy Markdown
Contributor

opensumi Bot commented May 7, 2025

🎉 PR Next publish successful!

3.8.3-next-1746626195.0

@erha19
Copy link
Copy Markdown
Member Author

erha19 commented May 7, 2025

/next

@opensumi
Copy link
Copy Markdown
Contributor

opensumi Bot commented May 7, 2025

🎉 PR Next publish successful!

3.8.3-next-1746629393.0

@erha19 erha19 merged commit 26ad68b into main May 8, 2025
12 checks passed
@erha19 erha19 deleted the fix/llm-context-service branch May 8, 2025 08:11
@erha19 erha19 mentioned this pull request May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🎨 feature feature required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants