Skip to content

feat: Chat → Agent 迁移功能(手动按钮 + LLM 工具建议)#49

Open
zongshuai818 wants to merge 2 commits intoErlichLiu:mainfrom
zongshuai818:feat/chat-to-agent-migration
Open

feat: Chat → Agent 迁移功能(手动按钮 + LLM 工具建议)#49
zongshuai818 wants to merge 2 commits intoErlichLiu:mainfrom
zongshuai818:feat/chat-to-agent-migration

Conversation

@zongshuai818
Copy link
Contributor

@zongshuai818 zongshuai818 commented Feb 26, 2026

概述

实现 Chat → Agent 模式迁移功能,让用户在 Chat 中遇到复杂任务时可以无缝切换到 Agent 模式,携带完整对话历史。

功能

Phase 1:手动迁移按钮

  • ChatInput 底部工具栏新增 Bot 图标按钮,点击即可迁移当前对话到 Agent 模式
  • 迁移时逐条同步 Chat 消息到 Agent 会话,保留完整对话历史
  • 自动添加迁移提示消息,告知用户已切换模式
  • 使用当前 Agent 工作区,无工作区时自动创建默认工作区
  • 流式生成中 / 迁移中按钮自动禁用,防止误操作

Phase 2:LLM 工具建议

  • 新增 suggest_agent_mode 工具,模型判断任务适合 Agent 时主动建议
  • 消息列表末尾显示建议卡片(MigrationSuggestionCard),用户可接受或关闭
  • 系统提示词限制每次对话最多建议一次

变更文件

文件 说明
packages/shared/src/types/chat.ts IPC 常量 + 迁移/建议类型定义
apps/electron/src/main/lib/chat-migration-service.ts 迁移核心逻辑(新建)
apps/electron/src/main/lib/chat-service.ts 注入 suggest_agent_mode 工具
apps/electron/src/main/ipc.ts 注册迁移 IPC handler
apps/electron/src/preload/index.ts 桥接 migrateToAgent + onStreamAgentSuggestion
apps/electron/src/renderer/atoms/chat-atoms.ts 迁移状态 + 建议状态 atoms
apps/electron/src/renderer/hooks/useMigrateToAgent.ts 迁移 Hook(新建)
apps/electron/src/renderer/components/chat/ChatInput.tsx Bot 迁移按钮
apps/electron/src/renderer/components/chat/ChatMessages.tsx 渲染建议卡片
apps/electron/src/renderer/components/chat/ChatView.tsx 订阅建议事件
apps/electron/src/renderer/components/chat/MigrationSuggestionCard.tsx 建议卡片组件(新建)

测试

  • Chat 中发消息 → 点击 Bot 按钮 → 自动切换到 Agent 模式,历史消息完整同步
  • Agent 会话中显示迁移提示消息
  • 流式生成中按钮禁用
  • 无工作区时迁移不报错(fallback 默认工作区)
  • 迁移失败时建议卡片保留,toast 提示错误

联系邮箱:qizongshuai@163.com

Phase 1: ChatHeader 手动迁移按钮,点击后自动携带对话上下文创建 Agent 会话
Phase 2: suggest_agent_mode 工具注入,模型自主判断并推送建议卡片

新增文件:
- chat-migration-service.ts: 迁移核心逻辑(3层上下文压缩、XML构建)
- useMigrateToAgent.ts: 渲染进程迁移 Hook
- MigrationSuggestionCard.tsx: 建议卡片组件

修改文件:
- shared/chat.ts: 迁移类型 + IPC 常量
- chat-service.ts: suggest_agent_mode 工具定义与分发
- ipc.ts / preload: 迁移 handler 注册与桥接
- chat-atoms.ts: 建议状态 atoms
- ChatHeader/ChatView/ChatMessages: UI 集成
- 移除 chat-migration-service.ts 中的 console.log
- 修正 MigrateToAgentResult.contextPrompt 过时注释
- MigrationSuggestionCard.accept 改为 await migrate 后再 dismiss
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.

1 participant