Skip to content

feat(use-x-chat): add updating status #833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

wzc520pyfm
Copy link
Contributor

@wzc520pyfm wzc520pyfm commented May 17, 2025

中文版模板 / Chinese template

🤔 This is a ...

  • 🆕 New feature
  • 🐞 Bug fix
  • 📝 Site / documentation improvement
  • 📽️ Demo improvement
  • 💄 Component style improvement
  • 🤖 TypeScript definition improvement
  • 📦 Bundle size optimization
  • ⚡️ Performance optimization
  • ⭐️ Feature enhancement
  • 🌐 Internationalization
  • 🛠 Refactoring
  • 🎨 Code style optimization
  • ✅ Test Case
  • 🔀 Branch merge
  • ⏩ Workflow
  • ⌨️ Accessibility improvement
  • ❓ Other (about what?)

🔗 Related Issues

  • Describe the source of related requirements, such as links to relevant issue discussions.
  • For example: close #xxxx, fix #xxxx

Close #832 .

💡 Background and Solution

  • The specific problem to be addressed.
  • List the final API implementation and usage if needed.
  • If there are UI/interaction changes, consider providing screenshots or GIFs.

之前的行为:

使用流式返回时,消息更新的回调(onUpdate)status为loading

pr改动:

使用流式返回时,消息更新的回调(onUpdate)设置status为updating而不是loading,以此区分开loading和updating。

这样,流式返回和非流式返回就可以使用相同的方式设置bubble loading:

  const { onRequest, messages } = useXChat({
    agent,
  });

<Bubble.List
        roles={roles}
        style={{ maxHeight: 300 }}
        items={messages.map(({ id, message, status }) => ({
          key: id,
          // Loading
          loading: status === 'loading',
          role: status === 'local' ? 'local' : 'ai',
          content: message,
        }))}
      />

📝 Change Log

Language Changelog
🇺🇸 English add updating status for useXChat MessageStatus
🇨🇳 Chinese 为MessageStatus添加updating状态

Summary by CodeRabbit

  • 新功能

    • 消息状态新增“更新中”标识,区分消息流式更新与初始加载阶段。
    • 聊天消息列表中新增加载状态显示,提升消息加载反馈体验。
  • 测试

    • 测试用例同步更新,验证消息中间状态为“更新中”。

Copy link
Contributor

coderabbitai bot commented May 17, 2025

📝 Walkthrough

"""

Walkthrough

本次变更在 useXChat 组件中,为消息状态 MessageStatus 新增了 'updating' 状态,并在流式返回期间(onUpdate 回调)将消息状态从 'loading' 改为 'updating',以便更精确地区分消息加载与更新阶段。其余逻辑未发生变化。

Changes

文件/分组 变更摘要
components/use-x-chat/index.ts MessageStatus 类型新增 'updating',onUpdate 回调中状态由 'loading' 改为 'updating',简化 requestParams 判断逻辑。
components/use-x-chat/tests/index.test.tsx 测试中期望的消息状态由 'loading' 改为 'updating',调整相关断言以匹配状态变更。
components/use-x-chat/demo/stream.tsx 在传递给 Bubble.List 的消息项中新增 loading 属性,基于消息状态为 'loading' 时设置为 true。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant useXChat
    participant Agent

    User->>useXChat: 发起消息请求
    useXChat->>Agent: 调用 agent.request
    Agent-->>useXChat: onUpdate(流式返回)
    useXChat->>useXChat: updateMessage(status: 'updating')
    Agent-->>useXChat: onSuccess/完成
    useXChat->>useXChat: updateMessage(status: 'success')
Loading

Assessment against linked issues

Objective Addressed Explanation
为 useXChat 添加 'updating' 状态,onUpdate 时传递该状态,便于区分 loading 和 updating (#832)

Suggested reviewers

  • afc163

Poem

🐇
新增状态“updating”,消息流转不迷茫,
loading 只在等待时,更新时有新光。
小兔写代码,气泡不再慌,
消息流动间,体验更舒畅!
🐰✨

"""

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ 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.


📜 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 411d21e and 13f90c3.

📒 Files selected for processing (2)
  • components/use-x-chat/__tests__/index.test.tsx (8 hunks)
  • components/use-x-chat/index.ts (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • components/use-x-chat/tests/index.test.tsx
  • components/use-x-chat/index.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test / react component workflow
  • GitHub Check: size
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch feat/add-updating-status-for-use-x-chat
  • Post Copyable Unit Tests in Comment

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 generate unit tests to generate unit tests for 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

github-actions bot commented May 17, 2025

Preview is ready

Copy link

Walkthrough

This pull request introduces a new feature to the use-x-chat component by adding an updating status to the MessageStatus type. This change allows for more granular status updates during message processing.

Changes

File Summary
components/use-x-chat/index.ts Added updating status to MessageStatus type and modified logic to use this status during message updates.

@@ -8,7 +8,7 @@ import useSyncState from './useSyncState';

export type SimpleType = string | number | boolean | object;

export type MessageStatus = 'local' | 'loading' | 'success' | 'error';
export type MessageStatus = 'local' | 'loading' | 'updating' | 'success' | 'error';

Choose a reason for hiding this comment

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

The addition of the updating status to the MessageStatus type is a critical change that allows for more precise tracking of message states during updates. Ensure that all parts of the codebase that rely on MessageStatus are updated accordingly to handle this new status.

Copy link

codecov bot commented May 17, 2025

Bundle Report

Bundle size has no change ✅

@dosubot dosubot bot added the enhancement New feature or request label May 17, 2025
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

🧹 Nitpick comments (1)
components/use-x-chat/index.ts (1)

11-11: 添加了新的消息状态类型

MessageStatus 类型扩展为包含 'updating' 状态,有助于更精确地区分消息的不同阶段。这是一个公共类型的变更,可能需要在文档或 changelog 中说明此变化。

使用新的 'updating' 状态可以帮助 UI 层区分初始加载和内容更新阶段,提供更精细的用户体验。

建议在 changelog 中明确记录这个类型变更,以便使用者了解新增状态的用途。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 10e3cc2 and df366d6.

📒 Files selected for processing (1)
  • components/use-x-chat/index.ts (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build preview
  • GitHub Check: test / react component workflow
  • GitHub Check: size
🔇 Additional comments (2)
components/use-x-chat/index.ts (2)

181-181: 代码简化改进

将多行条件检查简化为单行表达式,保持了相同的逻辑功能,同时提高了代码的可读性。这是一个良好的重构实践。


1-300: 整体评估:功能增强和状态区分

此变更通过添加新的消息状态 'updating' 并在流式返回期间使用该状态,提高了组件状态管理的精确度。这种区分有助于 UI 层提供更精细的反馈。

变更范围相对集中且影响可控,主要是在消息状态类型和状态更新逻辑上。考虑到这是一个公共 API 的变更,建议:

  1. 在文档中明确新状态的用途和使用场景
  2. 确认是否需要调整依赖消息状态的其他逻辑(如过滤函数)
  3. 在 changelog 中记录这一变更

请确认消息状态变更是否会影响依赖此组件的现有功能,特别是那些基于消息状态进行条件渲染或逻辑处理的组件。

Copy link

codecov bot commented May 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.34%. Comparing base (10e3cc2) to head (13f90c3).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #833      +/-   ##
==========================================
- Coverage   92.35%   92.34%   -0.02%     
==========================================
  Files          66       66              
  Lines        1492     1490       -2     
  Branches      388      401      +13     
==========================================
- Hits         1378     1376       -2     
  Misses        114      114              

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

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: 0

🧹 Nitpick comments (1)
components/use-x-chat/demo/stream.tsx (1)

49-49: 确保UI正确反映新的'updating'状态

当前实现仅为'loading'状态的消息设置了加载指示器。根据学习内容,'updating'状态的消息应被视为正常内容返回,这与当前实现一致。但考虑到PR的目标是引入'updating'状态以区分消息加载与更新阶段,可能需要考虑是否应该为'updating'状态的消息提供某种视觉指示。

建议修改为:

-          loading: status === 'loading',
+          loading: status === 'loading',
+          updating: status === 'updating',

并在组件中适当处理updating属性,以便用户能够区分消息的加载状态和更新状态。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6f72729 and 411d21e.

📒 Files selected for processing (1)
  • components/use-x-chat/demo/stream.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: wzc520pyfm
PR: ant-design/x#833
File: components/use-x-chat/index.ts:256-256
Timestamp: 2025-05-17T05:29:02.470Z
Learning: 在 'use-x-chat' 组件中,'updating' 状态的消息应被视为正常的内容返回,不应被过滤掉。与 'loading' 和 'error' 状态不同,'updating' 状态代表内容正在更新的中间状态,但仍然是有效内容。
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test / react component workflow
  • GitHub Check: build preview
  • GitHub Check: size

@wzc520pyfm wzc520pyfm marked this pull request as draft May 17, 2025 06:11
@wzc520pyfm wzc520pyfm marked this pull request as ready for review May 18, 2025 15:05
@@ -46,6 +46,7 @@ const App = () => {
style={{ maxHeight: 300 }}
items={messages.map(({ id, message, status }) => ({
key: id,
loading: status === 'loading',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

该pr之后,流式输出和非流式输出可以使用相同的方式设置bubble loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

使用useXChat时为bubble设置loading
1 participant