Feat: add duplicate action to agent list (#14769) (#14856)

closes #14769 


### What problem does this PR solve?

_Briefly describe what this PR aims to solve. Include background context
that will help reviewers understand the purpose of the PR._

### Type of change

- [ ] Bug Fix (non-breaking change which fixes an issue)
- [x] New Feature (non-breaking change which adds functionality)
- [ ] Documentation Update
- [ ] Refactoring
- [ ] Performance Improvement
- [ ] Other (please describe):

---------

Co-authored-by: Zhichang Yu <yuzhichang@gmail.com>
This commit is contained in:
Rene Arredondo
2026-06-28 18:17:44 -07:00
committed by yzc
parent 9f6f0c5582
commit dc07b6ca8f
4 changed files with 59 additions and 2 deletions

View File

@@ -251,6 +251,59 @@ export const useUpdateAgentSetting = () => {
return { data, loading, updateAgentSetting: mutateAsync };
};
export const useDuplicateAgent = () => {
const queryClient = useQueryClient();
const {
data,
isPending: loading,
mutateAsync,
} = useMutation({
mutationKey: [AgentApiAction.SetAgent, 'duplicate'],
mutationFn: async (agent: Pick<IFlow, 'id' | 'title'>) => {
try {
const { data: detail } = await agentService.getAgent(agent.id);
const source = detail?.data;
if (!source) {
message.error(i18n.t('message.requestError'));
return null;
}
const sourceTitle = agent.title ?? source.title ?? '';
const { data } = await agentService.createAgent({
title: i18n.t('flow.copyOfAgentName', {
name: sourceTitle,
defaultValue: `${sourceTitle} (Copy)`,
}),
dsl: source.dsl,
avatar: source.avatar,
description: source.description,
canvas_category: source.canvas_category,
});
if (data?.code === 0) {
message.success(i18n.t('message.created'));
queryClient.invalidateQueries({
queryKey: [AgentApiAction.FetchAgentListByPage],
});
return data;
}
message.error(data?.message ?? i18n.t('message.requestError'));
return null;
} catch (error) {
console.error('useDuplicateAgent failed:', error);
message.error(
(error as { message?: string })?.message ??
i18n.t('message.requestError'),
);
return null;
}
},
});
return { data, loading, duplicateAgent: mutateAsync };
};
export const useDeleteAgent = () => {
const queryClient = useQueryClient();
const {