diff --git a/web/app/components/workflow/nodes/agent/panel.tsx b/web/app/components/workflow/nodes/agent/panel.tsx index 7ea501815b..26b2663592 100644 --- a/web/app/components/workflow/nodes/agent/panel.tsx +++ b/web/app/components/workflow/nodes/agent/panel.tsx @@ -1,4 +1,5 @@ import type { FC } from 'react' +import { useMemo } from 'react' import type { NodePanelProps } from '../../types' import type { AgentNodeType } from './types' import Field from '../_base/components/field' @@ -8,6 +9,11 @@ import { useTranslation } from 'react-i18next' import OutputVars, { VarItem } from '../_base/components/output-vars' import type { StrategyParamItem } from '@/app/components/plugins/types' import type { CredentialFormSchema } from '@/app/components/header/account-setting/model-provider-page/declarations' +import BeforeRunForm from '@/app/components/workflow/nodes/_base/components/before-run-form' +import ResultPanel from '@/app/components/workflow/run/result-panel' +import formatTracing from '@/app/components/workflow/run/utils/format-log' +import { useLogs } from '@/app/components/workflow/run/hooks' +import type { Props as FormProps } from '@/app/components/workflow/nodes/_base/components/before-run-form/form' const i18nPrefix = 'workflow.nodes.agent' @@ -20,8 +26,47 @@ export function strategyParamToCredientialForm(param: StrategyParamItem): Creden } const AgentPanel: FC> = (props) => { - const { inputs, setInputs, currentStrategy, formData, onFormChange } = useConfig(props.id, props.data) + const { + inputs, + setInputs, + currentStrategy, + formData, + onFormChange, + + isShowSingleRun, + hideSingleRun, + runningStatus, + handleRun, + handleStop, + runResult, + runInputData, + setRunInputData, + varInputs, + } = useConfig(props.id, props.data) const { t } = useTranslation() + const nodeInfo = useMemo(() => { + if (!runResult) + return + return formatTracing([runResult], t)[0] + }, [runResult, t]) + const logsParams = useLogs() + const singleRunForms = (() => { + const forms: FormProps[] = [] + + if (varInputs.length > 0) { + forms.push( + { + label: t(`${i18nPrefix}.singleRun.variable`)!, + inputs: varInputs, + values: runInputData, + onChange: setRunInputData, + }, + ) + } + + return forms + })() + return
> = (props) => { ))}
+ { + isShowSingleRun && ( + } + /> + ) + } } diff --git a/web/app/components/workflow/nodes/agent/use-config.ts b/web/app/components/workflow/nodes/agent/use-config.ts index fcd1bed5aa..a1f96e33a2 100644 --- a/web/app/components/workflow/nodes/agent/use-config.ts +++ b/web/app/components/workflow/nodes/agent/use-config.ts @@ -21,26 +21,6 @@ const useConfig = (id: string, payload: AgentNodeType) => { inputs.agent_strategy_provider_name || '', ) - // single run - const agentInputKey = `${id}.input_selector` - const { - isShowSingleRun, - showSingleRun, - hideSingleRun, - toVarInputs, - runningStatus, - handleRun, - handleStop, - runInputData, - setRunInputData, - runResult, - } = useOneStepRun({ - id, - data: inputs, - defaultRunInputData: { - [agentInputKey]: [''], - }, - }) const currentStrategy = strategyProvider.data?.declaration.strategies.find( str => str.identity.name === inputs.agent_strategy_name, ) @@ -70,6 +50,36 @@ const useConfig = (id: string, payload: AgentNodeType) => { agent_parameters: res, }) } + + // single run + const { + isShowSingleRun, + showSingleRun, + hideSingleRun, + toVarInputs, + runningStatus, + handleRun, + handleStop, + runInputData, + setRunInputData, + runResult, + getInputVars, + } = useOneStepRun({ + id, + data: inputs, + defaultRunInputData: {}, + }) + const allVarStrArr = (() => { + const arr = [''] + + return arr + })() + const varInputs = (() => { + const vars = getInputVars(allVarStrArr) + + return vars + })() + return { readOnly, inputs, @@ -92,7 +102,7 @@ const useConfig = (id: string, payload: AgentNodeType) => { runInputData, setRunInputData, runResult, - agentInputKey, + varInputs, } } diff --git a/web/app/components/workflow/run/node.tsx b/web/app/components/workflow/run/node.tsx index 4d27c9bb4c..9efd03df7a 100644 --- a/web/app/components/workflow/run/node.tsx +++ b/web/app/components/workflow/run/node.tsx @@ -78,10 +78,10 @@ const NodePanel: FC = ({ setCollapseState(!nodeInfo.expand) }, [nodeInfo.expand, setCollapseState]) - 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 + const isIterationNode = nodeInfo.node_type === BlockEnum.Iteration && nodeInfo.details?.length + const isRetryNode = hasRetryNode(nodeInfo.node_type) && nodeInfo.retryDetail?.length + const isAgentNode = nodeInfo.node_type === BlockEnum.Agent && nodeInfo.agentLog?.length + const isToolNode = nodeInfo.node_type === BlockEnum.Tool && nodeInfo.agentLog?.length return (
diff --git a/web/app/components/workflow/run/result-panel.tsx b/web/app/components/workflow/run/result-panel.tsx index f977987785..a198b2ff6d 100644 --- a/web/app/components/workflow/run/result-panel.tsx +++ b/web/app/components/workflow/run/result-panel.tsx @@ -57,10 +57,10 @@ const ResultPanel: FC = ({ handleShowAgentOrToolLog, }) => { const { t } = useTranslation() - 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 + const isIterationNode = nodeInfo?.node_type === BlockEnum.Iteration && nodeInfo?.details?.length + const isRetryNode = hasRetryNode(nodeInfo?.node_type) && nodeInfo?.retryDetail?.length + const isAgentNode = nodeInfo?.node_type === BlockEnum.Agent && nodeInfo?.agentLog?.length + const isToolNode = nodeInfo?.node_type === BlockEnum.Tool && nodeInfo?.agentLog?.length return (