From 9e9f2d11d7a64a2963d2084854c9499444ce2d6f Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 18 Apr 2025 18:14:51 +0800 Subject: [PATCH] feat: support change run value --- .../_base/components/workflow-panel/index.tsx | 25 +++++++++++-- .../components/workflow/nodes/agent/panel.tsx | 22 +++++------ .../workflow/nodes/agent/use-config.ts | 37 +++---------------- web/app/components/workflow/types.ts | 3 +- web/types/workflow.ts | 9 ++++- 5 files changed, 47 insertions(+), 49 deletions(-) diff --git a/web/app/components/workflow/nodes/_base/components/workflow-panel/index.tsx b/web/app/components/workflow/nodes/_base/components/workflow-panel/index.tsx index a92432fe78..f6f431a46f 100644 --- a/web/app/components/workflow/nodes/_base/components/workflow-panel/index.tsx +++ b/web/app/components/workflow/nodes/_base/components/workflow-panel/index.tsx @@ -53,6 +53,7 @@ import LastRun from './last-run' import useOneStepRun from '../../hooks/use-one-step-run' import type { PanelExposedType } from '@/types/workflow' import BeforeRunForm from '../before-run-form' +import { sleep } from '@/utils' type BasePanelProps = { children: ReactNode @@ -110,6 +111,8 @@ const BasePanel: FC = ({ }, [handleNodeDataUpdateWithSyncDraft, id, saveStateToHistory]) const isSupportSingleRun = canRunBySingle(data.type) + const childPanelRef = useRef(null) + const { isShowSingleRun, showSingleRun, @@ -119,7 +122,7 @@ const BasePanel: FC = ({ handleRun, handleStop, runInputData, - setRunInputData, + setRunInputData: doSetRunInputData, runResult, getInputVars, } = useOneStepRun({ @@ -127,9 +130,15 @@ const BasePanel: FC = ({ data, defaultRunInputData: {}, }) - const childPanelRef = useRef(null) const [singleRunParams, setSingleRunParams] = useState(undefined) + const setRunInputData = useCallback(async (data: Record) => { + doSetRunInputData(data) + // console.log(childPanelRef.current?.singleRunParams) + await sleep(0) // wait for childPanelRef.current?.singleRunParams refresh + setSingleRunParams(childPanelRef.current?.singleRunParams) + }, [doSetRunInputData]) + const [tabType, setTabType] = useState(TabType.settings) const hasLastRunData = true // TODO: add disabled logic @@ -217,7 +226,17 @@ const BasePanel: FC = ({ {tabType === TabType.settings && ( <>
- {cloneElement(children as any, { id, data, ref: childPanelRef })} + {cloneElement(children as any, { + id, + data, + panelProps: { + getInputVars, + runInputData, + setRunInputData, + runResult, + }, + ref: childPanelRef, + })}
{ diff --git a/web/app/components/workflow/nodes/agent/panel.tsx b/web/app/components/workflow/nodes/agent/panel.tsx index d5f4a3ff02..e6fa49f2b7 100644 --- a/web/app/components/workflow/nodes/agent/panel.tsx +++ b/web/app/components/workflow/nodes/agent/panel.tsx @@ -1,4 +1,4 @@ -import { forwardRef, memo, useImperativeHandle, useMemo } from 'react' +import { forwardRef, memo, useImperativeHandle } from 'react' import type { NodePanelProps } from '../../types' import { AgentFeature, type AgentNodeType } from './types' import Field from '../_base/components/field' @@ -8,7 +8,6 @@ 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 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' import { toType } from '@/app/components/tools/utils/to-form-schema' @@ -28,6 +27,10 @@ export function strategyParamToCredientialForm(param: StrategyParamItem): Creden } const AgentPanel = forwardRef>((props, ref) => { + const { + runInputData, + setRunInputData, + } = props.panelProps const { inputs, setInputs, @@ -38,28 +41,21 @@ const AgentPanel = forwardRef>(( availableNodesWithParent, availableVars, readOnly, - runResult, - runInputData, - setRunInputData, varInputs, outputSchema, handleMemoryChange, - } = useConfig(props.id, props.data) + } = useConfig(props.id, props.data, props.panelProps) 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) { + if (varInputs!.length > 0) { forms.push( { label: t(`${i18nPrefix}.singleRun.variable`)!, - inputs: varInputs, + inputs: varInputs!, values: runInputData, onChange: setRunInputData, }, diff --git a/web/app/components/workflow/nodes/agent/use-config.ts b/web/app/components/workflow/nodes/agent/use-config.ts index 32d7c6f9db..a72684aa3d 100644 --- a/web/app/components/workflow/nodes/agent/use-config.ts +++ b/web/app/components/workflow/nodes/agent/use-config.ts @@ -1,7 +1,6 @@ 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 { useIsChatMode, @@ -14,6 +13,7 @@ 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,7 +63,9 @@ export const useStrategyInfo = ( } } -const useConfig = (id: string, payload: AgentNodeType) => { +const useConfig = (id: string, payload: AgentNodeType, panelProps?: PanelProps) => { + const getInputVars = panelProps?.getInputVars + const { nodesReadOnly: readOnly } = useNodesReadOnly() const { inputs, setInputs } = useNodeCrud(id, payload) // variables @@ -130,23 +132,7 @@ const useConfig = (id: string, payload: AgentNodeType) => { }) // single run - const { - isShowSingleRun, - showSingleRun, - hideSingleRun, - toVarInputs, - runningStatus, - handleRun, - handleStop, - runInputData, - setRunInputData, - runResult, - getInputVars, - } = useOneStepRun({ - id, - data: inputs, - defaultRunInputData: {}, - }) + const allVarStrArr = (() => { const arr = currentStrategy?.parameters.filter(item => item.type === 'string').map((item) => { return formData[item.name] @@ -155,7 +141,7 @@ const useConfig = (id: string, payload: AgentNodeType) => { return arr })() const varInputs = (() => { - const vars = getInputVars(allVarStrArr) + const vars = getInputVars?.(allVarStrArr) return vars })() @@ -198,17 +184,6 @@ const useConfig = (id: string, payload: AgentNodeType) => { pluginDetail: pluginDetail.data?.plugins.at(0), availableVars, availableNodesWithParent, - - isShowSingleRun, - showSingleRun, - hideSingleRun, - toVarInputs, - runningStatus, - handleRun, - handleStop, - runInputData, - setRunInputData, - runResult, varInputs, outputSchema, handleMemoryChange, diff --git a/web/app/components/workflow/types.ts b/web/app/components/workflow/types.ts index 884bdfbd10..2f75e6bf2c 100644 --- a/web/app/components/workflow/types.ts +++ b/web/app/components/workflow/types.ts @@ -6,7 +6,7 @@ import type { import type { Resolution, TransferMethod } from '@/types/app' import type { ToolDefaultValue } from '@/app/components/workflow/block-selector/types' import type { VarType as VarKindType } from '@/app/components/workflow/nodes/tool/types' -import type { FileResponse, NodeTracing } from '@/types/workflow' +import type { FileResponse, NodeTracing, PanelProps } from '@/types/workflow' import type { Collection, Tool } from '@/app/components/tools/types' import type { ChatVarType } from '@/app/components/workflow/panel/chat-variable-panel/type' import type { @@ -114,6 +114,7 @@ export type NodeProps = { id: string; data: CommonNodeType } export type NodePanelProps = { id: string data: CommonNodeType + panelProps: PanelProps } export type Edge = ReactFlowEdge diff --git a/web/types/workflow.ts b/web/types/workflow.ts index f275539ff0..b69739919b 100644 --- a/web/types/workflow.ts +++ b/web/types/workflow.ts @@ -1,5 +1,5 @@ import type { Viewport } from 'reactflow' -import type { BlockEnum, ConversationVariable, Edge, EnvironmentVariable, Node } from '@/app/components/workflow/types' +import type { BlockEnum, ConversationVariable, Edge, EnvironmentVariable, InputVar, Node } from '@/app/components/workflow/types' import type { TransferMethod } from '@/types/app' import type { ErrorHandleTypeEnum } from '@/app/components/workflow/nodes/_base/components/error-handle/types' import type { BeforeRunFormProps } from '@/app/components/workflow/nodes/_base/components/before-run-form' @@ -357,3 +357,10 @@ export type UpdateWorkflowParams = { export type PanelExposedType = { singleRunParams: Pick & Partial } + +export type PanelProps = { + getInputVars: (textList: string[]) => InputVar[] + runInputData: Record + setRunInputData: (data: Record) => void + runResult: any +}