diff --git a/web/app/components/app/text-generate/item/index.tsx b/web/app/components/app/text-generate/item/index.tsx index 5b1265384e..b73ac40043 100644 --- a/web/app/components/app/text-generate/item/index.tsx +++ b/web/app/components/app/text-generate/item/index.tsx @@ -25,6 +25,7 @@ import EditReplyModal from '@/app/components/app/annotation/edit-annotation-moda const MAX_DEPTH = 3 export type IGenerationItemProps = { + isWorkflow?: boolean className?: string isError: boolean onRetry: () => void @@ -75,6 +76,7 @@ export const copyIcon = ( ) const GenerationItem: FC = ({ + isWorkflow, className, isError, onRetry, @@ -137,6 +139,7 @@ const GenerationItem: FC = ({ isInstalledApp, installedAppId, controlClearMoreLikeThis, + isWorkflow, } const handleMoreLikeThis = async () => { @@ -191,7 +194,7 @@ const GenerationItem: FC = ({ const ratingContent = ( <> - {!isError && messageId && !feedback?.rating && ( + {!isWorkflow && !isError && messageId && !feedback?.rating && ( <>
= ({ )} - {!isError && messageId && feedback?.rating === 'like' && ( + {!isWorkflow && !isError && messageId && feedback?.rating === 'like' && (
{ onFeedback?.({ @@ -226,7 +229,7 @@ const GenerationItem: FC = ({
)} - {!isError && messageId && feedback?.rating === 'dislike' && ( + {!isWorkflow && !isError && messageId && feedback?.rating === 'dislike' && (
{ onFeedback?.({ @@ -308,14 +311,16 @@ const GenerationItem: FC = ({ {isInWebApp && ( <> - { onSave?.(messageId as string) }} - > - - {!isMobile &&
{t('common.operation.save')}
} -
+ {!isWorkflow && ( + { onSave?.(messageId as string) }} + > + + {!isMobile &&
{t('common.operation.save')}
} +
+ )} {(moreLikeThis && depth < MAX_DEPTH) && ( = ({ > {!isMobile &&
{t('appDebug.feature.moreLikeThis.title')}
} -
)} - {isError && - - {!isMobile &&
{t('share.generation.batchFailed.retry')}
} -
} - {!isError && messageId &&
} + + )} + {isError && ( + + + {!isMobile &&
{t('share.generation.batchFailed.retry')}
} +
+ )} + {!isError && messageId && !isWorkflow && ( +
+ )} {ratingContent} )} diff --git a/web/app/components/explore/installed-app/index.tsx b/web/app/components/explore/installed-app/index.tsx index 350a6d4dca..2785fcc4bc 100644 --- a/web/app/components/explore/installed-app/index.tsx +++ b/web/app/components/explore/installed-app/index.tsx @@ -27,13 +27,15 @@ const InstalledApp: FC = ({ return (
- {installedApp?.app.mode === 'chat' - ? ( - - ) - : ( - - )} + {installedApp.app.mode !== 'completion' && installedApp.app.mode !== 'workflow' && ( + + )} + {installedApp.app.mode === 'completion' && ( + + )} + {installedApp.app.mode === 'workflow' && ( + + )}
) } diff --git a/web/app/components/share/text-generation/index.tsx b/web/app/components/share/text-generation/index.tsx index 2940a38741..9405ac7d7f 100644 --- a/web/app/components/share/text-generation/index.tsx +++ b/web/app/components/share/text-generation/index.tsx @@ -348,7 +348,6 @@ const TextGeneration: FC = ({ useEffect(() => { (async () => { - console.log('isWorkflow', isWorkflow) const [appData, appParams]: any = await fetchInitData() const { app_id: appId, site: siteInfo, can_replace_logo } = appData setAppId(appId) @@ -395,6 +394,7 @@ const TextGeneration: FC = ({ const renderRes = (task?: Task) => ( = ({ items={[ { id: 'create', name: t('share.generation.tabs.create') }, { id: 'batch', name: t('share.generation.tabs.batch') }, - { - id: 'saved', - name: t('share.generation.tabs.saved'), - isRight: true, - extra: savedMessages.length > 0 - ? ( -
- {savedMessages.length} -
- ) - : null, - }, + ...(!isWorkflow + ? [{ + id: 'saved', + name: t('share.generation.tabs.saved'), + isRight: true, + extra: savedMessages.length > 0 + ? ( +
+ {savedMessages.length} +
+ ) + : null, + }] + : []), ]} value={currTab} onChange={setCurrTab} diff --git a/web/app/components/share/text-generation/result/index.tsx b/web/app/components/share/text-generation/result/index.tsx index ad7f5b92bc..e537618432 100644 --- a/web/app/components/share/text-generation/result/index.tsx +++ b/web/app/components/share/text-generation/result/index.tsx @@ -7,7 +7,7 @@ import cn from 'classnames' import TextGenerationRes from '@/app/components/app/text-generate/item' import NoData from '@/app/components/share/text-generation/no-data' import Toast from '@/app/components/base/toast' -import { sendCompletionMessage, updateFeedback } from '@/service/share' +import { sendCompletionMessage, sendWorkflowMessage, updateFeedback } from '@/service/share' import type { Feedbacktype } from '@/app/components/app/chat/type' import Loading from '@/app/components/base/loading' import type { PromptConfig } from '@/models/debug' @@ -16,6 +16,7 @@ import type { ModerationService } from '@/models/common' import { TransferMethod, type VisionFile, type VisionSettings } from '@/types/app' export type IResultProps = { + isWorkflow: boolean isCallBatchAPI: boolean isPC: boolean isMobile: boolean @@ -40,6 +41,7 @@ export type IResultProps = { } const Result: FC = ({ + isWorkflow, isCallBatchAPI, isPC, isMobile, @@ -176,34 +178,71 @@ const Result: FC = ({ isTimeout = true } }, 1000) - sendCompletionMessage(data, { - onData: (data: string, _isFirstMessage: boolean, { messageId }) => { - tempMessageId = messageId - res.push(data) - setCompletionRes(res.join('')) - }, - onCompleted: () => { - if (isTimeout) - return - setRespondingFalse() - setMessageId(tempMessageId) - onCompleted(getCompletionRes(), taskId, true) - clearInterval(runId) - }, - onMessageReplace: (messageReplace) => { - res = [messageReplace.answer] - setCompletionRes(res.join('')) - }, - onError() { - if (isTimeout) - return - - setRespondingFalse() - onCompleted(getCompletionRes(), taskId, false) - clearInterval(runId) - }, - }, isInstalledApp, installedAppInfo?.id) + if (isWorkflow) { + // ###TODO### + sendWorkflowMessage( + data, + { + onWorkflowStarted: ({ workflow_run_id }) => { + tempMessageId = workflow_run_id + }, + onTextChunk: ({ data }) => { + res.push(data.text) + setCompletionRes(res.join('')) + }, + onWorkflowFinished: () => { + if (isTimeout) + return + setRespondingFalse() + setMessageId(tempMessageId) + onCompleted(getCompletionRes(), taskId, true) + clearInterval(runId) + }, + onTextReplace: ({ data }) => { + res = [data.text] + setCompletionRes(res.join('')) + }, + onError() { + if (isTimeout) + return + setRespondingFalse() + onCompleted(getCompletionRes(), taskId, false) + clearInterval(runId) + }, + }, + isInstalledApp, + installedAppInfo?.id, + ) + } + else { + sendCompletionMessage(data, { + onData: (data: string, _isFirstMessage: boolean, { messageId }) => { + tempMessageId = messageId + res.push(data) + setCompletionRes(res.join('')) + }, + onCompleted: () => { + if (isTimeout) + return + setRespondingFalse() + setMessageId(tempMessageId) + onCompleted(getCompletionRes(), taskId, true) + clearInterval(runId) + }, + onMessageReplace: (messageReplace) => { + res = [messageReplace.answer] + setCompletionRes(res.join('')) + }, + onError() { + if (isTimeout) + return + setRespondingFalse() + onCompleted(getCompletionRes(), taskId, false) + clearInterval(runId) + }, + }, isInstalledApp, installedAppInfo?.id) + } } const [controlClearMoreLikeThis, setControlClearMoreLikeThis] = useState(0) @@ -221,6 +260,7 @@ const Result: FC = ({ const renderTextGenerationRes = () => ( , { onData, }, { onData, onCompleted, isPublicAPI: !isInstalledApp, onError, onMessageReplace }) } +export const sendWorkflowMessage = async ( + body: Record, + { + onTextChunk, + onWorkflowStarted, + onTextReplace, + onWorkflowFinished, + onError, + }: { + onTextChunk: IOnTextChunk + onWorkflowStarted: IOnWorkflowStarted + onWorkflowFinished: IOnWorkflowFinished + onTextReplace: IOnTextReplace + onError: IOnError + }, + isInstalledApp: boolean, + installedAppId = '', +) => { + return ssePost(getUrl('workflows/run', isInstalledApp, installedAppId), { + body: { + ...body, + response_mode: 'streaming', + }, + }, { onTextChunk, onWorkflowStarted, onWorkflowFinished, isPublicAPI: !isInstalledApp, onError, onTextReplace }) +} + export const fetchAppInfo = async () => { return get('/site') as Promise }