diff --git a/web/app/components/base/chat/chat-with-history/chat-wrapper.tsx b/web/app/components/base/chat/chat-with-history/chat-wrapper.tsx index 6520696934..ea68953fff 100644 --- a/web/app/components/base/chat/chat-with-history/chat-wrapper.tsx +++ b/web/app/components/base/chat/chat-with-history/chat-wrapper.tsx @@ -70,14 +70,12 @@ const ChatWrapper = () => { const doSend: OnSend = useCallback((message, files, last_answer) => { const data: any = { query: message, + files, inputs: currentConversationId ? currentConversationItem?.inputs : newConversationInputs, conversation_id: currentConversationId, parent_message_id: last_answer?.id || getLastAnswer(chatListRef.current)?.id || null, } - if (appConfig?.file_upload?.image?.enabled && files?.length) - data.files = files - handleSend( getUrl('chat-messages', isInstalledApp, appId || ''), data, diff --git a/web/app/components/base/chat/chat-with-history/config-panel/form.tsx b/web/app/components/base/chat/chat-with-history/config-panel/form.tsx index cd375a887e..0b8b4dc0bb 100644 --- a/web/app/components/base/chat/chat-with-history/config-panel/form.tsx +++ b/web/app/components/base/chat/chat-with-history/config-panel/form.tsx @@ -1,4 +1,3 @@ -import { useCallback } from 'react' import { useTranslation } from 'react-i18next' import { useChatWithHistoryContext } from '../context' import Input from './form-input' @@ -12,16 +11,17 @@ const Form = () => { appParams, inputsForms, newConversationInputs, + newConversationInputsRef, handleNewConversationInputsChange, isMobile, } = useChatWithHistoryContext() - const handleFormChange = useCallback((variable: string, value: any) => { + const handleFormChange = (variable: string, value: any) => { handleNewConversationInputsChange({ - ...newConversationInputs, + ...newConversationInputsRef.current, [variable]: value, }) - }, [newConversationInputs, handleNewConversationInputsChange]) + } const renderField = (form: any) => { const { @@ -51,6 +51,20 @@ const Form = () => { /> ) } + if (form.type === InputVarType.singleFile) { + return ( + handleFormChange(variable, files[0])} + fileConfig={{ + allowed_file_types: appParams?.file_upload?.allowed_file_types, + allowed_file_extensions: appParams?.file_upload?.allowed_file_extensions, + allowed_file_upload_methods: appParams?.file_upload?.allowed_file_upload_methods, + number_limits: 1, + }} + /> + ) + } if (form.type === InputVarType.multiFiles) { return ( + newConversationInputsRef: RefObject> handleNewConversationInputsChange: (v: Record) => void inputsForms: any[] handleNewConversation: () => void @@ -57,6 +58,7 @@ export const ChatWithHistoryContext = createContext conversationList: [], showConfigPanelBeforeChat: false, newConversationInputs: {}, + newConversationInputsRef: { current: {} }, handleNewConversationInputsChange: () => {}, inputsForms: [], handleNewConversation: () => {}, diff --git a/web/app/components/base/chat/chat-with-history/hooks.tsx b/web/app/components/base/chat/chat-with-history/hooks.tsx index 2247f067e3..3a8eb5c7e3 100644 --- a/web/app/components/base/chat/chat-with-history/hooks.tsx +++ b/web/app/components/base/chat/chat-with-history/hooks.tsx @@ -391,6 +391,7 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => { setShowConfigPanelBeforeChat, setShowNewConversationItemInList, newConversationInputs, + newConversationInputsRef, handleNewConversationInputsChange, inputsForms, handleNewConversation, diff --git a/web/app/components/base/chat/chat-with-history/index.tsx b/web/app/components/base/chat/chat-with-history/index.tsx index 5910a7f949..16524406d4 100644 --- a/web/app/components/base/chat/chat-with-history/index.tsx +++ b/web/app/components/base/chat/chat-with-history/index.tsx @@ -125,6 +125,7 @@ const ChatWithHistoryWrap: FC = ({ conversationList, showConfigPanelBeforeChat, newConversationInputs, + newConversationInputsRef, handleNewConversationInputsChange, inputsForms, handleNewConversation, @@ -158,6 +159,7 @@ const ChatWithHistoryWrap: FC = ({ conversationList, showConfigPanelBeforeChat, newConversationInputs, + newConversationInputsRef, handleNewConversationInputsChange, inputsForms, handleNewConversation, diff --git a/web/app/components/base/chat/chat/check-input-forms-hooks.ts b/web/app/components/base/chat/chat/check-input-forms-hooks.ts index bf6dd6f26a..802333cd88 100644 --- a/web/app/components/base/chat/chat/check-input-forms-hooks.ts +++ b/web/app/components/base/chat/chat/check-input-forms-hooks.ts @@ -14,6 +14,8 @@ export const useCheckInputsForms = () => { let fileIsUploading = false const requiredVars = inputsForm.filter(({ required }) => required) + console.log(inputs, inputsForm, 'inputs, inputsForm') + if (requiredVars?.length) { requiredVars.forEach(({ variable, label, type }) => { if (hasEmptyInput) @@ -42,7 +44,7 @@ export const useCheckInputsForms = () => { return } - return true + return false }, [notify, t]) return { diff --git a/web/app/components/base/chat/embedded-chatbot/chat-wrapper.tsx b/web/app/components/base/chat/embedded-chatbot/chat-wrapper.tsx index 576cb42a3d..ae4667306f 100644 --- a/web/app/components/base/chat/embedded-chatbot/chat-wrapper.tsx +++ b/web/app/components/base/chat/embedded-chatbot/chat-wrapper.tsx @@ -72,14 +72,12 @@ const ChatWrapper = () => { const doSend: OnSend = useCallback((message, files, last_answer) => { const data: any = { query: message, + files, inputs: currentConversationId ? currentConversationItem?.inputs : newConversationInputs, conversation_id: currentConversationId, parent_message_id: last_answer?.id || getLastAnswer(chatListRef.current)?.id || null, } - if (appConfig?.file_upload?.image?.enabled && files?.length) - data.files = files - handleSend( getUrl('chat-messages', isInstalledApp, appId || ''), data, diff --git a/web/app/components/base/chat/embedded-chatbot/config-panel/form.tsx b/web/app/components/base/chat/embedded-chatbot/config-panel/form.tsx index 15adf9f8a6..19a8aa7c49 100644 --- a/web/app/components/base/chat/embedded-chatbot/config-panel/form.tsx +++ b/web/app/components/base/chat/embedded-chatbot/config-panel/form.tsx @@ -12,13 +12,14 @@ const Form = () => { appParams, inputsForms, newConversationInputs, + newConversationInputsRef, handleNewConversationInputsChange, isMobile, } = useEmbeddedChatbotContext() const handleFormChange = useCallback((variable: string, value: any) => { handleNewConversationInputsChange({ - ...newConversationInputs, + ...newConversationInputsRef.current, [variable]: value, }) }, [newConversationInputs, handleNewConversationInputsChange]) @@ -63,6 +64,20 @@ const Form = () => { /> ) } + if (form.type === InputVarType.singleFile) { + return ( + handleFormChange(variable, files[0])} + fileConfig={{ + allowed_file_types: appParams?.file_upload?.allowed_file_types, + allowed_file_extensions: appParams?.file_upload?.allowed_file_extensions, + allowed_file_upload_methods: appParams?.file_upload?.allowed_file_upload_methods, + number_limits: 1, + }} + /> + ) + } if (form.type === InputVarType.multiFiles) { return ( + newConversationInputsRef: RefObject> handleNewConversationInputsChange: (v: Record) => void inputsForms: any[] handleNewConversation: () => void @@ -51,6 +52,7 @@ export const EmbeddedChatbotContext = createContext conversationList: [], showConfigPanelBeforeChat: false, newConversationInputs: {}, + newConversationInputsRef: { current: {} }, handleNewConversationInputsChange: () => {}, inputsForms: [], handleNewConversation: () => {}, diff --git a/web/app/components/base/chat/embedded-chatbot/hooks.tsx b/web/app/components/base/chat/embedded-chatbot/hooks.tsx index db3ef434f7..fa6e80c336 100644 --- a/web/app/components/base/chat/embedded-chatbot/hooks.tsx +++ b/web/app/components/base/chat/embedded-chatbot/hooks.tsx @@ -292,6 +292,7 @@ export const useEmbeddedChatbot = () => { setShowConfigPanelBeforeChat, setShowNewConversationItemInList, newConversationInputs, + newConversationInputsRef, handleNewConversationInputsChange, inputsForms, handleNewConversation, diff --git a/web/app/components/base/chat/embedded-chatbot/index.tsx b/web/app/components/base/chat/embedded-chatbot/index.tsx index 407c0de6d8..703dde1076 100644 --- a/web/app/components/base/chat/embedded-chatbot/index.tsx +++ b/web/app/components/base/chat/embedded-chatbot/index.tsx @@ -124,6 +124,7 @@ const EmbeddedChatbotWrapper = () => { conversationList, showConfigPanelBeforeChat, newConversationInputs, + newConversationInputsRef, handleNewConversationInputsChange, inputsForms, handleNewConversation, @@ -151,6 +152,7 @@ const EmbeddedChatbotWrapper = () => { conversationList, showConfigPanelBeforeChat, newConversationInputs, + newConversationInputsRef, handleNewConversationInputsChange, inputsForms, handleNewConversation,