fix: agent log structure
This commit is contained in:
parent
b5ad9a58f7
commit
84febd5e94
@ -12,9 +12,11 @@ import { CodeLanguage } from '@/app/components/workflow/nodes/code/types'
|
|||||||
|
|
||||||
type AgentLogItemProps = {
|
type AgentLogItemProps = {
|
||||||
item: AgentLogItemWithChildren
|
item: AgentLogItemWithChildren
|
||||||
|
onShowAgentOrToolLog: (detail: AgentLogItemWithChildren) => void
|
||||||
}
|
}
|
||||||
const AgentLogItem = ({
|
const AgentLogItem = ({
|
||||||
item,
|
item,
|
||||||
|
onShowAgentOrToolLog,
|
||||||
}: AgentLogItemProps) => {
|
}: AgentLogItemProps) => {
|
||||||
const {
|
const {
|
||||||
label,
|
label,
|
||||||
@ -51,7 +53,7 @@ const AgentLogItem = ({
|
|||||||
<Button
|
<Button
|
||||||
className='flex items-center justify-between mb-1 w-full'
|
className='flex items-center justify-between mb-1 w-full'
|
||||||
variant='tertiary'
|
variant='tertiary'
|
||||||
onClick={() => {}}
|
onClick={() => onShowAgentOrToolLog(item)}
|
||||||
>
|
>
|
||||||
<div className='flex items-center'>
|
<div className='flex items-center'>
|
||||||
<RiListView className='mr-1 w-4 h-4 text-components-button-tertiary-text shrink-0' />
|
<RiListView className='mr-1 w-4 h-4 text-components-button-tertiary-text shrink-0' />
|
||||||
|
@ -6,11 +6,11 @@ import type {
|
|||||||
|
|
||||||
type AgentLogTriggerProps = {
|
type AgentLogTriggerProps = {
|
||||||
nodeInfo: NodeTracing
|
nodeInfo: NodeTracing
|
||||||
onShowAgentResultList: (agentLogs: AgentLogItemWithChildren[]) => void
|
onShowAgentOrToolLog: (detail: AgentLogItemWithChildren) => void
|
||||||
}
|
}
|
||||||
const AgentLogTrigger = ({
|
const AgentLogTrigger = ({
|
||||||
nodeInfo,
|
nodeInfo,
|
||||||
onShowAgentResultList,
|
onShowAgentOrToolLog,
|
||||||
}: AgentLogTriggerProps) => {
|
}: AgentLogTriggerProps) => {
|
||||||
const { agentLog } = nodeInfo
|
const { agentLog } = nodeInfo
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ const AgentLogTrigger = ({
|
|||||||
<div className='grow mx-0.5 px-1 system-xs-medium text-text-secondary'></div>
|
<div className='grow mx-0.5 px-1 system-xs-medium text-text-secondary'></div>
|
||||||
<div
|
<div
|
||||||
className='shrink-0 flex items-center px-[1px] system-xs-regular-uppercase text-text-tertiary cursor-pointer'
|
className='shrink-0 flex items-center px-[1px] system-xs-regular-uppercase text-text-tertiary cursor-pointer'
|
||||||
onClick={() => onShowAgentResultList(agentLog || [])}
|
onClick={() => onShowAgentOrToolLog({ id: nodeInfo.id, children: agentLog || [] } as AgentLogItemWithChildren)}
|
||||||
>
|
>
|
||||||
Detail
|
Detail
|
||||||
<RiArrowRightLine className='ml-0.5 w-3.5 h-3.5' />
|
<RiArrowRightLine className='ml-0.5 w-3.5 h-3.5' />
|
||||||
|
@ -3,12 +3,18 @@ import AgentLogNav from './agent-log-nav'
|
|||||||
import type { AgentLogItemWithChildren } from '@/types/workflow'
|
import type { AgentLogItemWithChildren } from '@/types/workflow'
|
||||||
|
|
||||||
type AgentResultPanelProps = {
|
type AgentResultPanelProps = {
|
||||||
list: AgentLogItemWithChildren[]
|
agentOrToolLogIdStack: string[]
|
||||||
setAgentResultList: (list: AgentLogItemWithChildren[]) => void
|
agentOrToolLogListMap: Record<string, AgentLogItemWithChildren[]>
|
||||||
|
onShowAgentOrToolLog: (detail: AgentLogItemWithChildren) => void
|
||||||
}
|
}
|
||||||
const AgentResultPanel = ({
|
const AgentResultPanel = ({
|
||||||
list,
|
agentOrToolLogIdStack,
|
||||||
|
agentOrToolLogListMap,
|
||||||
|
onShowAgentOrToolLog,
|
||||||
}: AgentResultPanelProps) => {
|
}: AgentResultPanelProps) => {
|
||||||
|
const top = agentOrToolLogIdStack[agentOrToolLogIdStack.length - 1]
|
||||||
|
const list = agentOrToolLogListMap[top]
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='overflow-y-auto'>
|
<div className='overflow-y-auto'>
|
||||||
<AgentLogNav />
|
<AgentLogNav />
|
||||||
@ -19,6 +25,7 @@ const AgentResultPanel = ({
|
|||||||
<AgentLogItem
|
<AgentLogItem
|
||||||
key={item.id}
|
key={item.id}
|
||||||
item={item}
|
item={item}
|
||||||
|
onShowAgentOrToolLog={onShowAgentOrToolLog}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
useCallback,
|
useCallback,
|
||||||
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
import { useBoolean } from 'ahooks'
|
import { useBoolean } from 'ahooks'
|
||||||
@ -32,10 +33,33 @@ export const useLogs = () => {
|
|||||||
setIterationResultDurationMap(iterDurationMap)
|
setIterationResultDurationMap(iterDurationMap)
|
||||||
}, [setShowIteratingDetailTrue, setIterationResultList, setIterationResultDurationMap])
|
}, [setShowIteratingDetailTrue, setIterationResultList, setIterationResultDurationMap])
|
||||||
|
|
||||||
const [agentResultList, setAgentResultList] = useState<AgentLogItemWithChildren[]>([])
|
const [agentOrToolLogIdStack, setAgentOrToolLogIdStack] = useState<string[]>([])
|
||||||
|
const agentOrToolLogIdStackRef = useRef(agentOrToolLogIdStack)
|
||||||
|
const [agentOrToolLogListMap, setAgentOrToolLogListMap] = useState<Record<string, AgentLogItemWithChildren[]>>({})
|
||||||
|
const agentOrToolLogListMapRef = useRef(agentOrToolLogListMap)
|
||||||
|
const handleShowAgentOrToolLog = useCallback((detail: AgentLogItemWithChildren) => {
|
||||||
|
const { id, children } = detail
|
||||||
|
let currentAgentOrToolLogIdStack = agentOrToolLogIdStackRef.current.slice()
|
||||||
|
const index = currentAgentOrToolLogIdStack.findIndex(logId => logId === id)
|
||||||
|
|
||||||
|
if (index > -1)
|
||||||
|
currentAgentOrToolLogIdStack = currentAgentOrToolLogIdStack.slice(0, index + 1)
|
||||||
|
else
|
||||||
|
currentAgentOrToolLogIdStack = [...currentAgentOrToolLogIdStack.slice(), id]
|
||||||
|
|
||||||
|
setAgentOrToolLogIdStack(currentAgentOrToolLogIdStack)
|
||||||
|
agentOrToolLogIdStackRef.current = currentAgentOrToolLogIdStack
|
||||||
|
|
||||||
|
if (children) {
|
||||||
|
setAgentOrToolLogListMap({
|
||||||
|
...agentOrToolLogListMapRef.current,
|
||||||
|
[id]: children,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [setAgentOrToolLogIdStack, setAgentOrToolLogListMap])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
showSpecialResultPanel: showRetryDetail || showIteratingDetail || !!agentResultList.length,
|
showSpecialResultPanel: showRetryDetail || showIteratingDetail || !!agentOrToolLogIdStack.length,
|
||||||
showRetryDetail,
|
showRetryDetail,
|
||||||
setShowRetryDetailTrue,
|
setShowRetryDetailTrue,
|
||||||
setShowRetryDetailFalse,
|
setShowRetryDetailFalse,
|
||||||
@ -52,7 +76,8 @@ export const useLogs = () => {
|
|||||||
setIterationResultDurationMap,
|
setIterationResultDurationMap,
|
||||||
handleShowIterationResultList,
|
handleShowIterationResultList,
|
||||||
|
|
||||||
agentResultList,
|
agentOrToolLogIdStack,
|
||||||
setAgentResultList,
|
agentOrToolLogListMap,
|
||||||
|
handleShowAgentOrToolLog,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ type Props = {
|
|||||||
hideProcessDetail?: boolean
|
hideProcessDetail?: boolean
|
||||||
onShowIterationDetail?: (detail: NodeTracing[][], iterDurationMap: IterationDurationMap) => void
|
onShowIterationDetail?: (detail: NodeTracing[][], iterDurationMap: IterationDurationMap) => void
|
||||||
onShowRetryDetail?: (detail: NodeTracing[]) => void
|
onShowRetryDetail?: (detail: NodeTracing[]) => void
|
||||||
onShowAgentResultList?: (detail: AgentLogItemWithChildren[]) => void
|
onShowAgentOrToolLog?: (detail: AgentLogItemWithChildren) => void
|
||||||
notShowIterationNav?: boolean
|
notShowIterationNav?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ const NodePanel: FC<Props> = ({
|
|||||||
hideProcessDetail,
|
hideProcessDetail,
|
||||||
onShowIterationDetail,
|
onShowIterationDetail,
|
||||||
onShowRetryDetail,
|
onShowRetryDetail,
|
||||||
onShowAgentResultList,
|
onShowAgentOrToolLog,
|
||||||
notShowIterationNav,
|
notShowIterationNav,
|
||||||
}) => {
|
}) => {
|
||||||
const [collapseState, doSetCollapseState] = useState<boolean>(true)
|
const [collapseState, doSetCollapseState] = useState<boolean>(true)
|
||||||
@ -144,10 +144,10 @@ const NodePanel: FC<Props> = ({
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{
|
{
|
||||||
isAgentNode && onShowAgentResultList && (
|
isAgentNode && onShowAgentOrToolLog && (
|
||||||
<AgentLogTrigger
|
<AgentLogTrigger
|
||||||
nodeInfo={nodeInfo}
|
nodeInfo={nodeInfo}
|
||||||
onShowAgentResultList={onShowAgentResultList}
|
onShowAgentOrToolLog={onShowAgentOrToolLog}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,10 @@ import MetaData from './meta'
|
|||||||
import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor'
|
import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor'
|
||||||
import { CodeLanguage } from '@/app/components/workflow/nodes/code/types'
|
import { CodeLanguage } from '@/app/components/workflow/nodes/code/types'
|
||||||
import ErrorHandleTip from '@/app/components/workflow/nodes/_base/components/error-handle/error-handle-tip'
|
import ErrorHandleTip from '@/app/components/workflow/nodes/_base/components/error-handle/error-handle-tip'
|
||||||
import type { NodeTracing } from '@/types/workflow'
|
import type {
|
||||||
|
AgentLogItemWithChildren,
|
||||||
|
NodeTracing,
|
||||||
|
} from '@/types/workflow'
|
||||||
import { BlockEnum } from '@/app/components/workflow/types'
|
import { BlockEnum } from '@/app/components/workflow/types'
|
||||||
import { hasRetryNode } from '@/app/components/workflow/utils'
|
import { hasRetryNode } from '@/app/components/workflow/utils'
|
||||||
import { IterationLogTrigger } from '@/app/components/workflow/run/iteration-log'
|
import { IterationLogTrigger } from '@/app/components/workflow/run/iteration-log'
|
||||||
@ -31,7 +34,7 @@ type ResultPanelProps = {
|
|||||||
execution_metadata?: any
|
execution_metadata?: any
|
||||||
handleShowIterationResultList?: (detail: NodeTracing[][], iterDurationMap: any) => void
|
handleShowIterationResultList?: (detail: NodeTracing[][], iterDurationMap: any) => void
|
||||||
onShowRetryDetail?: (detail: NodeTracing[]) => void
|
onShowRetryDetail?: (detail: NodeTracing[]) => void
|
||||||
onShowAgentResultList?: () => void
|
handleShowAgentOrToolLog?: (detail: AgentLogItemWithChildren) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const ResultPanel: FC<ResultPanelProps> = ({
|
const ResultPanel: FC<ResultPanelProps> = ({
|
||||||
@ -51,7 +54,7 @@ const ResultPanel: FC<ResultPanelProps> = ({
|
|||||||
execution_metadata,
|
execution_metadata,
|
||||||
handleShowIterationResultList,
|
handleShowIterationResultList,
|
||||||
onShowRetryDetail,
|
onShowRetryDetail,
|
||||||
onShowAgentResultList,
|
handleShowAgentOrToolLog,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const isIterationNode = nodeInfo?.node_type === BlockEnum.Iteration
|
const isIterationNode = nodeInfo?.node_type === BlockEnum.Iteration
|
||||||
@ -87,10 +90,10 @@ const ResultPanel: FC<ResultPanelProps> = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
isAgentNode && onShowAgentResultList && (
|
isAgentNode && handleShowAgentOrToolLog && (
|
||||||
<AgentLogTrigger
|
<AgentLogTrigger
|
||||||
nodeInfo={nodeInfo}
|
nodeInfo={nodeInfo}
|
||||||
onShowAgentResultList={onShowAgentResultList}
|
onShowAgentOrToolLog={handleShowAgentOrToolLog}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,9 @@ export type SpecialResultPanelProps = {
|
|||||||
iterationResultList?: NodeTracing[][]
|
iterationResultList?: NodeTracing[][]
|
||||||
iterationResultDurationMap?: IterationDurationMap
|
iterationResultDurationMap?: IterationDurationMap
|
||||||
|
|
||||||
agentResultList?: AgentLogItemWithChildren[]
|
agentOrToolLogIdStack?: string[]
|
||||||
setAgentResultList?: (list: AgentLogItemWithChildren[]) => void
|
agentOrToolLogListMap?: Record<string, AgentLogItemWithChildren[]>
|
||||||
|
handleShowAgentOrToolLog?: (detail: AgentLogItemWithChildren) => void
|
||||||
}
|
}
|
||||||
const SpecialResultPanel = ({
|
const SpecialResultPanel = ({
|
||||||
showRetryDetail,
|
showRetryDetail,
|
||||||
@ -30,8 +31,9 @@ const SpecialResultPanel = ({
|
|||||||
iterationResultList,
|
iterationResultList,
|
||||||
iterationResultDurationMap,
|
iterationResultDurationMap,
|
||||||
|
|
||||||
agentResultList,
|
agentOrToolLogIdStack,
|
||||||
setAgentResultList,
|
agentOrToolLogListMap,
|
||||||
|
handleShowAgentOrToolLog,
|
||||||
}: SpecialResultPanelProps) => {
|
}: SpecialResultPanelProps) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -53,10 +55,11 @@ const SpecialResultPanel = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
!!agentResultList?.length && setAgentResultList && (
|
!!agentOrToolLogIdStack?.length && agentOrToolLogListMap && handleShowAgentOrToolLog && (
|
||||||
<AgentResultPanel
|
<AgentResultPanel
|
||||||
list={agentResultList}
|
agentOrToolLogIdStack={agentOrToolLogIdStack}
|
||||||
setAgentResultList={setAgentResultList}
|
agentOrToolLogListMap={agentOrToolLogListMap}
|
||||||
|
onShowAgentOrToolLog={handleShowAgentOrToolLog}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -79,8 +79,9 @@ const TracingPanel: FC<TracingPanelProps> = ({
|
|||||||
iterationResultDurationMap,
|
iterationResultDurationMap,
|
||||||
handleShowIterationResultList,
|
handleShowIterationResultList,
|
||||||
|
|
||||||
agentResultList,
|
agentOrToolLogIdStack,
|
||||||
setAgentResultList,
|
agentOrToolLogListMap,
|
||||||
|
handleShowAgentOrToolLog,
|
||||||
} = useLogs()
|
} = useLogs()
|
||||||
|
|
||||||
const renderNode = (node: NodeTracing) => {
|
const renderNode = (node: NodeTracing) => {
|
||||||
@ -136,7 +137,7 @@ const TracingPanel: FC<TracingPanelProps> = ({
|
|||||||
nodeInfo={node!}
|
nodeInfo={node!}
|
||||||
onShowIterationDetail={handleShowIterationResultList}
|
onShowIterationDetail={handleShowIterationResultList}
|
||||||
onShowRetryDetail={handleShowRetryResultList}
|
onShowRetryDetail={handleShowRetryResultList}
|
||||||
onShowAgentResultList={setAgentResultList}
|
onShowAgentOrToolLog={handleShowAgentOrToolLog}
|
||||||
hideInfo={hideNodeInfo}
|
hideInfo={hideNodeInfo}
|
||||||
hideProcessDetail={hideNodeProcessDetail}
|
hideProcessDetail={hideNodeProcessDetail}
|
||||||
/>
|
/>
|
||||||
@ -157,8 +158,9 @@ const TracingPanel: FC<TracingPanelProps> = ({
|
|||||||
iterationResultList={iterationResultList}
|
iterationResultList={iterationResultList}
|
||||||
iterationResultDurationMap={iterationResultDurationMap}
|
iterationResultDurationMap={iterationResultDurationMap}
|
||||||
|
|
||||||
agentResultList={agentResultList}
|
agentOrToolLogIdStack={agentOrToolLogIdStack}
|
||||||
setAgentResultList={setAgentResultList}
|
agentOrToolLogListMap={agentOrToolLogListMap}
|
||||||
|
handleShowAgentOrToolLog={handleShowAgentOrToolLog}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user