Skip to content

refactor(SelectModelPopup): use the same base popup for chat and agent pages#13700

Merged
DeJeune merged 8 commits intoCherryHQ:mainfrom
alephpiece:refactor/select-model-popups
Mar 23, 2026
Merged

refactor(SelectModelPopup): use the same base popup for chat and agent pages#13700
DeJeune merged 8 commits intoCherryHQ:mainfrom
alephpiece:refactor/select-model-popups

Conversation

@alephpiece
Copy link
Copy Markdown
Collaborator

@alephpiece alephpiece commented Mar 22, 2026

What this PR does

Uses the same base popup for Chat and Agent.

  • SelectModelPopup is now the base popup. It accepts filtered models and sorted providers.
  • SelectChatModelPopup is used on the Chat page.
  • SelectAgentModelPopup is used on the Agent page.

Maintains consistent sorting logic across Chat and Agent.

  • Providers are sorted according to their order in settings.

Before this PR:

  • SelectModelPopup had duplicated implementations.
  • The Agent page popup was missing some features, such as searching by provider.

After this PR:

  • Duplication is removed.
  • All existing features are preserved.

Popup on the Agent page:

image

Fixes #

Why we need it and why it was done in this way

The following tradeoffs were made:

The following alternatives were considered:

Links to places where the discussion took place:

Breaking changes

If this PR introduces breaking changes, please describe the changes and the impact on users.

Special notes for your reviewer

Checklist

This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.

Release note

Use the same base popup for Chat and Agent to enable the same set of features.

…t pages

- `SelectModelPopup` is the base popup now. It accepts filtered models and sorted providers.
- `SelectChatModelPopup` is for the chat page.
- `SelectAgentModelPopup` is for the agent page.
Copy link
Copy Markdown
Collaborator

@GeorgeDong32 GeorgeDong32 left a comment

Choose a reason for hiding this comment

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

📋 代码审查总结

感谢这个重构 PR!成功消除了约 369 行重复代码,统一了 Chat 和 Agent 页面的模型选择弹窗实现。

✅ 良好实践

  1. 工厂模式应用得当 - createModelPopup 有效复用了 popup 逻辑
  2. 组件组合清晰 - 职责分离明确
  3. 排序逻辑集中化 - 消除了重复实现
  4. Memoization 使用正确 - useMemouseCallback 使用恰当

⚠️ 待改进项

优先级 问题 文件
🔴 高 createModelPopupas any 类型安全问题 base-popup.tsx:628
🔴 高 Agent popup 中类型转换风险 agent-model-popup.tsx:80
🟡 低 注释掉的 logger 应清理 base-popup.tsx:36

建议

  • 考虑为 createModelPopup 添加更严格的泛型约束
  • 为类型转换添加运行时检查或类型守卫
  • 清理注释代码

整体来说这是一个高质量的重构,建议解决上述类型安全问题后合并。

@alephpiece alephpiece force-pushed the refactor/select-model-popups branch from caa3ec8 to 86de7c2 Compare March 22, 2026 09:05
Copy link
Copy Markdown
Collaborator

@EurFelux EurFelux left a comment

Choose a reason for hiding this comment

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

整体是一个高质量的重构,成功消除了约 370 行重复代码,统一了 Chat 和 Agent 页面的模型选择弹窗实现。工厂模式和组件组合都很清晰。

留了三个建议:

  1. SelectModelPopup 基础 popup 是否需要从 index 导出
  2. buildFallbackProvider 是数据不同步的 workaround,建议留个 TODO(v2) 注释
  3. resolve 回调中的 as AdaptedApiModel 类型转换建议加强类型安全

Copy link
Copy Markdown
Collaborator

@GeorgeDong32 GeorgeDong32 left a comment

Choose a reason for hiding this comment

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

代码审查总结

✅ 优点

架构改进: 成功消除代码重复,将 ~500 行的 agent-model-popup 精简至 ~100 行,净减少 357 行代码。

设计模式: createModelPopup 工厂函数设计优雅,类型安全,可复用性强。

关注点分离: base-popup、chat-model-popup、agent-model-popup 各司其职,职责清晰。

性能优化: useMemouseCallback 使用得当,虚拟列表实现高效渲染。

文档质量: fallback provider 的 TODO 注释清晰说明了技术债务和后续改进方向。

类型清理: 正确移除了未使用的 FlatListApiModelFlatListApiItem 类型。

📝 建议性改进

已在内联评论中提出两个建议性改进:

  1. 添加 API 错误状态处理
  2. 在非预期情况下添加警告日志

这些都是非阻塞性建议,不影响代码功能正确性。

🎯 结论

批准合并

这是一个高质量的重构 PR,成功统一了 Chat 和 Agent 页面的模型选择弹窗实现。代码结构清晰,消除了大量重复代码,遵循了 DRY 原则。建议性改进可在后续迭代中考虑。

Copy link
Copy Markdown
Collaborator

@DeJeune DeJeune left a comment

Choose a reason for hiding this comment

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

LGTM

@DeJeune DeJeune merged commit 2c3d694 into CherryHQ:main Mar 23, 2026
14 checks passed
@alephpiece alephpiece deleted the refactor/select-model-popups branch March 23, 2026 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants