diff --git a/web/app/components/workflow/nodes/_base/components/before-run-form/index.tsx b/web/app/components/workflow/nodes/_base/components/before-run-form/index.tsx index bb150c778a..0812c1f9e1 100644 --- a/web/app/components/workflow/nodes/_base/components/before-run-form/index.tsx +++ b/web/app/components/workflow/nodes/_base/components/before-run-form/index.tsx @@ -40,6 +40,8 @@ export type BeforeRunFormProps = { } & Partial function formatValue(value: string | any, type: InputVarType) { + if(value === undefined || value === null) + return value if (type === InputVarType.number) return Number.parseFloat(value) if (type === InputVarType.json) 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 025a617653..9715a62405 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 @@ -329,6 +329,7 @@ const BasePanel: FC = ({ runningStatus={runningStatus} onSingleRunClicked={handleSingleRun} nodeInfo={nodeInfo} + singleRunResult={runResult!} {...passedLogParams} /> )} diff --git a/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/index.tsx b/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/index.tsx index 5702353a69..0ef37b7bf1 100644 --- a/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/index.tsx +++ b/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/index.tsx @@ -16,6 +16,7 @@ type Props = { nodeInfo?: NodeTracing runningStatus?: NodeRunningStatus onSingleRunClicked: () => void + singleRunResult?: NodeTracing } & Partial const LastRun: FC = ({ @@ -23,12 +24,16 @@ const LastRun: FC = ({ nodeId, canSingleRun, nodeInfo, - runningStatus, + runningStatus: oneStepRunRunningStatus, onSingleRunClicked, + singleRunResult, ...otherResultPanelProps }) => { - const isRunning = runningStatus === NodeRunningStatus.Running - const { data: runResult, isFetching } = useLastRun(appId, nodeId, !isRunning) + const isRunning = oneStepRunRunningStatus === NodeRunningStatus.Running + const isOneStepRunSuccess = oneStepRunRunningStatus === NodeRunningStatus.Succeeded + const isOneStepRunFailed = oneStepRunRunningStatus === NodeRunningStatus.Failed + const { data: lastRunResult, isFetching } = useLastRun(appId, nodeId, isOneStepRunSuccess) + const runResult = (isOneStepRunFailed ? singleRunResult : lastRunResult) || {} if (isFetching) { return ( diff --git a/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts b/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts index fb4229b92d..cee96cce59 100644 --- a/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts +++ b/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts @@ -243,6 +243,7 @@ const useOneStepRun = ({ }, }) let res: any + let hasError = false try { if (!isIteration && !isLoop) { res = await singleNodeRun(appId!, id, { inputs: submitData }) as any @@ -451,6 +452,13 @@ const useOneStepRun = ({ } catch (e: any) { console.error(e) + hasError = true + const result = res || {} + setRunResult({ + ...result, + error: e.message, + status: NodeRunningStatus.Failed, + }) if (!isIteration && !isLoop) { handleNodeDataUpdate({ id, @@ -464,7 +472,7 @@ const useOneStepRun = ({ } } finally { - if (!isIteration && !isLoop) { + if (!isIteration && !isLoop && res) { setRunResult({ ...res, total_tokens: res.execution_metadata?.total_tokens || 0, @@ -472,7 +480,7 @@ const useOneStepRun = ({ }) } } - if (!isIteration && !isLoop) { + if (!isIteration && !isLoop && !hasError) { handleNodeDataUpdate({ id, data: { diff --git a/web/app/components/workflow/nodes/start/use-single-run-form-params.ts b/web/app/components/workflow/nodes/start/use-single-run-form-params.ts index d3c8ee61f8..38abbf2a63 100644 --- a/web/app/components/workflow/nodes/start/use-single-run-form-params.ts +++ b/web/app/components/workflow/nodes/start/use-single-run-form-params.ts @@ -1,6 +1,7 @@ import type { MutableRefObject } from 'react' import { useTranslation } from 'react-i18next' import type { Props as FormProps } from '@/app/components/workflow/nodes/_base/components/before-run-form/form' +import type { ValueSelector } from '@/app/components/workflow/types' import { type InputVar, InputVarType, type Variable } from '@/app/components/workflow/types' import type { StartNodeType } from './types' import { useIsChatMode } from '../../hooks' @@ -15,6 +16,7 @@ type Params = { toVarInputs: (variables: Variable[]) => InputVar[] } const useSingleRunFormParams = ({ + id, payload, runInputData, setRunInputData, @@ -24,12 +26,12 @@ const useSingleRunFormParams = ({ const forms = (() => { const forms: FormProps[] = [] - const inputs = payload.variables.map((item: InputVar) => ({ - label: item.variable, - variable: item.variable, - type: item.type, - required: item.required, - })) + const inputs: InputVar[] = payload.variables.map((item) => { + return { + ...item, + getVarValueFromDependent: true, + } + }) if (isChatMode) { inputs.push({ @@ -46,6 +48,7 @@ const useSingleRunFormParams = ({ type: InputVarType.multiFiles, required: false, }) + forms.push( { label: t('workflow.nodes.llm.singleRun.variable')!, @@ -58,8 +61,26 @@ const useSingleRunFormParams = ({ return forms })() + const getDependentVars = () => { + const inputVars = payload.variables.map((item) => { + return [id, item.variable] + }) + const vars: ValueSelector[] = [...inputVars, ['sys', 'files']] + + if (isChatMode) + vars.push(['sys', 'query']) + + return vars + } + + const getDependentVar = (variable: string) => { + return [id, variable] + } + return { forms, + getDependentVars, + getDependentVar, } } diff --git a/web/app/components/workflow/nodes/variable-assigner/use-single-run-form-params.ts b/web/app/components/workflow/nodes/variable-assigner/use-single-run-form-params.ts index f3a5060ac2..11c38d6c8c 100644 --- a/web/app/components/workflow/nodes/variable-assigner/use-single-run-form-params.ts +++ b/web/app/components/workflow/nodes/variable-assigner/use-single-run-form-params.ts @@ -66,8 +66,21 @@ const useSingleRunFormParams = ({ ] })() + const getDependentVars = () => { + if(payload.advanced_settings?.group_enabled) { + const vars: ValueSelector[] = [] + payload.advanced_settings.groups.forEach((group) => { + if(group.variables) + vars.push(...group.variables) + }) + return vars + } + return payload.variables + } + return { forms, + getDependentVars, } }