|
| 1 | +import { |
| 2 | + VariableInputEnum, |
| 3 | + variableConfigs, |
| 4 | + WorkflowIOValueTypeEnum |
| 5 | +} from '@fastgpt/global/core/workflow/constants'; |
| 6 | +import { FlowNodeInputTypeEnum } from '@fastgpt/global/core/workflow/node/constant'; |
| 7 | +import { i18nT } from '../../../i18n/utils'; |
| 8 | + |
| 9 | +export type InputTypeConfigItem = { |
| 10 | + icon: string; |
| 11 | + label: string; |
| 12 | + value: string; |
| 13 | + description?: string; |
| 14 | + defaultValueType?: WorkflowIOValueTypeEnum; |
| 15 | +}; |
| 16 | +export type PluginInputTypeConfigItem = { |
| 17 | + icon: string; |
| 18 | + label: string; |
| 19 | + value: FlowNodeInputTypeEnum[]; |
| 20 | + defaultValueType: WorkflowIOValueTypeEnum; |
| 21 | + description?: string; |
| 22 | +}; |
| 23 | + |
| 24 | +export const getVariableInputTypeList = (): InputTypeConfigItem[][] => { |
| 25 | + return variableConfigs |
| 26 | + .map((group) => |
| 27 | + group |
| 28 | + .filter((item) => item && item.value !== VariableInputEnum.textarea) |
| 29 | + .map((item) => ({ |
| 30 | + icon: item.icon, |
| 31 | + label: item.label, |
| 32 | + value: item.value, |
| 33 | + description: item.description, |
| 34 | + defaultValueType: item.defaultValueType |
| 35 | + })) |
| 36 | + ) |
| 37 | + .filter((group) => group.length > 0); |
| 38 | +}; |
| 39 | +export const getFormInputTypeList = (): InputTypeConfigItem[][] => { |
| 40 | + return [ |
| 41 | + [ |
| 42 | + { |
| 43 | + icon: 'core/workflow/inputType/input', |
| 44 | + label: i18nT('common:core.workflow.inputType.textInput'), |
| 45 | + value: FlowNodeInputTypeEnum.input, |
| 46 | + defaultValueType: WorkflowIOValueTypeEnum.string |
| 47 | + }, |
| 48 | + { |
| 49 | + icon: 'core/workflow/inputType/password', |
| 50 | + label: i18nT('common:core.workflow.inputType.password'), |
| 51 | + value: FlowNodeInputTypeEnum.password, |
| 52 | + defaultValueType: WorkflowIOValueTypeEnum.string |
| 53 | + }, |
| 54 | + { |
| 55 | + icon: 'core/workflow/inputType/numberInput', |
| 56 | + label: i18nT('common:core.workflow.inputType.number input'), |
| 57 | + value: FlowNodeInputTypeEnum.numberInput, |
| 58 | + defaultValueType: WorkflowIOValueTypeEnum.number |
| 59 | + }, |
| 60 | + { |
| 61 | + icon: 'core/workflow/inputType/option', |
| 62 | + label: i18nT('common:core.workflow.inputType.select'), |
| 63 | + value: FlowNodeInputTypeEnum.select, |
| 64 | + defaultValueType: WorkflowIOValueTypeEnum.string |
| 65 | + }, |
| 66 | + { |
| 67 | + icon: 'core/workflow/inputType/multipleSelect', |
| 68 | + label: i18nT('common:core.workflow.inputType.multipleSelect'), |
| 69 | + value: FlowNodeInputTypeEnum.multipleSelect, |
| 70 | + defaultValueType: WorkflowIOValueTypeEnum.arrayString |
| 71 | + }, |
| 72 | + { |
| 73 | + icon: 'core/workflow/inputType/switch', |
| 74 | + label: i18nT('common:core.workflow.inputType.switch'), |
| 75 | + value: FlowNodeInputTypeEnum.switch, |
| 76 | + defaultValueType: WorkflowIOValueTypeEnum.boolean |
| 77 | + }, |
| 78 | + { |
| 79 | + icon: 'core/workflow/inputType/timePointSelect', |
| 80 | + label: i18nT('common:core.workflow.inputType.timePointSelect'), |
| 81 | + value: FlowNodeInputTypeEnum.timePointSelect, |
| 82 | + defaultValueType: WorkflowIOValueTypeEnum.string |
| 83 | + }, |
| 84 | + { |
| 85 | + icon: 'core/workflow/inputType/timeRangeSelect', |
| 86 | + label: i18nT('common:core.workflow.inputType.timeRangeSelect'), |
| 87 | + value: FlowNodeInputTypeEnum.timeRangeSelect, |
| 88 | + defaultValueType: WorkflowIOValueTypeEnum.arrayString |
| 89 | + } |
| 90 | + ], |
| 91 | + [ |
| 92 | + { |
| 93 | + icon: 'core/workflow/inputType/file', |
| 94 | + label: i18nT('common:core.workflow.inputType.file'), |
| 95 | + value: FlowNodeInputTypeEnum.fileSelect, |
| 96 | + defaultValueType: WorkflowIOValueTypeEnum.arrayString |
| 97 | + }, |
| 98 | + { |
| 99 | + icon: 'core/workflow/inputType/selectLLM', |
| 100 | + label: i18nT('common:core.workflow.inputType.selectLLMModel'), |
| 101 | + value: FlowNodeInputTypeEnum.selectLLMModel, |
| 102 | + defaultValueType: WorkflowIOValueTypeEnum.string |
| 103 | + } |
| 104 | + ] |
| 105 | + ]; |
| 106 | +}; |
| 107 | +export const getPluginInputTypeRawList = (options?: { |
| 108 | + hasDynamicInput?: boolean; |
| 109 | +}): PluginInputTypeConfigItem[][] => { |
| 110 | + const { hasDynamicInput = false } = options || {}; |
| 111 | + |
| 112 | + return [ |
| 113 | + [ |
| 114 | + { |
| 115 | + icon: 'core/workflow/inputType/reference', |
| 116 | + label: i18nT('common:core.workflow.inputType.Reference'), |
| 117 | + value: [FlowNodeInputTypeEnum.reference], |
| 118 | + defaultValueType: WorkflowIOValueTypeEnum.string |
| 119 | + }, |
| 120 | + { |
| 121 | + icon: 'core/workflow/inputType/input', |
| 122 | + label: i18nT('common:core.workflow.inputType.textInput'), |
| 123 | + value: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference], |
| 124 | + defaultValueType: WorkflowIOValueTypeEnum.string |
| 125 | + }, |
| 126 | + { |
| 127 | + icon: 'core/workflow/inputType/password', |
| 128 | + label: i18nT('common:core.workflow.inputType.password'), |
| 129 | + value: [FlowNodeInputTypeEnum.password], |
| 130 | + defaultValueType: WorkflowIOValueTypeEnum.string |
| 131 | + }, |
| 132 | + { |
| 133 | + icon: 'core/workflow/inputType/numberInput', |
| 134 | + label: i18nT('common:core.workflow.inputType.number input'), |
| 135 | + value: [FlowNodeInputTypeEnum.numberInput, FlowNodeInputTypeEnum.reference], |
| 136 | + defaultValueType: WorkflowIOValueTypeEnum.number |
| 137 | + }, |
| 138 | + { |
| 139 | + icon: 'core/workflow/inputType/option', |
| 140 | + label: i18nT('common:core.workflow.inputType.select'), |
| 141 | + value: [FlowNodeInputTypeEnum.select, FlowNodeInputTypeEnum.reference], |
| 142 | + defaultValueType: WorkflowIOValueTypeEnum.string |
| 143 | + }, |
| 144 | + { |
| 145 | + icon: 'core/workflow/inputType/multipleSelect', |
| 146 | + label: i18nT('common:core.workflow.inputType.multipleSelect'), |
| 147 | + value: [FlowNodeInputTypeEnum.multipleSelect, FlowNodeInputTypeEnum.reference], |
| 148 | + defaultValueType: WorkflowIOValueTypeEnum.arrayString |
| 149 | + }, |
| 150 | + { |
| 151 | + icon: 'core/workflow/inputType/switch', |
| 152 | + label: i18nT('common:core.workflow.inputType.switch'), |
| 153 | + value: [FlowNodeInputTypeEnum.switch, FlowNodeInputTypeEnum.reference], |
| 154 | + defaultValueType: WorkflowIOValueTypeEnum.boolean |
| 155 | + }, |
| 156 | + { |
| 157 | + icon: 'core/workflow/inputType/timePointSelect', |
| 158 | + label: i18nT('common:core.workflow.inputType.timePointSelect'), |
| 159 | + value: [FlowNodeInputTypeEnum.timePointSelect, FlowNodeInputTypeEnum.reference], |
| 160 | + defaultValueType: WorkflowIOValueTypeEnum.string |
| 161 | + }, |
| 162 | + { |
| 163 | + icon: 'core/workflow/inputType/timeRangeSelect', |
| 164 | + label: i18nT('common:core.workflow.inputType.timeRangeSelect'), |
| 165 | + value: [FlowNodeInputTypeEnum.timeRangeSelect, FlowNodeInputTypeEnum.reference], |
| 166 | + defaultValueType: WorkflowIOValueTypeEnum.arrayString |
| 167 | + } |
| 168 | + ], |
| 169 | + [ |
| 170 | + { |
| 171 | + icon: 'core/workflow/inputType/file', |
| 172 | + label: i18nT('common:core.workflow.inputType.file'), |
| 173 | + value: [FlowNodeInputTypeEnum.fileSelect, FlowNodeInputTypeEnum.reference], |
| 174 | + defaultValueType: WorkflowIOValueTypeEnum.arrayString |
| 175 | + }, |
| 176 | + { |
| 177 | + icon: 'core/workflow/inputType/selectLLM', |
| 178 | + label: i18nT('common:core.workflow.inputType.selectLLMModel'), |
| 179 | + value: [FlowNodeInputTypeEnum.selectLLMModel, FlowNodeInputTypeEnum.reference], |
| 180 | + defaultValueType: WorkflowIOValueTypeEnum.string |
| 181 | + }, |
| 182 | + { |
| 183 | + icon: 'core/workflow/inputType/selectDataset', |
| 184 | + label: i18nT('common:core.workflow.inputType.selectDataset'), |
| 185 | + value: [FlowNodeInputTypeEnum.selectDataset, FlowNodeInputTypeEnum.reference], |
| 186 | + defaultValueType: WorkflowIOValueTypeEnum.selectDataset |
| 187 | + }, |
| 188 | + // 动态输入选项(根据条件显示) |
| 189 | + ...(hasDynamicInput |
| 190 | + ? [] |
| 191 | + : [ |
| 192 | + { |
| 193 | + icon: 'core/workflow/inputType/dynamic', |
| 194 | + label: i18nT('common:core.workflow.inputType.dynamicTargetInput'), |
| 195 | + value: [FlowNodeInputTypeEnum.addInputParam], |
| 196 | + defaultValueType: WorkflowIOValueTypeEnum.dynamic |
| 197 | + } |
| 198 | + ]) |
| 199 | + ], |
| 200 | + [ |
| 201 | + { |
| 202 | + icon: 'core/workflow/inputType/customVariable', |
| 203 | + label: i18nT('common:core.workflow.inputType.custom'), |
| 204 | + value: [FlowNodeInputTypeEnum.customVariable], |
| 205 | + defaultValueType: WorkflowIOValueTypeEnum.string, |
| 206 | + description: i18nT('app:variable.select type_desc') |
| 207 | + }, |
| 208 | + { |
| 209 | + icon: 'core/workflow/inputType/internal', |
| 210 | + label: i18nT('common:core.workflow.inputType.internal'), |
| 211 | + value: [FlowNodeInputTypeEnum.hidden], |
| 212 | + defaultValueType: WorkflowIOValueTypeEnum.string, |
| 213 | + description: i18nT('app:variable.internal_type_desc') |
| 214 | + } |
| 215 | + ] |
| 216 | + ]; |
| 217 | +}; |
| 218 | +export const getPluginInputTypeList = (options?: { |
| 219 | + hasDynamicInput?: boolean; |
| 220 | +}): InputTypeConfigItem[][] => { |
| 221 | + const rawList = getPluginInputTypeRawList(options); |
| 222 | + |
| 223 | + return rawList.map((group) => |
| 224 | + group.map((item) => ({ |
| 225 | + icon: item.icon, |
| 226 | + label: item.label, |
| 227 | + value: item.value[0], // 取第一个值作为标识 |
| 228 | + defaultValueType: item.defaultValueType, |
| 229 | + description: item.description |
| 230 | + })) |
| 231 | + ); |
| 232 | +}; |
0 commit comments