| | |
| | | getProcessedFiles, |
| | | getProcessedFilesFromResponse, |
| | | } from '@/app/components/base/file-uploader/utils' |
| | | import { noop } from 'lodash-es' |
| | | |
| | | type GetAbortController = (abortController: AbortController) => void |
| | | type SendCallback = { |
| | |
| | | }, |
| | | prevChatTree?: ChatItemInTree[], |
| | | stopChat?: (taskId: string) => void, |
| | | clearChatList?: boolean, |
| | | clearChatListCallback?: (state: boolean) => void, |
| | | ) => { |
| | | const { t } = useTranslation() |
| | | const { formatTime } = useTimestamp() |
| | |
| | | } |
| | | else { |
| | | ret.unshift({ |
| | | id: 'opening-statement', |
| | | id: `${Date.now()}`, |
| | | content: getIntroduction(config.opening_statement), |
| | | isAnswer: true, |
| | | isOpeningStatement: true, |
| | |
| | | suggestedQuestionsAbortControllerRef.current.abort() |
| | | }, [stopChat, handleResponding]) |
| | | |
| | | const handleRestart = useCallback((cb?: any) => { |
| | | const handleRestart = useCallback(() => { |
| | | conversationId.current = '' |
| | | taskIdRef.current = '' |
| | | handleStop() |
| | | setChatTree([]) |
| | | setSuggestQuestions([]) |
| | | cb?.() |
| | | }, [handleStop]) |
| | | |
| | | const updateCurrentQAOnTree = useCallback(({ |
| | |
| | | else |
| | | ttsUrl = `/apps/${params.appId}/text-to-audio` |
| | | } |
| | | const player = AudioPlayerManager.getInstance().getAudioPlayer(ttsUrl, ttsIsPublic, uuidV4(), 'none', 'none', noop) |
| | | const player = AudioPlayerManager.getInstance().getAudioPlayer(ttsUrl, ttsIsPublic, uuidV4(), 'none', 'none', (_: any): any => {}) |
| | | ssePost( |
| | | url, |
| | | { |
| | |
| | | ) |
| | | setSuggestQuestions(data) |
| | | } |
| | | // eslint-disable-next-line unused-imports/no-unused-vars |
| | | catch (e) { |
| | | setSuggestQuestions([]) |
| | | } |
| | |
| | | const response = responseItem as any |
| | | if (thought.message_id && !hasSetResponseId) |
| | | response.id = thought.message_id |
| | | if (thought.conversation_id) |
| | | response.conversationId = thought.conversation_id |
| | | |
| | | if (response.agent_thoughts.length === 0) { |
| | | response.agent_thoughts.push(thought) |
| | |
| | | responseItem.workflowProcess!.tracing!.push({ |
| | | ...iterationStartedData, |
| | | status: WorkflowRunningStatus.Running, |
| | | }) |
| | | } as any) |
| | | updateCurrentQAOnTree({ |
| | | placeholderQuestionId, |
| | | questionItem, |
| | |
| | | ...tracing[iterationIndex], |
| | | ...iterationFinishedData, |
| | | status: WorkflowRunningStatus.Succeeded, |
| | | } |
| | | } as any |
| | | |
| | | updateCurrentQAOnTree({ |
| | | placeholderQuestionId, |
| | |
| | | if (nodeStartedData.iteration_id) |
| | | return |
| | | |
| | | if (data.loop_id) |
| | | return |
| | | |
| | | responseItem.workflowProcess!.tracing!.push({ |
| | | ...nodeStartedData, |
| | | status: WorkflowRunningStatus.Running, |
| | | }) |
| | | } as any) |
| | | updateCurrentQAOnTree({ |
| | | placeholderQuestionId, |
| | | questionItem, |
| | |
| | | if (nodeFinishedData.iteration_id) |
| | | return |
| | | |
| | | if (data.loop_id) |
| | | return |
| | | |
| | | const currentIndex = responseItem.workflowProcess!.tracing!.findIndex((item) => { |
| | | if (!item.execution_metadata?.parallel_id) |
| | | return item.node_id === nodeFinishedData.node_id |
| | | |
| | | return item.node_id === nodeFinishedData.node_id && (item.execution_metadata?.parallel_id === nodeFinishedData.execution_metadata?.parallel_id) |
| | | return item.node_id === nodeFinishedData.node_id && (item.execution_metadata?.parallel_id === nodeFinishedData.execution_metadata.parallel_id) |
| | | }) |
| | | responseItem.workflowProcess!.tracing[currentIndex] = nodeFinishedData as any |
| | | |
| | |
| | | }, |
| | | onTTSEnd: (messageId: string, audio: string) => { |
| | | player.playAudioWithAudio(audio, false) |
| | | }, |
| | | onLoopStart: ({ data: loopStartedData }) => { |
| | | responseItem.workflowProcess!.tracing!.push({ |
| | | ...loopStartedData, |
| | | status: WorkflowRunningStatus.Running, |
| | | }) |
| | | updateCurrentQAOnTree({ |
| | | placeholderQuestionId, |
| | | questionItem, |
| | | responseItem, |
| | | parentId: data.parent_message_id, |
| | | }) |
| | | }, |
| | | onLoopFinish: ({ data: loopFinishedData }) => { |
| | | const tracing = responseItem.workflowProcess!.tracing! |
| | | const loopIndex = tracing.findIndex(item => item.node_id === loopFinishedData.node_id |
| | | && (item.execution_metadata?.parallel_id === loopFinishedData.execution_metadata?.parallel_id || item.parallel_id === loopFinishedData.execution_metadata?.parallel_id))! |
| | | tracing[loopIndex] = { |
| | | ...tracing[loopIndex], |
| | | ...loopFinishedData, |
| | | status: WorkflowRunningStatus.Succeeded, |
| | | } |
| | | |
| | | updateCurrentQAOnTree({ |
| | | placeholderQuestionId, |
| | | questionItem, |
| | | responseItem, |
| | | parentId: data.parent_message_id, |
| | | }) |
| | | }, |
| | | }) |
| | | return true |
| | |
| | | } as Annotation, |
| | | }) |
| | | }, [chatList, updateChatTreeNode]) |
| | | |
| | | useEffect(() => { |
| | | if (clearChatList) |
| | | handleRestart(() => clearChatListCallback?.(false)) |
| | | }, [clearChatList, clearChatListCallback, handleRestart]) |
| | | |
| | | return { |
| | | chatList, |