feat(ui): 实现 Agent 模式切换和 Auto Edit 功能
- 添加 AgentModeSelector 组件,支持 Build/Plan 模式切换 - Build 模式下显示 Auto Edit 开关,自动授权文件写入/编辑 - 扩展 useChat hook 添加会话级别的 agentMode/autoApprove 状态 - 服务端支持解析和应用 Agent 模式配置 - 权限处理器实现 auto-approve 检查(仅 write/edit,不含 delete)
This commit is contained in:
@@ -12,6 +12,7 @@ import clsx from 'clsx';
|
||||
import { CommandMenu, type CommandMenuItem } from './CommandMenu.js';
|
||||
import { FileMenu, type FileMenuItem } from './FileMenu.js';
|
||||
import { FileMentionTag } from './FileMentionTag.js';
|
||||
import { AgentModeSelector, type AgentModeType } from './AgentModeSelector.js';
|
||||
import { useCommands } from '../hooks/useCommands.js';
|
||||
import { useFileMention } from '../hooks/useFileMention.js';
|
||||
|
||||
@@ -26,6 +27,14 @@ interface ChatInputProps {
|
||||
enableCommands?: boolean;
|
||||
/** 是否启用文件提及 (@) */
|
||||
enableFileMention?: boolean;
|
||||
/** Agent 模式 (build/plan) */
|
||||
agentMode?: AgentModeType;
|
||||
/** Agent 模式变更回调 */
|
||||
onAgentModeChange?: (mode: AgentModeType) => void;
|
||||
/** 是否自动授权文件写入/编辑 */
|
||||
autoApprove?: boolean;
|
||||
/** 自动授权变更回调 */
|
||||
onAutoApproveChange?: (enabled: boolean) => void;
|
||||
}
|
||||
|
||||
export function ChatInput({
|
||||
@@ -36,6 +45,10 @@ export function ChatInput({
|
||||
responsive = false,
|
||||
enableCommands = true,
|
||||
enableFileMention = true,
|
||||
agentMode = 'build',
|
||||
onAgentModeChange,
|
||||
autoApprove = false,
|
||||
onAutoApproveChange,
|
||||
}: ChatInputProps) {
|
||||
const [input, setInput] = useState('');
|
||||
const [showCommandMenu, setShowCommandMenu] = useState(false);
|
||||
@@ -281,7 +294,20 @@ export function ChatInput({
|
||||
)}
|
||||
|
||||
{/* 输入区域 */}
|
||||
<div className="flex gap-2">
|
||||
<div className="flex gap-2 items-end">
|
||||
{/* Agent 模式选择器 */}
|
||||
{onAgentModeChange && (
|
||||
<div className="flex-shrink-0 pb-1.5">
|
||||
<AgentModeSelector
|
||||
mode={agentMode}
|
||||
onModeChange={onAgentModeChange}
|
||||
autoApprove={autoApprove}
|
||||
onAutoApproveChange={onAutoApproveChange ?? (() => {})}
|
||||
disabled={disabled || isLoading}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex-1 relative">
|
||||
<textarea
|
||||
ref={textareaRef}
|
||||
|
||||
Reference in New Issue
Block a user