Skip to content

Conversation

dengfuping
Copy link

@dengfuping dengfuping commented Aug 7, 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

💡 Background and Solution

  • useXAgent add refreshDeps option to get latest value in request function.
import React from 'react';
import { useXAgent } from '@ant-design/x';

const App = () => {
  const [value, setValue] = React.useState('');

  const [form] = Form.useForm();

  const [agent] = useXAgent({
    request: () => {
      console.log(value);
    },
    refreshDeps: [value],
  });
};

export default App;

📝 Change Log

Language Changelog
🇺🇸 English - 🆕 useXAgent add refreshDeps option.
🇨🇳 Chinese - 🆕 useXAgent 新增 refreshDeps 选项,作为 Agent 实例更新的依赖列表,使用场景详见 #536

Summary by CodeRabbit

  • 新功能

    • 配置中新增可选属性 refreshDeps,用于在依赖项变化时自动刷新 Agent 实例。
  • 文档

    • 更新文档,介绍 refreshDeps 属性的用法及相关说明。

Copy link
Contributor

coderabbitai bot commented Aug 7, 2025

📝 Walkthrough

Walkthrough

本次变更为 useXAgent 钩子新增了一个可选配置项 refreshDeps,允许开发者自定义依赖项数组。当 refreshDeps 中的任意项发生变化时,XAgent 实例会重新计算。相关接口文档也同步更新,增加了该属性的说明。

Changes

Cohort / File(s) Change Summary
Hook 及类型定义增强
components/use-x-agent/index.ts
XAgentConfigCustom 接口新增可选属性 refreshDeps?: any[]useXAgent 钩子支持解构 refreshDeps,并将其展开加入 useMemo 依赖数组。
文档同步
components/use-x-agent/index.zh-CN.md
文档中为 XAgentConfigCustom 增加 refreshDeps 属性说明,并补充了相关使用场景及 issue 引用。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant useXAgent
    participant XAgent

    User->>useXAgent: 提供 config(含 refreshDeps)
    useXAgent->>useXAgent: 解构 refreshDeps, 默认[]
    useXAgent->>useXAgent: useMemo 依赖 [baseURL, dangerouslyApiKey, model, ...refreshDeps]
    useXAgent->>XAgent: 创建/重建实例(依赖变化时)
    XAgent-->>useXAgent: 返回新实例
    useXAgent-->>User: 返回 XAgent 实例
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 分钟

Assessment against linked issues

Objective Addressed Explanation
支持 useXAgent 传递额外参数 refreshDeps,实现依赖项动态更新(#536
能够通过 refreshDeps 获取到动态修改后的全局参数值(#536

Assessment against linked issues: Out-of-scope changes

(本次提交未发现与已关联 issue 目标无关的功能性代码变更。)

Possibly related PRs

Suggested reviewers

  • kimteayon

Poem

🐰
新增依赖 refreshDeps,
智能体重建真灵活。
参数变化随心意,
钩子响应不拖沓。
代码如春风,
兔子也点赞,
文档同步更周全!

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 faba48f and ff94286.

📒 Files selected for processing (2)
  • components/use-x-agent/index.ts (3 hunks)
  • components/use-x-agent/index.zh-CN.md (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: afc163
PR: ant-design/x#0
File: :0-0
Timestamp: 2025-04-11T14:47:09.527Z
Learning: 当评审 ant-design/x 仓库中的 PR 时,需要用中文回复中文评论。该项目的文档支持中英双语。
Learnt from: afc163
PR: ant-design/x#0
File: :0-0
Timestamp: 2025-04-11T14:47:09.527Z
Learning: 当评审 ant-design/x 仓库中的 PR 时,需要用中文回复中文评论。该项目的文档支持中英双语。
🔇 Additional comments (4)
components/use-x-agent/index.ts (3)

29-29: 接口扩展合理

新增的 refreshDeps 属性设计恰当,使用 any[] 类型与 React 的依赖数组模式保持一致,可选属性确保了向后兼容性。


101-101: 解构和默认值处理正确

使用空数组作为 refreshDeps 的默认值是合适的选择,既保证了功能的正常工作,又避免了不必要的重新渲染。


117-117: 核心功能实现正确

通过将 refreshDeps 展开到 useMemo 的依赖数组中,正确实现了当指定依赖项发生变化时重新创建 XAgent 实例的功能,这直接解决了 issue #536 中提到的需求。

components/use-x-agent/index.zh-CN.md (1)

54-54: 文档更新完整准确

新增的 refreshDeps 属性文档描述清晰,提供了 GitHub issue 链接帮助开发者了解使用场景,中文描述准确简洁。

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a 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.
  • 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 Aug 7, 2025

Preview is ready

@dosubot dosubot bot added the enhancement New feature or request label Aug 7, 2025
Copy link

codecov bot commented Aug 7, 2025

Bundle Report

Changes will decrease total bundle size by 5 bytes (-0.0%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
antdx-array-push 139.75kB -5 bytes (-0.0%) ⬇️

Affected Assets, Files, and Routes:

view changes for bundle: antdx-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
antdx.min.js -5 bytes 139.75kB -0.0%

Copy link

codecov bot commented Aug 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.46%. Comparing base (faba48f) to head (ff94286).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1104   +/-   ##
=======================================
  Coverage   92.46%   92.46%           
=======================================
  Files          69       69           
  Lines        1579     1579           
  Branches      428      429    +1     
=======================================
  Hits         1460     1460           
  Misses        119      119           

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

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.

useXAgent 支持额外参数 传递
1 participant