Fix duplicate agents being applied by copilot

This commit is contained in:
akhisud3195 2025-07-29 12:01:31 +05:30
parent 4fd06f9761
commit 1ce43eb268

View file

@ -59,6 +59,7 @@ export function Action({
const handleFieldChange = (field: string) => { const handleFieldChange = (field: string) => {
const changes = { [field]: action.config_changes[field] }; const changes = { [field]: action.config_changes[field] };
// Dispatch the field change directly (this is for partial updates)
switch (action.config_type) { switch (action.config_type) {
case 'agent': case 'agent':
dispatch({ dispatch({
@ -94,74 +95,16 @@ export function Action({
newApplied[getAppliedChangeKey(msgIndex, actionIndex, key)] newApplied[getAppliedChangeKey(msgIndex, actionIndex, key)]
); );
// If all fields are applied, notify parent // If all fields are applied, mark as externally applied but don't call onApplied
if (allFieldsApplied) { // to avoid duplicate dispatch (the parent's onApplied would dispatch the full action again)
onApplied?.();
}
return newApplied; return newApplied;
}); });
}; };
// Handle applying all changes // Handle applying all changes - delegate to parent
const handleApplyAll = () => { const handleApplyAll = () => {
if (action.action === 'create_new') { // Mark all fields as applied locally for UI state
switch (action.config_type) {
case 'agent':
dispatch({
type: 'add_agent',
agent: {
name: action.name,
...action.config_changes
}
});
break;
case 'tool':
dispatch({
type: 'add_tool',
tool: {
name: action.name,
...action.config_changes
}
});
break;
case 'prompt':
dispatch({
type: 'add_prompt',
prompt: {
name: action.name,
...action.config_changes
}
});
break;
}
} else if (action.action === 'edit') {
switch (action.config_type) {
case 'agent':
dispatch({
type: 'update_agent',
name: action.name,
agent: action.config_changes
});
break;
case 'tool':
dispatch({
type: 'update_tool',
name: action.name,
tool: action.config_changes
});
break;
case 'prompt':
dispatch({
type: 'update_prompt',
name: action.name,
prompt: action.config_changes
});
break;
}
}
// Mark all fields as applied
const appliedKeys = Object.keys(action.config_changes).reduce((acc, key) => { const appliedKeys = Object.keys(action.config_changes).reduce((acc, key) => {
acc[getAppliedChangeKey(msgIndex, actionIndex, key)] = true; acc[getAppliedChangeKey(msgIndex, actionIndex, key)] = true;
return acc; return acc;
@ -171,7 +114,7 @@ export function Action({
...appliedKeys ...appliedKeys
})); }));
// Notify parent that this action has been applied // Notify parent to handle the actual dispatching
onApplied?.(); onApplied?.();
}; };