This commit is contained in:
2025-12-01 17:21:38 +08:00
parent 32fee2b8ab
commit fab8c13cb3
7511 changed files with 996300 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
import type { NodeDefault } from '../../types'
import type { EndNodeType } from './types'
import { genNodeMetaData } from '@/app/components/workflow/utils'
import { BlockEnum } from '@/app/components/workflow/types'
const metaData = genNodeMetaData({
sort: 2.1,
type: BlockEnum.End,
isRequired: false,
})
const nodeDefault: NodeDefault<EndNodeType> = {
metaData,
defaultValue: {
outputs: [],
},
checkValid(payload: EndNodeType, t: any) {
const outputs = payload.outputs || []
let errorMessage = ''
if (!outputs.length) {
errorMessage = t('workflow.errorMsg.fieldRequired', { field: t('workflow.nodes.end.output.variable') })
}
else {
const invalidOutput = outputs.find((output) => {
const variableName = output.variable?.trim()
const hasSelector = Array.isArray(output.value_selector) && output.value_selector.length > 0
return !variableName || !hasSelector
})
if (invalidOutput)
errorMessage = t('workflow.errorMsg.fieldRequired', { field: t('workflow.nodes.end.output.variable') })
}
return {
isValid: !errorMessage,
errorMessage,
}
},
}
export default nodeDefault

View File

@@ -0,0 +1,63 @@
import type { FC } from 'react'
import React from 'react'
import type { EndNodeType } from './types'
import type { NodeProps, Variable } from '@/app/components/workflow/types'
import {
useIsChatMode,
useWorkflow,
useWorkflowVariables,
} from '@/app/components/workflow/hooks'
import { BlockEnum } from '@/app/components/workflow/types'
import {
VariableLabelInNode,
} from '@/app/components/workflow/nodes/_base/components/variable/variable-label'
const Node: FC<NodeProps<EndNodeType>> = ({
id,
data,
}) => {
const { getBeforeNodesInSameBranch } = useWorkflow()
const availableNodes = getBeforeNodesInSameBranch(id)
const { getCurrentVariableType } = useWorkflowVariables()
const isChatMode = useIsChatMode()
const startNode = availableNodes.find((node: any) => {
return node.data.type === BlockEnum.Start
})
const getNode = (id: string) => {
return availableNodes.find(node => node.id === id) || startNode
}
const { outputs } = data
const filteredOutputs = (outputs as Variable[]).filter(({ value_selector }) => value_selector.length > 0)
if (!filteredOutputs.length)
return null
return (
<div className='mb-1 space-y-0.5 px-3 py-1'>
{filteredOutputs.map(({ value_selector }, index) => {
const node = getNode(value_selector[0])
const varType = getCurrentVariableType({
valueSelector: value_selector,
availableNodes,
isChatMode,
})
return (
<VariableLabelInNode
key={index}
variables={value_selector}
nodeType={node?.data.type}
nodeTitle={node?.data.title}
variableType={varType}
/>
)
})}
</div>
)
}
export default React.memo(Node)

View File

@@ -0,0 +1,50 @@
import type { FC } from 'react'
import React from 'react'
import { useTranslation } from 'react-i18next'
import useConfig from './use-config'
import type { EndNodeType } from './types'
import VarList from '@/app/components/workflow/nodes/_base/components/variable/var-list'
import Field from '@/app/components/workflow/nodes/_base/components/field'
import AddButton from '@/app/components/base/button/add-button'
import type { NodePanelProps } from '@/app/components/workflow/types'
const i18nPrefix = 'workflow.nodes.end'
const Panel: FC<NodePanelProps<EndNodeType>> = ({
id,
data,
}) => {
const { t } = useTranslation()
const {
readOnly,
inputs,
handleVarListChange,
handleAddVariable,
} = useConfig(id, data)
const outputs = inputs.outputs
return (
<div className='mt-2'>
<div className='space-y-4 px-4 pb-4'>
<Field
title={t(`${i18nPrefix}.output.variable`)}
required
operations={
!readOnly ? <AddButton onClick={handleAddVariable} /> : undefined
}
>
<VarList
nodeId={id}
readonly={readOnly}
list={outputs}
onChange={handleVarListChange}
/>
</Field>
</div>
</div>
)
}
export default React.memo(Panel)

View File

@@ -0,0 +1,5 @@
import type { CommonNodeType, Variable } from '@/app/components/workflow/types'
export type EndNodeType = CommonNodeType & {
outputs: Variable[]
}

View File

@@ -0,0 +1,27 @@
import useVarList from '../_base/hooks/use-var-list'
import type { EndNodeType } from './types'
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
import {
useNodesReadOnly,
} from '@/app/components/workflow/hooks'
const useConfig = (id: string, payload: EndNodeType) => {
const { nodesReadOnly: readOnly } = useNodesReadOnly()
const { inputs, setInputs } = useNodeCrud<EndNodeType>(id, payload)
const { handleVarListChange, handleAddVariable } = useVarList<EndNodeType>({
inputs,
setInputs: (newInputs) => {
setInputs(newInputs)
},
varKey: 'outputs',
})
return {
readOnly,
inputs,
handleVarListChange,
handleAddVariable,
}
}
export default useConfig

View File

@@ -0,0 +1,5 @@
import type { EndNodeType } from './types'
export const checkNodeValid = (_payload: EndNodeType) => {
return true
}