mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-25 18:03:29 +08:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user