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 d6b4bdfafe..a23be569cc 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 @@ -29,6 +29,7 @@ const ChatWrapper = () => { appPrevChatTree, currentConversationId, currentConversationItem, + currentConversationInputs, inputsForms, newConversationInputs, newConversationInputsRef, @@ -69,7 +70,7 @@ const ChatWrapper = () => { } = useChat( appConfig, { - inputs: (currentConversationId ? currentConversationItem?.inputs : newConversationInputs) as any, + inputs: (currentConversationId ? currentConversationInputs : newConversationInputs) as any, inputsForm: inputsForms, }, appPrevChatTree, @@ -77,7 +78,7 @@ const ChatWrapper = () => { clearChatList, setClearChatList, ) - const inputsFormValue = currentConversationId ? currentConversationItem?.inputs : newConversationInputsRef?.current + const inputsFormValue = currentConversationId ? currentConversationInputs : newConversationInputsRef?.current const inputDisabled = useMemo(() => { let hasEmptyInput = '' let fileIsUploading = false @@ -124,7 +125,7 @@ const ChatWrapper = () => { const data: any = { query: message, files, - inputs: currentConversationId ? currentConversationItem?.inputs : newConversationInputs, + inputs: currentConversationId ? currentConversationInputs : newConversationInputs, conversation_id: currentConversationId, parent_message_id: (isRegenerate ? parentAnswer?.id : getLastAnswer(chatList)?.id) || null, } @@ -144,6 +145,7 @@ const ChatWrapper = () => { handleSend, currentConversationId, currentConversationItem, + currentConversationInputs, newConversationInputs, isInstalledApp, appId, @@ -245,7 +247,7 @@ const ChatWrapper = () => { chatFooterClassName='pb-4' chatFooterInnerClassName={`mx-auto w-full max-w-[768px] ${isMobile ? 'px-2' : 'px-4'}`} onSend={doSend} - inputs={currentConversationId ? currentConversationItem?.inputs as any : newConversationInputs} + inputs={currentConversationId ? currentConversationInputs as any : newConversationInputs} inputsForm={inputsForms} onRegenerate={doRegenerate} onStopResponding={handleStop} diff --git a/web/app/components/base/chat/chat-with-history/context.tsx b/web/app/components/base/chat/chat-with-history/context.tsx index ed8c27e841..e5ea0d7379 100644 --- a/web/app/components/base/chat/chat-with-history/context.tsx +++ b/web/app/components/base/chat/chat-with-history/context.tsx @@ -54,6 +54,8 @@ export type ChatWithHistoryContextValue = { setClearChatList: (state: boolean) => void isResponding?: boolean setIsResponding: (state: boolean) => void, + currentConversationInputs: Record | null, + setCurrentConversationInputs: (v: Record) => void, } export const ChatWithHistoryContext = createContext({ @@ -85,5 +87,7 @@ export const ChatWithHistoryContext = createContext setClearChatList: () => {}, isResponding: false, setIsResponding: () => {}, + currentConversationInputs: {}, + setCurrentConversationInputs: () => {}, }) export const useChatWithHistoryContext = () => useContext(ChatWithHistoryContext) diff --git a/web/app/components/base/chat/chat-with-history/header-in-mobile.tsx b/web/app/components/base/chat/chat-with-history/header-in-mobile.tsx index e3e1fc3cd0..6a8292c54f 100644 --- a/web/app/components/base/chat/chat-with-history/header-in-mobile.tsx +++ b/web/app/components/base/chat/chat-with-history/header-in-mobile.tsx @@ -120,7 +120,7 @@ const HeaderInMobile = () => {
{t('share.chat.chatSettingsTitle')}
- +
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 7b6780761a..adf4cc7e57 100644 --- a/web/app/components/base/chat/chat-with-history/hooks.tsx +++ b/web/app/components/base/chat/chat-with-history/hooks.tsx @@ -263,6 +263,17 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => { return conversationItem }, [conversationList, currentConversationId, pinnedConversationList]) + const currentConversationLatestInputs = useMemo(() => { + if (!currentConversationId || !appChatListData?.data.length) + return {} + return appChatListData.data.slice().pop().inputs || {} + }, [appChatListData, currentConversationId]) + const [currentConversationInputs, setCurrentConversationInputs] = useState>(currentConversationLatestInputs || {}) + useEffect(() => { + if (currentConversationItem) + setCurrentConversationInputs(currentConversationLatestInputs || {}) + }, [currentConversationItem, currentConversationLatestInputs]) + const { notify } = useToastContext() const checkInputsRequired = useCallback((silent?: boolean) => { let hasEmptyInput = '' @@ -464,5 +475,7 @@ export const useChatWithHistory = (installedAppInfo?: InstalledApp) => { setClearChatList, isResponding, setIsResponding, + currentConversationInputs, + setCurrentConversationInputs, } } 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 35c85d2ad9..dfd7bd21a7 100644 --- a/web/app/components/base/chat/chat-with-history/index.tsx +++ b/web/app/components/base/chat/chat-with-history/index.tsx @@ -157,6 +157,8 @@ const ChatWithHistoryWrap: FC = ({ setClearChatList, isResponding, setIsResponding, + currentConversationInputs, + setCurrentConversationInputs, } = useChatWithHistory(installedAppInfo) return ( @@ -198,6 +200,8 @@ const ChatWithHistoryWrap: FC = ({ setClearChatList, isResponding, setIsResponding, + currentConversationInputs, + setCurrentConversationInputs, }}> diff --git a/web/app/components/base/chat/chat-with-history/inputs-form/content.tsx b/web/app/components/base/chat/chat-with-history/inputs-form/content.tsx index aff5bbb8fb..d33dac492d 100644 --- a/web/app/components/base/chat/chat-with-history/inputs-form/content.tsx +++ b/web/app/components/base/chat/chat-with-history/inputs-form/content.tsx @@ -17,20 +17,24 @@ const InputsFormContent = ({ showTip }: Props) => { appParams, inputsForms, currentConversationId, - currentConversationItem, + currentConversationInputs, + setCurrentConversationInputs, newConversationInputs, newConversationInputsRef, handleNewConversationInputsChange, } = useChatWithHistoryContext() - const inputsFormValue = currentConversationId ? currentConversationItem?.inputs : newConversationInputs - const readonly = !!currentConversationId + const inputsFormValue = currentConversationId ? currentConversationInputs : newConversationInputs const handleFormChange = useCallback((variable: string, value: any) => { + setCurrentConversationInputs({ + ...currentConversationInputs, + [variable]: value, + }) handleNewConversationInputsChange({ ...newConversationInputsRef.current, [variable]: value, }) - }, [newConversationInputsRef, handleNewConversationInputsChange]) + }, [newConversationInputsRef, handleNewConversationInputsChange, currentConversationInputs, setCurrentConversationInputs]) return (
@@ -47,8 +51,6 @@ const InputsFormContent = ({ showTip }: Props) => { value={inputsFormValue?.[form.variable] || ''} onChange={e => handleFormChange(form.variable, e.target.value)} placeholder={form.label} - readOnly={readonly} - disabled={readonly} /> )} {form.type === InputVarType.number && ( @@ -57,8 +59,6 @@ const InputsFormContent = ({ showTip }: Props) => { value={inputsFormValue?.[form.variable] || ''} onChange={e => handleFormChange(form.variable, e.target.value)} placeholder={form.label} - readOnly={readonly} - disabled={readonly} /> )} {form.type === InputVarType.paragraph && ( @@ -66,8 +66,6 @@ const InputsFormContent = ({ showTip }: Props) => { value={inputsFormValue?.[form.variable] || ''} onChange={e => handleFormChange(form.variable, e.target.value)} placeholder={form.label} - readOnly={readonly} - disabled={readonly} /> )} {form.type === InputVarType.select && ( @@ -77,7 +75,6 @@ const InputsFormContent = ({ showTip }: Props) => { items={form.options.map((option: string) => ({ value: option, name: option }))} onSelect={item => handleFormChange(form.variable, item.value as string)} placeholder={form.label} - readonly={readonly} /> )} {form.type === InputVarType.singleFile && ( diff --git a/web/app/components/base/chat/chat-with-history/inputs-form/index.tsx b/web/app/components/base/chat/chat-with-history/inputs-form/index.tsx index e4d27fb776..30ec11c729 100644 --- a/web/app/components/base/chat/chat-with-history/inputs-form/index.tsx +++ b/web/app/components/base/chat/chat-with-history/inputs-form/index.tsx @@ -38,7 +38,7 @@ const InputsFormNode = ({
{t('share.chat.chatSettingsTitle')}
{collapsed && ( - + )} {!collapsed && currentConversationId && ( @@ -46,7 +46,7 @@ const InputsFormNode = ({
{!collapsed && (
- +
)} {!collapsed && !currentConversationId && ( diff --git a/web/app/components/base/chat/chat-with-history/inputs-form/view-form-dropdown.tsx b/web/app/components/base/chat/chat-with-history/inputs-form/view-form-dropdown.tsx index 85500d0510..43df99c38e 100644 --- a/web/app/components/base/chat/chat-with-history/inputs-form/view-form-dropdown.tsx +++ b/web/app/components/base/chat/chat-with-history/inputs-form/view-form-dropdown.tsx @@ -36,7 +36,7 @@ const ViewFormDropdown = () => {
{t('share.chat.chatSettingsTitle')}
- +
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 bcd372bb50..12bf53e5e2 100644 --- a/web/app/components/base/chat/embedded-chatbot/chat-wrapper.tsx +++ b/web/app/components/base/chat/embedded-chatbot/chat-wrapper.tsx @@ -32,6 +32,7 @@ const ChatWrapper = () => { appPrevChatList, currentConversationId, currentConversationItem, + currentConversationInputs, inputsForms, newConversationInputs, newConversationInputsRef, @@ -70,7 +71,7 @@ const ChatWrapper = () => { } = useChat( appConfig, { - inputs: (currentConversationId ? currentConversationItem?.inputs : newConversationInputs) as any, + inputs: (currentConversationId ? currentConversationInputs : newConversationInputs) as any, inputsForm: inputsForms, }, appPrevChatList, @@ -78,7 +79,7 @@ const ChatWrapper = () => { clearChatList, setClearChatList, ) - const inputsFormValue = currentConversationId ? currentConversationItem?.inputs : newConversationInputsRef?.current + const inputsFormValue = currentConversationId ? currentConversationInputs : newConversationInputsRef?.current const inputDisabled = useMemo(() => { let hasEmptyInput = '' let fileIsUploading = false @@ -123,7 +124,7 @@ const ChatWrapper = () => { const data: any = { query: message, files, - inputs: currentConversationId ? currentConversationItem?.inputs : newConversationInputs, + inputs: currentConversationId ? currentConversationInputs : newConversationInputs, conversation_id: currentConversationId, parent_message_id: (isRegenerate ? parentAnswer?.id : getLastAnswer(chatList)?.id) || null, } @@ -241,7 +242,7 @@ const ChatWrapper = () => { chatFooterClassName={cn('pb-4', !isMobile && 'rounded-b-2xl')} chatFooterInnerClassName={cn('mx-auto w-full max-w-full px-4', isMobile && 'px-2')} onSend={doSend} - inputs={currentConversationId ? currentConversationItem?.inputs as any : newConversationInputs} + inputs={currentConversationId ? currentConversationInputs as any : newConversationInputs} inputsForm={inputsForms} onRegenerate={doRegenerate} onStopResponding={handleStop} diff --git a/web/app/components/base/chat/embedded-chatbot/context.tsx b/web/app/components/base/chat/embedded-chatbot/context.tsx index 4f344bd841..d2ea4b02ba 100644 --- a/web/app/components/base/chat/embedded-chatbot/context.tsx +++ b/web/app/components/base/chat/embedded-chatbot/context.tsx @@ -46,6 +46,8 @@ export type EmbeddedChatbotContextValue = { setClearChatList: (state: boolean) => void isResponding?: boolean setIsResponding: (state: boolean) => void, + currentConversationInputs: Record | null, + setCurrentConversationInputs: (v: Record) => void, } export const EmbeddedChatbotContext = createContext({ @@ -70,5 +72,7 @@ export const EmbeddedChatbotContext = createContext setClearChatList: () => {}, isResponding: false, setIsResponding: () => {}, + currentConversationInputs: {}, + setCurrentConversationInputs: () => {}, }) export const useEmbeddedChatbotContext = () => useContext(EmbeddedChatbotContext) diff --git a/web/app/components/base/chat/embedded-chatbot/hooks.tsx b/web/app/components/base/chat/embedded-chatbot/hooks.tsx index 5e13cf77b7..730db3550e 100644 --- a/web/app/components/base/chat/embedded-chatbot/hooks.tsx +++ b/web/app/components/base/chat/embedded-chatbot/hooks.tsx @@ -239,6 +239,17 @@ export const useEmbeddedChatbot = () => { return conversationItem }, [conversationList, currentConversationId, pinnedConversationList]) + const currentConversationLatestInputs = useMemo(() => { + if (!currentConversationId || !appChatListData?.data.length) + return {} + return appChatListData.data.slice().pop().inputs || {} + }, [appChatListData, currentConversationId]) + const [currentConversationInputs, setCurrentConversationInputs] = useState>(currentConversationLatestInputs || {}) + useEffect(() => { + if (currentConversationItem) + setCurrentConversationInputs(currentConversationLatestInputs || {}) + }, [currentConversationItem, currentConversationLatestInputs]) + const { notify } = useToastContext() const checkInputsRequired = useCallback((silent?: boolean) => { let hasEmptyInput = '' @@ -347,5 +358,7 @@ export const useEmbeddedChatbot = () => { setClearChatList, isResponding, setIsResponding, + currentConversationInputs, + setCurrentConversationInputs, } } diff --git a/web/app/components/base/chat/embedded-chatbot/index.tsx b/web/app/components/base/chat/embedded-chatbot/index.tsx index 495ccc97fa..aaf59ca4e4 100644 --- a/web/app/components/base/chat/embedded-chatbot/index.tsx +++ b/web/app/components/base/chat/embedded-chatbot/index.tsx @@ -160,6 +160,8 @@ const EmbeddedChatbotWrapper = () => { setClearChatList, isResponding, setIsResponding, + currentConversationInputs, + setCurrentConversationInputs, } = useEmbeddedChatbot() return { setClearChatList, isResponding, setIsResponding, + currentConversationInputs, + setCurrentConversationInputs, }}> diff --git a/web/app/components/base/chat/embedded-chatbot/inputs-form/content.tsx b/web/app/components/base/chat/embedded-chatbot/inputs-form/content.tsx index 3b3ae44abe..a26db14416 100644 --- a/web/app/components/base/chat/embedded-chatbot/inputs-form/content.tsx +++ b/web/app/components/base/chat/embedded-chatbot/inputs-form/content.tsx @@ -17,20 +17,25 @@ const InputsFormContent = ({ showTip }: Props) => { appParams, inputsForms, currentConversationId, - currentConversationItem, + currentConversationInputs, + setCurrentConversationInputs, newConversationInputs, newConversationInputsRef, handleNewConversationInputsChange, } = useEmbeddedChatbotContext() - const inputsFormValue = currentConversationId ? currentConversationItem?.inputs : newConversationInputs + const inputsFormValue = currentConversationId ? currentConversationInputs : newConversationInputs const readonly = !!currentConversationId const handleFormChange = useCallback((variable: string, value: any) => { + setCurrentConversationInputs({ + ...currentConversationInputs, + [variable]: value, + }) handleNewConversationInputsChange({ ...newConversationInputsRef.current, [variable]: value, }) - }, [newConversationInputsRef, handleNewConversationInputsChange]) + }, [newConversationInputsRef, handleNewConversationInputsChange, currentConversationInputs, setCurrentConversationInputs]) return (
@@ -47,8 +52,6 @@ const InputsFormContent = ({ showTip }: Props) => { value={inputsFormValue?.[form.variable] || ''} onChange={e => handleFormChange(form.variable, e.target.value)} placeholder={form.label} - readOnly={readonly} - disabled={readonly} /> )} {form.type === InputVarType.number && ( @@ -57,8 +60,6 @@ const InputsFormContent = ({ showTip }: Props) => { value={inputsFormValue?.[form.variable] || ''} onChange={e => handleFormChange(form.variable, e.target.value)} placeholder={form.label} - readOnly={readonly} - disabled={readonly} /> )} {form.type === InputVarType.paragraph && ( @@ -66,8 +67,6 @@ const InputsFormContent = ({ showTip }: Props) => { value={inputsFormValue?.[form.variable] || ''} onChange={e => handleFormChange(form.variable, e.target.value)} placeholder={form.label} - readOnly={readonly} - disabled={readonly} /> )} {form.type === InputVarType.select && ( @@ -77,7 +76,6 @@ const InputsFormContent = ({ showTip }: Props) => { items={form.options.map((option: string) => ({ value: option, name: option }))} onSelect={item => handleFormChange(form.variable, item.value as string)} placeholder={form.label} - readonly={readonly} /> )} {form.type === InputVarType.singleFile && ( diff --git a/web/app/components/base/chat/embedded-chatbot/inputs-form/index.tsx b/web/app/components/base/chat/embedded-chatbot/inputs-form/index.tsx index 909348b70d..4ac4aaa16b 100644 --- a/web/app/components/base/chat/embedded-chatbot/inputs-form/index.tsx +++ b/web/app/components/base/chat/embedded-chatbot/inputs-form/index.tsx @@ -38,7 +38,7 @@ const InputsFormNode = ({
{t('share.chat.chatSettingsTitle')}
{collapsed && ( - + )} {!collapsed && currentConversationId && ( @@ -46,7 +46,7 @@ const InputsFormNode = ({
{!collapsed && (
- +
)} {!collapsed && !currentConversationId && ( diff --git a/web/app/components/base/chat/embedded-chatbot/inputs-form/view-form-dropdown.tsx b/web/app/components/base/chat/embedded-chatbot/inputs-form/view-form-dropdown.tsx index bce04cec52..d6c89864d9 100644 --- a/web/app/components/base/chat/embedded-chatbot/inputs-form/view-form-dropdown.tsx +++ b/web/app/components/base/chat/embedded-chatbot/inputs-form/view-form-dropdown.tsx @@ -40,7 +40,7 @@ const ViewFormDropdown = ({ iconColor }: Props) => {
{t('share.chat.chatSettingsTitle')}
- +