mirror of https://github.com/langgenius/dify.git
feat: try chat flow app
This commit is contained in:
parent
ac351b700c
commit
b0aef35c63
|
|
@ -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 || {}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<EmbeddedChatbotContextValue>
|
|||
handleNewConversationCompleted: noop,
|
||||
chatShouldReloadKey: '',
|
||||
isMobile: false,
|
||||
appSourceType: AppSourceType.webApp,
|
||||
isInstalledApp: false,
|
||||
allowResetChat: true,
|
||||
handleFeedback: noop,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ const TryApp: FC<Props> = ({
|
|||
disableFeedback: true,
|
||||
isMobile,
|
||||
themeBuilder,
|
||||
}}>
|
||||
} as any}>
|
||||
<div className={cn('bg-background-section-burn', className)}>
|
||||
<ChatWrapper />
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ const TryApp: FC<Props> = ({
|
|||
}) => {
|
||||
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 (
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import type {
|
|||
|
||||
type TryAppInfo = {
|
||||
name: string
|
||||
mode: 'chat' | 'text-generation' | 'workflow'
|
||||
mode: 'chat' | 'advanced-chat' | 'text-generation' | 'workflow'
|
||||
site: SiteInfo
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue