dify/web/app/components/workflow/run/hooks.ts

59 lines
1.9 KiB
TypeScript
Raw Normal View History

2024-12-25 16:14:51 +08:00
import {
useCallback,
useState,
} from 'react'
import { useBoolean } from 'ahooks'
2024-12-26 15:44:40 +08:00
import type {
AgentLogItemWithChildren,
IterationDurationMap,
NodeTracing,
} from '@/types/workflow'
2024-12-25 16:14:51 +08:00
export const useLogs = () => {
const [showRetryDetail, {
setTrue: setShowRetryDetailTrue,
setFalse: setShowRetryDetailFalse,
}] = useBoolean(false)
const [retryResultList, setRetryResultList] = useState<NodeTracing[]>([])
const handleShowRetryResultList = useCallback((detail: NodeTracing[]) => {
setShowRetryDetailTrue()
setRetryResultList(detail)
}, [setShowRetryDetailTrue, setRetryResultList])
const [showIteratingDetail, {
setTrue: setShowIteratingDetailTrue,
setFalse: setShowIteratingDetailFalse,
}] = useBoolean(false)
const [iterationResultList, setIterationResultList] = useState<NodeTracing[][]>([])
const [iterationResultDurationMap, setIterationResultDurationMap] = useState<IterationDurationMap>({})
const handleShowIterationResultList = useCallback((detail: NodeTracing[][], iterDurationMap: IterationDurationMap) => {
setShowIteratingDetailTrue()
setIterationResultList(detail)
setIterationResultDurationMap(iterDurationMap)
}, [setShowIteratingDetailTrue, setIterationResultList, setIterationResultDurationMap])
2024-12-26 15:44:40 +08:00
const [agentResultList, setAgentResultList] = useState<AgentLogItemWithChildren[]>([])
2024-12-26 10:16:12 +08:00
2024-12-25 16:14:51 +08:00
return {
2024-12-26 15:44:40 +08:00
showSpecialResultPanel: showRetryDetail || showIteratingDetail || !!agentResultList.length,
2024-12-25 16:14:51 +08:00
showRetryDetail,
setShowRetryDetailTrue,
setShowRetryDetailFalse,
retryResultList,
setRetryResultList,
handleShowRetryResultList,
2024-12-26 10:16:12 +08:00
2024-12-25 16:14:51 +08:00
showIteratingDetail,
setShowIteratingDetailTrue,
setShowIteratingDetailFalse,
iterationResultList,
setIterationResultList,
iterationResultDurationMap,
setIterationResultDurationMap,
handleShowIterationResultList,
2024-12-26 10:16:12 +08:00
2024-12-26 15:44:40 +08:00
agentResultList,
setAgentResultList,
2024-12-25 16:14:51 +08:00
}
}