+10









-LAN-
GitHub
twwu
crazywoola
jyong
Wu Tianwei
QuantumGhost
lyzno1
quicksand
Jyong
lyzno1
zxhlyh
Yongtao Huang
autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Joel
Copilot
nite-knite
Hanqing Zhao
gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Harry
85cda47c70
Signed-off-by: -LAN- <[email protected]> Co-authored-by: twwu <[email protected]> Co-authored-by: crazywoola <[email protected]> Co-authored-by: jyong <[email protected]> Co-authored-by: Wu Tianwei <[email protected]> Co-authored-by: QuantumGhost <[email protected]> Co-authored-by: lyzno1 <[email protected]> Co-authored-by: quicksand <[email protected]> Co-authored-by: Jyong <[email protected]> Co-authored-by: lyzno1 <[email protected]> Co-authored-by: zxhlyh <[email protected]> Co-authored-by: Yongtao Huang <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Joel <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: nite-knite <[email protected]> Co-authored-by: Hanqing Zhao <[email protected]> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Harry <[email protected]>
116 lines
4.2 KiB
TypeScript
116 lines
4.2 KiB
TypeScript
import {
|
|
useCallback,
|
|
useRef,
|
|
useState,
|
|
} from 'react'
|
|
import { useBoolean } from 'ahooks'
|
|
import type {
|
|
AgentLogItemWithChildren,
|
|
IterationDurationMap,
|
|
LoopDurationMap,
|
|
LoopVariableMap,
|
|
NodeTracing,
|
|
} from '@/types/workflow'
|
|
|
|
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])
|
|
|
|
const [showLoopingDetail, {
|
|
setTrue: setShowLoopingDetailTrue,
|
|
setFalse: setShowLoopingDetailFalse,
|
|
}] = useBoolean(false)
|
|
const [loopResultList, setLoopResultList] = useState<NodeTracing[][]>([])
|
|
const [loopResultDurationMap, setLoopResultDurationMap] = useState<LoopDurationMap>({})
|
|
const [loopResultVariableMap, setLoopResultVariableMap] = useState<Record<string, any>>({})
|
|
const handleShowLoopResultList = useCallback((detail: NodeTracing[][], loopDurationMap: LoopDurationMap, loopVariableMap: LoopVariableMap) => {
|
|
setShowLoopingDetailTrue()
|
|
setLoopResultList(detail)
|
|
setLoopResultDurationMap(loopDurationMap)
|
|
setLoopResultVariableMap(loopVariableMap)
|
|
}, [setShowLoopingDetailTrue, setLoopResultList, setLoopResultDurationMap])
|
|
|
|
const [agentOrToolLogItemStack, setAgentOrToolLogItemStack] = useState<AgentLogItemWithChildren[]>([])
|
|
const agentOrToolLogItemStackRef = useRef(agentOrToolLogItemStack)
|
|
const [agentOrToolLogListMap, setAgentOrToolLogListMap] = useState<Record<string, AgentLogItemWithChildren[]>>({})
|
|
const agentOrToolLogListMapRef = useRef(agentOrToolLogListMap)
|
|
const handleShowAgentOrToolLog = useCallback((detail?: AgentLogItemWithChildren) => {
|
|
if (!detail) {
|
|
setAgentOrToolLogItemStack([])
|
|
agentOrToolLogItemStackRef.current = []
|
|
return
|
|
}
|
|
const { message_id: id, children } = detail
|
|
let currentAgentOrToolLogItemStack = agentOrToolLogItemStackRef.current.slice()
|
|
const index = currentAgentOrToolLogItemStack.findIndex(logItem => logItem.message_id === id)
|
|
|
|
if (index > -1)
|
|
currentAgentOrToolLogItemStack = currentAgentOrToolLogItemStack.slice(0, index + 1)
|
|
else
|
|
currentAgentOrToolLogItemStack = [...currentAgentOrToolLogItemStack.slice(), detail]
|
|
|
|
setAgentOrToolLogItemStack(currentAgentOrToolLogItemStack)
|
|
agentOrToolLogItemStackRef.current = currentAgentOrToolLogItemStack
|
|
|
|
if (children) {
|
|
setAgentOrToolLogListMap({
|
|
...agentOrToolLogListMapRef.current,
|
|
[id]: children,
|
|
})
|
|
}
|
|
}, [setAgentOrToolLogItemStack, setAgentOrToolLogListMap])
|
|
|
|
return {
|
|
showSpecialResultPanel: showRetryDetail || showIteratingDetail || showLoopingDetail || !!agentOrToolLogItemStack.length,
|
|
showRetryDetail,
|
|
setShowRetryDetailTrue,
|
|
setShowRetryDetailFalse,
|
|
retryResultList,
|
|
setRetryResultList,
|
|
handleShowRetryResultList,
|
|
|
|
showIteratingDetail,
|
|
setShowIteratingDetailTrue,
|
|
setShowIteratingDetailFalse,
|
|
iterationResultList,
|
|
setIterationResultList,
|
|
iterationResultDurationMap,
|
|
setIterationResultDurationMap,
|
|
handleShowIterationResultList,
|
|
|
|
showLoopingDetail,
|
|
setShowLoopingDetailTrue,
|
|
setShowLoopingDetailFalse,
|
|
loopResultList,
|
|
setLoopResultList,
|
|
loopResultDurationMap,
|
|
setLoopResultDurationMap,
|
|
loopResultVariableMap,
|
|
setLoopResultVariableMap,
|
|
handleShowLoopResultList,
|
|
|
|
agentOrToolLogItemStack,
|
|
agentOrToolLogListMap,
|
|
handleShowAgentOrToolLog,
|
|
}
|
|
}
|