Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

erha19
Copy link
Member

@erha19 erha19 commented May 13, 2025

Types

  • 🐛 Bug Fixes

Background or solution

引用 file 等内容时移除多余的文本结构

Changelog

not process attached key to LLM

Summary by CodeRabbit

  • 新功能

    • 增加了用于处理文件和文件夹引用的上下文标识符及其正则表达式,提升消息内容中相关引用的处理一致性。
  • 样式

    • 优化了提及标签的字体大小显示,使其更为统一(字体大小设为12px)。
  • 优化

    • 聊天输入框中的“代码”提及项现在显示在菜单末尾,提升选择体验。
    • 对话框服务在隐藏时增加了健壮性,避免因未定义状态导致的潜在错误。

@erha19 erha19 requested review from life2015, ensorrow and Aaaaash May 13, 2025 07:10
@opensumi opensumi bot added the 🐞 bug Something isn't working label May 13, 2025
Copy link
Contributor

@ensorrow ensorrow left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

coderabbitai bot commented May 13, 2025

Walkthrough

本次更改主要引入了用于文件和文件夹占位符的新枚举和正则表达式常量,并在聊天相关逻辑中用这些符号化键替换了硬编码字符串。同时,调整了提及输入组件的菜单项顺序,并为提及标签添加了字体大小样式。此外,对对话框服务的隐藏方法进行了空值安全处理。

Changes

文件/分组 变更摘要
packages/ai-native/src/browser/chat/chat.view.tsx 扩展了对 LLM context 常量的导入,发送消息时用 LLM_CONTEXT_KEY 替换硬编码占位符,并在历史记录中移除匹配 LLM_CONTEXT_KEY_REGEX 的内容。
packages/ai-native/src/common/llm-context.ts 新增导出枚举 LLM_CONTEXT_KEY(含 <attached_file><attached_folder>)及正则常量 LLM_CONTEXT_KEY_REGEX
packages/ai-native/src/browser/components/ChatMentionInput.tsx 将 "code" 提及菜单项从数组首位移至末尾,内容和逻辑未变。
packages/ai-native/src/browser/components/mention-input/mention-input.module.less .mention_tag 类新增 font-size: 12px; 样式。
packages/overlay/src/browser/dialog.service.ts hide 方法中对 this.deferred 的调用增加可选链,避免未定义时出错。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ChatView
    participant LLMContext

    User->>ChatView: 发送消息(含文件/文件夹占位符)
    ChatView->>LLMContext: 用 LLM_CONTEXT_KEY 替换占位符
    ChatView->>ChatView: 移除历史消息中匹配 LLM_CONTEXT_KEY_REGEX 的内容
    ChatView->>User: 显示处理后的消息
Loading

Possibly related PRs

Suggested labels

🐞 bug

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.

🔧 ESLint

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 [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/[email protected]: Use @eslint/config-array instead
warning eslint > @humanwhocodes/config-array > @humanwhocodes/[email protected]: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > [email protected]: Rimraf versions prior to v4 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > [email protected]: 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-import-resolver-typescript > [email protected]: 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.

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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 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 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 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 for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 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 d0efae9 and 5fa4ae2.

📒 Files selected for processing (5)
  • packages/ai-native/src/browser/chat/chat.view.tsx (5 hunks)
  • packages/ai-native/src/browser/components/ChatMentionInput.tsx (1 hunks)
  • packages/ai-native/src/browser/components/mention-input/mention-input.module.less (1 hunks)
  • packages/ai-native/src/common/llm-context.ts (1 hunks)
  • packages/overlay/src/browser/dialog.service.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/ai-native/src/browser/chat/chat.view.tsx (1)
packages/ai-native/src/common/llm-context.ts (1)
  • LLM_CONTEXT_KEY_REGEX (74-74)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: build (ubuntu-latest, 20.x)
  • GitHub Check: build-windows
  • GitHub Check: build (macos-latest, 20.x)
  • 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
🔇 Additional comments (9)
packages/overlay/src/browser/dialog.service.ts (1)

67-67: 增强了防护性编程

使用可选链操作符(?.)可以防止在 this.deferred 为 null 或 undefined 时的运行时错误,提高了代码的健壮性。

packages/ai-native/src/common/llm-context.ts (2)

69-72: 良好的常量定义方式

将附加文件和文件夹的标记抽取为枚举常量很好地集中了这些值的管理,提高了代码的可维护性。


74-74: 有效集中正则表达式定义

定义一个正则表达式常量以匹配附加文件和文件夹标记,使得在代码中可以统一处理这些标记,避免硬编码重复。

packages/ai-native/src/browser/components/mention-input/mention-input.module.less (1)

330-330: 提升 UI 一致性

为提及标签添加明确的字体大小设置,确保了 UI 显示的一致性。

packages/ai-native/src/browser/chat/chat.view.tsx (4)

44-48: 合理扩展导入

扩展导入以包含新定义的枚举和正则表达式常量,为后续修改做准备。


709-710: 使用枚举替代硬编码字符串

使用 LLM_CONTEXT_KEY.AttachedFile 枚举值替代硬编码的字符串,提高了代码的可维护性和一致性。


720-721: 使用枚举替代硬编码字符串

使用 LLM_CONTEXT_KEY.AttachedFolder 枚举值替代硬编码的字符串,保持了与文件处理的一致性。


737-739: 一致使用常量进行代码引用处理

在处理代码引用时也使用了枚举常量,确保整个代码库中标记的处理方式保持一致,避免潜在的不匹配问题。

packages/ai-native/src/browser/components/ChatMentionInput.tsx (1)

267-314: 顺序调整符合优化提及项显示逻辑

将"Code"提及项从数组开头移动到末尾,这个调整与PR的目标一致,有助于确保附加键不被LLM处理。此更改与其他文件中使用LLM_CONTEXT_KEY枚举标准化引用上下文的方式相协调。

菜单项的重新排序不影响功能,只改变了UI中显示的顺序,使用户界面更加一致。

msgHistoryManager.addUserMessage({
content: message,
content: message.replaceAll(LLM_CONTEXT_KEY_REGEX, ''),
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

修复关键 Bug:防止将附加键发送给 LLM

使用正则表达式移除消息中的附加文件和文件夹标记,确保这些标记不会被发送给 LLM 处理,符合 PR 的主要目标。

这个修改解决了原始问题,确保 LLM 不会处理附加的标记文本。

🤖 Prompt for AI Agents (early access)
In packages/ai-native/src/browser/chat/chat.view.tsx at line 645, the content
field should be set by removing all occurrences of additional key markers from
the message using the LLM_CONTEXT_KEY_REGEX regular expression. This prevents
sending appended file and folder tags to the LLM, ensuring only the cleaned
message content is processed. Update the code to replace all matches of
LLM_CONTEXT_KEY_REGEX in the message with an empty string before assigning it to
content.

Copy link

codecov bot commented May 13, 2025

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.

Project coverage is 52.88%. Comparing base (4f0501b) to head (5fa4ae2).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
packages/ai-native/src/common/llm-context.ts 0.00% 3 Missing and 1 partial ⚠️
packages/overlay/src/browser/dialog.service.ts 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4545   +/-   ##
=======================================
  Coverage   52.88%   52.88%           
=======================================
  Files        1677     1677           
  Lines      103354   103358    +4     
  Branches    22381    22391   +10     
=======================================
+ Hits        54657    54662    +5     
+ Misses      40519    40516    -3     
- Partials     8178     8180    +2     
Flag Coverage Δ
jsdom 48.39% <0.00%> (+<0.01%) ⬆️
node 12.06% <0.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 erha19 merged commit b838b53 into main May 13, 2025
13 checks passed
@erha19 erha19 deleted the feat/improve-attach-file-ux branch May 13, 2025 07:32
@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
🐞 bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants