Skip to content

SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.

Refactor file upload error handling in AI chat feature to always display errors for invalid files and limit the number of attached files.

Salman-Ahameda87afcfdc85b
diff --git a/packages/app/src/react/features/ai-chat/hooks/use-fileupload.ts b/packages/app/src/react/features/ai-chat/hooks/use-fileupload.ts
index 19cee3c9..68e33d90 100644
--- a/packages/app/src/react/features/ai-chat/hooks/use-fileupload.ts
+++ b/packages/app/src/react/features/ai-chat/hooks/use-fileupload.ts
@@ -76,10 +76,8 @@ export const useFileUpload = (): UseFileUploadReturn => {
const validFiles = validatedFiles.filter((item) => !item.error);
const invalidFiles = validatedFiles.filter((item) => item.error);
- if (
- invalidFiles.length > 0 &&
- validFiles.length + files.length < FILE_LIMITS.MAX_ATTACHED_FILES
- ) {
+ // Always surface an error if any invalid files were included
+ if (invalidFiles.length > 0) {
setUploadError({
show: true,
message: invalidFiles[0].error || 'Failed to upload file',
@@ -89,6 +87,13 @@ export const useFileUpload = (): UseFileUploadReturn => {
if (validFiles.length > 0) {
const filesToUpload = validFiles.slice(0, remainingSlots);
+ if (validFiles.length > remainingSlots) {
+ setUploadError({
+ show: true,
+ message: `You can only attach ${FILE_LIMITS.MAX_ATTACHED_FILES} files. Extra files were ignored.`,
+ });
+ }
+
// Add files to uploadingFiles set using unique IDs
const newFileIds = new Set(filesToUpload.map((f) => f.id));
setUploadingFiles((prev) => new Set([...prev, ...newFileIds]));