diff --git a/web/app/components/base/chat/chat/__tests__/utils.spec.ts b/web/app/components/base/chat/chat/__tests__/utils.spec.ts index bcdbbcab14f1f8..6dd7cbf0fef7b3 100644 --- a/web/app/components/base/chat/chat/__tests__/utils.spec.ts +++ b/web/app/components/base/chat/chat/__tests__/utils.spec.ts @@ -92,6 +92,13 @@ describe('chat/chat/utils.ts', () => { expect(result.files2[0]).toHaveProperty('processed', true) }) + it('handles an empty multiFiles array without throwing', () => { + const inputs = { files1: [] } + const inputsForm = [{ variable: 'files1', type: InputVarType.multiFiles as string }] + const result = getProcessedInputs(inputs, inputsForm as InputForm[]) + expect(result.files1).toEqual([]) + }) + it('processes jsonObject parsing correct json', () => { const inputs = { json1: '{"key": "value"}', diff --git a/web/app/components/base/chat/chat/utils.ts b/web/app/components/base/chat/chat/utils.ts index a64c8162dcee39..56a089eaf96b14 100644 --- a/web/app/components/base/chat/chat/utils.ts +++ b/web/app/components/base/chat/chat/utils.ts @@ -47,7 +47,7 @@ export const getProcessedInputs = (inputs: Record, inputsForm: Inpu processedInputs[item.variable] = getProcessedFiles([inputValue])[0] } else if (item.type === InputVarType.multiFiles) { - if ('transfer_method' in inputValue[0]) + if (inputValue[0] && 'transfer_method' in inputValue[0]) processedInputs[item.variable] = inputValue.map(processInputFileFromServer) else processedInputs[item.variable] = getProcessedFiles(inputValue)