Skip to content

feat(chat): add message summary provider to ChatFeatureRegistry#4573

Merged
Aaaaash merged 9 commits into
mainfrom
feat/add-chat-message-summary-provider
Jun 4, 2025
Merged

feat(chat): add message summary provider to ChatFeatureRegistry#4573
Aaaaash merged 9 commits into
mainfrom
feat/add-chat-message-summary-provider

Conversation

@Aaaaash
Copy link
Copy Markdown
Member

@Aaaaash Aaaaash commented May 28, 2025

Types

  • 🎉 New Features
  • 🐛 Bug Fixes
  • 📚 Documentation Changes
  • 💄 Code Style Changes
  • 💄 Style Changes
  • 🪚 Refactors
  • 🚀 Performance Improvements
  • 🏗️ Build System
  • ⏱ Tests
  • 🧹 Chores
  • Other Changes

Background or solution

Changelog

Summary by CodeRabbit

  • 新功能
    • 聊天会话标题现在可通过消息摘要提供者自动生成摘要,提升标题的智能化和简洁性。
    • 新增消息摘要提供者接口及其注册功能,支持基于会话消息自动生成简洁摘要。
    • 引入消息摘要缓存机制,减少频繁摘要请求,提高性能和响应速度。
  • 改进
    • 支持注册和获取自定义消息摘要提供者,为未来扩展和个性化摘要功能打下基础。

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

coderabbitai Bot commented May 28, 2025

"""

Walkthrough

本次更改为聊天功能引入了消息摘要提供器的注册与获取机制。通过扩展注册表和类型接口,允许异步获取会话摘要,以优化聊天视图标题的展示逻辑。涉及的主要变动包括注册表、类型声明和视图组件的调整,以及在示例模块中注册具体的摘要提供器实现。

Changes

文件/分组 变更摘要
packages/ai-native/src/browser/chat/chat.feature.registry.ts 增加了消息摘要提供器的私有字段,新增注册和获取摘要提供器的方法。
packages/ai-native/src/browser/types.ts 扩展注册表接口,新增消息摘要提供器接口及相关方法声明。
packages/ai-native/src/browser/chat/chat.view.tsx 聊天头部组件引入注册表依赖,根据摘要提供器异步设置会话标题。
packages/startup/entry/sample-modules/ai-native/ai-native.contribution.ts 新增私有异步方法获取摘要,注册消息摘要提供器实现,调用AI后端生成摘要。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DefaultChatViewHeader
    participant ChatFeatureRegistry
    participant IMessageSummaryProvider

    User->>DefaultChatViewHeader: 进入聊天界面
    DefaultChatViewHeader->>ChatFeatureRegistry: 获取MessageSummaryProvider
    alt 存在摘要提供器
        DefaultChatViewHeader->>IMessageSummaryProvider: getMessageSummary(消息列表)
        IMessageSummaryProvider-->>DefaultChatViewHeader: 返回摘要或undefined
        alt 返回摘要
            DefaultChatViewHeader->>DefaultChatViewHeader: 设置标题为摘要(截断)
        else 未返回摘要
            DefaultChatViewHeader->>DefaultChatViewHeader: 设置标题为最新用户消息(截断)
        end
    else 不存在摘要提供器
        DefaultChatViewHeader->>DefaultChatViewHeader: 设置标题为最新用户消息(截断)
    end
Loading

Suggested labels

🎨 feature

Suggested reviewers

  • Ricbet
  • life2015
    """

📜 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 0721634 and f95d604.

📒 Files selected for processing (1)
  • packages/extension/__tests__/browser/extension-service/extension.service.test.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/extension/tests/browser/extension-service/extension.service.test.ts
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: build (macos-latest, 20.x)
  • GitHub Check: build (ubuntu-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, node)
  • GitHub Check: unittest (macos-latest, 18.x, jsdom)
  • GitHub Check: ubuntu-latest, Node.js 20.x
✨ 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
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 (2)
packages/ai-native/src/browser/types.ts (1)

303-308: 接口设计良好,但建议增强错误处理

IMessageSummaryProvider接口设计简洁明确,方法签名合理。不过建议考虑以下增强:

  1. 添加取消令牌参数以支持长时间运行的摘要生成任务的取消
  2. 考虑添加错误类型定义以便更好地处理异常情况

可选的增强建议:

export interface IMessageSummaryProvider {
  /**
   * @param sessionId 会话 ID
+   * @param token 取消令牌,用于支持长时间运行任务的取消
   */
-  getMessageSummary(sessionId: string): Promise<string | undefined>;
+  getMessageSummary(sessionId: string, token?: CancellationToken): Promise<string | undefined>;
}
packages/ai-native/src/browser/chat/chat.feature.registry.ts (1)

33-39: 方法实现正确但可以考虑增强

方法实现简洁正确,遵循了类中其他提供器注册方法的模式。建议考虑以下增强:

  1. registerMessageSummaryProvider中添加重复注册的警告日志,与registerSlashCommand方法保持一致
  2. 考虑返回IDisposable以支持注销功能

可选的增强建议:

public registerMessageSummaryProvider(provider: IMessageSummaryProvider): void {
+  if (this.messageSummaryProvider) {
+    this.logger.warn('ChatFeatureRegistry: messageSummaryProvider already exists, replacing');
+  }
  this.messageSummaryProvider = provider;
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9d7784b and d0fcaa8.

📒 Files selected for processing (3)
  • packages/ai-native/src/browser/chat/chat.feature.registry.ts (3 hunks)
  • packages/ai-native/src/browser/chat/chat.view.tsx (2 hunks)
  • packages/ai-native/src/browser/types.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
packages/ai-native/src/browser/types.ts (1)
packages/ai-native/src/browser/chat/chat-model.ts (1)
  • sessionId (307-309)
packages/ai-native/src/browser/chat/chat.feature.registry.ts (1)
packages/ai-native/src/browser/types.ts (1)
  • IMessageSummaryProvider (303-308)
packages/ai-native/src/browser/chat/chat.view.tsx (3)
packages/core-browser/src/react-hooks/injectable-hooks.tsx (1)
  • useInjectable (16-39)
packages/core-common/src/types/ai-native/index.ts (1)
  • ChatFeatureRegistryToken (297-297)
packages/ai-native/src/common/utils.ts (1)
  • cleanAttachedTextWrapper (60-66)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: build-windows
  • GitHub Check: build (ubuntu-latest, 20.x)
  • GitHub Check: build (macos-latest, 20.x)
  • GitHub Check: unittest (macos-latest, 18.x, node)
  • 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, jsdom)
🔇 Additional comments (4)
packages/ai-native/src/browser/types.ts (1)

137-138: 接口扩展设计合理

IChatFeatureRegistry接口中添加registerMessageSummaryProvider方法的设计是合理的,与现有的注册模式保持一致。方法签名清晰,参数类型正确。

packages/ai-native/src/browser/chat/chat.feature.registry.ts (2)

5-11: 导入语句正确

新增的IMessageSummaryProvider导入语句正确,与其他类型导入保持一致的格式。


23-23: 私有字段声明合理

私有字段messageSummaryProvider的声明遵循了类中其他类似字段的模式,使用可选类型是合适的设计。

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

921-921: 依赖注入正确

通过useInjectable钩子注入ChatFeatureRegistry的方式正确,与文件中其他服务注入保持一致。

Comment thread packages/ai-native/src/browser/chat/chat.view.tsx
@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2025

Codecov Report

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

Project coverage is 52.78%. Comparing base (e68714e) to head (f95d604).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...i-native/src/browser/chat/chat.feature.registry.ts 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #4573       +/-   ##
===========================================
+ Coverage   12.07%   52.78%   +40.70%     
===========================================
  Files        1673     1681        +8     
  Lines      102620   103740     +1120     
  Branches    20965    22484     +1519     
===========================================
+ Hits        12394    54758    +42364     
+ Misses      76037    40736    -35301     
+ Partials    14189     8246     -5943     
Flag Coverage Δ
jsdom 48.29% <0.00%> (?)
node 12.07% <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.

@Aaaaash
Copy link
Copy Markdown
Member Author

Aaaaash commented May 28, 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 d0fcaa8 and 0e655f7.

📒 Files selected for processing (3)
  • packages/ai-native/src/browser/chat/chat.view.tsx (2 hunks)
  • packages/ai-native/src/browser/types.ts (3 hunks)
  • packages/startup/entry/sample-modules/ai-native/ai-native.contribution.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/ai-native/src/browser/chat/chat.view.tsx
  • packages/ai-native/src/browser/types.ts
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: 🚀🚀🚀 Next Version for pull request
  • GitHub Check: build (macos-latest, 20.x)
  • GitHub Check: build-windows
  • GitHub Check: build (ubuntu-latest, 20.x)
  • GitHub Check: ubuntu-latest, Node.js 20.x
🔇 Additional comments (2)
packages/startup/entry/sample-modules/ai-native/ai-native.contribution.ts (2)

38-38: 导入添加正确

正确添加了 ChatMessageRole 导入,这是下面新功能所需要的类型。


249-282: 消息摘要提供器实现良好

实现包含了以下优秀的实践:

  • 限制消息数量(最近10条)避免请求过大
  • 清晰的提示工程,包含具体要求和示例
  • 适当的错误处理(取消和错误码检查)
  • 返回空字符串作为降级处理

代码逻辑正确且健壮。

Comment thread packages/startup/entry/sample-modules/ai-native/ai-native.contribution.ts Outdated
@opensumi
Copy link
Copy Markdown
Contributor

opensumi Bot commented May 28, 2025

🎉 PR Next publish successful!

3.9.1-next-1748425792.0

@Aaaaash
Copy link
Copy Markdown
Member Author

Aaaaash commented May 29, 2025

/next

@opensumi
Copy link
Copy Markdown
Contributor

opensumi Bot commented May 29, 2025

🎉 PR Next publish successful!

3.9.1-next-1748523870.0

@Aaaaash Aaaaash merged commit e591531 into main Jun 4, 2025
15 of 19 checks passed
@Aaaaash Aaaaash deleted the feat/add-chat-message-summary-provider branch June 4, 2025 03:47
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.

2 participants