feat: tool single run

This commit is contained in:
zxhlyh
2024-12-31 14:02:50 +08:00
parent 2cdf2b2e05
commit 21d082f3da
8 changed files with 67 additions and 9 deletions

View File

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

View File

@@ -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 ResultPanel from '@/app/components/workflow/run/result-panel'
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'
@@ -51,6 +53,8 @@ const Panel: FC<NodePanelProps<ToolNodeType>> = ({
outputSchema,
} = useConfig(id, data)
const toolIcon = useToolIcon(data)
const logsParams = useLogs()
const nodeInfo = formatToTracingNodeList([runResult], t)[0]
if (isLoading) {
return <div className='flex h-[200px] items-center justify-center'>
@@ -161,7 +165,8 @@ const Panel: FC<NodePanelProps<ToolNodeType>> = ({
runningStatus={runningStatus}
onRun={handleRun}
onStop={handleStop}
result={<ResultPanel {...runResult} showSteps={false} />}
{...logsParams}
result={<ResultPanel {...runResult} showSteps={false} {...logsParams} nodeInfo={nodeInfo} />}
/>
)}
</div>

View File

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

View File

@@ -1,9 +1,10 @@
import { RiAlertFill } from '@remixicon/react'
import AgentLogItem from './agent-log-item'
import AgentLogNav from './agent-log-nav'
import type { AgentLogItemWithChildren } from '@/types/workflow'
type AgentResultPanelProps = {
agentOrToolLogItemStack: { id: string; label: string }[]
agentOrToolLogItemStack: AgentLogItemWithChildren[]
agentOrToolLogListMap: Record<string, AgentLogItemWithChildren[]>
onShowAgentOrToolLog: (detail?: AgentLogItemWithChildren) => void
}
@@ -34,6 +35,22 @@ const AgentResultPanel = ({
}
</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>
)
}

View File

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

View File

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

View File

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

View File

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