From 082179f70f28f269bf19dc91430357d0b5e72ca5 Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 27 Oct 2025 13:38:41 +0800 Subject: [PATCH] fix: try chat has not set converstaion --- .../base/chat/chat/answer/index.tsx | 2 +- web/app/components/base/chat/chat/index.tsx | 2 +- .../chat/embedded-chatbot/chat-wrapper.tsx | 4 +++- .../base/chat/embedded-chatbot/hooks.tsx | 22 ++++++++++++++----- .../components/explore/try-app/app/chat.tsx | 9 ++++++-- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/web/app/components/base/chat/chat/answer/index.tsx b/web/app/components/base/chat/chat/answer/index.tsx index a1b458ba9a..533df61594 100644 --- a/web/app/components/base/chat/chat/answer/index.tsx +++ b/web/app/components/base/chat/chat/answer/index.tsx @@ -150,7 +150,7 @@ const Answer: FC = ({ data={workflowProcess} item={item} hideProcessDetail={hideProcessDetail} - readonly={hideProcessDetail && appData ? !appData.site.show_workflow_steps : undefined} + readonly={hideProcessDetail && appData ? !appData.site?.show_workflow_steps : undefined} /> ) } diff --git a/web/app/components/base/chat/chat/index.tsx b/web/app/components/base/chat/chat/index.tsx index 4afc434ee9..61ed1a3a20 100644 --- a/web/app/components/base/chat/chat/index.tsx +++ b/web/app/components/base/chat/chat/index.tsx @@ -316,7 +316,7 @@ const Chat: FC = ({ { !noChatInput && ( { return null if (!collapsed && inputsForms.length > 0 && !allInputsHidden) return null + if (!appData?.site) + return null if (welcomeMessage.suggestedQuestions && welcomeMessage.suggestedQuestions?.length > 0) { return (
@@ -226,7 +228,7 @@ const ChatWrapper = () => {
) - }, [appData?.site.icon, appData?.site.icon_background, appData?.site.icon_type, appData?.site.icon_url, chatList, collapsed, currentConversationId, inputsForms.length, respondingState, allInputsHidden]) + }, [appData?.site, chatList, collapsed, currentConversationId, inputsForms.length, respondingState, allInputsHidden]) const answerIcon = isDify() ? diff --git a/web/app/components/base/chat/embedded-chatbot/hooks.tsx b/web/app/components/base/chat/embedded-chatbot/hooks.tsx index 698f212693..2f7cf23191 100644 --- a/web/app/components/base/chat/embedded-chatbot/hooks.tsx +++ b/web/app/components/base/chat/embedded-chatbot/hooks.tsx @@ -72,8 +72,12 @@ export const useEmbeddedChatbot = (appSourceType: AppSourceType, tryAppId?: stri const isInstalledApp = false // just can be webapp and try app const systemFeatures = useGlobalPublicStore(s => s.systemFeatures) const isTryApp = appSourceType === AppSourceType.tryApp - const { data: appInfo, isLoading: appInfoLoading, error: appInfoError } = useSWR('appInfo', isTryApp ? () => fetchTryAppInfo(tryAppId) : fetchAppInfo) - const appId = useMemo(() => isTryApp ? tryAppId : appInfo?.app_id, [appInfo]) + const { data: appInfo, isLoading: appInfoLoading, error: appInfoError } = useSWR('appInfo', () => { + return isTryApp ? () => fetchTryAppInfo(tryAppId!) : fetchAppInfo + }) + const appId = useMemo(() => { + return isTryApp ? tryAppId : (appInfo as any)?.app_id + }, [appInfo]) const [userId, setUserId] = useState() const [conversationId, setConversationId] = useState() @@ -116,9 +120,16 @@ export const useEmbeddedChatbot = (appSourceType: AppSourceType, tryAppId?: stri const [conversationIdInfo, setConversationIdInfo] = useLocalStorageState>>(CONVERSATION_ID_INFO, { defaultValue: {}, }) + const removeConversationIdInfo = useCallback((appId: string) => { + setConversationIdInfo((prev) => { + const newInfo = { ...prev } + delete newInfo[appId] + return newInfo + }) + }, [setConversationIdInfo]) const allowResetChat = !conversationId - const currentConversationId = useMemo(() => isTryApp ? '' : conversationIdInfo?.[appId || '']?.[userId || 'DEFAULT'] || conversationId || '', - [isTryApp, appId, conversationIdInfo, userId, conversationId]) + const currentConversationId = useMemo(() => conversationIdInfo?.[appId || '']?.[userId || 'DEFAULT'] || conversationId || '', + [appId, conversationIdInfo, userId, conversationId]) const handleConversationIdInfoChange = useCallback((changeConversationId: string) => { if (appId) { let prevValue = conversationIdInfo?.[appId || ''] @@ -146,7 +157,7 @@ export const useEmbeddedChatbot = (appSourceType: AppSourceType, tryAppId?: stri const { data: appMeta } = useSWR(isTryApp ? null : ['appMeta', appSourceType, appId], () => fetchAppMeta(appSourceType, appId)) const { data: appPinnedConversationData } = useSWR(isTryApp ? null : ['appConversationData', appSourceType, appId, true], () => fetchConversations(appSourceType, appId, undefined, true, 100)) const { data: appConversationData, isLoading: appConversationDataLoading, mutate: mutateAppConversationData } = useSWR(isTryApp ? null : ['appConversationData', appSourceType, appId, false], () => fetchConversations(appSourceType, appId, undefined, false, 100)) - const { data: appChatListData, isLoading: appChatListDataLoading } = useSWR(chatShouldReloadKey ? ['appChatList', chatShouldReloadKey, appSourceType, appId] : null, () => fetchChatList(chatShouldReloadKey, appSourceType, appId)) + const { data: appChatListData, isLoading: appChatListDataLoading } = useSWR((chatShouldReloadKey && !isTryApp) ? ['appChatList', chatShouldReloadKey, appSourceType, appId] : null, () => fetchChatList(chatShouldReloadKey, appSourceType, appId)) const [clearChatList, setClearChatList] = useState(false) const [isResponding, setIsResponding] = useState(false) @@ -406,6 +417,7 @@ export const useEmbeddedChatbot = (appSourceType: AppSourceType, tryAppId?: stri appId, currentConversationId, currentConversationItem, + removeConversationIdInfo, handleConversationIdInfoChange, appData: appInfo, appParams: appParams || {} as ChatConfig, diff --git a/web/app/components/explore/try-app/app/chat.tsx b/web/app/components/explore/try-app/app/chat.tsx index 54f167391d..501b275535 100644 --- a/web/app/components/explore/try-app/app/chat.tsx +++ b/web/app/components/explore/try-app/app/chat.tsx @@ -1,6 +1,6 @@ 'use client' import type { FC } from 'react' -import React from 'react' +import React, { useEffect } from 'react' import ChatWrapper from '@/app/components/base/chat/embedded-chatbot/chat-wrapper' import { useThemeContext } from '../../../base/chat/embedded-chatbot/theme/theme-context' import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' @@ -33,7 +33,12 @@ const TryApp: FC = ({ const media = useBreakpoints() const isMobile = media === MediaType.mobile const themeBuilder = useThemeContext() - const chatData = useEmbeddedChatbot(AppSourceType.tryApp, appId) + const { removeConversationIdInfo, ...chatData } = useEmbeddedChatbot(AppSourceType.tryApp, appId) + + useEffect(() => { + if (appId) + removeConversationIdInfo(appId) + }, [appId]) const [isHideTryNotice, { setTrue: hideTryNotice, }] = useBoolean(false)