MCPcopy
hub / github.com/codeaashu/claude-code / AgentEditor

Function AgentEditor

src/components/agents/AgentEditor.tsx:30–177  ·  view source on GitHub ↗
({
  agent,
  tools,
  onSaved,
  onBack
}: Props)

Source from the content-addressed store, hash-verified

28 model?: string;
29};
30export function AgentEditor({
31 agent,
32 tools,
33 onSaved,
34 onBack
35}: Props): React.ReactNode {
36 const setAppState = useSetAppState();
37 const [editMode, setEditMode] = useState<EditMode>('menu');
38 const [selectedMenuIndex, setSelectedMenuIndex] = useState(0);
39 const [error, setError] = useState<string | null>(null);
40 const [selectedColor, setSelectedColor] = useState<AgentColorName | undefined>(agent.color as AgentColorName | undefined);
41 const handleOpenInEditor = useCallback(async () => {
42 const filePath = getActualAgentFilePath(agent);
43 const result = await editFileInEditor(filePath);
44 if (result.error) {
45 setError(result.error);
46 } else {
47 onSaved(`Opened ${agent.agentType} in editor. If you made edits, restart to load the latest version.`);
48 }
49 }, [agent, onSaved]);
50 const handleSave = useCallback(async (changes: SaveChanges = {}) => {
51 const {
52 tools: newTools,
53 color: newColor,
54 model: newModel
55 } = changes;
56 const finalColor = newColor ?? selectedColor;
57 const hasToolsChanged = newTools !== undefined;
58 const hasModelChanged = newModel !== undefined;
59 const hasColorChanged = finalColor !== agent.color;
60 if (!hasToolsChanged && !hasModelChanged && !hasColorChanged) {
61 return false;
62 }
63 try {
64 // Only custom/plugin agents can be edited
65 // this is for type safety; the UI shouldn't allow editing otherwise
66 if (!isCustomAgent(agent) && !isPluginAgent(agent)) {
67 return false;
68 }
69 await updateAgentFile(agent, agent.whenToUse, newTools ?? agent.tools, agent.getSystemPrompt(), finalColor, newModel ?? agent.model);
70 if (hasColorChanged && finalColor) {
71 setAgentColor(agent.agentType, finalColor);
72 }
73 setAppState(state => {
74 const allAgents = state.agentDefinitions.allAgents.map(a => a.agentType === agent.agentType ? {
75 ...a,
76 tools: newTools ?? a.tools,
77 color: finalColor,
78 model: newModel ?? a.model
79 } : a);
80 return {
81 ...state,
82 agentDefinitions: {
83 ...state.agentDefinitions,
84 activeAgents: getActiveAgentsFromList(allAgents),
85 allAgents
86 }
87 };

Callers

nothing calls this directly

Calls 13

useSetAppStateFunction · 0.85
getActualAgentFilePathFunction · 0.85
editFileInEditorFunction · 0.85
isCustomAgentFunction · 0.85
isPluginAgentFunction · 0.85
updateAgentFileFunction · 0.85
setAgentColorFunction · 0.85
getActiveAgentsFromListFunction · 0.85
useKeybindingFunction · 0.85
renderMenuFunction · 0.85
preventDefaultMethod · 0.80
maxMethod · 0.80

Tested by

no test coverage detected