From 7218b7458b9b98c95a2b03c6b3d4b5e914adf3e8 Mon Sep 17 00:00:00 2001 From: Jake Turner Date: Thu, 2 Apr 2026 18:31:32 +0000 Subject: [PATCH] feat(KnowledgeBase): support up to 5 files upload of 100mb each per req --- admin/config/bodyparser.ts | 2 +- .../components/chat/KnowledgeBaseModal.tsx | 59 +++++++++++-------- .../components/file-uploader/index.tsx | 2 +- 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/admin/config/bodyparser.ts b/admin/config/bodyparser.ts index f3d1ead..c995755 100644 --- a/admin/config/bodyparser.ts +++ b/admin/config/bodyparser.ts @@ -47,7 +47,7 @@ const bodyParserConfig = defineConfig({ * Maximum limit of data to parse including all files * and fields */ - limit: '20mb', + limit: '110mb', // Set to 110MB to allow for some overhead beyond the 100MB file size limit types: ['multipart/form-data'], }, }) diff --git a/admin/inertia/components/chat/KnowledgeBaseModal.tsx b/admin/inertia/components/chat/KnowledgeBaseModal.tsx index 00425d9..e77a0c9 100644 --- a/admin/inertia/components/chat/KnowledgeBaseModal.tsx +++ b/admin/inertia/components/chat/KnowledgeBaseModal.tsx @@ -24,6 +24,7 @@ function sourceToDisplayName(source: string): string { export default function KnowledgeBaseModal({ aiAssistantName = "AI Assistant", onClose }: KnowledgeBaseModalProps) { const { addNotification } = useNotifications() const [files, setFiles] = useState([]) + const [isUploading, setIsUploading] = useState(false) const [confirmDeleteSource, setConfirmDeleteSource] = useState(null) const fileUploaderRef = useRef>(null) const { openModal, closeModal } = useModals() @@ -37,23 +38,6 @@ export default function KnowledgeBaseModal({ aiAssistantName = "AI Assistant", o const uploadMutation = useMutation({ mutationFn: (file: File) => api.uploadDocument(file), - onSuccess: (data) => { - addNotification({ - type: 'success', - message: data?.message || 'Document uploaded and queued for processing', - }) - setFiles([]) - if (fileUploaderRef.current) { - fileUploaderRef.current.clear() - } - queryClient.invalidateQueries({ queryKey: ['embed-jobs'] }) - }, - onError: (error: any) => { - addNotification({ - type: 'error', - message: error?.message || 'Failed to upload document', - }) - }, }) const deleteMutation = useMutation({ @@ -96,9 +80,34 @@ export default function KnowledgeBaseModal({ aiAssistantName = "AI Assistant", o }, }) - const handleUpload = () => { - if (files.length > 0) { - uploadMutation.mutate(files[0]) + const handleUpload = async () => { + if (files.length === 0) return + setIsUploading(true) + let successCount = 0 + const failedNames: string[] = [] + + for (const file of files) { + try { + await uploadMutation.mutateAsync(file) + successCount++ + } catch (error: any) { + failedNames.push(file.name) + } + } + + setIsUploading(false) + setFiles([]) + fileUploaderRef.current?.clear() + queryClient.invalidateQueries({ queryKey: ['embed-jobs'] }) + + if (successCount > 0) { + addNotification({ + type: 'success', + message: `${successCount} file${successCount > 1 ? 's' : ''} queued for processing.`, + }) + } + for (const name of failedNames) { + addNotification({ type: 'error', message: `Failed to upload: ${name}` }) } } @@ -145,7 +154,7 @@ export default function KnowledgeBaseModal({ aiAssistantName = "AI Assistant", o { setFiles(Array.from(uploadedFiles)) }} @@ -156,8 +165,8 @@ export default function KnowledgeBaseModal({ aiAssistantName = "AI Assistant", o size="lg" icon="IconUpload" onClick={handleUpload} - disabled={files.length === 0 || uploadMutation.isPending} - loading={uploadMutation.isPending} + disabled={files.length === 0 || isUploading} + loading={isUploading} > Upload @@ -243,8 +252,8 @@ export default function KnowledgeBaseModal({ aiAssistantName = "AI Assistant", o size="md" icon='IconRefresh' onClick={handleConfirmSync} - disabled={syncMutation.isPending || uploadMutation.isPending} - loading={syncMutation.isPending || uploadMutation.isPending} + disabled={syncMutation.isPending || isUploading} + loading={syncMutation.isPending || isUploading} > Sync Storage diff --git a/admin/inertia/components/file-uploader/index.tsx b/admin/inertia/components/file-uploader/index.tsx index 0dac08a..7d37d4f 100644 --- a/admin/inertia/components/file-uploader/index.tsx +++ b/admin/inertia/components/file-uploader/index.tsx @@ -29,7 +29,7 @@ const FileUploader = forwardRef((props, ref) const { minFiles = 0, maxFiles = 1, - maxFileSize = 10485760, // default to 10MB + maxFileSize = 104857600, // default to 100MB fileTypes, disabled = false, onUpload,