diff --git a/web/app/components/workflow/nodes/agent/panel.tsx b/web/app/components/workflow/nodes/agent/panel.tsx index 501cd6ea19..654ad75f9c 100644 --- a/web/app/components/workflow/nodes/agent/panel.tsx +++ b/web/app/components/workflow/nodes/agent/panel.tsx @@ -1,4 +1,5 @@ -import { forwardRef, memo, useImperativeHandle } from 'react' +import type { FC } from 'react' +import { memo } from 'react' import type { NodePanelProps } from '../../types' import { AgentFeature, type AgentNodeType } from './types' import Field from '../_base/components/field' @@ -8,13 +9,10 @@ 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 { useLogs } from '@/app/components/workflow/run/hooks' -import type { Props as FormProps } from '@/app/components/workflow/nodes/_base/components/before-run-form/form' import { toType } from '@/app/components/tools/utils/to-form-schema' import { useStore } from '../../store' import Split from '../_base/components/split' import MemoryConfig from '../_base/components/memory-config' -import type { PanelExposedType } from '@/types/workflow' const i18nPrefix = 'workflow.nodes.agent' export function strategyParamToCredientialForm(param: StrategyParamItem): CredentialFormSchema { @@ -27,11 +25,7 @@ export function strategyParamToCredientialForm(param: StrategyParamItem): Creden } } -const AgentPanel = forwardRef>((props, ref) => { - const { - runInputData, - setRunInputData, - } = props.panelProps +const AgentPanel: FC> = (props) => { const { inputs, setInputs, @@ -42,39 +36,13 @@ const AgentPanel = forwardRef>(( availableNodesWithParent, availableVars, readOnly, - varInputs, outputSchema, handleMemoryChange, - } = useConfig(props.id, props.data, props.panelProps) + } = useConfig(props.id, props.data) const { t } = useTranslation() - 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 - })() - const resetEditor = useStore(s => s.setControlPromptEditorRerenderKey) - useImperativeHandle(ref, () => ({ - singleRunParams: { - forms: singleRunForms, - logsParams, - }, - })) - return
>((
-}) +} AgentPanel.displayName = 'AgentPanel' diff --git a/web/app/components/workflow/nodes/agent/use-config.ts b/web/app/components/workflow/nodes/agent/use-config.ts index a72684aa3d..36ca940e60 100644 --- a/web/app/components/workflow/nodes/agent/use-config.ts +++ b/web/app/components/workflow/nodes/agent/use-config.ts @@ -13,7 +13,6 @@ import type { Memory, Var } from '../../types' import { VarType as VarKindType } from '../../types' import useAvailableVarList from '../_base/hooks/use-available-var-list' import produce from 'immer' -import type { PanelProps } from '@/types/workflow' export type StrategyStatus = { plugin: { @@ -63,9 +62,7 @@ export const useStrategyInfo = ( } } -const useConfig = (id: string, payload: AgentNodeType, panelProps?: PanelProps) => { - const getInputVars = panelProps?.getInputVars - +const useConfig = (id: string, payload: AgentNodeType) => { const { nodesReadOnly: readOnly } = useNodesReadOnly() const { inputs, setInputs } = useNodeCrud(id, payload) // variables @@ -133,19 +130,6 @@ const useConfig = (id: string, payload: AgentNodeType, panelProps?: PanelProps) // single run - const allVarStrArr = (() => { - const arr = currentStrategy?.parameters.filter(item => item.type === 'string').map((item) => { - return formData[item.name] - }) || [] - - return arr - })() - const varInputs = (() => { - const vars = getInputVars?.(allVarStrArr) - - return vars - })() - const outputSchema = useMemo(() => { const res: any[] = [] if (!inputs.output_schema) @@ -184,7 +168,6 @@ const useConfig = (id: string, payload: AgentNodeType, panelProps?: PanelProps) pluginDetail: pluginDetail.data?.plugins.at(0), availableVars, availableNodesWithParent, - varInputs, outputSchema, handleMemoryChange, isChatMode, diff --git a/web/app/components/workflow/nodes/agent/use-single-run-form-params.ts b/web/app/components/workflow/nodes/agent/use-single-run-form-params.ts new file mode 100644 index 0000000000..3b99f58581 --- /dev/null +++ b/web/app/components/workflow/nodes/agent/use-single-run-form-params.ts @@ -0,0 +1,79 @@ +import type { MutableRefObject } from 'react' +import type { InputVar, Variable } from '@/app/components/workflow/types' +import { useMemo } from 'react' +import useNodeCrud from '../_base/hooks/use-node-crud' +import type { AgentNodeType } from './types' +import { useLogs } from '../../run/hooks' +import { useTranslation } from 'react-i18next' +import type { Props as FormProps } from '@/app/components/workflow/nodes/_base/components/before-run-form/form' +import { useStrategyInfo } from './use-config' + +const i18nPrefix = 'workflow.nodes.agent' + +type Params = { + id: string, + payload: AgentNodeType, + runInputData: Record + runInputDataRef: MutableRefObject> + getInputVars: (textList: string[]) => InputVar[] + setRunInputData: (data: Record) => void + toVarInputs: (variables: Variable[]) => InputVar[] +} +const useSingleRunFormParams = ({ + id, + payload, + runInputData, + getInputVars, + setRunInputData, +}: Params) => { + const { t } = useTranslation() + const { inputs } = useNodeCrud(id, payload) + const logsParams = useLogs() + + const formData = useMemo(() => { + return Object.fromEntries( + Object.entries(inputs.agent_parameters || {}).map(([key, value]) => { + return [key, value.value] + }), + ) + }, [inputs.agent_parameters]) + + const { + strategy: currentStrategy, + } = useStrategyInfo( + inputs.agent_strategy_provider_name, + inputs.agent_strategy_name, + ) + + const allVarStrArr = (() => { + const arr = currentStrategy?.parameters.filter(item => item.type === 'string').map((item) => { + return formData[item.name] + }) || [] + return arr + })() + + const varInputs = getInputVars?.(allVarStrArr) + + const forms = useMemo(() => { + const forms: FormProps[] = [] + + if (varInputs!.length > 0) { + forms.push( + { + label: t(`${i18nPrefix}.singleRun.variable`)!, + inputs: varInputs!, + values: runInputData, + onChange: setRunInputData, + }, + ) + } + return forms + }, [runInputData, setRunInputData, t, varInputs]) + + return { + forms, + logsParams, + } +} + +export default useSingleRunFormParams