This commit is contained in:
JzoNg
2024-03-09 12:48:14 +08:00
parent bc90fc885f
commit 90ee7fe201
6 changed files with 103 additions and 35 deletions

View File

@ -5,14 +5,13 @@ import { useTranslation } from 'react-i18next'
import cn from 'classnames'
import Result from './result'
import Tracing from './tracing'
// import type { App } from '@/types/app'
type RunProps = {
activeTab: 'RESULT' | 'TRACING'
activeTab?: 'RESULT' | 'TRACING'
runID: string
}
const RunPanel: FC<RunProps> = ({ activeTab, runID }) => {
const RunPanel: FC<RunProps> = ({ activeTab = 'RESULT', runID }) => {
const { t } = useTranslation()
const [currentTab, setCurrentTab] = useState<string>(activeTab)

View File

@ -3,24 +3,15 @@ import { useTranslation } from 'react-i18next'
import type { FC } from 'react'
import cn from 'classnames'
import BlockIcon from '../block-icon'
import type { BlockEnum } from '../types'
import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor'
import { CodeLanguage } from '@/app/components/workflow/nodes/code/types'
import { AlertCircle, AlertTriangle } from '@/app/components/base/icons/src/vender/line/alertsAndFeedback'
import { CheckCircle, Loading02 } from '@/app/components/base/icons/src/vender/line/general'
import { ChevronRight } from '@/app/components/base/icons/src/vender/line/arrows'
export type NodeInfo = {
type: BlockEnum
title: string
time: number
tokens: number
status: string
error?: string
}
import type { NodeTracing } from '@/types/workflow'
type Props = {
nodeInfo: NodeInfo
nodeInfo: NodeTracing
collapsed: boolean
collapseHandle: () => void
}
@ -60,9 +51,9 @@ const NodePanel: FC<Props> = ({ nodeInfo, collapsed, collapseHandle }) => {
!collapsed && 'rotate-90',
)}
/>
<BlockIcon className='shrink-0 mr-2' type={nodeInfo.type} />
<BlockIcon className='shrink-0 mr-2' type={nodeInfo.node_type} />
<div className='grow text-gray-700 text-[13px] leading-[16px] font-semibold truncate' title={nodeInfo.title}>{nodeInfo.title}</div>
<div className='shrink-0 text-gray-500 text-xs leading-[18px]'>{`${getTime(nodeInfo.time)} · ${getTokenCount(nodeInfo.tokens)} tokens`}</div>
<div className='shrink-0 text-gray-500 text-xs leading-[18px]'>{`${getTime(nodeInfo.elapsed_time)} · ${getTokenCount(nodeInfo.execution_metadata.total_tokens)} tokens`}</div>
{nodeInfo.status === 'succeeded' && (
<CheckCircle className='shrink-0 ml-2 w-3.5 h-3.5 text-[#12B76A]' />
)}

View File

@ -1,35 +1,76 @@
'use client'
import type { FC } from 'react'
import React, { useState } from 'react'
// import { useTranslation } from 'react-i18next'
// import cn from 'classnames'
import { BlockEnum } from '../types'
import React, { useCallback, useEffect, useState } from 'react'
import { useContext } from 'use-context-selector'
import produce from 'immer'
import NodePanel from './node'
import Loading from '@/app/components/base/loading'
import { fetchTracingList } from '@/service/log'
import { useStore as useAppStore } from '@/app/components/app/store'
import type { NodeTracing } from '@/types/workflow'
import { ToastContext } from '@/app/components/base/toast'
type TracingProps = {
runID: string
}
const nodeInfoFake = {
type: BlockEnum.Start,
title: 'START',
time: 67.349,
tokens: 2708,
status: 'failed',
error: 'lvlvlvlv',
}
const Tracing: FC<TracingProps> = ({ runID }) => {
// const { t } = useTranslation()
const [nodeCollapsed, setCurrentTab] = useState<boolean>(false)
const { notify } = useContext(ToastContext)
const { appDetail } = useAppStore()
const [loading, setLoading] = useState<boolean>(true)
const [list, setList] = useState<NodeTracing[]>([])
const [collapseState, setCollapseState] = useState<boolean[]>([])
const collapseStateChange = () => {
setCurrentTab(!nodeCollapsed)
const getTracingList = useCallback(async (appID: string, runID: string) => {
setLoading(true)
try {
const { data: nodeList } = await fetchTracingList({
url: `/apps/${appID}/workflow-runs/${runID}/node-executions`,
})
const collapseState = nodeList.map(node => node.status === 'succeeded')
setList(nodeList)
setCollapseState(collapseState)
setLoading(false)
}
catch (err) {
notify({
type: 'error',
message: `${err}`,
})
setLoading(false)
}
}, [notify])
useEffect(() => {
if (appDetail && runID)
getTracingList(appDetail.id, runID)
}, [appDetail, getTracingList, runID])
const collapseStateChange = (index: number) => {
const newCollapseState = produce(collapseState, (draft: boolean[]) => {
draft[index] = !draft[index]
})
setCollapseState(newCollapseState)
}
if (loading) {
return (
<div className='flex h-full items-center justify-center bg-white'>
<Loading />
</div>
)
}
return (
<div className='bg-gray-50 py-2'>
<NodePanel nodeInfo={nodeInfoFake} collapsed={nodeCollapsed} collapseHandle={collapseStateChange} />
{list.map((node, index) => (
<NodePanel
key={node.id}
nodeInfo={node}
collapsed={collapseState[index]}
collapseHandle={() => collapseStateChange(index)}
/>
))}
</div>
)
}