Skip to content

Commit e345c30

Browse files
authored
add more variable types (#5540)
* variable types * password * time picker * internal var * file * fix-test * time select default value & range * password & type render * fix * fix build * fix * move method * split date select * icon
1 parent 3e64a1b commit e345c30

File tree

49 files changed

+1162
-235
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1162
-235
lines changed

packages/global/core/app/type.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,23 @@ export type VariableItemType = {
162162

163163
// input
164164
maxLength?: number;
165+
// password
166+
minLength?: number;
165167
// numberInput
166168
max?: number;
167169
min?: number;
168170
// select
169171
list?: { label: string; value: string }[];
172+
// file
173+
canSelectFile?: boolean;
174+
canSelectImg?: boolean;
175+
maxFiles?: number;
176+
// timeSelect
177+
timeGranularity?: 'second' | 'minute' | 'hour' | 'day';
178+
timeType?: 'point' | 'range';
179+
timeRangeStart?: string;
180+
timeRangeEnd?: string;
181+
170182
// @deprecated
171183
enums?: { value: string; label: string }[];
172184
};

packages/global/core/workflow/constants.ts

Lines changed: 127 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -332,53 +332,144 @@ export enum VariableInputEnum {
332332
input = 'input',
333333
textarea = 'textarea',
334334
numberInput = 'numberInput',
335+
JSONEditor = 'JSONEditor',
335336
select = 'select',
336-
custom = 'custom'
337+
multipleSelect = 'multipleSelect',
338+
timePointSelect = 'timePointSelect',
339+
timeRangeSelect = 'timeRangeSelect',
340+
switch = 'switch',
341+
password = 'password',
342+
file = 'file',
343+
344+
modelSelect = 'modelSelect',
345+
datasetSelect = 'datasetSelect',
346+
347+
custom = 'custom',
348+
internal = 'internal'
337349
}
338-
export const variableMap: Record<
339-
VariableInputEnum,
340-
{
341-
icon: string;
342-
label: string;
343-
value: VariableInputEnum;
344-
defaultValueType: WorkflowIOValueTypeEnum;
345-
description?: string;
346-
}
347-
> = {
348-
[VariableInputEnum.input]: {
349-
icon: 'core/workflow/inputType/input',
350-
label: i18nT('common:core.workflow.inputType.textInput'),
351-
value: VariableInputEnum.input,
352-
defaultValueType: WorkflowIOValueTypeEnum.string
353-
},
350+
351+
type VariableConfigType = {
352+
icon: string;
353+
label: string;
354+
value: VariableInputEnum;
355+
defaultValueType: WorkflowIOValueTypeEnum;
356+
description?: string;
357+
};
358+
359+
export const variableConfigs: VariableConfigType[][] = [
360+
[
361+
{
362+
icon: 'core/workflow/inputType/input',
363+
label: i18nT('common:core.workflow.inputType.textInput'),
364+
value: VariableInputEnum.input,
365+
defaultValueType: WorkflowIOValueTypeEnum.string
366+
},
367+
{
368+
icon: 'core/workflow/inputType/numberInput',
369+
label: i18nT('common:core.workflow.inputType.number input'),
370+
value: VariableInputEnum.numberInput,
371+
defaultValueType: WorkflowIOValueTypeEnum.number
372+
},
373+
{
374+
icon: 'core/workflow/inputType/jsonEditor',
375+
label: i18nT('common:core.workflow.inputType.jsonEditor'),
376+
value: VariableInputEnum.JSONEditor,
377+
defaultValueType: WorkflowIOValueTypeEnum.object
378+
},
379+
{
380+
icon: 'core/workflow/inputType/option',
381+
label: i18nT('common:core.workflow.inputType.select'),
382+
value: VariableInputEnum.select,
383+
defaultValueType: WorkflowIOValueTypeEnum.string
384+
},
385+
{
386+
icon: 'core/workflow/inputType/multipleSelect',
387+
label: i18nT('common:core.workflow.inputType.multipleSelect'),
388+
value: VariableInputEnum.multipleSelect,
389+
defaultValueType: WorkflowIOValueTypeEnum.arrayString
390+
},
391+
{
392+
icon: 'core/workflow/inputType/switch',
393+
label: i18nT('common:core.workflow.inputType.switch'),
394+
value: VariableInputEnum.switch,
395+
defaultValueType: WorkflowIOValueTypeEnum.boolean
396+
},
397+
{
398+
icon: 'core/workflow/inputType/timePointSelect',
399+
label: i18nT('common:core.workflow.inputType.timePointSelect'),
400+
value: VariableInputEnum.timePointSelect,
401+
defaultValueType: WorkflowIOValueTypeEnum.string
402+
},
403+
{
404+
icon: 'core/workflow/inputType/timeRangeSelect',
405+
label: i18nT('common:core.workflow.inputType.timeRangeSelect'),
406+
value: VariableInputEnum.timeRangeSelect,
407+
defaultValueType: WorkflowIOValueTypeEnum.arrayString
408+
},
409+
{
410+
icon: 'core/workflow/inputType/file',
411+
label: i18nT('common:core.workflow.inputType.file'),
412+
value: VariableInputEnum.file,
413+
defaultValueType: WorkflowIOValueTypeEnum.arrayString
414+
},
415+
{
416+
icon: 'core/workflow/inputType/password',
417+
label: i18nT('common:core.workflow.inputType.password'),
418+
value: VariableInputEnum.password,
419+
defaultValueType: WorkflowIOValueTypeEnum.string
420+
}
421+
],
422+
[
423+
{
424+
icon: 'core/workflow/inputType/model',
425+
label: i18nT('common:core.workflow.inputType.modelSelect'),
426+
value: VariableInputEnum.modelSelect,
427+
defaultValueType: WorkflowIOValueTypeEnum.string
428+
},
429+
{
430+
icon: 'core/workflow/inputType/dataset',
431+
label: i18nT('common:core.workflow.inputType.datasetSelect'),
432+
value: VariableInputEnum.datasetSelect,
433+
defaultValueType: WorkflowIOValueTypeEnum.arrayString
434+
}
435+
],
436+
[
437+
{
438+
icon: 'core/workflow/inputType/external',
439+
label: i18nT('common:core.workflow.inputType.custom'),
440+
value: VariableInputEnum.custom,
441+
defaultValueType: WorkflowIOValueTypeEnum.string,
442+
description: i18nT('app:variable.select type_desc')
443+
},
444+
{
445+
icon: 'core/workflow/inputType/internal',
446+
label: i18nT('common:core.workflow.inputType.internal'),
447+
value: VariableInputEnum.internal,
448+
defaultValueType: WorkflowIOValueTypeEnum.string,
449+
description: i18nT('app:variable.internal_type_desc')
450+
}
451+
]
452+
];
453+
454+
export const variableMap: Record<VariableInputEnum, VariableConfigType> = {
455+
...variableConfigs
456+
.flat()
457+
.reduce(
458+
(acc, config) => ({ ...acc, [config.value]: config }),
459+
{} as Record<VariableInputEnum, VariableConfigType>
460+
),
354461
[VariableInputEnum.textarea]: {
355462
icon: 'core/workflow/inputType/textarea',
356463
label: i18nT('common:core.workflow.inputType.textarea'),
357464
value: VariableInputEnum.textarea,
358465
defaultValueType: WorkflowIOValueTypeEnum.string,
359466
description: i18nT('app:variable.textarea_type_desc')
360-
},
361-
[VariableInputEnum.numberInput]: {
362-
icon: 'core/workflow/inputType/numberInput',
363-
label: i18nT('common:core.workflow.inputType.number input'),
364-
value: VariableInputEnum.numberInput,
365-
defaultValueType: WorkflowIOValueTypeEnum.number
366-
},
367-
[VariableInputEnum.select]: {
368-
icon: 'core/workflow/inputType/option',
369-
label: i18nT('common:core.workflow.inputType.select'),
370-
value: VariableInputEnum.select,
371-
defaultValueType: WorkflowIOValueTypeEnum.string
372-
},
373-
[VariableInputEnum.custom]: {
374-
icon: 'core/workflow/inputType/customVariable',
375-
label: i18nT('common:core.workflow.inputType.custom'),
376-
value: VariableInputEnum.custom,
377-
defaultValueType: WorkflowIOValueTypeEnum.string,
378-
description: i18nT('app:variable.select type_desc')
379467
}
380468
};
381469

470+
// Keep backward compatibility
471+
export const variableMapGroups = variableConfigs;
472+
382473
/* run time */
383474
export enum RuntimeEdgeStatusEnum {
384475
'waiting' = 'waiting',

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ export enum FlowNodeInputTypeEnum { // render ui
3030
hidden = 'hidden',
3131
custom = 'custom',
3232

33-
fileSelect = 'fileSelect'
33+
fileSelect = 'fileSelect',
34+
timePointSelect = 'timePointSelect',
35+
timeRangeSelect = 'timeRangeSelect',
36+
password = 'password'
3437
}
3538
export const FlowNodeInputMap: Record<
3639
FlowNodeInputTypeEnum,
@@ -94,6 +97,15 @@ export const FlowNodeInputMap: Record<
9497
},
9598
[FlowNodeInputTypeEnum.fileSelect]: {
9699
icon: 'core/workflow/inputType/file'
100+
},
101+
[FlowNodeInputTypeEnum.timePointSelect]: {
102+
icon: 'core/workflow/inputType/timePointSelect'
103+
},
104+
[FlowNodeInputTypeEnum.timeRangeSelect]: {
105+
icon: 'core/workflow/inputType/timeRangeSelect'
106+
},
107+
[FlowNodeInputTypeEnum.password]: {
108+
icon: 'core/workflow/inputType/password'
97109
}
98110
};
99111

packages/global/core/workflow/runtime/utils.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
NodeInputKeyEnum,
88
NodeOutputKeyEnum,
99
VARIABLE_NODE_ID,
10+
VariableInputEnum,
1011
WorkflowIOValueTypeEnum
1112
} from '../constants';
1213
import { FlowNodeTypeEnum } from '../node/constant';
@@ -67,7 +68,11 @@ export const getMaxHistoryLimitFromNodes = (nodes: StoreNodeItemType[]): number
6768
};
6869

6970
/* value type format */
70-
export const valueTypeFormat = (value: any, type?: WorkflowIOValueTypeEnum) => {
71+
export const valueTypeFormat = (
72+
value: any,
73+
valueType?: WorkflowIOValueTypeEnum,
74+
type?: VariableInputEnum
75+
) => {
7176
const isObjectString = (value: any) => {
7277
if (typeof value === 'string' && value !== 'false' && value !== 'true') {
7378
const trimmedValue = value.trim();
@@ -81,42 +86,45 @@ export const valueTypeFormat = (value: any, type?: WorkflowIOValueTypeEnum) => {
8186

8287
// 1. any值,忽略格式化
8388
if (value === undefined || value === null) return value;
84-
if (!type || type === WorkflowIOValueTypeEnum.any) return value;
89+
if (!valueType || valueType === WorkflowIOValueTypeEnum.any) return value;
90+
91+
// password 忽略格式化
92+
if (type === VariableInputEnum.password) return value;
8593

8694
// 2. 如果值已经符合目标类型,直接返回
8795
if (
88-
(type === WorkflowIOValueTypeEnum.string && typeof value === 'string') ||
89-
(type === WorkflowIOValueTypeEnum.number && typeof value === 'number') ||
90-
(type === WorkflowIOValueTypeEnum.boolean && typeof value === 'boolean') ||
91-
(type.startsWith('array') && Array.isArray(value)) ||
92-
(type === WorkflowIOValueTypeEnum.object && typeof value === 'object') ||
93-
(type === WorkflowIOValueTypeEnum.chatHistory &&
96+
(valueType === WorkflowIOValueTypeEnum.string && typeof value === 'string') ||
97+
(valueType === WorkflowIOValueTypeEnum.number && typeof value === 'number') ||
98+
(valueType === WorkflowIOValueTypeEnum.boolean && typeof value === 'boolean') ||
99+
(valueType.startsWith('array') && Array.isArray(value)) ||
100+
(valueType === WorkflowIOValueTypeEnum.object && typeof value === 'object') ||
101+
(valueType === WorkflowIOValueTypeEnum.chatHistory &&
94102
(Array.isArray(value) || typeof value === 'number')) ||
95-
(type === WorkflowIOValueTypeEnum.datasetQuote && Array.isArray(value)) ||
96-
(type === WorkflowIOValueTypeEnum.selectDataset && Array.isArray(value)) ||
97-
(type === WorkflowIOValueTypeEnum.selectApp && typeof value === 'object')
103+
(valueType === WorkflowIOValueTypeEnum.datasetQuote && Array.isArray(value)) ||
104+
(valueType === WorkflowIOValueTypeEnum.selectDataset && Array.isArray(value)) ||
105+
(valueType === WorkflowIOValueTypeEnum.selectApp && typeof value === 'object')
98106
) {
99107
return value;
100108
}
101109

102110
// 4. 按目标类型,进行格式转化
103111
// 4.1 基本类型转换
104-
if (type === WorkflowIOValueTypeEnum.string) {
112+
if (valueType === WorkflowIOValueTypeEnum.string) {
105113
return typeof value === 'object' ? JSON.stringify(value) : String(value);
106114
}
107-
if (type === WorkflowIOValueTypeEnum.number) {
115+
if (valueType === WorkflowIOValueTypeEnum.number) {
108116
if (value === '') return undefined;
109117
return Number(value);
110118
}
111-
if (type === WorkflowIOValueTypeEnum.boolean) {
119+
if (valueType === WorkflowIOValueTypeEnum.boolean) {
112120
if (typeof value === 'string') {
113121
return value.toLowerCase() === 'true';
114122
}
115123
return Boolean(value);
116124
}
117125

118126
// 4.3 字符串转对象
119-
if (type === WorkflowIOValueTypeEnum.object) {
127+
if (valueType === WorkflowIOValueTypeEnum.object) {
120128
if (isObjectString(value)) {
121129
const trimmedValue = value.trim();
122130
try {
@@ -127,7 +135,7 @@ export const valueTypeFormat = (value: any, type?: WorkflowIOValueTypeEnum) => {
127135
}
128136

129137
// 4.4 数组类型(这里 value 不是数组类型)(TODO: 嵌套数据类型转化)
130-
if (type.startsWith('array')) {
138+
if (valueType.startsWith('array')) {
131139
if (isObjectString(value)) {
132140
try {
133141
return json5.parse(value);
@@ -142,7 +150,7 @@ export const valueTypeFormat = (value: any, type?: WorkflowIOValueTypeEnum) => {
142150
WorkflowIOValueTypeEnum.datasetQuote,
143151
WorkflowIOValueTypeEnum.selectDataset,
144152
WorkflowIOValueTypeEnum.selectApp
145-
].includes(type)
153+
].includes(valueType)
146154
) {
147155
if (isObjectString(value)) {
148156
try {
@@ -153,7 +161,7 @@ export const valueTypeFormat = (value: any, type?: WorkflowIOValueTypeEnum) => {
153161
}
154162

155163
// Invalid history type
156-
if (type === WorkflowIOValueTypeEnum.chatHistory) {
164+
if (valueType === WorkflowIOValueTypeEnum.chatHistory) {
157165
if (isObjectString(value)) {
158166
try {
159167
return json5.parse(value);

packages/global/core/workflow/utils.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
type ReferenceArrayValueType,
1919
type ReferenceItemValueType
2020
} from './type/io.d';
21-
import type { NodeToolConfigType } from './type/node';
2221
import { type StoreNodeItemType } from './type/node';
2322
import type {
2423
VariableItemType,
@@ -247,24 +246,30 @@ export const appData2FlowNodeIO = ({
247246
const variableInput = !chatConfig?.variables
248247
? []
249248
: chatConfig.variables.map((item) => {
250-
const renderTypeMap = {
249+
const renderTypeMap: Record<VariableInputEnum, FlowNodeInputTypeEnum[]> = {
251250
[VariableInputEnum.input]: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference],
252251
[VariableInputEnum.textarea]: [
253252
FlowNodeInputTypeEnum.textarea,
254253
FlowNodeInputTypeEnum.reference
255254
],
256255
[VariableInputEnum.numberInput]: [FlowNodeInputTypeEnum.numberInput],
257256
[VariableInputEnum.select]: [FlowNodeInputTypeEnum.select],
258-
[VariableInputEnum.custom]: [
259-
FlowNodeInputTypeEnum.input,
260-
FlowNodeInputTypeEnum.reference
261-
],
262-
default: [FlowNodeInputTypeEnum.reference]
257+
[VariableInputEnum.multipleSelect]: [FlowNodeInputTypeEnum.multipleSelect],
258+
[VariableInputEnum.JSONEditor]: [FlowNodeInputTypeEnum.JSONEditor],
259+
[VariableInputEnum.timePointSelect]: [FlowNodeInputTypeEnum.timePointSelect],
260+
[VariableInputEnum.timeRangeSelect]: [FlowNodeInputTypeEnum.timeRangeSelect],
261+
[VariableInputEnum.switch]: [FlowNodeInputTypeEnum.switch],
262+
[VariableInputEnum.password]: [FlowNodeInputTypeEnum.password],
263+
[VariableInputEnum.file]: [FlowNodeInputTypeEnum.fileSelect],
264+
[VariableInputEnum.modelSelect]: [FlowNodeInputTypeEnum.selectLLMModel],
265+
[VariableInputEnum.datasetSelect]: [FlowNodeInputTypeEnum.selectDataset],
266+
[VariableInputEnum.internal]: [FlowNodeInputTypeEnum.hidden],
267+
[VariableInputEnum.custom]: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference]
263268
};
264269

265270
return {
266271
key: item.key,
267-
renderTypeList: renderTypeMap[item.type] || renderTypeMap.default,
272+
renderTypeList: renderTypeMap[item.type] || [FlowNodeInputTypeEnum.reference],
268273
label: item.label,
269274
debugLabel: item.label,
270275
description: '',

0 commit comments

Comments
 (0)