Skip to content

Commit

Permalink
perf: optimize global variables (labring#2863)
Browse files Browse the repository at this point in the history
* feat: add global variable types

* add global variables to debug

* fix select dnd

* unify InputTypeConfig params
  • Loading branch information
newfish-cmyk authored and c121914yu committed Oct 12, 2024
1 parent daa5b55 commit a5b0a43
Show file tree
Hide file tree
Showing 18 changed files with 603 additions and 431 deletions.
15 changes: 11 additions & 4 deletions packages/global/core/app/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { StoreEdgeItemType } from '../workflow/type/edge';
import { PermissionSchemaType, PermissionValueType } from '../../support/permission/type';
import { AppPermission } from '../../support/permission/app/controller';
import { ParentIdType } from '../../common/parentFolder/type';
import { FlowNodeInputTypeEnum } from 'core/workflow/node/constant';

export type AppSchema = {
_id: string;
Expand Down Expand Up @@ -114,11 +115,17 @@ export type VariableItemType = {
id: string;
key: string;
label: string;
type: `${VariableInputEnum}`;
type: VariableInputEnum;
required: boolean;
maxLen: number;
enums: { value: string }[];
valueType: WorkflowIOValueTypeEnum;
description: string;
valueType?: WorkflowIOValueTypeEnum;
defaultValue?: any;

// numberInput
max?: number;
min?: number;
// select
enums?: { value: string; label: string }[];
};
// tts
export type AppTTSConfigType = {
Expand Down
55 changes: 42 additions & 13 deletions packages/global/core/workflow/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,29 +267,58 @@ export enum NodeOutputKeyEnum {
export enum VariableInputEnum {
input = 'input',
textarea = 'textarea',
numberInput = 'numberInput',
select = 'select',
switch = 'switch',
custom = 'custom'
}
export const variableMap = {
export const variableMap: Record<
VariableInputEnum,
{
icon: string;
label: string;
value: VariableInputEnum;
defaultValueType: WorkflowIOValueTypeEnum;
description?: string;
}
> = {
[VariableInputEnum.input]: {
icon: 'core/app/variable/input',
title: i18nT('common:core.module.variable.input type'),
desc: ''
icon: 'core/workflow/inputType/input',
label: i18nT('common:core.workflow.inputType.input'),
value: VariableInputEnum.input,
defaultValueType: WorkflowIOValueTypeEnum.string
},
[VariableInputEnum.textarea]: {
icon: 'core/app/variable/textarea',
title: i18nT('common:core.module.variable.textarea type'),
desc: i18nT('app:variable.textarea_type_desc')
icon: 'core/workflow/inputType/textarea',
label: i18nT('common:core.workflow.inputType.textarea'),
value: VariableInputEnum.textarea,
defaultValueType: WorkflowIOValueTypeEnum.string,
description: i18nT('app:variable.textarea_type_desc')
},
[VariableInputEnum.numberInput]: {
icon: 'core/workflow/inputType/numberInput',
label: i18nT('common:core.workflow.inputType.number input'),
value: VariableInputEnum.numberInput,
defaultValueType: WorkflowIOValueTypeEnum.number
},
[VariableInputEnum.switch]: {
icon: 'core/workflow/inputType/switch',
label: i18nT('common:core.workflow.inputType.switch'),
value: VariableInputEnum.switch,
defaultValueType: WorkflowIOValueTypeEnum.boolean
},
[VariableInputEnum.select]: {
icon: 'core/app/variable/select',
title: i18nT('common:core.module.variable.select type'),
desc: ''
icon: 'core/workflow/inputType/option',
label: i18nT('common:core.workflow.inputType.select'),
value: VariableInputEnum.select,
defaultValueType: WorkflowIOValueTypeEnum.string
},
[VariableInputEnum.custom]: {
icon: 'core/app/variable/external',
title: i18nT('common:core.module.variable.Custom type'),
desc: i18nT('app:variable.select type_desc')
icon: 'core/workflow/inputType/customVariable',
label: i18nT('common:core.workflow.inputType.custom'),
value: VariableInputEnum.custom,
defaultValueType: WorkflowIOValueTypeEnum.string,
description: i18nT('app:variable.select type_desc')
}
};

Expand Down
4 changes: 3 additions & 1 deletion packages/global/core/workflow/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ export const appData2FlowNodeIO = ({
FlowNodeInputTypeEnum.textarea,
FlowNodeInputTypeEnum.reference
],
[VariableInputEnum.numberInput]: [FlowNodeInputTypeEnum.numberInput],
[VariableInputEnum.select]: [FlowNodeInputTypeEnum.select],
[VariableInputEnum.switch]: [FlowNodeInputTypeEnum.switch],
[VariableInputEnum.custom]: [
FlowNodeInputTypeEnum.input,
FlowNodeInputTypeEnum.reference
Expand All @@ -246,7 +248,7 @@ export const appData2FlowNodeIO = ({
description: '',
valueType: WorkflowIOValueTypeEnum.any,
required: item.required,
list: item.enums.map((enumItem) => ({
list: item.enums?.map((enumItem) => ({
label: enumItem.value,
value: enumItem.value
}))
Expand Down
1 change: 1 addition & 0 deletions packages/web/components/common/Icon/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ export const iconPaths = {
'core/workflow/versionHistories': () => import('./icons/core/workflow/versionHistories.svg'),
date: () => import('./icons/date.svg'),
delete: () => import('./icons/delete.svg'),
drag: () => import('./icons/drag.svg'),
edit: () => import('./icons/edit.svg'),
empty: () => import('./icons/empty.svg'),
export: () => import('./icons/export.svg'),
Expand Down
8 changes: 8 additions & 0 deletions packages/web/components/common/Icon/icons/drag.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion packages/web/i18n/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,6 @@
"core.module.variable.select type": "Dropdown Single Select",
"core.module.variable.text max length": "Max Length",
"core.module.variable.textarea type": "Paragraph",
"core.module.variable.variable name": "Variable Name",
"core.module.variable.variable name is required": "Variable Name Cannot Be Empty",
"core.module.variable.variable option is required": "Options Cannot Be All Empty",
"core.module.variable.variable option is value is required": "Option Content Cannot Be Empty",
Expand Down
2 changes: 2 additions & 0 deletions packages/web/i18n/en/workflow.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"Code": "Code",
"Confirm_sync_node": "It will be updated to the latest node configuration and fields that do not exist in the template will be deleted (including all custom fields).\n\nIf the fields are complex, it is recommended that you copy a node first and then update the original node to facilitate parameter copying.",
"Quote_prompt_setting": "Quote prompt",
"Variable_name": "Variable name",
"add_new_input": "Add New Input",
"add_new_output": "New output",
"append_application_reply_to_history_as_new_context": "Append the application's reply to the history as new context",
Expand Down Expand Up @@ -179,6 +180,7 @@
"user_question": "User Question",
"user_question_tool_desc": "User input questions (questions need to be improved)",
"value_type": "Value type",
"variable_description": "Variable description",
"variable_picker_tips": "Type node name or variable name to search",
"variable_update": "Variable Update",
"workflow.My edit": "My Edit",
Expand Down
1 change: 0 additions & 1 deletion packages/web/i18n/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,6 @@
"core.module.variable.select type": "下拉单选",
"core.module.variable.text max length": "最大长度",
"core.module.variable.textarea type": "段落",
"core.module.variable.variable name": "变量名",
"core.module.variable.variable name is required": "变量名不能为空",
"core.module.variable.variable option is required": "选项不能全空",
"core.module.variable.variable option is value is required": "选项内容不能为空",
Expand Down
2 changes: 2 additions & 0 deletions packages/web/i18n/zh/workflow.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"Code": "代码",
"Confirm_sync_node": "将会更新至最新的节点配置,不存在模板中的字段将会被删除(包括所有自定义字段)。\n如果字段较为复杂,建议您先复制一份节点,再更新原来的节点,便于参数复制。",
"Quote_prompt_setting": "引用提示词配置",
"Variable_name": "变量名",
"add_new_input": "新增输入",
"add_new_output": "新增输出",
"append_application_reply_to_history_as_new_context": "将该应用回复内容拼接到历史记录中,作为新的上下文返回",
Expand Down Expand Up @@ -180,6 +181,7 @@
"user_question": "用户问题",
"user_question_tool_desc": "用户输入的问题(问题需要完善)",
"value_type": "数据类型",
"variable_description": "变量描述",
"variable_picker_tips": "可输入节点名或变量名搜索",
"variable_update": "变量更新",
"workflow.My edit": "我的编辑",
Expand Down
Loading

0 comments on commit a5b0a43

Please sign in to comment.