diff --git a/web/app/(commonLayout)/try/right/page.tsx b/web/app/(commonLayout)/try/right/page.tsx new file mode 100644 index 0000000000..8ea68b5b3d --- /dev/null +++ b/web/app/(commonLayout)/try/right/page.tsx @@ -0,0 +1,9 @@ +import Meta from '../../../components/try/app/meta' + +const Page = () => { + return ( + + ) +} + +export default Page diff --git a/web/app/components/try/app/meta.tsx b/web/app/components/try/app/meta.tsx new file mode 100644 index 0000000000..9c19e40f83 --- /dev/null +++ b/web/app/components/try/app/meta.tsx @@ -0,0 +1,17 @@ +'use client' +import type { FC } from 'react' +import React from 'react' + +type Props = { + +} + +const Meta: FC = ({ +}) => { + return ( +
+ Meta Info +
+ ) +} +export default React.memo(Meta) diff --git a/web/app/components/try/app/text-generation.tsx b/web/app/components/try/app/text-generation.tsx index f05523223f..447b851f1b 100644 --- a/web/app/components/try/app/text-generation.tsx +++ b/web/app/components/try/app/text-generation.tsx @@ -9,7 +9,18 @@ import Loading from '@/app/components/base/loading' import { appDefaultIconBackground } from '@/config' import RunOnce from '../../share/text-generation/run-once' import { useWebAppStore } from '@/context/web-app-context' -import type { AppData } from '@/models/share' +import type { AppData, SiteInfo } from '@/models/share' +import { useGetTryAppParams } from '@/service/use-try-app' +import type { MoreLikeThisConfig, PromptConfig, TextToSpeechConfig } from '@/models/debug' +import { userInputsFormToPromptVariables } from '@/utils/model-config' +import type { VisionFile, VisionSettings } from '@/types/app' +import { Resolution, TransferMethod } from '@/types/app' +import { useBoolean } from 'ahooks' +import { noop } from 'lodash' +import type { Task } from '../../share/text-generation/types' +import Res from '@/app/components/share/text-generation/result' +import { AppSourceType } from '@/service/share' +import { TaskStatus } from '@/app/components/share/text-generation/types' type Props = { appId: string @@ -33,130 +44,127 @@ const TextGeneration: FC = ({ doSetInputs(newInputs) inputsRef.current = newInputs }, []) - console.log(isPC, setInputs) + // console.log(isPC, setInputs) const updateAppInfo = useWebAppStore(s => s.updateAppInfo) - // 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(appId) - // const handleSend = () => { - // setControlSend(Date.now()) - // showResultPanel() - // } + 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 [resultExisted, setResultExisted] = useState(false) + const handleSend = () => { + setControlSend(Date.now()) + showResultPanel() + } + + const [resultExisted, setResultExisted] = useState(false) useEffect(() => { 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) - - if(isFetchingAppInfo || !siteInfo || !promptConfig) { + if(!siteInfo || !promptConfig) { return (
diff --git a/web/service/share.ts b/web/service/share.ts index a940af98c5..70f1044c61 100644 --- a/web/service/share.ts +++ b/web/service/share.ts @@ -39,7 +39,7 @@ export enum AppSourceType { const apiPrefix = { [AppSourceType.webApp]: '', [AppSourceType.installedApp]: 'installed-apps', - [AppSourceType.tryApp]: 'installed-apps', // 'trial-apps', use 'installed-apps' for test + [AppSourceType.tryApp]: 'trial-apps', } function getIsPublicAPI(appSourceType: AppSourceType) { diff --git a/web/service/use-try-app.ts b/web/service/use-try-app.ts index 1350997990..1d7ed2ca02 100644 --- a/web/service/use-try-app.ts +++ b/web/service/use-try-app.ts @@ -13,11 +13,11 @@ export const useGetTryAppInfo = (appId: string) => { }) } -export const useGetTryAppParams = () => { +export const useGetTryAppParams = (appId: string) => { return useQuery({ queryKey: [NAME_SPACE, 'appParams'], queryFn: () => { - return fetchAppParams(AppSourceType.webApp) // todo: wait api + return fetchAppParams(AppSourceType.tryApp, appId) }, }) }