Skip to content

Commit 3147695

Browse files
committed
Refactor ACP dialog and agent management components
- Refactored the App component to streamline agent management by passing the entire agent object to the startAgent function. - Removed the AcpDialog component and its associated CSS, replacing it with a new structure for agent dialogs and settings. - Introduced new components for agent list, input, messages, and settings, enhancing modularity and maintainability. - Updated styles for the new components to ensure a consistent user interface. - Improved the handling of agent interactions and settings, allowing for better user experience and functionality.
1 parent d436f1a commit 3147695

17 files changed

Lines changed: 1166 additions & 1052 deletions

anycode/App.tsx

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,15 +1135,19 @@ const App: React.FC = () => {
11351135
return uniqueId;
11361136
};
11371137

1138-
const startAgent = (agentId: string, agentName: string, command: string, args: string[]) => {
1138+
const startAgent = (agent: AcpAgent | undefined) => {
1139+
if (!agent) return;
1140+
11391141
if (!wsRef.current || !isConnected) return;
11401142

1143+
const { id, name, command, args } = agent;
1144+
11411145
// Generate unique agent ID
1142-
const uniqueAgentId = generateUniqueAgentId(agentId);
1146+
const uniqueAgentId = generateUniqueAgentId(id);
11431147

11441148
wsRef.current.emit('acp:start', {
11451149
agent_id: uniqueAgentId,
1146-
agent_name: agentName,
1150+
agent_name: name,
11471151
command,
11481152
args,
11491153
}, (response: any) => {
@@ -1152,7 +1156,7 @@ const App: React.FC = () => {
11521156
const newSessions = new Map(prev);
11531157
newSessions.set(uniqueAgentId, {
11541158
agentId: uniqueAgentId,
1155-
agentName,
1159+
agentName: name,
11561160
messages: [],
11571161
isActive: true,
11581162
});
@@ -1464,33 +1468,15 @@ const App: React.FC = () => {
14641468
selectedAgentId={selectedAgentId}
14651469
onSelectAgent={setSelectedAgentId}
14661470
onCloseAgent={closeAgent}
1467-
onAddAgent={() => {
1468-
const agent = defaultAgent;
1469-
if (agent) {
1470-
startAgent(agent.id, agent.name, agent.command, agent.args);
1471-
}
1472-
}}
1471+
onAddAgent={() => startAgent(defaultAgent)}
14731472
onOpenSettings={() => {
1474-
ensureDefaultAgents(); // Ensure all default agents are present
1473+
ensureDefaultAgents();
14751474
setIsAgentSettingsOpen(true);
14761475
}}
14771476
agentId={currentSession?.agentId || defaultAgent?.id || 'gemini'}
1478-
agentName={currentSession?.agentName || defaultAgent?.name || 'AI Agent'}
1479-
agentCommand={(() => {
1480-
const agentId = currentSession?.agentId || defaultAgent?.id || 'gemini';
1481-
const agent = getAllAgents().find(a => a.id === agentId);
1482-
return agent?.command || '';
1483-
})()}
1484-
agentArgs={(() => {
1485-
const agentId = currentSession?.agentId || defaultAgent?.id || 'gemini';
1486-
const agent = getAllAgents().find(a => a.id === agentId);
1487-
return agent?.args || [];
1488-
})()}
14891477
isOpen={true}
14901478
onClose={closeAcpDialog}
14911479
onSendPrompt={sendPrompt}
1492-
onStartAgent={startAgent}
1493-
onStopAgent={stopAgent}
14941480
onCancelPrompt={cancelPrompt}
14951481
messages={currentSession?.messages || []}
14961482
toolCalls={[]}

0 commit comments

Comments
 (0)