(e, selectedInput, action, humanInput)
| 1008 | |
| 1009 | // Handle form submission |
| 1010 | const handleSubmit = async (e, selectedInput, action, humanInput) => { |
| 1011 | if (e) e.preventDefault() |
| 1012 | |
| 1013 | if (!selectedInput && userInput.trim() === '') { |
| 1014 | const containsFile = previews.filter((item) => !item.mime.startsWith('image') && item.type !== 'audio').length > 0 |
| 1015 | if (!previews.length || (previews.length && containsFile)) { |
| 1016 | return |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | let input = userInput |
| 1021 | |
| 1022 | if (typeof selectedInput === 'string') { |
| 1023 | if (selectedInput !== undefined && selectedInput.trim() !== '') input = selectedInput |
| 1024 | |
| 1025 | if (input.trim()) { |
| 1026 | inputHistory.addToHistory(input) |
| 1027 | } |
| 1028 | } else if (typeof selectedInput === 'object') { |
| 1029 | input = Object.entries(selectedInput) |
| 1030 | .map(([key, value]) => `${key}: ${value}`) |
| 1031 | .join('\n') |
| 1032 | } |
| 1033 | |
| 1034 | setLoading(true) |
| 1035 | clearAgentflowNodeStatus() |
| 1036 | |
| 1037 | let uploads = previews.map((item) => { |
| 1038 | return { |
| 1039 | data: item.data, |
| 1040 | type: item.type, |
| 1041 | name: item.name, |
| 1042 | mime: item.mime |
| 1043 | } |
| 1044 | }) |
| 1045 | |
| 1046 | try { |
| 1047 | uploads = await handleFileUploads(uploads) |
| 1048 | } catch (error) { |
| 1049 | handleError('Unable to upload documents') |
| 1050 | return |
| 1051 | } |
| 1052 | |
| 1053 | clearPreviews() |
| 1054 | setMessages((prevMessages) => [...prevMessages, { message: input, type: 'userMessage', fileUploads: uploads }]) |
| 1055 | |
| 1056 | // Send user question to Prediction Internal API |
| 1057 | try { |
| 1058 | const params = { |
| 1059 | question: input, |
| 1060 | chatId |
| 1061 | } |
| 1062 | if (typeof selectedInput === 'object') { |
| 1063 | params.form = selectedInput |
| 1064 | delete params.question |
| 1065 | } |
| 1066 | if (uploads && uploads.length > 0) params.uploads = uploads |
| 1067 | if (leadEmail) params.leadEmail = leadEmail |
no test coverage detected