fix: chat log

pull/12560/head
zxhlyh 1 year ago
parent 05d273d643
commit 4b01ef2b48

@ -1,5 +1,4 @@
import { import {
useCallback,
useEffect, useEffect,
useMemo, useMemo,
useState, useState,
@ -15,9 +14,8 @@ import TracingPanel from '@/app/components/workflow/run/tracing-panel'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import { CheckCircle } from '@/app/components/base/icons/src/vender/solid/general' import { CheckCircle } from '@/app/components/base/icons/src/vender/solid/general'
import { WorkflowRunningStatus } from '@/app/components/workflow/types' import { WorkflowRunningStatus } from '@/app/components/workflow/types'
import { useStore as useAppStore } from '@/app/components/app/store'
interface WorkflowProcessProps { type WorkflowProcessProps = {
data: WorkflowProcess data: WorkflowProcess
item?: ChatItem item?: ChatItem
expand?: boolean expand?: boolean
@ -26,7 +24,6 @@ interface WorkflowProcessProps {
} }
const WorkflowProcessItem = ({ const WorkflowProcessItem = ({
data, data,
item,
expand = false, expand = false,
hideInfo = false, hideInfo = false,
hideProcessDetail = false, hideProcessDetail = false,
@ -54,22 +51,6 @@ const WorkflowProcessItem = ({
setCollapse(!expand) setCollapse(!expand)
}, [expand]) }, [expand])
const setCurrentLogItem = useAppStore(s => s.setCurrentLogItem)
const setShowMessageLogModal = useAppStore(s => s.setShowMessageLogModal)
const setCurrentLogModalActiveTab = useAppStore(s => s.setCurrentLogModalActiveTab)
const showIterationDetail = useCallback(() => {
setCurrentLogItem(item)
setCurrentLogModalActiveTab('TRACING')
setShowMessageLogModal(true)
}, [item, setCurrentLogItem, setCurrentLogModalActiveTab, setShowMessageLogModal])
const showRetryDetail = useCallback(() => {
setCurrentLogItem(item)
setCurrentLogModalActiveTab('TRACING')
setShowMessageLogModal(true)
}, [item, setCurrentLogItem, setCurrentLogModalActiveTab, setShowMessageLogModal])
return ( return (
<div <div
className={cn( className={cn(
@ -110,8 +91,6 @@ const WorkflowProcessItem = ({
{ {
<TracingPanel <TracingPanel
list={data.tracing} list={data.tracing}
onShowIterationDetail={showIterationDetail}
onShowRetryDetail={showRetryDetail}
hideNodeInfo={hideInfo} hideNodeInfo={hideInfo}
hideNodeProcessDetail={hideProcessDetail} hideNodeProcessDetail={hideProcessDetail}
/> />

@ -12,6 +12,7 @@ import { useInstallPackageFromMarketPlace, useUpdatePackageFromMarketPlace } fro
import checkTaskStatus from '../../base/check-task-status' import checkTaskStatus from '../../base/check-task-status'
import useCheckInstalled from '@/app/components/plugins/install-plugin/hooks/use-check-installed' import useCheckInstalled from '@/app/components/plugins/install-plugin/hooks/use-check-installed'
import Version from '../../base/version' import Version from '../../base/version'
import { usePluginTaskList } from '@/service/use-plugins'
const i18nPrefix = 'plugin.installModal' const i18nPrefix = 'plugin.installModal'
@ -50,6 +51,7 @@ const Installed: FC<Props> = ({
check, check,
stop, stop,
} = checkTaskStatus() } = checkTaskStatus()
const { handleRefetch } = usePluginTaskList()
useEffect(() => { useEffect(() => {
if (hasInstalled && uniqueIdentifier === installedInfoPayload.uniqueIdentifier) if (hasInstalled && uniqueIdentifier === installedInfoPayload.uniqueIdentifier)
@ -93,6 +95,9 @@ const Installed: FC<Props> = ({
onInstalled() onInstalled()
return return
} }
handleRefetch()
const { status, error } = await check({ const { status, error } = await check({
taskId, taskId,
pluginUniqueIdentifier: uniqueIdentifier, pluginUniqueIdentifier: uniqueIdentifier,

@ -28,7 +28,7 @@ import {
import { useStore as useAppStore } from '@/app/components/app/store' import { useStore as useAppStore } from '@/app/components/app/store'
import { getLastAnswer } from '@/app/components/base/chat/utils' import { getLastAnswer } from '@/app/components/base/chat/utils'
interface ChatWrapperProps { type ChatWrapperProps = {
showConversationVariableModal: boolean showConversationVariableModal: boolean
onConversationModalHide: () => void onConversationModalHide: () => void
showInputsFieldsPanel: boolean showInputsFieldsPanel: boolean

@ -27,10 +27,9 @@ import {
getProcessedFilesFromResponse, getProcessedFilesFromResponse,
} from '@/app/components/base/file-uploader/utils' } from '@/app/components/base/file-uploader/utils'
import type { FileEntity } from '@/app/components/base/file-uploader/types' import type { FileEntity } from '@/app/components/base/file-uploader/types'
import type { NodeTracing } from '@/types/workflow'
type GetAbortController = (abortController: AbortController) => void type GetAbortController = (abortController: AbortController) => void
interface SendCallback { type SendCallback = {
onGetSuggestedQuestions?: (responseItemId: string, getAbortController: GetAbortController) => Promise<any> onGetSuggestedQuestions?: (responseItemId: string, getAbortController: GetAbortController) => Promise<any>
} }
export const useChat = ( export const useChat = (
@ -276,6 +275,7 @@ export const useChat = (
) )
setSuggestQuestions(data) setSuggestQuestions(data)
} }
// eslint-disable-next-line unused-imports/no-unused-vars
catch (error) { catch (error) {
setSuggestQuestions([]) setSuggestQuestions([])
} }
@ -331,8 +331,7 @@ export const useChat = (
responseItem.workflowProcess!.tracing!.push({ responseItem.workflowProcess!.tracing!.push({
...data, ...data,
status: NodeRunningStatus.Running, status: NodeRunningStatus.Running,
details: [], })
} as any)
handleUpdateChatList(produce(chatListRef.current, (draft) => { handleUpdateChatList(produce(chatListRef.current, (draft) => {
const currentIndex = draft.findIndex(item => item.id === responseItem.id) const currentIndex = draft.findIndex(item => item.id === responseItem.id)
draft[currentIndex] = { draft[currentIndex] = {
@ -341,30 +340,21 @@ export const useChat = (
} }
})) }))
}, },
onIterationNext: ({ data }) => {
const tracing = responseItem.workflowProcess!.tracing!
const iterations = 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))!
iterations.details!.push([])
handleUpdateChatList(produce(chatListRef.current, (draft) => {
const currentIndex = draft.length - 1
draft[currentIndex] = responseItem
}))
},
onIterationFinish: ({ data }) => { onIterationFinish: ({ data }) => {
const tracing = responseItem.workflowProcess!.tracing! const currentTracingIndex = responseItem.workflowProcess!.tracing!.findIndex(item => item.id === data.id)
const iterationsIndex = tracing.findIndex(item => item.node_id === data.node_id if (currentTracingIndex > -1) {
&& (item.execution_metadata?.parallel_id === data.execution_metadata?.parallel_id || item.parallel_id === data.execution_metadata?.parallel_id))! responseItem.workflowProcess!.tracing[currentTracingIndex] = {
tracing[iterationsIndex] = { ...responseItem.workflowProcess!.tracing[currentTracingIndex],
...tracing[iterationsIndex], ...data,
...data, }
status: NodeRunningStatus.Succeeded, handleUpdateChatList(produce(chatListRef.current, (draft) => {
} as any const currentIndex = draft.findIndex(item => item.id === responseItem.id)
handleUpdateChatList(produce(chatListRef.current, (draft) => { draft[currentIndex] = {
const currentIndex = draft.length - 1 ...draft[currentIndex],
draft[currentIndex] = responseItem ...responseItem,
})) }
}))
}
}, },
onNodeStarted: ({ data }) => { onNodeStarted: ({ data }) => {
if (data.iteration_id) if (data.iteration_id)
@ -386,16 +376,7 @@ export const useChat = (
if (data.iteration_id) if (data.iteration_id)
return return
const currentIndex = responseItem.workflowProcess!.tracing!.findIndex((item) => { responseItem.workflowProcess!.tracing!.push(data)
if (!item.execution_metadata?.parallel_id)
return item.node_id === data.node_id
return item.node_id === data.node_id && (item.execution_metadata?.parallel_id === data.execution_metadata?.parallel_id || item.parallel_id === data.execution_metadata?.parallel_id)
})
if (responseItem.workflowProcess!.tracing[currentIndex].retryDetail)
responseItem.workflowProcess!.tracing[currentIndex].retryDetail?.push(data as NodeTracing)
else
responseItem.workflowProcess!.tracing[currentIndex].retryDetail = [data as NodeTracing]
handleUpdateChatList(produce(chatListRef.current, (draft) => { handleUpdateChatList(produce(chatListRef.current, (draft) => {
const currentIndex = draft.findIndex(item => item.id === responseItem.id) const currentIndex = draft.findIndex(item => item.id === responseItem.id)
draft[currentIndex] = { draft[currentIndex] = {
@ -408,27 +389,20 @@ export const useChat = (
if (data.iteration_id) if (data.iteration_id)
return return
const currentIndex = responseItem.workflowProcess!.tracing!.findIndex((item) => { const currentTracingIndex = responseItem.workflowProcess!.tracing!.findIndex(item => item.id === data.id)
if (!item.execution_metadata?.parallel_id) if (currentTracingIndex > -1) {
return item.node_id === data.node_id responseItem.workflowProcess!.tracing[currentTracingIndex] = {
return item.node_id === data.node_id && (item.execution_metadata?.parallel_id === data.execution_metadata?.parallel_id || item.parallel_id === data.execution_metadata?.parallel_id) ...responseItem.workflowProcess!.tracing[currentTracingIndex],
}) ...data,
responseItem.workflowProcess!.tracing[currentIndex] = {
...(responseItem.workflowProcess!.tracing[currentIndex]?.extras
? { extras: responseItem.workflowProcess!.tracing[currentIndex].extras }
: {}),
...(responseItem.workflowProcess!.tracing[currentIndex]?.retryDetail
? { retryDetail: responseItem.workflowProcess!.tracing[currentIndex].retryDetail }
: {}),
...data,
} as any
handleUpdateChatList(produce(chatListRef.current, (draft) => {
const currentIndex = draft.findIndex(item => item.id === responseItem.id)
draft[currentIndex] = {
...draft[currentIndex],
...responseItem,
} }
})) handleUpdateChatList(produce(chatListRef.current, (draft) => {
const currentIndex = draft.findIndex(item => item.id === responseItem.id)
draft[currentIndex] = {
...draft[currentIndex],
...responseItem,
}
}))
}
}, },
}, },
) )

@ -22,7 +22,7 @@ import Tooltip from '@/app/components/base/tooltip'
import ActionButton, { ActionButtonState } from '@/app/components/base/action-button' import ActionButton, { ActionButtonState } from '@/app/components/base/action-button'
import { useStore } from '@/app/components/workflow/store' import { useStore } from '@/app/components/workflow/store'
export interface ChatWrapperRefType { export type ChatWrapperRefType = {
handleRestart: () => void handleRestart: () => void
} }
const DebugAndPreview = () => { const DebugAndPreview = () => {

@ -24,7 +24,6 @@ import Toast from '../../base/toast'
import InputsPanel from './inputs-panel' import InputsPanel from './inputs-panel'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import Loading from '@/app/components/base/loading' import Loading from '@/app/components/base/loading'
import formatNodeList from '@/app/components/workflow/run/utils/format-log'
const WorkflowPreview = () => { const WorkflowPreview = () => {
const { t } = useTranslation() const { t } = useTranslation()
@ -161,7 +160,7 @@ const WorkflowPreview = () => {
{currentTab === 'TRACING' && ( {currentTab === 'TRACING' && (
<TracingPanel <TracingPanel
className='bg-background-section-burn' className='bg-background-section-burn'
list={formatNodeList(workflowRunningData?.tracing || [], t)} list={workflowRunningData?.tracing || []}
/> />
)} )}
{currentTab === 'TRACING' && !workflowRunningData?.tracing?.length && ( {currentTab === 'TRACING' && !workflowRunningData?.tracing?.length && (

@ -13,7 +13,6 @@ import { fetchRunDetail, fetchTracingList } from '@/service/log'
import type { NodeTracing } from '@/types/workflow' import type { NodeTracing } from '@/types/workflow'
import type { WorkflowRunDetailResponse } from '@/models/log' import type { WorkflowRunDetailResponse } from '@/models/log'
import { useStore as useAppStore } from '@/app/components/app/store' import { useStore as useAppStore } from '@/app/components/app/store'
import formatNodeList from './utils/format-log'
export type RunProps = { export type RunProps = {
hideResult?: boolean hideResult?: boolean
activeTab?: 'RESULT' | 'DETAIL' | 'TRACING' activeTab?: 'RESULT' | 'DETAIL' | 'TRACING'
@ -61,7 +60,7 @@ const RunPanel: FC<RunProps> = ({ hideResult, activeTab = 'RESULT', runID, getRe
const { data: nodeList } = await fetchTracingList({ const { data: nodeList } = await fetchTracingList({
url: `/apps/${appID}/workflow-runs/${runID}/node-executions`, url: `/apps/${appID}/workflow-runs/${runID}/node-executions`,
}) })
setList(formatNodeList(nodeList, t)) setList(nodeList)
} }
catch (err) { catch (err) {
notify({ notify({

@ -11,10 +11,12 @@ import {
RiArrowDownSLine, RiArrowDownSLine,
RiMenu4Line, RiMenu4Line,
} from '@remixicon/react' } from '@remixicon/react'
import { useTranslation } from 'react-i18next'
import { useLogs } from './hooks' import { useLogs } from './hooks'
import NodePanel from './node' import NodePanel from './node'
import SpecialResultPanel from './special-result-panel' import SpecialResultPanel from './special-result-panel'
import type { NodeTracing } from '@/types/workflow' import type { NodeTracing } from '@/types/workflow'
import formatNodeList from '@/app/components/workflow/run/utils/format-log'
type TracingPanelProps = { type TracingPanelProps = {
list: NodeTracing[] list: NodeTracing[]
@ -29,7 +31,8 @@ const TracingPanel: FC<TracingPanelProps> = ({
hideNodeInfo = false, hideNodeInfo = false,
hideNodeProcessDetail = false, hideNodeProcessDetail = false,
}) => { }) => {
const treeNodes = list const { t } = useTranslation()
const treeNodes = formatNodeList(list, t)
const [collapsedNodes, setCollapsedNodes] = useState<Set<string>>(new Set()) const [collapsedNodes, setCollapsedNodes] = useState<Set<string>>(new Set())
const [hoveredParallel, setHoveredParallel] = useState<string | null>(null) const [hoveredParallel, setHoveredParallel] = useState<string | null>(null)

@ -23,6 +23,7 @@ export type NodeTracing = {
index: number index: number
predecessor_node_id: string predecessor_node_id: string
node_id: string node_id: string
iteration_id?: string
node_type: BlockEnum node_type: BlockEnum
title: string title: string
inputs: any inputs: any

Loading…
Cancel
Save