Feat: Support uploading files when running agent #3221 (#8697)

### What problem does this PR solve?

Feat: Support uploading files when running agent #3221

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2025-07-07 12:18:18 +08:00
committed by GitHub
parent 9580e99650
commit 4a9708889e
9 changed files with 1634 additions and 27 deletions

View File

@ -26,6 +26,7 @@ export const enum AgentApiAction {
ResetAgent = 'resetAgent',
SetAgent = 'setAgent',
FetchAgentTemplates = 'fetchAgentTemplates',
UploadCanvasFile = 'uploadCanvasFile',
}
export const EmptyDsl = {
@ -268,3 +269,34 @@ export const useSetAgent = () => {
return { data, loading, setAgent: mutateAsync };
};
export const useUploadCanvasFile = () => {
const {
data,
isPending: loading,
mutateAsync,
} = useMutation({
mutationKey: [AgentApiAction.UploadCanvasFile],
mutationFn: async (body: any) => {
let nextBody = body;
try {
if (Array.isArray(body)) {
nextBody = new FormData();
body.forEach((file: File) => {
nextBody.append('file', file as any);
});
}
const { data } = await flowService.uploadCanvasFile(nextBody);
if (data?.code === 0) {
message.success(i18n.t('message.uploaded'));
}
return data;
} catch (error) {
message.error('error');
}
},
});
return { data, loading, uploadCanvasFile: mutateAsync };
};