Skip to content

Conversation

@iamkun-2
Copy link
Contributor

@iamkun-2 iamkun-2 commented Jul 24, 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

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

Background:
Developers often need to integrate intelligent agent capabilities into their applications, but implementing flexible UIs and connecting to the underlying agent platform can be complex and time-consuming.

Solution:
We have integrated support for the Tbox AI Agent Platform, allowing developers to easily leverage its agent capabilities via the new X component. By using the X component, developers can quickly build customizable agent UIs and access the full power of the Tbox platform. To facilitate adoption, we also provide an interactive online demo and comprehensive documentation.

📝 Change Log

Language Changelog
🇺🇸 English add tbox agent & docs
🇨🇳 Chinese 新增百宝箱智能体和相关文档

Summary by CodeRabbit

  • 新功能

    • 新增“百宝箱 X 智能体”完整聊天示例,支持会话管理、流式 AI 回复、快捷提示和错误处理,集成 Tbox 智能体服务,并支持中英文切换。
    • 新增 Tbox 智能体集成指南及 React 示例,帮助开发者快速上手。
  • 文档

    • 新增和完善中英文文档,包括百宝箱智能体示例、集成指南及相关分组说明。
    • 多处文档分组标题和排序优化,提升文档导航体验。
    • 修正部分文档格式与分组元数据。
  • 杂项

    • 新增 tbox-nodejs-sdk 依赖。
    • 优化全局布局中 PeterCat 组件的显示逻辑,避免在特定演示路径下渲染。

@github-actions
Copy link
Contributor

github-actions bot commented Jul 24, 2025

Preview is ready

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 24, 2025

📝 Walkthrough

Walkthrough

本次更新主要新增了 Tbox 智能体集成的中英文文档与完整 React 组件示例,并对现有文档的分组标题与排序元数据进行了调整优化。此外,增加了 tbox-nodejs-sdk 依赖,为 Tbox 智能体服务的接入提供支持。

Changes

文件/文件组 变更摘要
docs/playground/agent-tbox.en-US.md
docs/playground/agent-tbox.zh-CN.md
新增 Tbox 智能体样板间文档(中英文),包含组件嵌入示例与页面元数据。
docs/playground/agent-tbox.tsx 新增完整 React 组件,集成 Tbox 智能体服务,支持多会话、流式对话、消息管理、提示词等功能。
docs/react/agent-use-tbox.en-US.md
docs/react/agent-use-tbox.zh-CN.md
新增 Tbox 智能体服务集成指南(中英文),包含代码示例与官方文档链接。
docs/playground/copilot.en-US.md
docs/playground/copilot.zh-CN.md
docs/playground/independent.en-US.md
docs/playground/independent.zh-CN.md
修改分组标题及顺序元数据,无内容变动。
docs/react/contributing.en-US.md
docs/react/contributing.zh-CN.md
docs/react/dangerously-api-key.en-US.md
docs/react/dangerously-api-key.zh-CN.md
docs/react/faq.en-US.md
docs/react/faq.zh-CN.md
docs/react/model-use-openai.en-US.md
docs/react/model-use-openai.zh-CN.md
docs/react/model-use-other.en-US.md
docs/react/model-use-other.zh-CN.md
docs/react/model-use-qwen.en-US.md
docs/react/model-use-qwen.zh-CN.md
docs/react/use-with-create-react-app.en-US.md
docs/react/use-with-create-react-app.zh-CN.md
docs/react/use-with-next.en-US.md
docs/react/use-with-next.zh-CN.md
docs/react/use-with-rsbuild.en-US.md
docs/react/use-with-rsbuild.zh-CN.md
docs/react/use-with-umi.en-US.md
docs/react/use-with-umi.zh-CN.md
docs/react/use-with-vite.en-US.md
docs/react/use-with-vite.zh-CN.md
增加或调整 group/order 元数据,部分代码格式微调,无功能变更。
package.json 新增依赖 tbox-nodejs-sdk@^0.0.13,为 Tbox 智能体功能提供 SDK 支持。
.dumi/theme/layouts/GlobalLayout.tsx 调整导入顺序,无功能变更。

Sequence Diagram(s)

sequenceDiagram
    participant User as 用户
    participant UI as React 组件(Independent)
    participant Tbox as Tbox AI 服务

    User->>UI: 选择/创建会话或输入消息
    UI->>Tbox: 通过 tbox-nodejs-sdk 发起 chat 请求(流式)
    Tbox-->>UI: 返回数据流(data、end、error事件)
    UI->>UI: 解析流数据,更新消息列表
    UI-->>User: 实时显示 AI 回复、支持中断、重试等操作
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~18 分钟

Suggested labels

javascript, lgtm

Suggested reviewers

  • kimteayon
  • afc163

Poem

🐇
新添百宝箱,智能体闪亮,
代码流转间,消息两端忙。
文档中英双,样例配齐装,
兔子挥挥爪,集成更顺畅!
🎉✨

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 cfd8221 and a613720.

📒 Files selected for processing (5)
  • docs/playground/agent-tbox.tsx (1 hunks)
  • docs/react/model-use-openai.en-US.md (1 hunks)
  • docs/react/model-use-openai.zh-CN.md (1 hunks)
  • docs/react/model-use-qwen.en-US.md (1 hunks)
  • docs/react/model-use-qwen.zh-CN.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • docs/react/model-use-qwen.zh-CN.md
  • docs/react/model-use-openai.zh-CN.md
  • docs/react/model-use-qwen.en-US.md
  • docs/react/model-use-openai.en-US.md
  • docs/playground/agent-tbox.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: test / react component workflow
  • GitHub Check: size
  • GitHub Check: build preview
✨ 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.
    • @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.

@dosubot dosubot bot added documentation Improvements or additions to documentation enhancement New feature or request labels Jul 24, 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: 12

🧹 Nitpick comments (7)
docs/react/model-use-other.zh-CN.md (1)

21-22: 示例代码占位符易产生歧义

fetch() 未传入 URL,读者可能误认为空参数即可正常调用。可在示例中明确占位符,减少困惑:

-  const response = await fetch();
+  const response = await fetch('https://your-model-endpoint');
docs/react/use-with-next.zh-CN.md (1)

4-4: group.order 与根级 order 数值重复,可能引起阅读者困惑

虽然 YAML 解析上不会冲突,但同时把两个层级都设为 3 缺乏语义区分,后期维护者难以判断哪个数字真正影响排序。建议只在需要的层级保留一个 order,或保持不同值以体现层级含义。

docs/react/use-with-next.en-US.md (1)

4-4: 重复的排序值同样存在,可考虑精简

与中文版相同,group.order 与根级 order 都为 3,阅读上可能造成歧义。参考上面的建议进行统一即可。

docs/react/model-use-other.en-US.md (1)

20-23: 示例代码可读性小改进

await fetch() 缺少 URL/Request 参数,新手阅读时可能误以为可直接调用。建议补充占位符,提高可读性:

-  const response = await fetch();
+  const response = await fetch('/your/api');
docs/playground/agent-tbox.en-US.md (1)

1-10: 校验 frontmatter 中 order 冲突

本文件与同组其他示例均设置 order: 0,Dumi 渲染时若存在重复 order,排序结果将依赖文件名而非显式权重,可能导致文档顺序不可预测。建议为各示例设定唯一 order 值(例如 0, 1, 2 …)。

docs/playground/agent-tbox.zh-CN.md (1)

1-10: 校验 frontmatter 中 order 冲突

同上,建议在「智能体样板间」分组内确保 order 唯一,避免排序混乱。

docs/playground/agent-tbox.tsx (1)

383-387: 使用 setTimeout 处理异步问题不够优雅

使用 setTimeout 来处理异步时序问题是一种不可靠的解决方案,可能在不同环境下表现不一致。

建议使用 Promise 或状态管理来确保正确的执行顺序,而不是依赖固定的延迟时间。注释中已经提到未来版本会通过 sessionId 来解决这个问题。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9084ec7 and ae0cac4.

📒 Files selected for processing (32)
  • docs/playground/agent-tbox.en-US.md (1 hunks)
  • docs/playground/agent-tbox.tsx (1 hunks)
  • docs/playground/agent-tbox.zh-CN.md (1 hunks)
  • docs/playground/copilot.en-US.md (1 hunks)
  • docs/playground/copilot.zh-CN.md (1 hunks)
  • docs/playground/independent.en-US.md (1 hunks)
  • docs/playground/independent.zh-CN.md (1 hunks)
  • docs/react/agent-use-tbox.en-US.md (1 hunks)
  • docs/react/agent-use-tbox.zh-CN.md (1 hunks)
  • docs/react/contributing.en-US.md (1 hunks)
  • docs/react/contributing.zh-CN.md (1 hunks)
  • docs/react/dangerously-api-key.en-US.md (1 hunks)
  • docs/react/dangerously-api-key.zh-CN.md (1 hunks)
  • docs/react/faq.en-US.md (1 hunks)
  • docs/react/faq.zh-CN.md (1 hunks)
  • docs/react/model-use-openai.en-US.md (1 hunks)
  • docs/react/model-use-openai.zh-CN.md (1 hunks)
  • docs/react/model-use-other.en-US.md (2 hunks)
  • docs/react/model-use-other.zh-CN.md (2 hunks)
  • docs/react/model-use-qwen.en-US.md (1 hunks)
  • docs/react/model-use-qwen.zh-CN.md (1 hunks)
  • docs/react/use-with-create-react-app.en-US.md (1 hunks)
  • docs/react/use-with-create-react-app.zh-CN.md (1 hunks)
  • docs/react/use-with-next.en-US.md (1 hunks)
  • docs/react/use-with-next.zh-CN.md (1 hunks)
  • docs/react/use-with-rsbuild.en-US.md (1 hunks)
  • docs/react/use-with-rsbuild.zh-CN.md (1 hunks)
  • docs/react/use-with-umi.en-US.md (1 hunks)
  • docs/react/use-with-umi.zh-CN.md (1 hunks)
  • docs/react/use-with-vite.en-US.md (1 hunks)
  • docs/react/use-with-vite.zh-CN.md (1 hunks)
  • package.json (1 hunks)
🧰 Additional context used
🧠 Learnings (6)
📓 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 时,需要用中文回复中文评论。该项目的文档支持中英双语。
docs/react/contributing.zh-CN.md (2)

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 时,需要用中文回复中文评论。该项目的文档支持中英双语。

docs/react/model-use-other.zh-CN.md (1)

Learnt from: YumoImer
PR: #293
File: components/x-request/demo/custom-transformer.tsx:75-79
Timestamp: 2024-12-04T03:46:13.221Z
Learning: When reviewing code examples in components/x-request/demo/custom-transformer.tsx that use mockFetch, it's unnecessary to suggest enhancements to the TransformStream implementation, such as adding error handling and data validation, since the code is intended as a simple demonstration.

docs/playground/agent-tbox.zh-CN.md (2)

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 时,需要用中文回复中文评论。该项目的文档支持中英双语。

docs/react/model-use-other.en-US.md (1)

Learnt from: YumoImer
PR: #293
File: components/x-request/demo/custom-transformer.tsx:75-79
Timestamp: 2024-12-04T03:46:13.221Z
Learning: When reviewing code examples in components/x-request/demo/custom-transformer.tsx that use mockFetch, it's unnecessary to suggest enhancements to the TransformStream implementation, such as adding error handling and data validation, since the code is intended as a simple demonstration.

docs/react/agent-use-tbox.zh-CN.md (2)

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 时,需要用中文回复中文评论。该项目的文档支持中英双语。

🪛 Biome (2.1.2)
docs/playground/agent-tbox.tsx

[error] 296-296: This variable implicitly has the any type.

Variable declarations without type annotation and initialization implicitly have the any type. Declare a type or initialize the variable with some value.

(lint/suspicious/noImplicitAnyLet)

🔇 Additional comments (24)
docs/react/model-use-qwen.zh-CN.md (1)

4-4: 元数据调整正确,保持一致性 👍

group 增补 order: 1 能确保“模型接入”分组在侧边栏中的排序一致,改动无风险。

docs/react/model-use-openai.zh-CN.md (1)

4-4: 排序字段补充合理

同样为“模型接入”追加 order: 1,与其他中文文档保持一致,OK。

docs/react/faq.en-US.md (1)

4-4: 新增 order 字段无异议

Other 分组补充 order: 4 有助于统一 FAQ 在导航中的位置,改动良好。

docs/react/model-use-openai.en-US.md (1)

4-4: 一致性排序更新

为“Model Integration”组添加 order: 1,与其他英文文档保持一致。

docs/react/model-use-qwen.en-US.md (1)

4-4: 文档侧边栏排序调整确认

补充 order: 1 与同组文档对齐,暂无其他问题。

docs/react/contributing.zh-CN.md (1)

4-4: 补充排序权重 👍

增加 group.order: 4 与其他文档保持一致,可保证侧边栏顺序统一。实现正确,无其他问题。

docs/react/faq.zh-CN.md (1)

4-4: 一致性更新已确认

同样的 group.order: 4 调整与其它文档保持同步,便于分组排序。

docs/react/dangerously-api-key.zh-CN.md (1)

4-4: 元数据排序 OK

group.order 字段补充正确,与其它文档保持一致。

docs/react/model-use-other.zh-CN.md (1)

4-4: 元数据完善

为“模型接入”组显式加 order: 1,逻辑正确。

docs/playground/independent.zh-CN.md (1)

3-3: 分组标题调整已同步

将组名改成“模型样板间”以匹配其余文档,改动无误。

docs/playground/copilot.zh-CN.md (1)

2-4: 更改符合分组命名规范,保持一致性即可

已将 title 更新为「模型样板间」,与其他文档保持一致,无问题。

docs/react/use-with-create-react-app.en-US.md (1)

2-5: group.order 与根级 order 可能产生冲突,建议确认导航排序

此处新增 group.order: 3,而根级仍为 order: 1。如果站点生成器同时读取两处 order 字段,可能导致排序结果不可预期,请确认规范。

docs/playground/independent.en-US.md (1)

2-4: 分组标题更新无误

英文版同步至「Model Sample」,保持中英一致,OK。

docs/playground/copilot.en-US.md (1)

2-4: 分组标题与排序同步,符合重构目标

SampleModel Sampleorder 设为 0,与其他示例统一,良好。

docs/react/use-with-rsbuild.en-US.md (1)

2-5: 检查 group.order 与根级 order 的相对优先级

此文件设置 group.order: 3,而根级 order 为 5。若站点侧边栏先按组再按根级排序,可能与预期不符;请确认排序逻辑或对齐两处值。

docs/react/dangerously-api-key.en-US.md (1)

4-4: ✅ 补充 order 字段提升分组排序可控性

group 元数据中新增 order: 4 与现有根级 order 不冲突,可精细控制左侧导航分组顺序。实现正确,无其他隐患。

docs/react/contributing.en-US.md (1)

4-4: 👍 合理增加分组排序字段

group 内加入 order: 4 可保证「Other」分组在侧边栏中的期望位置,改动简单且安全。

docs/react/use-with-rsbuild.zh-CN.md (1)

4-4: 分组排序字段添加正确,但需确认多语言一致性

新增 group.order: 3 与根级 order: 5 搭配合理。为了保持中英双语文档结构一致,请确认英文版对应文件也同步了该排序。

docs/react/use-with-create-react-app.zh-CN.md (1)

4-4: 新增 group.order 元数据合理
仅为文档导航排序补充字段,不影响正文内容或构建流程。

docs/react/use-with-umi.en-US.md (1)

4-4: 新增 group.order 元数据合理
纯文档层级调整,无需额外修改。

docs/react/use-with-umi.zh-CN.md (1)

4-4: 新增 group.order 元数据合理
仅调整文档分组排序,对其他内容无副作用。

docs/react/use-with-vite.zh-CN.md (1)

4-4: 新增 group.order 字段无问题
该修改仅影响侧边栏排序,内容保持不变。

docs/react/use-with-vite.en-US.md (1)

4-4: 添加 group.order 元数据 OK
属于文档结构优化,可直接合并。

package.json (1)

91-92: 确认 [email protected] 在浏览器端可用性与打包体积影响

  • npm Metadata:该包未声明 browser 字段,但在 exports 中同时提供了 ESM(import./dist/tbox-nodejs-sdk.js)和 CJS(require./dist/tbox-nodejs-sdk.umd.cjs)入口,主流打包器(Webpack/Vite)可直接选用 ESM 构建。
  • 运行时依赖:已在 dist 目录下扫描,发现对 Node 内置模块(http/https/stream 等)的引用,可安全在浏览器环境中运行,无需配置 resolve.fallback
  • 打包体积:SDK 以整体包形式发布、内部依赖 eventemitter3,无子模块拆分,可能造成首屏包体积增加。建议:
    • 按需通过 import() 动态加载,避免首页加载全部 SDK;
    • 若业务场景较轻量,可考虑直接调用 REST API 或官方 Web SDK(若有)并使用 fetch 封装最小客户端。

以上确认后,可正常引入该包,必要时再针对体积进行优化。

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

♻️ Duplicate comments (5)
docs/playground/agent-tbox.tsx (5)

34-39: 安全隐患:API 密钥硬编码

API 密钥和配置不应硬编码在源代码中,即使是演示代码也存在安全风险。


252-256: 安全问题:应用ID硬编码

appId 硬编码存在安全风险,应从环境变量或配置中获取。


316-318: 国际化支持不一致

错误消息硬编码为英文,与应用的双语支持不一致。


350-353: 国际化支持不一致

另一处错误消息也硬编码为英文,应支持国际化。


584-592: 内存泄漏风险

messageHistory 状态无限制累积消息历史,可能导致内存泄漏。

🧹 Nitpick comments (2)
docs/playground/agent-tbox.tsx (2)

41-44: 类型定义过于宽泛

BubbleDataType 类型定义过于简单,缺少必要的类型约束。

建议定义更具体的类型:

-type BubbleDataType = {
-  role: string;
-  content: string;
-};
+type BubbleDataType = {
+  role: 'user' | 'assistant';
+  content: string;
+  timestamp?: number;
+  status?: 'loading' | 'success' | 'error';
+};

233-607: 组件复杂度过高

整个组件超过 370 行,承担了过多职责,建议拆分为更小的子组件。

建议将组件拆分为:

  • ChatSidebar - 侧边栏组件
  • ChatMessageList - 消息列表组件
  • ChatSender - 发送消息组件
  • useConversation - 会话管理逻辑钩子
  • useTboxChat - Tbox 聊天逻辑钩子

这样可以提高代码的可维护性和可测试性。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ae0cac4 and 06f05a0.

📒 Files selected for processing (2)
  • docs/playground/agent-tbox.tsx (1 hunks)
  • package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json
🧰 Additional context used
🧠 Learnings (2)
📓 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 时,需要用中文回复中文评论。该项目的文档支持中英双语。
docs/playground/agent-tbox.tsx (6)

Learnt from: YumoImer
PR: #293
File: components/x-request/tests/index.test.tsx:21-25
Timestamp: 2024-12-03T13:19:38.409Z
Learning: 在测试代码中,可以使用硬编码的测试 API 密钥作为测试值。

Learnt from: afc163
PR: #293
File: components/x-request/demo/custom-transformer.tsx:51-51
Timestamp: 2024-12-04T03:23:41.937Z
Learning: 在代码中避免使用 any 类型,应该定义具体的类型以提高类型安全性。

Learnt from: YumoImer
PR: #293
File: components/x-request/demo/custom-transformer.tsx:75-79
Timestamp: 2024-12-04T03:46:13.221Z
Learning: When reviewing code examples in components/x-request/demo/custom-transformer.tsx that use mockFetch, it's unnecessary to suggest enhancements to the TransformStream implementation, such as adding error handling and data validation, since the code is intended as a simple demonstration.

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 时,需要用中文回复中文评论。该项目的文档支持中英双语。

Learnt from: wzc520pyfm
PR: #833
File: components/use-x-chat/index.ts:256-256
Timestamp: 2025-05-17T05:29:02.977Z
Learning: 在 'use-x-chat' 组件中,'updating' 状态的消息应被视为正常的内容返回,不应被过滤掉。与 'loading' 和 'error' 状态不同,'updating' 状态代表内容正在更新的中间状态,但仍然是有效内容。

🔇 Additional comments (1)
docs/playground/agent-tbox.tsx (1)

32-32: 依赖兼容性验证完成:tbox-nodejs-sdk 与项目 axios 版本兼容

已验证

  • [email protected] 发布的依赖项为
    • axios ^1.10.0
    • eventemitter3 ^5.0.1
    • eventsource-parser ^3.0.2
    • vite-plugin-dts ^4.5.4
  • 项目 package.json 中声明的 axios 为 ^1.7.7,二者均在 SemVer 1.x 范围内,安装后将统一解析到 1.10.x,无多版本冲突,兼容性良好。

无需对现有依赖版本进行额外调整。

@codecov
Copy link

codecov bot commented Jul 24, 2025

Bundle Report

Bundle size has no change ✅

@codecov
Copy link

codecov bot commented Jul 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.39%. Comparing base (9084ec7) to head (a613720).
⚠️ Report is 29 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1063   +/-   ##
=======================================
  Coverage   92.39%   92.39%           
=======================================
  Files          69       69           
  Lines        1564     1564           
  Branches      406      423   +17     
=======================================
  Hits         1445     1445           
  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.

@kimteayon
Copy link
Collaborator

image 样板间loading状态不对

@kimteayon
Copy link
Collaborator

发送中切换菜单交互和数据有问题
image

Comment on lines +560 to +566
if (messages?.length) {
setMessageHistory((prev) => ({
...prev,
[curConversation]: messages,
}));
}
}, [messages]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

兔子提的问题需要看下

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

♻️ Duplicate comments (2)
docs/playground/agent-tbox.tsx (2)

34-39: 安全隐患:API密钥硬编码问题依然存在

代码中仍然存在硬编码的API密钥,这是一个安全风险。虽然这是演示代码,但应该从环境变量或安全配置中获取密钥。


307-307: 安全问题:appId仍然硬编码

appId 仍然是硬编码的,应该从环境变量或安全配置中获取。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 594736b and cfd8221.

📒 Files selected for processing (2)
  • .dumi/theme/layouts/GlobalLayout.tsx (1 hunks)
  • docs/playground/agent-tbox.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .dumi/theme/layouts/GlobalLayout.tsx
🧰 Additional context used
🧠 Learnings (2)
📓 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 时,需要用中文回复中文评论。该项目的文档支持中英双语。
docs/playground/agent-tbox.tsx (7)

Learnt from: YumoImer
PR: #293
File: components/x-request/tests/index.test.tsx:21-25
Timestamp: 2024-12-03T13:19:38.409Z
Learning: 在测试代码中,可以使用硬编码的测试 API 密钥作为测试值。

Learnt from: afc163
PR: #293
File: components/x-request/demo/custom-transformer.tsx:51-51
Timestamp: 2024-12-04T03:23:41.937Z
Learning: 在代码中避免使用 any 类型,应该定义具体的类型以提高类型安全性。

Learnt from: YumoImer
PR: #293
File: components/x-request/demo/custom-transformer.tsx:75-79
Timestamp: 2024-12-04T03:46:13.221Z
Learning: When reviewing code examples in components/x-request/demo/custom-transformer.tsx that use mockFetch, it's unnecessary to suggest enhancements to the TransformStream implementation, such as adding error handling and data validation, since the code is intended as a simple demonstration.

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 时,需要用中文回复中文评论。该项目的文档支持中英双语。

Learnt from: wzc520pyfm
PR: #833
File: components/use-x-chat/index.ts:256-256
Timestamp: 2025-05-17T05:29:02.977Z
Learning: 在 'use-x-chat' 组件中,'updating' 状态的消息应被视为正常的内容返回,不应被过滤掉。与 'loading' 和 'error' 状态不同,'updating' 状态代表内容正在更新的中间状态,但仍然是有效内容。

Learnt from: YumoImer
PR: #479
File: components/bubble/demo/debug-list.tsx:39-57
Timestamp: 2025-01-27T09:36:11.490Z
Learning: In the Bubble.List debug demo component, the different typing behavior between pushBubble (sets typing: true) and unshiftBubble (no typing property) operations is intentional to facilitate testing different scenarios.

🔇 Additional comments (9)
docs/playground/agent-tbox.tsx (9)

41-101: 国际化实现符合最佳实践

国际化的实现很好地遵循了之前的反馈,将所有文本统一组织在对象中,支持通过key调用。语言检测逻辑也适合嵌入式组件的使用场景。


103-173: 数据结构设计合理

常量定义清晰,很好地利用了国际化系统,数据结构一致且易于维护。


175-284: 样式实现完整且响应式

使用 antd-style 创建的样式定义完整,布局考虑了响应式设计,组件样式组织清晰。


286-298: 状态管理和类型安全改进

组件状态管理结构合理,messageHistory 的类型定义相比之前的 any 类型有所改进,使用了 typeof messages 提供更好的类型安全性。


304-393: Agent和Chat钩子配置实现优秀

useXAgentuseXChat 的配置实现很好,包含了完整的流处理、错误处理和消息转换逻辑。AbortController 的集成也很恰当,类型安全性得到改善。


395-412: 事件处理实现恰当

事件处理函数实现良好,包含了适当的加载状态检查和用户反馈,验证逻辑合理。


659-667: 消息历史持久化逻辑正确

useEffect 中的消息历史更新逻辑实现正确,能够正确地将当前会话的消息保存到历史记录中。

注意:之前提到的内存泄漏问题(已删除会话的消息历史未清理)仍然存在,建议在删除会话时同步清理对应的消息历史。


670-682: 组件渲染结构清晰

组件的渲染逻辑结构清晰,三个主要部分(sidebar、chat list、sender)组织合理。


469-472: 需注意:setTimeout 时序处理可能影响菜单切换

定位:docs/playground/agent-tbox.tsx 第 469–472 行

setTimeout(() => {
  setCurConversation(val);
  setMessages(messageHistory?.[val] || []);
}, 100);

• 问题:当前使用固定 100ms 延时来更新会话和消息,快速切换或在请求中断(abort)后,可能会出现旧状态覆盖新状态的竞态条件,导致 UI 与数据不同步。
• 建议:

  • 考虑通过 useEffect 监听 curConversation 或使用会话标识(sessionId)来触发状态更新,确保过期的异步操作不会影响当前会话;
  • 或在 abortController 回调中明确清理或跳过延时任务,避免定时器回调执行后再更新已切换的会话。

请确认上述时序问题是否存在,并评估替换该 setTimeout 方案的必要性。

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jul 29, 2025
@kimteayon kimteayon merged commit e643f28 into ant-design:main Jul 29, 2025
11 checks passed
@kimteayon kimteayon added the 2.x Ant Design X 2.x label Sep 19, 2025
@kimteayon kimteayon added this to the Ant Design X v2 milestone Sep 19, 2025
miownag pushed a commit to miownag/x that referenced this pull request Oct 15, 2025
* feat: add tbox agent

* chore: update version

* chore: update ci

* chore: update ci

* chore: update abort

* chore: update abort

* chore: update hide petercat

* chore: update ci

* chore: i18n

* chore: loading

* chore: loading

* chore: i18n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.x Ant Design X 2.x documentation Improvements or additions to documentation enhancement New feature or request lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants