fix(web): guard empty multiFiles array in getProcessedInputs

This commit is contained in:
Yufeng He 2026-06-16 18:41:42 +08:00
parent 1427b0b098
commit 0dea743955
2 changed files with 8 additions and 1 deletions

View File

@ -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"}',

View File

@ -47,7 +47,7 @@ export const getProcessedInputs = (inputs: Record<string, any>, 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)