feat: tool single run

pull/12372/head
zxhlyh 1 year ago
parent 2cdf2b2e05
commit 21d082f3da

@ -1,6 +1,7 @@
import { useStrategyProviderDetail } from '@/service/use-strategy' import { useStrategyProviderDetail } from '@/service/use-strategy'
import useNodeCrud from '../_base/hooks/use-node-crud' import useNodeCrud from '../_base/hooks/use-node-crud'
import useVarList from '../_base/hooks/use-var-list' import useVarList from '../_base/hooks/use-var-list'
import useOneStepRun from '../_base/hooks/use-one-step-run'
import type { AgentNodeType } from './types' import type { AgentNodeType } from './types'
import { import {
useNodesReadOnly, useNodesReadOnly,
@ -19,6 +20,27 @@ const useConfig = (id: string, payload: AgentNodeType) => {
const strategyProvider = useStrategyProviderDetail( const strategyProvider = useStrategyProviderDetail(
inputs.agent_strategy_provider_name || '', inputs.agent_strategy_provider_name || '',
) )
// single run
const agentInputKey = `${id}.input_selector`
const {
isShowSingleRun,
showSingleRun,
hideSingleRun,
toVarInputs,
runningStatus,
handleRun,
handleStop,
runInputData,
setRunInputData,
runResult,
} = useOneStepRun<AgentNodeType>({
id,
data: inputs,
defaultRunInputData: {
[agentInputKey]: [''],
},
})
const currentStrategy = strategyProvider.data?.declaration.strategies.find( const currentStrategy = strategyProvider.data?.declaration.strategies.find(
str => str.identity.name === inputs.agent_strategy_name, str => str.identity.name === inputs.agent_strategy_name,
) )
@ -59,6 +81,18 @@ const useConfig = (id: string, payload: AgentNodeType) => {
onFormChange, onFormChange,
currentStrategyStatus, currentStrategyStatus,
strategyProvider: strategyProvider.data, strategyProvider: strategyProvider.data,
isShowSingleRun,
showSingleRun,
hideSingleRun,
toVarInputs,
runningStatus,
handleRun,
handleStop,
runInputData,
setRunInputData,
runResult,
agentInputKey,
} }
} }

@ -15,6 +15,8 @@ import BeforeRunForm from '@/app/components/workflow/nodes/_base/components/befo
import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars' import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
import ResultPanel from '@/app/components/workflow/run/result-panel' import ResultPanel from '@/app/components/workflow/run/result-panel'
import { useToolIcon } from '@/app/components/workflow/hooks' import { useToolIcon } from '@/app/components/workflow/hooks'
import { useLogs } from '@/app/components/workflow/run/hooks'
import formatToTracingNodeList from '@/app/components/workflow/run/utils/format-log'
const i18nPrefix = 'workflow.nodes.tool' const i18nPrefix = 'workflow.nodes.tool'
@ -51,6 +53,8 @@ const Panel: FC<NodePanelProps<ToolNodeType>> = ({
outputSchema, outputSchema,
} = useConfig(id, data) } = useConfig(id, data)
const toolIcon = useToolIcon(data) const toolIcon = useToolIcon(data)
const logsParams = useLogs()
const nodeInfo = formatToTracingNodeList([runResult], t)[0]
if (isLoading) { if (isLoading) {
return <div className='flex h-[200px] items-center justify-center'> return <div className='flex h-[200px] items-center justify-center'>
@ -161,7 +165,8 @@ const Panel: FC<NodePanelProps<ToolNodeType>> = ({
runningStatus={runningStatus} runningStatus={runningStatus}
onRun={handleRun} onRun={handleRun}
onStop={handleStop} onStop={handleStop}
result={<ResultPanel {...runResult} showSteps={false} />} {...logsParams}
result={<ResultPanel {...runResult} showSteps={false} {...logsParams} nodeInfo={nodeInfo} />}
/> />
)} )}
</div> </div>

@ -4,7 +4,7 @@ import Button from '@/app/components/base/button'
import type { AgentLogItemWithChildren } from '@/types/workflow' import type { AgentLogItemWithChildren } from '@/types/workflow'
type AgentLogNavProps = { type AgentLogNavProps = {
agentOrToolLogItemStack: { id: string; label: string }[] agentOrToolLogItemStack: AgentLogItemWithChildren[]
onShowAgentOrToolLog: (detail?: AgentLogItemWithChildren) => void onShowAgentOrToolLog: (detail?: AgentLogItemWithChildren) => void
} }
const AgentLogNav = ({ const AgentLogNav = ({

@ -1,9 +1,10 @@
import { RiAlertFill } from '@remixicon/react'
import AgentLogItem from './agent-log-item' import AgentLogItem from './agent-log-item'
import AgentLogNav from './agent-log-nav' import AgentLogNav from './agent-log-nav'
import type { AgentLogItemWithChildren } from '@/types/workflow' import type { AgentLogItemWithChildren } from '@/types/workflow'
type AgentResultPanelProps = { type AgentResultPanelProps = {
agentOrToolLogItemStack: { id: string; label: string }[] agentOrToolLogItemStack: AgentLogItemWithChildren[]
agentOrToolLogListMap: Record<string, AgentLogItemWithChildren[]> agentOrToolLogListMap: Record<string, AgentLogItemWithChildren[]>
onShowAgentOrToolLog: (detail?: AgentLogItemWithChildren) => void onShowAgentOrToolLog: (detail?: AgentLogItemWithChildren) => void
} }
@ -34,6 +35,22 @@ const AgentResultPanel = ({
} }
</div> </div>
} }
{
top.hasCircle && (
<div className='flex items-center rounded-xl px-3 pr-2 border border-components-panel-border bg-components-panel-bg-blur shadow-md'>
<div
className='absolute inset-0 opacity-[0.4] rounded-xl'
style={{
background: 'linear-gradient(92deg, rgba(247, 144, 9, 0.25) 0%, rgba(255, 255, 255, 0.00) 100%)',
}}
></div>
<RiAlertFill className='mr-1.5 w-4 h-4 text-text-warning-secondary' />
<div className='system-xs-medium text-text-primary'>
There is circular invocation of tools/nodes in the current workflow.
</div>
</div>
)
}
</div> </div>
) )
} }

@ -33,7 +33,7 @@ export const useLogs = () => {
setIterationResultDurationMap(iterDurationMap) setIterationResultDurationMap(iterDurationMap)
}, [setShowIteratingDetailTrue, setIterationResultList, setIterationResultDurationMap]) }, [setShowIteratingDetailTrue, setIterationResultList, setIterationResultDurationMap])
const [agentOrToolLogItemStack, setAgentOrToolLogItemStack] = useState<{ id: string; label: string }[]>([]) const [agentOrToolLogItemStack, setAgentOrToolLogItemStack] = useState<AgentLogItemWithChildren[]>([])
const agentOrToolLogItemStackRef = useRef(agentOrToolLogItemStack) const agentOrToolLogItemStackRef = useRef(agentOrToolLogItemStack)
const [agentOrToolLogListMap, setAgentOrToolLogListMap] = useState<Record<string, AgentLogItemWithChildren[]>>({}) const [agentOrToolLogListMap, setAgentOrToolLogListMap] = useState<Record<string, AgentLogItemWithChildren[]>>({})
const agentOrToolLogListMapRef = useRef(agentOrToolLogListMap) const agentOrToolLogListMapRef = useRef(agentOrToolLogListMap)
@ -43,14 +43,14 @@ export const useLogs = () => {
agentOrToolLogItemStackRef.current = [] agentOrToolLogItemStackRef.current = []
return return
} }
const { id, label, children } = detail const { id, children } = detail
let currentAgentOrToolLogItemStack = agentOrToolLogItemStackRef.current.slice() let currentAgentOrToolLogItemStack = agentOrToolLogItemStackRef.current.slice()
const index = currentAgentOrToolLogItemStack.findIndex(logItem => logItem.id === id) const index = currentAgentOrToolLogItemStack.findIndex(logItem => logItem.id === id)
if (index > -1) if (index > -1)
currentAgentOrToolLogItemStack = currentAgentOrToolLogItemStack.slice(0, index + 1) currentAgentOrToolLogItemStack = currentAgentOrToolLogItemStack.slice(0, index + 1)
else else
currentAgentOrToolLogItemStack = [...currentAgentOrToolLogItemStack.slice(), { id, label }] currentAgentOrToolLogItemStack = [...currentAgentOrToolLogItemStack.slice(), detail]
setAgentOrToolLogItemStack(currentAgentOrToolLogItemStack) setAgentOrToolLogItemStack(currentAgentOrToolLogItemStack)
agentOrToolLogItemStackRef.current = currentAgentOrToolLogItemStack agentOrToolLogItemStackRef.current = currentAgentOrToolLogItemStack

@ -81,6 +81,7 @@ const NodePanel: FC<Props> = ({
const isIterationNode = nodeInfo.node_type === BlockEnum.Iteration const isIterationNode = nodeInfo.node_type === BlockEnum.Iteration
const isRetryNode = hasRetryNode(nodeInfo.node_type) && nodeInfo.retryDetail const isRetryNode = hasRetryNode(nodeInfo.node_type) && nodeInfo.retryDetail
const isAgentNode = nodeInfo.node_type === BlockEnum.Agent const isAgentNode = nodeInfo.node_type === BlockEnum.Agent
const isToolNode = nodeInfo.node_type === BlockEnum.Tool
return ( return (
<div className={cn('px-2 py-1', className)}> <div className={cn('px-2 py-1', className)}>
@ -144,7 +145,7 @@ const NodePanel: FC<Props> = ({
/> />
)} )}
{ {
isAgentNode && onShowAgentOrToolLog && ( (isAgentNode || isToolNode) && onShowAgentOrToolLog && (
<AgentLogTrigger <AgentLogTrigger
nodeInfo={nodeInfo} nodeInfo={nodeInfo}
onShowAgentOrToolLog={onShowAgentOrToolLog} onShowAgentOrToolLog={onShowAgentOrToolLog}

@ -60,6 +60,7 @@ const ResultPanel: FC<ResultPanelProps> = ({
const isIterationNode = nodeInfo?.node_type === BlockEnum.Iteration const isIterationNode = nodeInfo?.node_type === BlockEnum.Iteration
const isRetryNode = hasRetryNode(nodeInfo?.node_type) && nodeInfo?.retryDetail const isRetryNode = hasRetryNode(nodeInfo?.node_type) && nodeInfo?.retryDetail
const isAgentNode = nodeInfo?.node_type === BlockEnum.Agent const isAgentNode = nodeInfo?.node_type === BlockEnum.Agent
const isToolNode = nodeInfo?.node_type === BlockEnum.Tool
return ( return (
<div className='bg-components-panel-bg py-2'> <div className='bg-components-panel-bg py-2'>
@ -90,7 +91,7 @@ const ResultPanel: FC<ResultPanelProps> = ({
) )
} }
{ {
isAgentNode && handleShowAgentOrToolLog && ( (isAgentNode || isToolNode) && handleShowAgentOrToolLog && (
<AgentLogTrigger <AgentLogTrigger
nodeInfo={nodeInfo} nodeInfo={nodeInfo}
onShowAgentOrToolLog={handleShowAgentOrToolLog} onShowAgentOrToolLog={handleShowAgentOrToolLog}

@ -17,7 +17,7 @@ export type SpecialResultPanelProps = {
iterationResultList?: NodeTracing[][] iterationResultList?: NodeTracing[][]
iterationResultDurationMap?: IterationDurationMap iterationResultDurationMap?: IterationDurationMap
agentOrToolLogItemStack?: { id: string; label: string }[] agentOrToolLogItemStack?: AgentLogItemWithChildren[]
agentOrToolLogListMap?: Record<string, AgentLogItemWithChildren[]> agentOrToolLogListMap?: Record<string, AgentLogItemWithChildren[]>
handleShowAgentOrToolLog?: (detail?: AgentLogItemWithChildren) => void handleShowAgentOrToolLog?: (detail?: AgentLogItemWithChildren) => void
} }

Loading…
Cancel
Save