mirror of
https://github.com/langgenius/dify.git
synced 2025-10-30 02:13:28 +00:00
fix: node default
This commit is contained in:
parent
2613a380b6
commit
66176c4d71
@ -0,0 +1,58 @@
|
||||
import { useState } from 'react'
|
||||
import { RiEditLine } from '@remixicon/react'
|
||||
import cn from '@/utils/classnames'
|
||||
import SegmentedControl from '@/app/components/base/segmented-control'
|
||||
import { VariableX } from '@/app/components/base/icons/src/vender/workflow'
|
||||
import type { LabelProps } from '../label'
|
||||
import Label from '../label'
|
||||
|
||||
type VariableOrConstantInputFieldProps = {
|
||||
label: string
|
||||
labelOptions?: Omit<LabelProps, 'htmlFor' | 'label'>
|
||||
className?: string
|
||||
}
|
||||
|
||||
const VariableOrConstantInputField = ({
|
||||
className,
|
||||
label,
|
||||
labelOptions,
|
||||
}: VariableOrConstantInputFieldProps) => {
|
||||
const [variableType, setVariableType] = useState('variable')
|
||||
|
||||
const options = [
|
||||
{
|
||||
Icon: VariableX,
|
||||
text: '',
|
||||
value: 'variable',
|
||||
},
|
||||
{
|
||||
Icon: RiEditLine,
|
||||
text: '',
|
||||
value: 'constant',
|
||||
},
|
||||
]
|
||||
|
||||
const handleVariableOrConstantChange = (value: string) => {
|
||||
setVariableType(value)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={cn('flex flex-col gap-y-0.5', className)}>
|
||||
<Label
|
||||
htmlFor={'variable-or-constant'}
|
||||
label={label}
|
||||
{...(labelOptions ?? {})}
|
||||
/>
|
||||
<div className='flex items-center'>
|
||||
<SegmentedControl
|
||||
className='mr-1 shrink-0'
|
||||
value={variableType}
|
||||
onChange={handleVariableOrConstantChange}
|
||||
options={options as any}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default VariableOrConstantInputField
|
||||
239
web/app/components/base/form/form-scenarios/node-panel/field.tsx
Normal file
239
web/app/components/base/form/form-scenarios/node-panel/field.tsx
Normal file
@ -0,0 +1,239 @@
|
||||
import React from 'react'
|
||||
import { type InputFieldConfiguration, InputFieldType } from './types'
|
||||
import { withForm } from '../..'
|
||||
import { useStore } from '@tanstack/react-form'
|
||||
|
||||
type InputFieldProps<T> = {
|
||||
initialData?: T
|
||||
config: InputFieldConfiguration<T>
|
||||
}
|
||||
|
||||
const NodePanelField = <T,>({
|
||||
initialData,
|
||||
config,
|
||||
}: InputFieldProps<T>) => withForm({
|
||||
defaultValues: initialData,
|
||||
render: function Render({
|
||||
form,
|
||||
}) {
|
||||
const {
|
||||
type,
|
||||
label,
|
||||
placeholder,
|
||||
variable,
|
||||
tooltip,
|
||||
showConditions,
|
||||
max,
|
||||
min,
|
||||
required,
|
||||
showOptional,
|
||||
supportFile,
|
||||
description,
|
||||
options,
|
||||
listeners,
|
||||
popupProps,
|
||||
} = config
|
||||
|
||||
const isAllConditionsMet = useStore(form.store, (state) => {
|
||||
const fieldValues = state.values
|
||||
return showConditions.every((condition) => {
|
||||
const { variable, value } = condition
|
||||
const fieldValue = fieldValues[variable as keyof typeof fieldValues]
|
||||
return fieldValue === value
|
||||
})
|
||||
})
|
||||
|
||||
if (!isAllConditionsMet)
|
||||
return <></>
|
||||
|
||||
if (type === InputFieldType.textInput) {
|
||||
return (
|
||||
<form.AppField
|
||||
name={variable}
|
||||
children={field => (
|
||||
<field.TextField
|
||||
label={label}
|
||||
labelOptions={{
|
||||
tooltip,
|
||||
isRequired: required,
|
||||
showOptional,
|
||||
}}
|
||||
placeholder={placeholder}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
if (type === InputFieldType.numberInput) {
|
||||
return (
|
||||
<form.AppField
|
||||
name={variable}
|
||||
children={field => (
|
||||
<field.NumberInputField
|
||||
label={label}
|
||||
labelOptions={{
|
||||
tooltip,
|
||||
isRequired: required,
|
||||
showOptional,
|
||||
}}
|
||||
placeholder={placeholder}
|
||||
max={max}
|
||||
min={min}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
if (type === InputFieldType.numberSlider) {
|
||||
return (
|
||||
<form.AppField
|
||||
name={variable}
|
||||
children={field => (
|
||||
<field.NumberSliderField
|
||||
label={label}
|
||||
labelOptions={{
|
||||
tooltip,
|
||||
isRequired: required,
|
||||
showOptional,
|
||||
}}
|
||||
description={description}
|
||||
max={max}
|
||||
min={min}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
if (type === InputFieldType.checkbox) {
|
||||
return (
|
||||
<form.AppField
|
||||
name={variable}
|
||||
children={field => (
|
||||
<field.CheckboxField
|
||||
label={label}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
if (type === InputFieldType.select) {
|
||||
return (
|
||||
<form.AppField
|
||||
name={variable}
|
||||
children={field => (
|
||||
<field.SelectField
|
||||
label={label}
|
||||
labelOptions={{
|
||||
tooltip,
|
||||
isRequired: required,
|
||||
showOptional,
|
||||
}}
|
||||
options={options!}
|
||||
popupProps={popupProps}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
if (type === InputFieldType.inputTypeSelect) {
|
||||
return (
|
||||
<form.AppField
|
||||
name={variable}
|
||||
listeners={listeners}
|
||||
children={field => (
|
||||
<field.InputTypeSelectField
|
||||
label={label}
|
||||
labelOptions={{
|
||||
tooltip,
|
||||
isRequired: required,
|
||||
showOptional,
|
||||
}}
|
||||
supportFile={!!supportFile}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
if (type === InputFieldType.uploadMethod) {
|
||||
return (
|
||||
<form.AppField
|
||||
name={variable}
|
||||
children={field => (
|
||||
<field.UploadMethodField
|
||||
label={label}
|
||||
labelOptions={{
|
||||
tooltip,
|
||||
isRequired: required,
|
||||
showOptional,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
if (type === InputFieldType.fileTypes) {
|
||||
return (
|
||||
<form.AppField
|
||||
name={variable}
|
||||
children={field => (
|
||||
<field.FileTypesField
|
||||
label={label}
|
||||
labelOptions={{
|
||||
tooltip,
|
||||
isRequired: required,
|
||||
showOptional,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
if (type === InputFieldType.options) {
|
||||
return (
|
||||
<form.AppField
|
||||
name={variable}
|
||||
children={field => (
|
||||
<field.OptionsField
|
||||
label={label}
|
||||
labelOptions={{
|
||||
tooltip,
|
||||
isRequired: required,
|
||||
showOptional,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
if (type === InputFieldType.variableOrConstant) {
|
||||
return (
|
||||
<form.AppField
|
||||
name={variable}
|
||||
children={field => (
|
||||
<field.VariableOrConstantInputField
|
||||
label={label}
|
||||
labelOptions={{
|
||||
tooltip,
|
||||
isRequired: required,
|
||||
showOptional,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
return <></>
|
||||
},
|
||||
})
|
||||
|
||||
export default NodePanelField
|
||||
@ -0,0 +1,40 @@
|
||||
import type { DeepKeys, FieldListeners } from '@tanstack/react-form'
|
||||
import type { NumberConfiguration, SelectConfiguration, ShowCondition } from '../base/types'
|
||||
|
||||
export enum InputFieldType {
|
||||
textInput = 'textInput',
|
||||
numberInput = 'numberInput',
|
||||
numberSlider = 'numberSlider',
|
||||
checkbox = 'checkbox',
|
||||
options = 'options',
|
||||
select = 'select',
|
||||
inputTypeSelect = 'inputTypeSelect',
|
||||
uploadMethod = 'uploadMethod',
|
||||
fileTypes = 'fileTypes',
|
||||
variableOrConstant = 'variableOrConstant',
|
||||
}
|
||||
|
||||
export type InputTypeSelectConfiguration = {
|
||||
supportFile: boolean
|
||||
}
|
||||
|
||||
export type NumberSliderConfiguration = {
|
||||
description: string
|
||||
max?: number
|
||||
min?: number
|
||||
}
|
||||
|
||||
export type InputFieldConfiguration<T> = {
|
||||
label: string
|
||||
variable: DeepKeys<T> // Variable name
|
||||
maxLength?: number // Max length for text input
|
||||
placeholder?: string
|
||||
required: boolean
|
||||
showOptional?: boolean // show optional label
|
||||
showConditions: ShowCondition<T>[] // Show this field only when all conditions are met
|
||||
type: InputFieldType
|
||||
tooltip?: string // Tooltip for this field
|
||||
listeners?: FieldListeners<T, DeepKeys<T>> // Listener for this field
|
||||
} & NumberConfiguration & Partial<InputTypeSelectConfiguration>
|
||||
& Partial<NumberSliderConfiguration>
|
||||
& Partial<SelectConfiguration>
|
||||
@ -2,6 +2,7 @@ import { useMemo } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useGetLanguage } from '@/context/i18n'
|
||||
import knowledgeBaseDefault from '@/app/components/workflow/nodes/knowledge-base/default'
|
||||
import dataSourceDefault from '@/app/components/workflow/nodes/data-source/default'
|
||||
import { WORKFLOW_COMMON_NODES } from '@/app/components/workflow/constants/node'
|
||||
import type { AvailableNodesMetaData } from '@/app/components/workflow/hooks-store/store'
|
||||
|
||||
@ -12,6 +13,7 @@ export const useAvailableNodesMetaData = () => {
|
||||
const mergedNodesMetaData = useMemo(() => [
|
||||
...WORKFLOW_COMMON_NODES,
|
||||
knowledgeBaseDefault,
|
||||
dataSourceDefault,
|
||||
], [])
|
||||
|
||||
const prefixLink = useMemo(() => {
|
||||
@ -22,21 +24,27 @@ export const useAvailableNodesMetaData = () => {
|
||||
}, [language])
|
||||
|
||||
const availableNodesMetaData = useMemo(() => mergedNodesMetaData.map((node) => {
|
||||
const { metaData } = node
|
||||
const title = t(`workflow.blocks.${metaData.type}`)
|
||||
const description = t(`workflow.blocksAbout.${metaData.type}`)
|
||||
return {
|
||||
...node,
|
||||
metaData: {
|
||||
...metaData,
|
||||
title,
|
||||
description,
|
||||
helpLinkUri: `${prefixLink}${metaData.helpLinkUri}`,
|
||||
},
|
||||
defaultValue: {
|
||||
...node.defaultValue,
|
||||
type: node.type,
|
||||
type: metaData.type,
|
||||
title,
|
||||
},
|
||||
title: t(`workflow.blocks.${node.type}`),
|
||||
description: t(`workflow.blocksAbout.${node.type}`),
|
||||
helpLinkUri: `${prefixLink}${node.helpLinkUri}`,
|
||||
|
||||
}
|
||||
}), [mergedNodesMetaData, t, prefixLink])
|
||||
|
||||
const availableNodesMetaDataMap = useMemo(() => availableNodesMetaData.reduce((acc, node) => {
|
||||
acc![node.type] = node
|
||||
acc![node.metaData.type] = node
|
||||
return acc
|
||||
}, {} as AvailableNodesMetaData['nodesMap']), [availableNodesMetaData])
|
||||
|
||||
|
||||
@ -3,21 +3,38 @@ import {
|
||||
WorkflowContextProvider,
|
||||
} from '@/app/components/workflow/context'
|
||||
import type { InjectWorkflowStoreSliceFn } from '@/app/components/workflow/store'
|
||||
import { generateNewNode } from '@/app/components/workflow/utils'
|
||||
import dataSourceNodeDefault from '@/app/components/workflow/nodes/data-source/default'
|
||||
import {
|
||||
NODE_WIDTH_X_OFFSET,
|
||||
START_INITIAL_POSITION,
|
||||
} from '@/app/components/workflow/constants'
|
||||
import { createRagPipelineSliceSlice } from './store'
|
||||
import RagPipelineMain from './components/rag-pipeline-main'
|
||||
|
||||
const RagPipeline = () => {
|
||||
const { newNode: DataSourceNode } = generateNewNode({
|
||||
data: {
|
||||
type: dataSourceNodeDefault.metaData.type,
|
||||
title: 'data-source',
|
||||
...dataSourceNodeDefault.defaultValue,
|
||||
},
|
||||
position: {
|
||||
x: START_INITIAL_POSITION.x + NODE_WIDTH_X_OFFSET,
|
||||
y: START_INITIAL_POSITION.y,
|
||||
},
|
||||
} as any)
|
||||
return (
|
||||
<WorkflowContextProvider
|
||||
injectWorkflowStoreSliceFn={createRagPipelineSliceSlice as InjectWorkflowStoreSliceFn}
|
||||
>
|
||||
<WorkflowWithDefaultContext
|
||||
edges={[]}
|
||||
nodes={[]}
|
||||
nodes={[DataSourceNode]}
|
||||
>
|
||||
<RagPipelineMain
|
||||
edges={[]}
|
||||
nodes={[]}
|
||||
nodes={[DataSourceNode]}
|
||||
/>
|
||||
</WorkflowWithDefaultContext>
|
||||
</WorkflowContextProvider>
|
||||
|
||||
@ -31,21 +31,27 @@ export const useAvailableNodesMetaData = () => {
|
||||
}, [language])
|
||||
|
||||
const availableNodesMetaData = useMemo(() => mergedNodesMetaData.map((node) => {
|
||||
const { metaData } = node
|
||||
const title = t(`workflow.blocks.${metaData.type}`)
|
||||
const description = t(`workflow.blocksAbout.${metaData.type}`)
|
||||
return {
|
||||
...node,
|
||||
metaData: {
|
||||
...metaData,
|
||||
title,
|
||||
description,
|
||||
helpLinkUri: `${prefixLink}${metaData.helpLinkUri}`,
|
||||
},
|
||||
defaultValue: {
|
||||
...node.defaultValue,
|
||||
type: node.type,
|
||||
type: metaData.type,
|
||||
title,
|
||||
},
|
||||
title: t(`workflow.blocks.${node.type}`),
|
||||
description: t(`workflow.blocksAbout.${node.type}`),
|
||||
helpLinkUri: `${prefixLink}${node.helpLinkUri}`,
|
||||
|
||||
}
|
||||
}), [mergedNodesMetaData, t, prefixLink])
|
||||
|
||||
const availableNodesMetaDataMap = useMemo(() => availableNodesMetaData.reduce((acc, node) => {
|
||||
acc![node.type] = node
|
||||
acc![node.metaData.type] = node
|
||||
return acc
|
||||
}, {} as AvailableNodesMetaData['nodesMap']), [availableNodesMetaData])
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { generateNewNode } from '@/app/components/workflow/utils'
|
||||
import {
|
||||
NODE_WIDTH_X_OFFSET,
|
||||
@ -11,9 +12,14 @@ import answerDefault from '@/app/components/workflow/nodes/answer/default'
|
||||
|
||||
export const useWorkflowTemplate = () => {
|
||||
const isChatMode = useIsChatMode()
|
||||
const { t } = useTranslation()
|
||||
|
||||
const { newNode: startNode } = generateNewNode({
|
||||
data: startDefault.defaultValue as StartNodeType,
|
||||
data: {
|
||||
...startDefault.defaultValue as StartNodeType,
|
||||
type: startDefault.metaData.type,
|
||||
title: t(`workflow.blocks.${startDefault.metaData.type}`),
|
||||
},
|
||||
position: START_INITIAL_POSITION,
|
||||
})
|
||||
|
||||
@ -27,6 +33,8 @@ export const useWorkflowTemplate = () => {
|
||||
query_prompt_template: '{{#sys.query#}}',
|
||||
},
|
||||
selected: true,
|
||||
type: llmDefault.metaData.type,
|
||||
title: t(`workflow.blocks.${llmDefault.metaData.type}`),
|
||||
},
|
||||
position: {
|
||||
x: START_INITIAL_POSITION.x + NODE_WIDTH_X_OFFSET,
|
||||
@ -39,6 +47,8 @@ export const useWorkflowTemplate = () => {
|
||||
data: {
|
||||
...answerDefault.defaultValue,
|
||||
answer: `{{#${llmNode.id}.text#}}`,
|
||||
type: answerDefault.metaData.type,
|
||||
title: t(`workflow.blocks.${answerDefault.metaData.type}`),
|
||||
},
|
||||
position: {
|
||||
x: START_INITIAL_POSITION.x + NODE_WIDTH_X_OFFSET * 2,
|
||||
|
||||
@ -19,7 +19,7 @@ export const useAvailableBlocks = (nodeType?: BlockEnum, inContainer?: boolean)
|
||||
const {
|
||||
nodes: availableNodes,
|
||||
} = useNodesMetaData()
|
||||
const availableNodesType = useMemo(() => availableNodes.map(node => node.type), [availableNodes])
|
||||
const availableNodesType = useMemo(() => availableNodes.map(node => node.metaData.type), [availableNodes])
|
||||
const availablePrevBlocks = useMemo(() => {
|
||||
if (!nodeType || nodeType === BlockEnum.Start)
|
||||
return []
|
||||
|
||||
@ -685,7 +685,6 @@ export const useNodesInteractions = () => {
|
||||
const nodesWithSameType = nodes.filter(node => node.data.type === nodeType)
|
||||
const {
|
||||
defaultValue,
|
||||
title,
|
||||
} = nodesMetaDataMap![nodeType]
|
||||
const {
|
||||
newNode,
|
||||
@ -695,7 +694,7 @@ export const useNodesInteractions = () => {
|
||||
type: getNodeCustomTypeByNodeDataType(nodeType),
|
||||
data: {
|
||||
...(defaultValue as any),
|
||||
title: nodesWithSameType.length > 0 ? `${title} ${nodesWithSameType.length + 1}` : title,
|
||||
title: nodesWithSameType.length > 0 ? `${defaultValue.title} ${nodesWithSameType.length + 1}` : defaultValue.title,
|
||||
...(toolDefaultValue || {}),
|
||||
selected: true,
|
||||
_showAddVariablePopup: (nodeType === BlockEnum.VariableAssigner || nodeType === BlockEnum.VariableAggregator) && !!prevNodeId,
|
||||
@ -1121,7 +1120,6 @@ export const useNodesInteractions = () => {
|
||||
const nodesWithSameType = nodes.filter(node => node.data.type === nodeType)
|
||||
const {
|
||||
defaultValue,
|
||||
title,
|
||||
} = nodesMetaDataMap![nodeType]
|
||||
const {
|
||||
newNode: newCurrentNode,
|
||||
@ -1131,7 +1129,7 @@ export const useNodesInteractions = () => {
|
||||
type: getNodeCustomTypeByNodeDataType(nodeType),
|
||||
data: {
|
||||
...(defaultValue as any),
|
||||
title: nodesWithSameType.length > 0 ? `${title} ${nodesWithSameType.length + 1}` : title,
|
||||
title: nodesWithSameType.length > 0 ? `${defaultValue.title} ${nodesWithSameType.length + 1}` : defaultValue.title,
|
||||
...(toolDefaultValue || {}),
|
||||
_connectedSourceHandleIds: [],
|
||||
_connectedTargetHandleIds: [],
|
||||
|
||||
@ -55,7 +55,7 @@ const PanelOperatorPopup = ({
|
||||
const edge = edges.find(edge => edge.target === id)
|
||||
const author = useMemo(() => {
|
||||
if (data.type !== BlockEnum.Tool)
|
||||
return nodesExtraData![data.type].author
|
||||
return nodesExtraData![data.type].metaData.author
|
||||
|
||||
if (data.provider_type === CollectionType.builtIn)
|
||||
return buildInTools.find(toolWithProvider => canFindTool(toolWithProvider.id, data.provider_id))?.author
|
||||
@ -68,7 +68,7 @@ const PanelOperatorPopup = ({
|
||||
|
||||
const about = useMemo(() => {
|
||||
if (data.type !== BlockEnum.Tool)
|
||||
return nodesExtraData![data.type].description
|
||||
return nodesExtraData![data.type].metaData.description
|
||||
|
||||
if (data.provider_type === CollectionType.builtIn)
|
||||
return buildInTools.find(toolWithProvider => canFindTool(toolWithProvider.id, data.provider_id))?.description[language]
|
||||
|
||||
@ -6,7 +6,7 @@ export const useNodeHelpLink = (nodeType: BlockEnum) => {
|
||||
const availableNodesMetaData = useNodesMetaData()
|
||||
|
||||
const link = useMemo(() => {
|
||||
const result = availableNodesMetaData?.nodesMap?.[nodeType]?.helpLinkUri || ''
|
||||
const result = availableNodesMetaData?.nodesMap?.[nodeType]?.metaData.helpLinkUri || ''
|
||||
|
||||
return result
|
||||
}, [availableNodesMetaData, nodeType])
|
||||
|
||||
@ -6,13 +6,13 @@ import { renderI18nObject } from '@/i18n'
|
||||
import { genNodeMetaData } from '@/app/components/workflow/utils'
|
||||
import { BlockEnum } from '@/app/components/workflow/types'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
sort: 3,
|
||||
type: BlockEnum.Agent,
|
||||
})
|
||||
const nodeDefault: NodeDefault<AgentNodeType> = {
|
||||
...genNodeMetaData({
|
||||
sort: 3,
|
||||
type: BlockEnum.Agent,
|
||||
}),
|
||||
defaultValue: {
|
||||
},
|
||||
metaData,
|
||||
defaultValue: {},
|
||||
checkValid(payload, t, moreDataForCheckValid: {
|
||||
strategyProvider?: StrategyPluginDetail,
|
||||
strategy?: StrategyDetail
|
||||
|
||||
@ -3,11 +3,12 @@ import type { AnswerNodeType } from './types'
|
||||
import { genNodeMetaData } from '@/app/components/workflow/utils'
|
||||
import { BlockEnum } from '@/app/components/workflow/types'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
sort: 2.1,
|
||||
type: BlockEnum.Answer,
|
||||
})
|
||||
const nodeDefault: NodeDefault<AnswerNodeType> = {
|
||||
...genNodeMetaData({
|
||||
sort: 2.1,
|
||||
type: BlockEnum.Answer,
|
||||
}),
|
||||
metaData,
|
||||
defaultValue: {
|
||||
variables: [],
|
||||
answer: '',
|
||||
|
||||
@ -5,13 +5,14 @@ import { BlockEnum } from '@/app/components/workflow/types'
|
||||
import { BlockClassificationEnum } from '@/app/components/workflow/block-selector/types'
|
||||
const i18nPrefix = 'workflow.errorMsg'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Transform,
|
||||
sort: 5,
|
||||
type: BlockEnum.Assigner,
|
||||
helpLinkUri: 'variable-assigner',
|
||||
})
|
||||
const nodeDefault: NodeDefault<AssignerNodeType> = {
|
||||
...genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Transform,
|
||||
sort: 5,
|
||||
type: BlockEnum.Assigner,
|
||||
helpLinkUri: 'variable-assigner',
|
||||
}),
|
||||
metaData,
|
||||
defaultValue: {
|
||||
version: '2',
|
||||
items: [],
|
||||
|
||||
@ -6,12 +6,13 @@ import { BlockClassificationEnum } from '@/app/components/workflow/block-selecto
|
||||
|
||||
const i18nPrefix = 'workflow.errorMsg'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Transform,
|
||||
sort: 1,
|
||||
type: BlockEnum.Code,
|
||||
})
|
||||
const nodeDefault: NodeDefault<CodeNodeType> = {
|
||||
...genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Transform,
|
||||
sort: 1,
|
||||
type: BlockEnum.Code,
|
||||
}),
|
||||
metaData,
|
||||
defaultValue: {
|
||||
code: '',
|
||||
code_language: CodeLanguage.python3,
|
||||
|
||||
@ -3,13 +3,13 @@ import type { DataSourceNodeType } from './types'
|
||||
import { genNodeMetaData } from '@/app/components/workflow/utils'
|
||||
import { BlockEnum } from '@/app/components/workflow/types'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
sort: -1,
|
||||
type: BlockEnum.DataSource,
|
||||
})
|
||||
const nodeDefault: NodeDefault<DataSourceNodeType> = {
|
||||
...genNodeMetaData({
|
||||
sort: -1,
|
||||
type: BlockEnum.DataSource,
|
||||
}),
|
||||
defaultValue: {
|
||||
},
|
||||
metaData,
|
||||
defaultValue: {},
|
||||
checkValid() {
|
||||
return {
|
||||
isValid: true,
|
||||
|
||||
@ -2,11 +2,15 @@ import type { FC } from 'react'
|
||||
import { memo } from 'react'
|
||||
import type { DataSourceNodeType } from './types'
|
||||
import type { NodePanelProps } from '@/app/components/workflow/types'
|
||||
import VariableOrConstantInputField from '@/app/components/base/form/components/field/variable-or-constant-input'
|
||||
|
||||
const Panel: FC<NodePanelProps<DataSourceNodeType>> = () => {
|
||||
return (
|
||||
<div className='mb-2 mt-2 space-y-4 px-4'>
|
||||
datasource
|
||||
<VariableOrConstantInputField
|
||||
label='Parent maximum chunk length'
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@ -5,13 +5,14 @@ import { BlockEnum } from '@/app/components/workflow/types'
|
||||
import { BlockClassificationEnum } from '@/app/components/workflow/block-selector/types'
|
||||
const i18nPrefix = 'workflow.errorMsg'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Transform,
|
||||
sort: 4,
|
||||
type: BlockEnum.DocExtractor,
|
||||
helpLinkUri: 'doc-extractor',
|
||||
})
|
||||
const nodeDefault: NodeDefault<DocExtractorNodeType> = {
|
||||
...genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Transform,
|
||||
sort: 4,
|
||||
type: BlockEnum.DocExtractor,
|
||||
helpLinkUri: 'doc-extractor',
|
||||
}),
|
||||
metaData,
|
||||
defaultValue: {
|
||||
variable_selector: [],
|
||||
is_array_file: false,
|
||||
|
||||
@ -3,11 +3,12 @@ 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,
|
||||
})
|
||||
const nodeDefault: NodeDefault<EndNodeType> = {
|
||||
...genNodeMetaData({
|
||||
sort: 2.1,
|
||||
type: BlockEnum.End,
|
||||
}),
|
||||
metaData,
|
||||
defaultValue: {
|
||||
outputs: [],
|
||||
},
|
||||
|
||||
@ -5,12 +5,13 @@ import { genNodeMetaData } from '@/app/components/workflow/utils'
|
||||
import { BlockEnum } from '@/app/components/workflow/types'
|
||||
import { BlockClassificationEnum } from '@/app/components/workflow/block-selector/types'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Utilities,
|
||||
sort: 1,
|
||||
type: BlockEnum.HttpRequest,
|
||||
})
|
||||
const nodeDefault: NodeDefault<HttpNodeType> = {
|
||||
...genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Utilities,
|
||||
sort: 1,
|
||||
type: BlockEnum.HttpRequest,
|
||||
}),
|
||||
metaData,
|
||||
defaultValue: {
|
||||
variables: [],
|
||||
method: Method.get,
|
||||
|
||||
@ -6,13 +6,14 @@ import { BlockEnum } from '@/app/components/workflow/types'
|
||||
import { BlockClassificationEnum } from '@/app/components/workflow/block-selector/types'
|
||||
const i18nPrefix = 'workflow.errorMsg'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Logic,
|
||||
sort: 1,
|
||||
type: BlockEnum.IfElse,
|
||||
helpLinkUri: 'ifelse',
|
||||
})
|
||||
const nodeDefault: NodeDefault<IfElseNodeType> = {
|
||||
...genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Logic,
|
||||
sort: 1,
|
||||
type: BlockEnum.IfElse,
|
||||
helpLinkUri: 'ifelse',
|
||||
}),
|
||||
metaData,
|
||||
defaultValue: {
|
||||
_targetBranches: [
|
||||
{
|
||||
|
||||
@ -3,11 +3,12 @@ import type { IterationStartNodeType } from './types'
|
||||
import { genNodeMetaData } from '@/app/components/workflow/utils'
|
||||
import { BlockEnum } from '@/app/components/workflow/types'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
sort: -1,
|
||||
type: BlockEnum.IterationStart,
|
||||
})
|
||||
const nodeDefault: NodeDefault<IterationStartNodeType> = {
|
||||
...genNodeMetaData({
|
||||
sort: -1,
|
||||
type: BlockEnum.IterationStart,
|
||||
}),
|
||||
metaData,
|
||||
defaultValue: {},
|
||||
checkValid() {
|
||||
return {
|
||||
|
||||
@ -6,12 +6,13 @@ import { BlockEnum } from '@/app/components/workflow/types'
|
||||
import { BlockClassificationEnum } from '@/app/components/workflow/block-selector/types'
|
||||
const i18nPrefix = 'workflow'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Logic,
|
||||
sort: 2,
|
||||
type: BlockEnum.Iteration,
|
||||
})
|
||||
const nodeDefault: NodeDefault<IterationNodeType> = {
|
||||
...genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Logic,
|
||||
sort: 2,
|
||||
type: BlockEnum.Iteration,
|
||||
}),
|
||||
metaData,
|
||||
defaultValue: {
|
||||
start_node_id: '',
|
||||
iterator_selector: [],
|
||||
|
||||
@ -129,6 +129,7 @@ export const useNodeIterationInteractions = () => {
|
||||
_connectedTargetHandleIds: [],
|
||||
title: nodesWithSameType.length > 0 ? `${t(`workflow.blocks.${childNodeType}`)} ${nodesWithSameType.length + 1}` : t(`workflow.blocks.${childNodeType}`),
|
||||
iteration_id: newNodeId,
|
||||
type: childNodeType,
|
||||
},
|
||||
position: child.position,
|
||||
positionAbsolute: child.positionAbsolute,
|
||||
|
||||
@ -3,13 +3,13 @@ import type { KnowledgeBaseNodeType } from './types'
|
||||
import { genNodeMetaData } from '@/app/components/workflow/utils'
|
||||
import { BlockEnum } from '@/app/components/workflow/types'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
sort: 3.1,
|
||||
type: BlockEnum.KnowledgeBase,
|
||||
})
|
||||
const nodeDefault: NodeDefault<KnowledgeBaseNodeType> = {
|
||||
...genNodeMetaData({
|
||||
sort: 3.1,
|
||||
type: BlockEnum.KnowledgeBase,
|
||||
}),
|
||||
defaultValue: {
|
||||
},
|
||||
metaData,
|
||||
defaultValue: {},
|
||||
checkValid() {
|
||||
return {
|
||||
isValid: true,
|
||||
|
||||
@ -7,11 +7,12 @@ import { genNodeMetaData } from '@/app/components/workflow/utils'
|
||||
import { BlockEnum } from '@/app/components/workflow/types'
|
||||
const i18nPrefix = 'workflow'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
sort: 2,
|
||||
type: BlockEnum.KnowledgeRetrieval,
|
||||
})
|
||||
const nodeDefault: NodeDefault<KnowledgeRetrievalNodeType> = {
|
||||
...genNodeMetaData({
|
||||
sort: 2,
|
||||
type: BlockEnum.KnowledgeRetrieval,
|
||||
}),
|
||||
metaData,
|
||||
defaultValue: {
|
||||
query_variable_selector: [],
|
||||
dataset_ids: [],
|
||||
|
||||
@ -7,12 +7,13 @@ import { BlockEnum } from '@/app/components/workflow/types'
|
||||
import { BlockClassificationEnum } from '@/app/components/workflow/block-selector/types'
|
||||
const i18nPrefix = 'workflow.errorMsg'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Utilities,
|
||||
sort: 2,
|
||||
type: BlockEnum.ListFilter,
|
||||
})
|
||||
const nodeDefault: NodeDefault<ListFilterNodeType> = {
|
||||
...genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Utilities,
|
||||
sort: 2,
|
||||
type: BlockEnum.ListFilter,
|
||||
}),
|
||||
metaData,
|
||||
defaultValue: {
|
||||
variable: [],
|
||||
filter_by: {
|
||||
|
||||
@ -6,11 +6,12 @@ import { BlockEnum } from '@/app/components/workflow/types'
|
||||
|
||||
const i18nPrefix = 'workflow.errorMsg'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
sort: 1,
|
||||
type: BlockEnum.LLM,
|
||||
})
|
||||
const nodeDefault: NodeDefault<LLMNodeType> = {
|
||||
...genNodeMetaData({
|
||||
sort: 1,
|
||||
type: BlockEnum.LLM,
|
||||
}),
|
||||
metaData,
|
||||
defaultValue: {
|
||||
model: {
|
||||
provider: '',
|
||||
|
||||
@ -6,12 +6,13 @@ import { genNodeMetaData } from '@/app/components/workflow/utils'
|
||||
import { BlockEnum } from '@/app/components/workflow/types'
|
||||
import { BlockClassificationEnum } from '@/app/components/workflow/block-selector/types'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Logic,
|
||||
sort: 2,
|
||||
type: BlockEnum.LoopEnd,
|
||||
})
|
||||
const nodeDefault: NodeDefault<SimpleNodeType> = {
|
||||
...genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Logic,
|
||||
sort: 2,
|
||||
type: BlockEnum.LoopEnd,
|
||||
}),
|
||||
metaData,
|
||||
defaultValue: {},
|
||||
checkValid() {
|
||||
return {
|
||||
|
||||
@ -3,11 +3,12 @@ import type { LoopStartNodeType } from './types'
|
||||
import { genNodeMetaData } from '@/app/components/workflow/utils'
|
||||
import { BlockEnum } from '@/app/components/workflow/types'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
sort: -1,
|
||||
type: BlockEnum.LoopStart,
|
||||
})
|
||||
const nodeDefault: NodeDefault<LoopStartNodeType> = {
|
||||
...genNodeMetaData({
|
||||
sort: -1,
|
||||
type: BlockEnum.LoopStart,
|
||||
}),
|
||||
metaData,
|
||||
defaultValue: {},
|
||||
checkValid() {
|
||||
return {
|
||||
|
||||
@ -8,13 +8,14 @@ import { BlockEnum } from '@/app/components/workflow/types'
|
||||
import { BlockClassificationEnum } from '@/app/components/workflow/block-selector/types'
|
||||
const i18nPrefix = 'workflow.errorMsg'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Logic,
|
||||
sort: 3,
|
||||
type: BlockEnum.Loop,
|
||||
author: 'AICT-Team',
|
||||
})
|
||||
const nodeDefault: NodeDefault<LoopNodeType> = {
|
||||
...genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Logic,
|
||||
sort: 3,
|
||||
type: BlockEnum.Loop,
|
||||
// author: 'AICT-Team',
|
||||
}),
|
||||
metaData,
|
||||
defaultValue: {
|
||||
start_node_id: '',
|
||||
break_conditions: [],
|
||||
|
||||
@ -116,7 +116,6 @@ export const useNodeLoopInteractions = () => {
|
||||
const childNodeType = child.data.type as BlockEnum
|
||||
const {
|
||||
defaultValue,
|
||||
title,
|
||||
} = nodesMetaDataMap![childNodeType]
|
||||
const nodesWithSameType = nodes.filter(node => node.data.type === childNodeType)
|
||||
const { newNode } = generateNewNode({
|
||||
@ -128,7 +127,7 @@ export const useNodeLoopInteractions = () => {
|
||||
_isBundled: false,
|
||||
_connectedSourceHandleIds: [],
|
||||
_connectedTargetHandleIds: [],
|
||||
title: nodesWithSameType.length > 0 ? `${title} ${nodesWithSameType.length + 1}` : title,
|
||||
title: nodesWithSameType.length > 0 ? `${defaultValue.title} ${nodesWithSameType.length + 1}` : defaultValue.title,
|
||||
loop_id: newNodeId,
|
||||
|
||||
},
|
||||
|
||||
@ -5,12 +5,13 @@ import { BlockEnum } from '@/app/components/workflow/types'
|
||||
import { BlockClassificationEnum } from '@/app/components/workflow/block-selector/types'
|
||||
const i18nPrefix = 'workflow'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Transform,
|
||||
sort: 6,
|
||||
type: BlockEnum.ParameterExtractor,
|
||||
})
|
||||
const nodeDefault: NodeDefault<ParameterExtractorNodeType> = {
|
||||
...genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Transform,
|
||||
sort: 6,
|
||||
type: BlockEnum.ParameterExtractor,
|
||||
}),
|
||||
metaData,
|
||||
defaultValue: {
|
||||
query: [],
|
||||
model: {
|
||||
|
||||
@ -6,12 +6,13 @@ import { BlockClassificationEnum } from '@/app/components/workflow/block-selecto
|
||||
|
||||
const i18nPrefix = 'workflow'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
classification: BlockClassificationEnum.QuestionUnderstand,
|
||||
sort: 1,
|
||||
type: BlockEnum.QuestionClassifier,
|
||||
})
|
||||
const nodeDefault: NodeDefault<QuestionClassifierNodeType> = {
|
||||
...genNodeMetaData({
|
||||
classification: BlockClassificationEnum.QuestionUnderstand,
|
||||
sort: 1,
|
||||
type: BlockEnum.QuestionClassifier,
|
||||
}),
|
||||
metaData,
|
||||
defaultValue: {
|
||||
query_variable_selector: [],
|
||||
model: {
|
||||
|
||||
@ -3,11 +3,12 @@ import type { StartNodeType } from './types'
|
||||
import { genNodeMetaData } from '@/app/components/workflow/utils'
|
||||
import { BlockEnum } from '@/app/components/workflow/types'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
sort: 0.1,
|
||||
type: BlockEnum.Start,
|
||||
})
|
||||
const nodeDefault: NodeDefault<StartNodeType> = {
|
||||
...genNodeMetaData({
|
||||
sort: 0.1,
|
||||
type: BlockEnum.Start,
|
||||
}),
|
||||
metaData,
|
||||
defaultValue: {
|
||||
variables: [],
|
||||
},
|
||||
|
||||
@ -5,13 +5,14 @@ import { BlockEnum } from '@/app/components/workflow/types'
|
||||
import { BlockClassificationEnum } from '@/app/components/workflow/block-selector/types'
|
||||
const i18nPrefix = 'workflow.errorMsg'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Transform,
|
||||
sort: 2,
|
||||
type: BlockEnum.TemplateTransform,
|
||||
helpLinkUri: 'template',
|
||||
})
|
||||
const nodeDefault: NodeDefault<TemplateTransformNodeType> = {
|
||||
...genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Transform,
|
||||
sort: 2,
|
||||
type: BlockEnum.TemplateTransform,
|
||||
helpLinkUri: 'template',
|
||||
}),
|
||||
metaData,
|
||||
defaultValue: {
|
||||
template: '',
|
||||
variables: [],
|
||||
|
||||
@ -6,12 +6,13 @@ import { BlockEnum } from '@/app/components/workflow/types'
|
||||
|
||||
const i18nPrefix = 'workflow.errorMsg'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
sort: -1,
|
||||
type: BlockEnum.Tool,
|
||||
helpLinkUri: 'tools',
|
||||
})
|
||||
const nodeDefault: NodeDefault<ToolNodeType> = {
|
||||
...genNodeMetaData({
|
||||
sort: -1,
|
||||
type: BlockEnum.Tool,
|
||||
helpLinkUri: 'tools',
|
||||
}),
|
||||
metaData,
|
||||
defaultValue: {
|
||||
tool_parameters: {},
|
||||
tool_configurations: {},
|
||||
|
||||
@ -6,12 +6,13 @@ import { BlockClassificationEnum } from '@/app/components/workflow/block-selecto
|
||||
|
||||
const i18nPrefix = 'workflow'
|
||||
|
||||
const metaData = genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Transform,
|
||||
sort: 3,
|
||||
type: BlockEnum.VariableAggregator,
|
||||
})
|
||||
const nodeDefault: NodeDefault<VariableAssignerNodeType> = {
|
||||
...genNodeMetaData({
|
||||
classification: BlockClassificationEnum.Transform,
|
||||
sort: 3,
|
||||
type: BlockEnum.VariableAggregator,
|
||||
}),
|
||||
metaData,
|
||||
defaultValue: {
|
||||
output_type: VarType.any,
|
||||
variables: [],
|
||||
|
||||
@ -59,13 +59,12 @@ const AddBlock = ({
|
||||
const nodesWithSameType = nodes.filter(node => node.data.type === type)
|
||||
const {
|
||||
defaultValue,
|
||||
title,
|
||||
} = nodesMetaDataMap![type]
|
||||
const { newNode } = generateNewNode({
|
||||
type: getNodeCustomTypeByNodeDataType(type),
|
||||
data: {
|
||||
...(defaultValue as any),
|
||||
title: nodesWithSameType.length > 0 ? `${title} ${nodesWithSameType.length + 1}` : title,
|
||||
title: nodesWithSameType.length > 0 ? `${defaultValue.title} ${nodesWithSameType.length + 1}` : defaultValue.title,
|
||||
...(toolDefaultValue || {}),
|
||||
_isCandidate: true,
|
||||
},
|
||||
|
||||
@ -292,13 +292,15 @@ export type NodeOutPutVar = {
|
||||
}
|
||||
|
||||
export type NodeDefault<T = {}> = {
|
||||
classification: BlockClassificationEnum
|
||||
sort: number
|
||||
type: BlockEnum
|
||||
title: string
|
||||
author: string
|
||||
description?: string
|
||||
helpLinkUri?: string
|
||||
metaData: {
|
||||
classification: BlockClassificationEnum
|
||||
sort: number
|
||||
type: BlockEnum
|
||||
title: string
|
||||
author: string
|
||||
description?: string
|
||||
helpLinkUri?: string
|
||||
}
|
||||
defaultValue: Partial<T>
|
||||
checkValid: (payload: T, t: any, moreDataForCheckValid?: any) => { isValid: boolean; errorMessage?: string }
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user