feat: start node run and node run result error handle error

pull/21369/head
Joel 1 year ago
parent 2ec1c34147
commit 618a6f9dba

@ -40,6 +40,8 @@ export type BeforeRunFormProps = {
} & Partial<SpecialResultPanelProps> } & Partial<SpecialResultPanelProps>
function formatValue(value: string | any, type: InputVarType) { function formatValue(value: string | any, type: InputVarType) {
if(value === undefined || value === null)
return value
if (type === InputVarType.number) if (type === InputVarType.number)
return Number.parseFloat(value) return Number.parseFloat(value)
if (type === InputVarType.json) if (type === InputVarType.json)

@ -329,6 +329,7 @@ const BasePanel: FC<BasePanelProps> = ({
runningStatus={runningStatus} runningStatus={runningStatus}
onSingleRunClicked={handleSingleRun} onSingleRunClicked={handleSingleRun}
nodeInfo={nodeInfo} nodeInfo={nodeInfo}
singleRunResult={runResult!}
{...passedLogParams} {...passedLogParams}
/> />
)} )}

@ -16,6 +16,7 @@ type Props = {
nodeInfo?: NodeTracing nodeInfo?: NodeTracing
runningStatus?: NodeRunningStatus runningStatus?: NodeRunningStatus
onSingleRunClicked: () => void onSingleRunClicked: () => void
singleRunResult?: NodeTracing
} & Partial<ResultPanelProps> } & Partial<ResultPanelProps>
const LastRun: FC<Props> = ({ const LastRun: FC<Props> = ({
@ -23,12 +24,16 @@ const LastRun: FC<Props> = ({
nodeId, nodeId,
canSingleRun, canSingleRun,
nodeInfo, nodeInfo,
runningStatus, runningStatus: oneStepRunRunningStatus,
onSingleRunClicked, onSingleRunClicked,
singleRunResult,
...otherResultPanelProps ...otherResultPanelProps
}) => { }) => {
const isRunning = runningStatus === NodeRunningStatus.Running const isRunning = oneStepRunRunningStatus === NodeRunningStatus.Running
const { data: runResult, isFetching } = useLastRun(appId, nodeId, !isRunning) 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) { if (isFetching) {
return ( return (

@ -243,6 +243,7 @@ const useOneStepRun = <T>({
}, },
}) })
let res: any let res: any
let hasError = false
try { try {
if (!isIteration && !isLoop) { if (!isIteration && !isLoop) {
res = await singleNodeRun(appId!, id, { inputs: submitData }) as any res = await singleNodeRun(appId!, id, { inputs: submitData }) as any
@ -451,6 +452,13 @@ const useOneStepRun = <T>({
} }
catch (e: any) { catch (e: any) {
console.error(e) console.error(e)
hasError = true
const result = res || {}
setRunResult({
...result,
error: e.message,
status: NodeRunningStatus.Failed,
})
if (!isIteration && !isLoop) { if (!isIteration && !isLoop) {
handleNodeDataUpdate({ handleNodeDataUpdate({
id, id,
@ -464,7 +472,7 @@ const useOneStepRun = <T>({
} }
} }
finally { finally {
if (!isIteration && !isLoop) { if (!isIteration && !isLoop && res) {
setRunResult({ setRunResult({
...res, ...res,
total_tokens: res.execution_metadata?.total_tokens || 0, total_tokens: res.execution_metadata?.total_tokens || 0,
@ -472,7 +480,7 @@ const useOneStepRun = <T>({
}) })
} }
} }
if (!isIteration && !isLoop) { if (!isIteration && !isLoop && !hasError) {
handleNodeDataUpdate({ handleNodeDataUpdate({
id, id,
data: { data: {

@ -1,6 +1,7 @@
import type { MutableRefObject } from 'react' import type { MutableRefObject } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import type { Props as FormProps } from '@/app/components/workflow/nodes/_base/components/before-run-form/form' 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 InputVar, InputVarType, type Variable } from '@/app/components/workflow/types'
import type { StartNodeType } from './types' import type { StartNodeType } from './types'
import { useIsChatMode } from '../../hooks' import { useIsChatMode } from '../../hooks'
@ -15,6 +16,7 @@ type Params = {
toVarInputs: (variables: Variable[]) => InputVar[] toVarInputs: (variables: Variable[]) => InputVar[]
} }
const useSingleRunFormParams = ({ const useSingleRunFormParams = ({
id,
payload, payload,
runInputData, runInputData,
setRunInputData, setRunInputData,
@ -24,12 +26,12 @@ const useSingleRunFormParams = ({
const forms = (() => { const forms = (() => {
const forms: FormProps[] = [] const forms: FormProps[] = []
const inputs = payload.variables.map((item: InputVar) => ({ const inputs: InputVar[] = payload.variables.map((item) => {
label: item.variable, return {
variable: item.variable, ...item,
type: item.type, getVarValueFromDependent: true,
required: item.required, }
})) })
if (isChatMode) { if (isChatMode) {
inputs.push({ inputs.push({
@ -46,6 +48,7 @@ const useSingleRunFormParams = ({
type: InputVarType.multiFiles, type: InputVarType.multiFiles,
required: false, required: false,
}) })
forms.push( forms.push(
{ {
label: t('workflow.nodes.llm.singleRun.variable')!, label: t('workflow.nodes.llm.singleRun.variable')!,
@ -58,8 +61,26 @@ const useSingleRunFormParams = ({
return forms 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 { return {
forms, forms,
getDependentVars,
getDependentVar,
} }
} }

@ -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 { return {
forms, forms,
getDependentVars,
} }
} }

Loading…
Cancel
Save