From b0aef35c63452004162050344a1836aa4f056767 Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 10 Oct 2025 18:24:56 +0800 Subject: [PATCH] feat: try chat flow app --- .../base/chat/embedded-chatbot/chat-wrapper.tsx | 3 +-- .../base/chat/embedded-chatbot/context.tsx | 3 +++ .../components/base/chat/embedded-chatbot/hooks.tsx | 12 ++++++------ web/app/components/try/app/chat.tsx | 2 +- web/app/components/try/app/index.tsx | 2 +- web/service/try-app.ts | 2 +- 6 files changed, 13 insertions(+), 11 deletions(-) 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 dc1e969b53..6dc504ad91 100644 --- a/web/app/components/base/chat/embedded-chatbot/chat-wrapper.tsx +++ b/web/app/components/base/chat/embedded-chatbot/chat-wrapper.tsx @@ -14,7 +14,6 @@ import { InputVarType } from '@/app/components/workflow/types' import { TransferMethod } from '@/types/app' import InputsForm from '@/app/components/base/chat/embedded-chatbot/inputs-form' import { - AppSourceType, fetchSuggestedQuestions, getUrl, stopChatMessageResponding, @@ -53,9 +52,9 @@ const ChatWrapper = () => { setIsResponding, allInputsHidden, initUserVariables, + appSourceType, } = useEmbeddedChatbotContext() - const appSourceType = isInstalledApp ? AppSourceType.installedApp : AppSourceType.webApp const appConfig = useMemo(() => { const config = appParams || {} diff --git a/web/app/components/base/chat/embedded-chatbot/context.tsx b/web/app/components/base/chat/embedded-chatbot/context.tsx index b8e385d33f..ef48d0a6c9 100644 --- a/web/app/components/base/chat/embedded-chatbot/context.tsx +++ b/web/app/components/base/chat/embedded-chatbot/context.tsx @@ -15,6 +15,7 @@ import type { ConversationItem, } from '@/models/share' import { noop } from 'lodash-es' +import { AppSourceType } from '@/service/share' export type EmbeddedChatbotContextValue = { userCanAccess?: boolean @@ -40,6 +41,7 @@ export type EmbeddedChatbotContextValue = { chatShouldReloadKey: string isMobile: boolean isInstalledApp: boolean + appSourceType: AppSourceType allowResetChat: boolean appId?: string disableFeedback?: boolean @@ -75,6 +77,7 @@ export const EmbeddedChatbotContext = createContext handleNewConversationCompleted: noop, chatShouldReloadKey: '', isMobile: false, + appSourceType: AppSourceType.webApp, isInstalledApp: false, allowResetChat: true, handleFeedback: noop, diff --git a/web/app/components/base/chat/embedded-chatbot/hooks.tsx b/web/app/components/base/chat/embedded-chatbot/hooks.tsx index ba7b902d5f..84309ba98b 100644 --- a/web/app/components/base/chat/embedded-chatbot/hooks.tsx +++ b/web/app/components/base/chat/embedded-chatbot/hooks.tsx @@ -70,13 +70,12 @@ function getFormattedChatList(messages: any[]) { } export const useEmbeddedChatbot = (appSourceType = AppSourceType.webApp, tryAppId?: string) => { - // const isWebApp = appSourceType === AppSourceType.webApp - const isInstalledApp = false // webapp and try app + const isInstalledApp = false // just can be webapp and try app const isTryApp = appSourceType === AppSourceType.tryApp const systemFeatures = useGlobalPublicStore(s => s.systemFeatures) - const { data: appInfo, isLoading: appInfoLoading, error: appInfoError } = useSWR('appInfo', isTryApp ? fetchTryAppInfo : fetchAppInfo) + const { data: appInfo, isLoading: appInfoLoading, error: appInfoError } = useSWR('appInfo', isTryApp ? () => fetchTryAppInfo(tryAppId) : fetchAppInfo) const { isPending: isCheckingPermission, data: userCanAccessResult } = useGetUserCanAccessApp({ - appId: appInfo?.app_id, + appId: appInfo?.app_id || tryAppId, isInstalledApp, enabled: systemFeatures.webapp_auth.enabled && !isTryApp, }) @@ -154,8 +153,8 @@ export const useEmbeddedChatbot = (appSourceType = AppSourceType.webApp, tryAppI }, [currentConversationId, newConversationId]) const { data: appParams } = useSWR(['appParams', appSourceType, appId], () => fetchAppParams(appSourceType, appId)) - const { data: appMeta } = useSWR(['appMeta', appSourceType, appId], () => fetchAppMeta(appSourceType, appId)) - const { data: appPinnedConversationData } = useSWR(['appConversationData', appSourceType, appId, true], () => fetchConversations(appSourceType, appId, undefined, true, 100)) + 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)) @@ -408,6 +407,7 @@ export const useEmbeddedChatbot = (appSourceType = AppSourceType.webApp, tryAppI appInfoError, appInfoLoading: appInfoLoading || (systemFeatures.webapp_auth.enabled && isCheckingPermission), userCanAccess: isTryApp || (systemFeatures.webapp_auth.enabled ? (userCanAccessResult as { result: boolean })?.result : true), + appSourceType, isInstalledApp, allowResetChat, appId, diff --git a/web/app/components/try/app/chat.tsx b/web/app/components/try/app/chat.tsx index 364f0d2860..56d00db099 100644 --- a/web/app/components/try/app/chat.tsx +++ b/web/app/components/try/app/chat.tsx @@ -32,7 +32,7 @@ const TryApp: FC = ({ disableFeedback: true, isMobile, themeBuilder, - }}> + } as any}>
diff --git a/web/app/components/try/app/index.tsx b/web/app/components/try/app/index.tsx index 5c737eb061..d5c1063705 100644 --- a/web/app/components/try/app/index.tsx +++ b/web/app/components/try/app/index.tsx @@ -16,7 +16,7 @@ const TryApp: FC = ({ }) => { const { isFetching: isFetchingAppInfo, data: appInfo } = useGetTryAppInfo(appId) const mode = appInfo?.mode - const isChat = mode === 'chat' + const isChat = mode === 'chat' || mode === 'advanced-chat' const isCompletion = !isChat if (isFetchingAppInfo) { return ( diff --git a/web/service/try-app.ts b/web/service/try-app.ts index 9425e1a71f..5384cba9f7 100644 --- a/web/service/try-app.ts +++ b/web/service/try-app.ts @@ -7,7 +7,7 @@ import type { type TryAppInfo = { name: string - mode: 'chat' | 'text-generation' | 'workflow' + mode: 'chat' | 'advanced-chat' | 'text-generation' | 'workflow' site: SiteInfo }