Skip to content
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

feat: support chat sessions management & recover from storage #4399

Merged
merged 5 commits into from
Feb 24, 2025

Conversation

ensorrow
Copy link
Contributor

@ensorrow ensorrow commented Feb 21, 2025

Types

  • 🎉 New Features

Background or solution

feat: support chat sessions management & recover from storage

image

Changelog

feat: support chat sessions management & recover from storage

Summary by CodeRabbit

  • 新功能

    • 集成全新聊天历史管理界面,支持查看、编辑、删除和搜索聊天记录。
    • 增强了聊天会话初始化与数据持久化,保障稳定安全的聊天体验。
    • 新增聊天会话的多语言支持,提升用户提示信息。
  • 样式

    • 精简调整了头部布局与间距,新样式使整体界面更加美观和清晰。

@opensumi opensumi bot added the 🎨 feature feature required label Feb 21, 2025
Copy link
Contributor

coderabbitai bot commented Feb 21, 2025

Walkthrough

此次变更涉及多个模块,主要增强了聊天功能。修改包括在核心贡献类中注入并异步初始化聊天服务、扩展聊天会话和模型的初始化与序列化方法、调整聊天 UI 组件(包含历史记录管理)的交互逻辑,以及更新 CSS 样式和国际化条目。此外,还在存储模块中添加了专用于聊天数据的命名空间,从而完善整体聊天功能的支持。

Changes

文件 变更简述
.../ai-core.contribution.ts AINativeBrowserContribution 类添加 IChatManagerServiceIChatInternalService 依赖;将 initialize() 方法改为异步并调用新服务的初始化方法。
.../chat/chat-manager.service.ts
.../chat/chat-model.ts
.../chat/chat-proxy.service.ts
.../chat/chat.internal.service.ts
- chat-manager.service.ts:新增 ISessionModel 接口,添加 init()saveSessions() 方法以及相关属性,更新会话启动、清理及请求后的存储逻辑。
- chat-model.ts:更新模型构造函数,支持 initParams 初始化;新增 toJSON() 方法实现 JSON 序列化。
- chat-proxy.service.ts:将静态 AGENT_ID 修改为固定值。
- chat.internal.service.ts:引入 init()getSessions() 方法;更新 clearSessionModel() 方法以支持可选会话 ID。
.../chat/chat.view.tsx
.../components/ChatHistory.tsx
.../components/ChatReply.tsx
.../components/ChatThinking.tsx
- chat.view.tsx:引入 ChatHistory 组件及 MAX_TITLE_LENGTH 常量,更新头部显示逻辑和消息发送检测。
- ChatHistory.tsx:新建组件,实现聊天历史的展示、搜索、编辑和删除功能。
- ChatReply.tsx:调整 hasMessage 条件,增加对 responseContents 长度的判断。
- ChatThinking.tsx:调整 isRenderRegenerate 条件,确保 requestId 为有效值。
.../chat/chat.module.less
.../components/chat-history.css
- chat.module.less:更新 .header_container 样式,移除 .left.right 类,并新增 .chat_history 类。
- chat-history.css:新增一整套样式类,用于定义聊天历史组件的布局、标题、操作按钮及列表显示。
.../model/msg-history-manager.ts 移除 @Injectable 装饰器;新增支持初始化数据的构造函数;增加 toJSON() 方法以序列化消息及补充数据。
.../storage.ts
.../en-US.lang.ts
.../zh-CN.lang.ts
- storage.ts:在 STORAGE_NAMESPACE 中新增 CHAT 属性,专用于聊天数据存储。
- 国际化文件(en-US.lang.ts 与 zh-CN.lang.ts):新增聊天操作和历史记录相关的本地化条目。

Sequence Diagram(s)

sequenceDiagram
  participant BC as BrowserContribution
  participant CMS as ChatManagerService
  participant CIS as ChatInternalService

  BC->>CMS: 调用 init() 进行存储初始化和会话加载
  CMS-->>BC: 返回会话数据
  BC->>CIS: 调用 init() 初始化内部会话管理
  CIS->>CMS: 订阅 onStorageInit 事件
  CMS-->>CIS: 触发 storageInit 事件
  CIS->>CMS: 获取并处理现有会话数据
Loading

Possibly related PRs

Suggested labels

🎨 feature

Suggested reviewers

  • Ricbet
  • bytemain

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.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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: 2

🧹 Nitpick comments (15)
packages/ai-native/src/browser/chat/chat.internal.service.ts (2)

79-79: 方法命名清晰,便于理解功能。若需要在外部使用创建的会话实例,可考虑在方法末尾返回该会话。


84-91: 在清理会话后立即重建当前会话,这样可以确保用户总有一个可用的活跃会话。若想在彻底清除后保持无会话状态,可额外提供可选配置。

packages/ai-native/src/browser/chat/chat-manager.service.ts (4)

7-34: 这些新的导入与 ISessionModel 接口为后续会话管理与序列化提供了良好的扩展性。ISessionModel 定义较为清晰,且包含必要的字段。请注意后续 TODO(行 55)中的功能是否需要尽快完善。


118-118: 在清理会话后立即调用 saveSessions(),可确保存储数据与内存保持一致。对于批量操作,建议考虑合并保存以提升性能。


137-137: 在会话不存在时抛出异常能及时暴露逻辑问题。若有可能在用户层面遇到此错误,或可改为返回可读性更高的提示信息。


199-201: 存储操作在多次请求中频繁调用,可能带来性能开销。可以考虑在高频场景中使用节流或批量写入策略来降低存储压力。

packages/ai-native/src/browser/chat/chat-model.ts (3)

83-105: 新的构造函数允许通过 initParams 自定义初始状态,增强了灵活性。若某些属性可能在外部未显式传入,建议使用安全默认值以免产生 undefined


239-247: ChatResponseModel.toJSON() 输出必要字段便于序列化。若后续需要从序列化结果反向恢复 requestIdagentId 等更多信息,可酌情添加相关字段。


337-343: ChatModel.toJSON() 会将所有请求与历史记录打包序列化。对于有大批消息的用户环境,可考虑在此处分页或按需序列化,以减轻一次性写入压力。

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

72-72: 建议将 MAX_TITLE_LENGTH 的值抽离到配置或常量文件中。
如果其他地方也需要相同的长度限制,统一管理会更易维护。

packages/ai-native/src/browser/components/ChatHistory.tsx (3)

116-135: 建议将时间格式化逻辑抽取为独立的工具函数。

getTimeKey 函数的逻辑可以移到一个单独的工具文件中,这样可以:

  1. 提高代码的可重用性
  2. 便于单元测试
  3. 使组件代码更加清晰

建议创建 utils/time.ts 文件:

export const formatTimeAgo = (timestamp: number): string => {
  const diff = Date.now() - timestamp;
  if (diff < 60 * 60 * 1000) {
    const minutes = Math.floor(diff / (60 * 1000));
    return minutes === 0 ? 'Just now' : `${minutes}m ago`;
  } else if (diff < 24 * 60 * 60 * 1000) {
    const hours = Math.floor(diff / (60 * 60 * 1000));
    return `${hours}h ago`;
  }
  // ... 其余逻辑
};

226-230: 优化搜索功能的性能。

当前的搜索实现在每次输入时都会重新过滤整个列表。对于大型历史记录,这可能会导致性能问题。

建议:

  1. 使用防抖(debounce)来减少不必要的过滤操作
  2. 考虑实现模糊搜索
  3. 对搜索结果进行缓存
import { debounce } from 'lodash';

const debouncedSearch = debounce((value: string) => {
  const filteredList = historyList
    .slice(0, MAX_HISTORY_LIST)
    .filter((item) => item.title && item.title.toLowerCase().includes(value.toLowerCase()));
  setFilteredResults(filteredList);
}, 300);

192-200: 删除被注释的代码。

建议删除被注释的编辑功能代码。如果将来需要这个功能,可以从版本控制系统中恢复。

packages/ai-native/src/browser/ai-core.contribution.ts (1)

243-252: 初始化聊天服务

初始化逻辑清晰,顺序合理:

  1. 先初始化内部服务
  2. 再异步初始化管理服务

建议添加错误处理。

 async initialize() {
   const { supportsChatAssistant } = this.aiNativeConfigService.capabilities;

   if (supportsChatAssistant) {
     ComponentRegistryImpl.addLayoutModule(this.appConfig.layoutConfig, AI_CHAT_VIEW_ID, AI_CHAT_CONTAINER_ID);
     ComponentRegistryImpl.addLayoutModule(this.appConfig.layoutConfig, DESIGN_MENU_BAR_RIGHT, AI_CHAT_LOGO_AVATAR_ID);
     this.chatProxyService.registerDefaultAgent();
+    try {
       this.chatInternalService.init();
       await this.chatManagerService.init();
+    } catch (error) {
+      console.error('Failed to initialize chat services:', error);
+    }
   }
 }
packages/i18n/src/common/zh-CN.lang.ts (1)

1255-1259: 新增聊天操作相关的本地化文案

文案清晰简洁,符合中文用户习惯。建议补充以下场景的文案:

  1. 聊天历史为空时的提示
  2. 删除确认对话框的文案
 'aiNative.operate.chatHistory.title': '聊天历史',
 'aiNative.operate.chatHistory.searchPlaceholder': '请搜索...',
 'aiNative.operate.chatHistory.edit': '编辑',
 'aiNative.operate.chatHistory.delete': '删除',
+'aiNative.operate.chatHistory.empty': '暂无聊天历史',
+'aiNative.operate.chatHistory.delete.confirm': '确定要删除该聊天记录吗?',
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7094c8c and 00e8eb5.

📒 Files selected for processing (15)
  • packages/ai-native/src/browser/ai-core.contribution.ts (2 hunks)
  • packages/ai-native/src/browser/chat/chat-manager.service.ts (3 hunks)
  • packages/ai-native/src/browser/chat/chat-model.ts (6 hunks)
  • packages/ai-native/src/browser/chat/chat-proxy.service.ts (1 hunks)
  • packages/ai-native/src/browser/chat/chat.internal.service.ts (2 hunks)
  • packages/ai-native/src/browser/chat/chat.module.less (2 hunks)
  • packages/ai-native/src/browser/chat/chat.view.tsx (7 hunks)
  • packages/ai-native/src/browser/components/ChatHistory.tsx (1 hunks)
  • packages/ai-native/src/browser/components/ChatReply.tsx (1 hunks)
  • packages/ai-native/src/browser/components/ChatThinking.tsx (1 hunks)
  • packages/ai-native/src/browser/components/chat-history.css (1 hunks)
  • packages/ai-native/src/browser/model/msg-history-manager.ts (2 hunks)
  • packages/core-common/src/storage.ts (1 hunks)
  • packages/i18n/src/common/en-US.lang.ts (1 hunks)
  • packages/i18n/src/common/zh-CN.lang.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/ai-native/src/browser/components/chat-history.css
🧰 Additional context used
🪛 Biome (1.9.4)
packages/ai-native/src/browser/chat/chat-manager.service.ts

[error] 82-86: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)

packages/ai-native/src/browser/components/ChatHistory.tsx

[error] 235-235: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
  • GitHub Check: build (ubuntu-latest, 20.x)
  • GitHub Check: unittest (ubuntu-latest, 18.x, node)
  • GitHub Check: build (macos-latest, 20.x)
  • GitHub Check: unittest (macos-latest, 18.x, jsdom)
  • GitHub Check: unittest (macos-latest, 18.x, node)
  • GitHub Check: build-windows
  • GitHub Check: ubuntu-latest, Node.js 20.x
🔇 Additional comments (29)
packages/ai-native/src/browser/chat/chat.internal.service.ts (2)

46-54: 在存储初始化事件中,根据已有会话决定是否创建新会话的逻辑十分合理。若后续需要根据时间戳或其他自定义优先级选择会话,建议在这里扩展相应的逻辑。


93-95: 对外暴露获取所有会话的接口,功能直观简单。若需要进行权限控制或过滤,可在此处扩展。

packages/ai-native/src/browser/chat/chat-manager.service.ts (7)

40-41: 通过 storageInitEmitteronStorageInit 来处理存储初始化事件,设计非常直观。对于复杂场景,可考虑在触发同时传递更多上下文信息。


49-52: 在该服务中引入并保存 StorageProvider 对象及 _chatStorage 有助于实现会话的持久化。若后续需要切换不同的命名空间或存储策略,可以在此处灵活扩展。


54-80: fromJSON 方法可将存储中的数据恢复为完整的 ChatModel 实例。建议在处理 item.requests 时增补空值判断或异常处理,以免数据不完整时引发错误。


96-98: 提供获取所有会话的方式,便于 UI 或其他服务调用。若后续需要基于会话属性进行筛选或排序,可以在此方法中进一步扩展。


101-101: 使用 new ChatModel() 的方式取代依赖注入,简化了会话创建流程。若需要更灵活的构造过程,可在此处引入参数或工厂模式。


195-195: 在响应请求流程的 finally 块中调用 this.saveSessions() 可确保无论成功或异常都能进行持久化,这种设计非常健壮。


207-207: 在取消请求后立即保存会话同样能保证数据一致性,但若取消操作频繁,建议评估对性能的影响并视情况进行优化。

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

277-284: 新的 ChatModel 构造函数允许自定义会话 ID、历史等,设计灵活。初始化逻辑简单明了,复用性强。


296-297: restoreRequests 通过一次性替换存储结构来恢复会话请求列表,简洁易懂。若需要在恢复前后执行校验或转换,可在此方法中进一步扩展。

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

24-24: 引入 DisposableCollection 很合理。
封装一处集中清理的思路可以有效避免事件监听或订阅的内存泄漏。


455-456: 在再生成流程中校验 request 安全性。
此处保证 request 存在便发起请求,逻辑简单明了,但也建议思考异常处理或请求失败的应对措施。


621-622: 在从存储恢复时判空逻辑合理。
request 为空或未完成做了保护,能有效避免异常。后续可考虑在 UI 上给用户展示正在恢复或未完成的提示。

Also applies to: 631-632


761-780: 状态与回调声明整体清晰易读。
handleNewChathandleHistoryItemSelecthandleHistoryItemDelete 各自单一职责明确,逻辑简单,便于后续维护和扩展。


781-831: React.useEffect 中动态监听多处 session 变动需谨慎。
虽然通过 DisposableCollection 可以正确清理,但应注意确保不会重复注册;如果 session 数量非常多,需做性能评估。


834-874: 头部区域布局与事件绑定逻辑简洁明了。
ChatHistory 组件与弹出操作配合默契,无明显问题。若要做更多定制操作,可考虑抽离通用 UI 组件以便在其他地方复用。

packages/ai-native/src/browser/model/msg-history-manager.ts (2)

18-24: 新增构造函数支持外部初始化数据,提升灵活性。
可以在创建实例时还原历史消息与附加数据,满足更多场景需求。


100-105: toJSON 方法实现非常便捷。
对接存储或网络传输场景时可直接使用本方法序列化。后续若需要只导出部分数据,可新增额外函数进行筛选处理。

packages/core-common/src/storage.ts (1)

56-56: 为聊天功能独立存储命名空间非常合适。
有助于实现对话数据的定向管理,避免与其他模块的存储相互影响。

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

119-125: 代码变更增强了重新生成按钮的显示逻辑。

通过添加 !!requestId 检查,确保只有在存在有效的请求 ID 时才显示重新生成按钮,这是一个很好的防御性编程实践。

packages/ai-native/src/browser/chat/chat-proxy.service.ts (1)

42-42:

❓ Verification inconclusive

请验证移除 UUID 后缀的影响。

AGENT_ID 从动态值更改为静态值可能会影响:

  1. 多个代理实例的唯一性
  2. 会话持久化
  3. 代理标识

建议确认这个更改不会导致任何并发或状态管理问题。

运行以下脚本来检查代码库中 AGENT_ID 的使用情况:


🏁 Script executed:

#!/bin/bash
# 描述:检查 AGENT_ID 的使用情况,特别是在并发和状态管理相关的代码中

# 搜索所有引用 AGENT_ID 的代码
rg "AGENT_ID" -A 5 -B 5

# 搜索可能的并发处理相关代码
rg "concurrent|async|await|Promise|setTimeout|setInterval" --type ts

Length of output: 68067


验证静态化 AGENT_ID 影响

经过代码库内的搜索,发现所有对 ChatProxyService.AGENT_ID 的引用都采用了固定字符串 'Default_Chat_Agent' 进行比较和过滤,未依赖原先动态附加 UUID 的机制来保证唯一性。从目前的使用情况来看:

  • 默认代理在注册、更新及视图显示时均基于固定 ID 进行逻辑判断(例如在对比、过滤和显示代理 ID 时)。
  • 没有明显迹象表明当前场景中需要依靠动态 UUID 来区分多个默认代理实例,也未发现并发处理或状态管理上的隐患。

建议:

  • 请确认系统设计中默认代理仅为单一实例。如果未来需要同时支持多个默认代理实例,可能需要重新考虑使用动态唯一 ID 来避免潜在冲突。
  • 对于当前默认代理的使用,确保其他功能模块(如会话持久化和代理区分)能够正确识别和处理该固定标识,防止误判或状态错乱。

综合来看,在现有的代码逻辑和使用场景中,此改动暂未引入并发或状态管理上的问题,但建议开发者在扩展多实例场景时保持警惕。

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

363-367: 完善了消息存在性的检查逻辑。

通过添加 responseContents.length 的检查,使消息存在性的判断更加完整和准确。这个改进可以更好地处理不同类型的响应内容。

packages/ai-native/src/browser/ai-core.contribution.ts (3)

76-77: 导入新的聊天服务接口

导入的接口定义清晰,符合命名规范。


83-85: 导入聊天服务实现类

导入的服务实现类符合命名规范。


233-237: 注入聊天服务依赖

通过 @Autowired 装饰器正确注入了聊天管理服务和内部服务。

packages/i18n/src/common/en-US.lang.ts (1)

1487-1491: 新增的本地化字符串看起来不错!

新增的聊天历史相关的本地化字符串遵循了现有的命名约定,使用了合适的命名空间,并且提供了清晰的英文翻译。

packages/ai-native/src/browser/chat/chat.module.less (2)

76-87: 头部容器样式优化得很好!

对header_container的改进:

  • 通过减小padding使头部更加紧凑
  • 简化了header结构,移除了复杂的left/right类,使代码更加清晰

282-285: 新增的chat_history样式定义合理!

chat_history类的样式设置:

  • 使用calc()计算宽度,保留了合适的边距
  • 使用CSS变量设置文字颜色,保持了主题的一致性

Copy link

codecov bot commented Feb 21, 2025

Codecov Report

Attention: Patch coverage is 22.78481% with 61 lines in your changes missing coverage. Please review.

Project coverage is 53.56%. Comparing base (7094c8c) to head (b344bca).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...ai-native/src/browser/chat/chat-manager.service.ts 17.24% 24 Missing ⚠️
packages/ai-native/src/browser/chat/chat-model.ts 38.46% 16 Missing ⚠️
...i-native/src/browser/chat/chat.internal.service.ts 0.00% 13 Missing and 3 partials ⚠️
...ai-native/src/browser/model/msg-history-manager.ts 42.85% 4 Missing ⚠️
...s/ai-native/src/browser/chat/chat-proxy.service.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4399      +/-   ##
==========================================
- Coverage   53.58%   53.56%   -0.03%     
==========================================
  Files        1651     1651              
  Lines      101806   101866      +60     
  Branches    22027    22035       +8     
==========================================
+ Hits        54557    54566       +9     
- Misses      39304    39351      +47     
- Partials     7945     7949       +4     
Flag Coverage Δ
jsdom 49.07% <22.78%> (-0.03%) ⬇️
node 12.22% <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.

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 (5)
packages/ai-native/src/browser/components/ChatHistory.tsx (5)

9-25: 建议为接口添加 JSDoc 文档注释

为了提高代码的可维护性和可读性,建议为 IChatHistoryItemIChatHistoryProps 接口添加详细的 JSDoc 文档注释,包括每个属性的用途说明。

+/**
+ * 聊天历史记录项的接口定义
+ */
 export interface IChatHistoryItem {
+  /** 唯一标识符 */
   id: string;
+  /** 聊天标题 */
   title: string;
+  /** 更新时间戳 */
   updatedAt: number;
+  /** 是否正在加载 */
   loading: boolean;
 }

+/**
+ * 聊天历史记录组件的属性接口
+ */
 export interface IChatHistoryProps {
   // ... 同样添加其他属性的文档注释
 }

45-45: 建议优化 inputRef 的类型定义

当前 inputRef 使用 any 类型,建议使用更具体的类型以提高类型安全性。

-const inputRef = useRef<any>(null);
+const inputRef = useRef<HTMLInputElement>(null);

191-199: 建议清理未使用的注释代码

建议移除或实现被注释的编辑功能代码。如果这是一个计划中的功能,建议使用 TODO 注释标记,或者完全移除这段代码。保留注释掉的代码可能会导致混淆。


115-134: 建议国际化时间标签

当前时间标签(如 "Just now", "5m ago" 等)使用硬编码的英文文本。建议使用 localize 函数进行国际化处理,以支持多语言。

 const getTimeKey = useCallback((diff: number): string => {
   if (diff < 60 * 60 * 1000) {
     const minutes = Math.floor(diff / (60 * 1000));
-    return minutes === 0 ? 'Just now' : `${minutes}m ago`;
+    return minutes === 0 
+      ? localize('aiNative.time.justNow')
+      : localize('aiNative.time.minutesAgo', minutes);
   }
   // ... 对其他时间标签进行类似处理
 }, []);

234-239: 建议使用可选链操作符优化代码

为了提高代码的健壮性,建议在事件处理中使用可选链操作符。

 <Input
   placeholder={localize('aiNative.operate.chatHistory.searchPlaceholder')}
   style={{ width: '100%', maxWidth: '100%' }}
   value={searchValue}
-  onChange={handleSearchChange}
+  onChange={handleSearchChange?.}
 />
🧰 Tools
🪛 Biome (1.9.4)

[error] 235-235: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 00e8eb5 and b344bca.

📒 Files selected for processing (1)
  • packages/ai-native/src/browser/components/ChatHistory.tsx (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/ai-native/src/browser/components/ChatHistory.tsx

[error] 235-235: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
  • GitHub Check: build (ubuntu-latest, 20.x)
  • GitHub Check: unittest (ubuntu-latest, 18.x, node)
  • GitHub Check: build (macos-latest, 20.x)
  • GitHub Check: build-windows
  • GitHub Check: ubuntu-latest, Node.js 20.x

@ensorrow ensorrow merged commit 23e4557 into main Feb 24, 2025
12 checks passed
@ensorrow ensorrow deleted the feat/chat-session-manager branch February 24, 2025 02:08
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