| | |
| | | import { useBoolean } from 'ahooks' |
| | | import { t } from 'i18next' |
| | | import produce from 'immer' |
| | | import cn from '@/utils/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 Loading from '@/app/components/base/loading' |
| | | import type { PromptConfig } from '@/models/debug' |
| | | import type { InstalledApp } from '@/models/explore' |
| | | import type { ModerationService } from '@/models/common' |
| | | import { TransferMethod, type VisionFile, type VisionSettings } from '@/types/app' |
| | | import { NodeRunningStatus, WorkflowRunningStatus } from '@/app/components/workflow/types' |
| | | import type { WorkflowProcess } from '@/app/components/base/chat/types' |
| | |
| | | handleSaveMessage: (messageId: string) => void |
| | | taskId?: number |
| | | onCompleted: (completionRes: string, taskId?: number, success?: boolean) => void |
| | | enableModeration?: boolean |
| | | moderationService?: (text: string) => ReturnType<ModerationService> |
| | | visionConfig: VisionSettings |
| | | completionFiles: VisionFile[] |
| | | siteInfo: SiteInfo | null |
| | | onRunStart: () => void |
| | | } |
| | | |
| | | const Result: FC<IResultProps> = ({ |
| | |
| | | visionConfig, |
| | | completionFiles, |
| | | siteInfo, |
| | | onRunStart, |
| | | }) => { |
| | | const [isResponding, { setTrue: setRespondingTrue, setFalse: setRespondingFalse }] = useBoolean(false) |
| | | useEffect(() => { |
| | |
| | | let res: string[] = [] |
| | | let tempMessageId = '' |
| | | |
| | | if (!isPC) { |
| | | if (!isPC) |
| | | onShowRes() |
| | | onRunStart() |
| | | } |
| | | |
| | | setRespondingTrue() |
| | | let isEnd = false |
| | |
| | | ...data, |
| | | status: NodeRunningStatus.Running, |
| | | expand: true, |
| | | }) |
| | | } as any) |
| | | })) |
| | | }, |
| | | onIterationNext: () => { |
| | |
| | | draft.tracing[iterationsIndex] = { |
| | | ...data, |
| | | expand: !!data.error, |
| | | } |
| | | })) |
| | | }, |
| | | onLoopStart: ({ data }) => { |
| | | setWorkflowProcessData(produce(getWorkflowProcessData()!, (draft) => { |
| | | draft.expand = true |
| | | draft.tracing!.push({ |
| | | ...data, |
| | | status: NodeRunningStatus.Running, |
| | | expand: true, |
| | | }) |
| | | })) |
| | | }, |
| | | onLoopNext: () => { |
| | | setWorkflowProcessData(produce(getWorkflowProcessData()!, (draft) => { |
| | | draft.expand = true |
| | | const loops = draft.tracing.find(item => item.node_id === data.node_id |
| | | && (item.execution_metadata?.parallel_id === data.execution_metadata?.parallel_id || item.parallel_id === data.execution_metadata?.parallel_id))! |
| | | loops?.details!.push([]) |
| | | })) |
| | | }, |
| | | onLoopFinish: ({ data }) => { |
| | | setWorkflowProcessData(produce(getWorkflowProcessData()!, (draft) => { |
| | | draft.expand = true |
| | | const loopsIndex = draft.tracing.findIndex(item => item.node_id === data.node_id |
| | | && (item.execution_metadata?.parallel_id === data.execution_metadata?.parallel_id || item.parallel_id === data.execution_metadata?.parallel_id))! |
| | | draft.tracing[loopsIndex] = { |
| | | ...data, |
| | | expand: !!data.error, |
| | | } |
| | | } as any |
| | | })) |
| | | }, |
| | | onNodeStarted: ({ data }) => { |
| | | if (data.iteration_id) |
| | | return |
| | | |
| | | if (data.loop_id) |
| | | return |
| | | |
| | | setWorkflowProcessData(produce(getWorkflowProcessData()!, (draft) => { |
| | | draft.expand = true |
| | | draft.tracing!.push({ |
| | | ...data, |
| | | status: NodeRunningStatus.Running, |
| | | expand: true, |
| | | }) |
| | | } as any) |
| | | })) |
| | | }, |
| | | onNodeFinished: ({ data }) => { |
| | | if (data.iteration_id) |
| | | return |
| | | |
| | | if (data.loop_id) |
| | | return |
| | | |
| | | setWorkflowProcessData(produce(getWorkflowProcessData()!, (draft) => { |
| | |
| | | : {}), |
| | | ...data, |
| | | expand: !!data.error, |
| | | } |
| | | } as any |
| | | } |
| | | })) |
| | | }, |
| | |
| | | <TextGenerationRes |
| | | isWorkflow={isWorkflow} |
| | | workflowProcessData={workflowProcessData} |
| | | className='mt-3' |
| | | isError={isError} |
| | | onRetry={handleSend} |
| | | content={completionRes} |
| | |
| | | ) |
| | | |
| | | return ( |
| | | <> |
| | | <div className={cn(isNoData && !isCallBatchAPI && 'h-full')}> |
| | | {!isCallBatchAPI && !isWorkflow && ( |
| | | (isResponding && !completionRes) |
| | | ? ( |
| | | <div className='flex h-full w-full items-center justify-center'> |
| | | <div className='flex h-full w-full justify-center items-center'> |
| | | <Loading type='area' /> |
| | | </div>) |
| | | : ( |
| | |
| | | </> |
| | | ) |
| | | )} |
| | | {!isCallBatchAPI && isWorkflow && ( |
| | | (isResponding && !workflowProcessData) |
| | | ? ( |
| | | <div className='flex h-full w-full items-center justify-center'> |
| | | <Loading type='area' /> |
| | | </div> |
| | | ) |
| | | : !workflowProcessData |
| | | ? <NoData /> |
| | | : renderTextGenerationRes() |
| | | { |
| | | !isCallBatchAPI && isWorkflow && ( |
| | | (isResponding && !workflowProcessData) |
| | | ? ( |
| | | <div className='flex h-full w-full justify-center items-center'> |
| | | <Loading type='area' /> |
| | | </div> |
| | | ) |
| | | : !workflowProcessData |
| | | ? <NoData /> |
| | | : renderTextGenerationRes() |
| | | ) |
| | | } |
| | | {isCallBatchAPI && ( |
| | | <div className='mt-2'> |
| | | {renderTextGenerationRes()} |
| | | </div> |
| | | )} |
| | | {isCallBatchAPI && renderTextGenerationRes()} |
| | | </> |
| | | </div> |
| | | ) |
| | | } |
| | | export default React.memo(Result) |