Skip to content

Commit 9dca724

Browse files
committed
plugin & form input variables
1 parent e157a09 commit 9dca724

File tree

16 files changed

+913
-623
lines changed

16 files changed

+913
-623
lines changed

packages/global/core/workflow/node/constant.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const FlowNodeInputMap: Record<
4949
icon: 'core/workflow/inputType/option'
5050
},
5151
[FlowNodeInputTypeEnum.multipleSelect]: {
52-
icon: 'core/workflow/inputType/option'
52+
icon: 'core/workflow/inputType/multipleSelect'
5353
},
5454
[FlowNodeInputTypeEnum.switch]: {
5555
icon: 'core/workflow/inputType/switch'
@@ -79,7 +79,7 @@ export const FlowNodeInputMap: Record<
7979
icon: 'core/workflow/inputType/selectDataset'
8080
},
8181
[FlowNodeInputTypeEnum.hidden]: {
82-
icon: 'core/workflow/inputType/select'
82+
icon: 'core/workflow/inputType/internal'
8383
},
8484
[FlowNodeInputTypeEnum.customVariable]: {
8585
icon: 'core/workflow/inputType/customVariable'
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
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+
};
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import React from 'react';
2+
import { Box, Flex } from '@chakra-ui/react';
3+
import MyIcon from '../Icon';
4+
import QuestionTip from '../MyTooltip/QuestionTip';
5+
import type { InputTypeConfigItem } from './configs';
6+
import { useTranslation } from 'next-i18next';
7+
8+
const InputTypeSelector = ({
9+
inputTypeList,
10+
selectedType,
11+
onTypeChange
12+
}: {
13+
inputTypeList: InputTypeConfigItem[][];
14+
selectedType: string;
15+
onTypeChange: (type: string) => void;
16+
}) => {
17+
const { t } = useTranslation();
18+
return (
19+
<Flex flexDirection={'column'} gap={4}>
20+
{inputTypeList.map((group, groupIndex) => {
21+
return (
22+
<Box
23+
key={groupIndex}
24+
display={'grid'}
25+
gridTemplateColumns={'repeat(3, 1fr)'}
26+
gap={4}
27+
mt={3}
28+
>
29+
{group.map((item) => {
30+
const isSelected = selectedType === item.value;
31+
return (
32+
<Box
33+
display={'flex'}
34+
key={item.label}
35+
border={'1px solid'}
36+
borderColor={isSelected ? 'primary.600' : 'myGray.250'}
37+
p={3}
38+
rounded={'6px'}
39+
fontWeight={'medium'}
40+
fontSize={'14px'}
41+
alignItems={'center'}
42+
cursor={'pointer'}
43+
boxShadow={isSelected ? '0px 0px 0px 2.4px rgba(51, 112, 255, 0.15)' : 'none'}
44+
_hover={{
45+
'& > svg': {
46+
color: 'primary.600'
47+
},
48+
'& > span': {
49+
color: 'myGray.900'
50+
},
51+
borderColor: 'primary.600',
52+
boxShadow: '0px 0px 0px 2.4px rgba(51, 112, 255, 0.15)'
53+
}}
54+
onClick={() => onTypeChange(item.value)}
55+
>
56+
<MyIcon
57+
name={item.icon as any}
58+
w={'20px'}
59+
mr={1.5}
60+
color={isSelected ? 'primary.600' : 'myGray.400'}
61+
/>
62+
<Box as="span" color={isSelected ? 'myGray.900' : 'inherit'} whiteSpace="nowrap">
63+
{t(item.label)}
64+
</Box>
65+
{item.description && <QuestionTip label={t(item.description)} ml={1} />}
66+
</Box>
67+
);
68+
})}
69+
</Box>
70+
);
71+
})}
72+
</Flex>
73+
);
74+
};
75+
76+
export default InputTypeSelector;

0 commit comments

Comments
 (0)