diff --git a/web/app/components/try/app/index.tsx b/web/app/components/try/app/index.tsx index 90c9f57677..24c0a9a4e8 100644 --- a/web/app/components/try/app/index.tsx +++ b/web/app/components/try/app/index.tsx @@ -3,6 +3,9 @@ import type { FC } from 'react' import React from 'react' import Chat from './chat' import TextGeneration from './text-generation' +import Loading from '../../base/loading' +import { useGetTryAppInfo } from '@/service/use-try-app' +import type { AppData } from '@/models/share' type Props = { appId: string @@ -11,16 +14,34 @@ type Props = { const TryApp: FC = ({ appId, }) => { - // get app type by /trial-apps/ - const isChat = appId === 'fsVnyqGJbriqnPxK' + const { isFetching: isFetchingAppInfo, data: appInfo } = useGetTryAppInfo(appId) + const mode = appInfo?.mode + const isChat = mode === 'chat' const isCompletion = !isChat + if (isFetchingAppInfo) { + return ( +
+ +
+ ) + } + console.log(appInfo) return (
{isChat && ( )} {isCompletion && ( - + )}
Right panel diff --git a/web/app/components/try/app/text-generation.tsx b/web/app/components/try/app/text-generation.tsx index 1485cfac6f..f05523223f 100644 --- a/web/app/components/try/app/text-generation.tsx +++ b/web/app/components/try/app/text-generation.tsx @@ -5,34 +5,25 @@ import cn from '@/utils/classnames' import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' import AppIcon from '@/app/components/base/app-icon' import MenuDropdown from '@/app/components/share/text-generation/menu-dropdown' -import type { SiteInfo } from '@/models/share' -import type { VisionFile, VisionSettings } from '@/types/app' -import { Resolution, TransferMethod } from '@/types/app' -import type { MoreLikeThisConfig, PromptConfig, TextToSpeechConfig } from '@/models/debug' -import { userInputsFormToPromptVariables } from '@/utils/model-config' -import { useWebAppStore } from '@/context/web-app-context' -import { useGetTryAppInfo, useGetTryAppParams } from '@/service/use-try-app' import Loading from '@/app/components/base/loading' import { appDefaultIconBackground } from '@/config' import RunOnce from '../../share/text-generation/run-once' -import { useBoolean } from 'ahooks' -import Res from '@/app/components/share/text-generation/result' -import type { Task } from '../../share/text-generation/types' -import { TaskStatus } from '../../share/text-generation/types' -import { noop } from 'lodash' -import { AppSourceType } from '@/service/share' +import { useWebAppStore } from '@/context/web-app-context' +import type { AppData } from '@/models/share' type Props = { appId: string className?: string + isWorkflow?: boolean + appData: AppData | null } const TextGeneration: FC = ({ appId, className, + isWorkflow, + appData, }) => { - // const { t } = useTranslation() - const isWorkflow = true // wait for detail app info to decide // app.mode === 'completion' | 'workflow' const media = useBreakpoints() const isPC = media === MediaType.pc @@ -42,125 +33,126 @@ const TextGeneration: FC = ({ doSetInputs(newInputs) inputsRef.current = newInputs }, []) + console.log(isPC, setInputs) - const { isFetching: isFetchingAppInfo, data: appInfo } = useGetTryAppInfo() const updateAppInfo = useWebAppStore(s => s.updateAppInfo) - const appData = useWebAppStore(s => s.appInfo) - const { data: tryAppParams } = useGetTryAppParams() - const updateAppParams = useWebAppStore(s => s.updateAppParams) - const appParams = useWebAppStore(s => s.appParams) - const [siteInfo, setSiteInfo] = useState(null) - const [promptConfig, setPromptConfig] = useState(null) - const [customConfig, setCustomConfig] = useState | null>(null) - const [moreLikeThisConfig, setMoreLikeThisConfig] = useState(null) - const [textToSpeechConfig, setTextToSpeechConfig] = useState(null) - const [controlSend, setControlSend] = useState(0) - const [visionConfig, setVisionConfig] = useState({ - enabled: false, - number_limits: 2, - detail: Resolution.low, - transfer_methods: [TransferMethod.local_file], - }) - const [completionFiles, setCompletionFiles] = useState([]) - const [isShowResultPanel, { setTrue: doShowResultPanel, setFalse: hideResultPanel }] = useBoolean(false) - const showResultPanel = () => { - // fix: useClickAway hideResSidebar will close sidebar - setTimeout(() => { - doShowResultPanel() - }, 0) - } + // const { data: tryAppParams } = useGetTryAppParams() + // const updateAppParams = useWebAppStore(s => s.updateAppParams) + // const appParams = useWebAppStore(s => s.appParams) + // const [siteInfo, setSiteInfo] = useState(null) + // const [promptConfig, setPromptConfig] = useState(null) + // const [customConfig, setCustomConfig] = useState | null>(null) + // const [moreLikeThisConfig, setMoreLikeThisConfig] = useState(null) + // const [textToSpeechConfig, setTextToSpeechConfig] = useState(null) + // const [controlSend, setControlSend] = useState(0) + // const [visionConfig, setVisionConfig] = useState({ + // enabled: false, + // number_limits: 2, + // detail: Resolution.low, + // transfer_methods: [TransferMethod.local_file], + // }) + // const [completionFiles, setCompletionFiles] = useState([]) + // const [isShowResultPanel, { setTrue: doShowResultPanel, setFalse: hideResultPanel }] = useBoolean(false) + // const showResultPanel = () => { + // // fix: useClickAway hideResSidebar will close sidebar + // setTimeout(() => { + // doShowResultPanel() + // }, 0) + // } - const handleSend = () => { - setControlSend(Date.now()) - showResultPanel() - } + // const handleSend = () => { + // setControlSend(Date.now()) + // showResultPanel() + // } - const [resultExisted, setResultExisted] = useState(false) + // const [resultExisted, setResultExisted] = useState(false) useEffect(() => { - if (!appInfo) return - updateAppInfo(appInfo) - }, [appInfo, updateAppInfo]) + if (!appData) return + updateAppInfo(appData) + }, [appData, updateAppInfo]) - useEffect(() => { - if (!tryAppParams) return - updateAppParams(tryAppParams) - }, [tryAppParams, updateAppParams]) + // useEffect(() => { + // if (!tryAppParams) return + // updateAppParams(tryAppParams) + // }, [tryAppParams, updateAppParams]) - useEffect(() => { - (async () => { - if (!appData || !appParams) - return - const { site: siteInfo, custom_config } = appData - setSiteInfo(siteInfo as SiteInfo) - setCustomConfig(custom_config) + // useEffect(() => { + // (async () => { + // if (!appData || !appParams) + // return + // const { site: siteInfo, custom_config } = appData + // setSiteInfo(siteInfo as SiteInfo) + // setCustomConfig(custom_config) - const { user_input_form, more_like_this, file_upload, text_to_speech }: any = appParams - setVisionConfig({ - // legacy of image upload compatible - ...file_upload, - transfer_methods: file_upload?.allowed_file_upload_methods || file_upload?.allowed_upload_methods, - // legacy of image upload compatible - image_file_size_limit: appParams?.system_parameters.image_file_size_limit, - fileUploadConfig: appParams?.system_parameters, - } as any) - const prompt_variables = userInputsFormToPromptVariables(user_input_form) - setPromptConfig({ - prompt_template: '', // placeholder for future - prompt_variables, - } as PromptConfig) - setMoreLikeThisConfig(more_like_this) - setTextToSpeechConfig(text_to_speech) - })() - }, [appData, appParams]) + // const { user_input_form, more_like_this, file_upload, text_to_speech }: any = appParams + // setVisionConfig({ + // // legacy of image upload compatible + // ...file_upload, + // transfer_methods: file_upload?.allowed_file_upload_methods || file_upload?.allowed_upload_methods, + // // legacy of image upload compatible + // image_file_size_limit: appParams?.system_parameters.image_file_size_limit, + // fileUploadConfig: appParams?.system_parameters, + // } as any) + // const prompt_variables = userInputsFormToPromptVariables(user_input_form) + // setPromptConfig({ + // prompt_template: '', // placeholder for future + // prompt_variables, + // } as PromptConfig) + // setMoreLikeThisConfig(more_like_this) + // setTextToSpeechConfig(text_to_speech) + // })() + // }, [appData, appParams]) - const handleCompleted = noop + // const handleCompleted = noop - const renderRes = (task?: Task) => ( setResultExisted(true)} - />) + // const renderRes = (task?: Task) => ( setResultExisted(true)} + // />) - const renderResWrap = ( -
-
- {renderRes()} -
-
- ) + // const renderResWrap = ( + //
+ //
+ // {renderRes()} + //
+ //
+ // ) + + return (
xxxx
) // console.log(siteInfo, promptConfig) diff --git a/web/service/try-app.ts b/web/service/try-app.ts index 05a55e0c51..9425e1a71f 100644 --- a/web/service/try-app.ts +++ b/web/service/try-app.ts @@ -1,11 +1,16 @@ import { - getPublic as get, + get, } from './base' import type { - AppData, + SiteInfo, } from '@/models/share' -// would use trial-apps after api is ok -export const fetchTryAppInfo = async () => { - return get('/site') as Promise +type TryAppInfo = { + name: string + mode: 'chat' | 'text-generation' | 'workflow' + site: SiteInfo +} + +export const fetchTryAppInfo = async (appId: string) => { + return get(`/trial-apps/${appId}`) as Promise } diff --git a/web/service/use-try-app.ts b/web/service/use-try-app.ts index c3a686dbcb..1350997990 100644 --- a/web/service/use-try-app.ts +++ b/web/service/use-try-app.ts @@ -4,11 +4,11 @@ import { AppSourceType, fetchAppParams } from './share' const NAME_SPACE = 'try-app' -export const useGetTryAppInfo = () => { +export const useGetTryAppInfo = (appId: string) => { return useQuery({ queryKey: [NAME_SPACE, 'appInfo'], queryFn: () => { - return fetchTryAppInfo() + return fetchTryAppInfo(appId) }, }) }