From e88ad93f8322329d88a2ae40746c8f19bd651c88 Mon Sep 17 00:00:00 2001 From: heheer Date: Tue, 22 Oct 2024 11:21:28 +0800 Subject: [PATCH] perf: all plugin variables type support referense & replace input and textarea with prompt editor (#2950) * support reference as plugin variables * replace input and textarea with prompt editor * adjust height & optimize textarea and input * input select --- packages/global/core/workflow/constants.ts | 7 + .../global/core/workflow/node/constant.ts | 24 ++- packages/global/core/workflow/utils.ts | 4 + .../core/workflow/NodeInputSelect.tsx | 5 + packages/web/i18n/en/common.json | 1 + packages/web/i18n/en/workflow.json | 3 +- packages/web/i18n/zh/common.json | 1 + packages/web/i18n/zh/workflow.json | 3 +- .../src/components/core/app/VariableEdit.tsx | 21 ++- .../ChatBox/components/VariableInput.tsx | 11 ++ .../core/chat/components/AIResponseBox.tsx | 10 ++ .../Flow/hooks/useDebug.tsx | 14 +- .../NodeFormInput/InputFormEditModal.tsx | 12 +- .../nodes/NodePluginIO/InputEditModal.tsx | 27 ++- .../nodes/NodePluginIO/InputTypeConfig.tsx | 164 ++++++++++-------- .../Flow/nodes/render/RenderInput/index.tsx | 16 +- .../RenderInput/templates/TextInput.tsx | 76 +++++--- 17 files changed, 258 insertions(+), 141 deletions(-) diff --git a/packages/global/core/workflow/constants.ts b/packages/global/core/workflow/constants.ts index 49481e077..a7918f7f6 100644 --- a/packages/global/core/workflow/constants.ts +++ b/packages/global/core/workflow/constants.ts @@ -267,6 +267,7 @@ export enum NodeOutputKeyEnum { export enum VariableInputEnum { input = 'input', textarea = 'textarea', + textInput = 'textInput', numberInput = 'numberInput', select = 'select', custom = 'custom' @@ -294,6 +295,12 @@ export const variableMap: Record< defaultValueType: WorkflowIOValueTypeEnum.string, description: i18nT('app:variable.textarea_type_desc') }, + [VariableInputEnum.textInput]: { + icon: 'core/workflow/inputType/input', + label: i18nT('common:core.workflow.inputType.textInput'), + value: VariableInputEnum.textInput, + defaultValueType: WorkflowIOValueTypeEnum.string + }, [VariableInputEnum.numberInput]: { icon: 'core/workflow/inputType/numberInput', label: i18nT('common:core.workflow.inputType.number input'), diff --git a/packages/global/core/workflow/node/constant.ts b/packages/global/core/workflow/node/constant.ts index 18f224e68..5f05852e8 100644 --- a/packages/global/core/workflow/node/constant.ts +++ b/packages/global/core/workflow/node/constant.ts @@ -1,14 +1,13 @@ import { WorkflowIOValueTypeEnum } from '../constants'; import { i18nT } from '../../../../web/i18n/utils'; export enum FlowNodeInputTypeEnum { // render ui + textInput = 'textInput', reference = 'reference', // reference to other node output - input = 'input', // one line input numberInput = 'numberInput', switch = 'switch', // true/false select = 'select', // editor - textarea = 'textarea', JSONEditor = 'JSONEditor', addInputParam = 'addInputParam', // params input @@ -27,7 +26,11 @@ export enum FlowNodeInputTypeEnum { // render ui settingDatasetQuotePrompt = 'settingDatasetQuotePrompt', hidden = 'hidden', - custom = 'custom' + custom = 'custom', + + // deprecated + input = 'input', // one line input + textarea = 'textarea' } export const FlowNodeInputMap: Record< FlowNodeInputTypeEnum, @@ -35,12 +38,12 @@ export const FlowNodeInputMap: Record< icon: string; } > = { + [FlowNodeInputTypeEnum.textInput]: { + icon: 'core/workflow/inputType/input' + }, [FlowNodeInputTypeEnum.reference]: { icon: 'core/workflow/inputType/reference' }, - [FlowNodeInputTypeEnum.input]: { - icon: 'core/workflow/inputType/input' - }, [FlowNodeInputTypeEnum.numberInput]: { icon: 'core/workflow/inputType/numberInput' }, @@ -50,9 +53,6 @@ export const FlowNodeInputMap: Record< [FlowNodeInputTypeEnum.switch]: { icon: 'core/workflow/inputType/switch' }, - [FlowNodeInputTypeEnum.textarea]: { - icon: 'core/workflow/inputType/textarea' - }, [FlowNodeInputTypeEnum.JSONEditor]: { icon: 'core/workflow/inputType/jsonEditor' }, @@ -85,6 +85,12 @@ export const FlowNodeInputMap: Record< }, [FlowNodeInputTypeEnum.custom]: { icon: 'core/workflow/inputType/custom' + }, + [FlowNodeInputTypeEnum.input]: { + icon: 'core/workflow/inputType/input' + }, + [FlowNodeInputTypeEnum.textarea]: { + icon: 'core/workflow/inputType/textarea' } }; diff --git a/packages/global/core/workflow/utils.ts b/packages/global/core/workflow/utils.ts index 6fbb98138..af2c7cc6a 100644 --- a/packages/global/core/workflow/utils.ts +++ b/packages/global/core/workflow/utils.ts @@ -230,6 +230,10 @@ export const appData2FlowNodeIO = ({ FlowNodeInputTypeEnum.textarea, FlowNodeInputTypeEnum.reference ], + [VariableInputEnum.textInput]: [ + FlowNodeInputTypeEnum.textInput, + FlowNodeInputTypeEnum.reference + ], [VariableInputEnum.numberInput]: [FlowNodeInputTypeEnum.numberInput], [VariableInputEnum.select]: [FlowNodeInputTypeEnum.select], [VariableInputEnum.custom]: [ diff --git a/packages/web/components/core/workflow/NodeInputSelect.tsx b/packages/web/components/core/workflow/NodeInputSelect.tsx index 044754a67..223556d62 100644 --- a/packages/web/components/core/workflow/NodeInputSelect.tsx +++ b/packages/web/components/core/workflow/NodeInputSelect.tsx @@ -36,6 +36,11 @@ const NodeInputSelect = ({ icon: FlowNodeInputMap[FlowNodeInputTypeEnum.input].icon, title: t('common:core.workflow.inputType.Manual input') }, + { + type: FlowNodeInputTypeEnum.textInput, + icon: FlowNodeInputMap[FlowNodeInputTypeEnum.input].icon, + title: t('common:core.workflow.inputType.Manual input') + }, { type: FlowNodeInputTypeEnum.numberInput, icon: FlowNodeInputMap[FlowNodeInputTypeEnum.numberInput].icon, diff --git a/packages/web/i18n/en/common.json b/packages/web/i18n/en/common.json index c5165d3cd..8cc64354f 100644 --- a/packages/web/i18n/en/common.json +++ b/packages/web/i18n/en/common.json @@ -800,6 +800,7 @@ "core.workflow.inputType.selectDataset": "Dataset Select", "core.workflow.inputType.selectLLMModel": "Chat Model Select", "core.workflow.inputType.switch": "Switch", + "core.workflow.inputType.textInput": "Text Input box", "core.workflow.inputType.textarea": "Multi-line Input Box", "core.workflow.publish.OnRevert version": "Click to Revert to This Version", "core.workflow.publish.OnRevert version confirm": "Confirm to Revert to This Version? The configuration of the editing version will be saved, and a new release version will be created for the reverted version.", diff --git a/packages/web/i18n/en/workflow.json b/packages/web/i18n/en/workflow.json index 338a5909c..c0297ab1f 100644 --- a/packages/web/i18n/en/workflow.json +++ b/packages/web/i18n/en/workflow.json @@ -2,8 +2,8 @@ "Array_element": "Array element", "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.", - "Node_variables": "Node variables", "Node.Open_Node_Course": "Open node course", + "Node_variables": "Node variables", "Quote_prompt_setting": "Quote prompt", "Variable.Variable type": "Variable type", "Variable_name": "Variable name", @@ -54,6 +54,7 @@ "field_description_placeholder": "Describe the function of this input field. If it is a tool call parameter, this description will affect the quality of the model generation.", "field_name_already_exists": "Field name already exists", "field_required": "Required", + "field_used_as_reference": "Support reference", "field_used_as_tool_input": "Used as Tool Call Parameter", "filter_description": "Currently supports filtering by tags and creation time. Fill in the format as follows:\n{\n \"tags\": {\n \"$and\": [\"Tag 1\",\"Tag 2\"],\n \"$or\": [\"When there are $and tags, and is effective, or is not effective\"]\n },\n \"createTime\": {\n \"$gte\": \"YYYY-MM-DD HH:mm format, collection creation time greater than this time\",\n \"$lte\": \"YYYY-MM-DD HH:mm format, collection creation time less than this time, can be used with $gte\"\n }\n}", "form_input_result": "User complete input result", diff --git a/packages/web/i18n/zh/common.json b/packages/web/i18n/zh/common.json index ec5102b77..deb9b1040 100644 --- a/packages/web/i18n/zh/common.json +++ b/packages/web/i18n/zh/common.json @@ -805,6 +805,7 @@ "core.workflow.inputType.selectDataset": "知识库选择", "core.workflow.inputType.selectLLMModel": "对话模型选择", "core.workflow.inputType.switch": "开关", + "core.workflow.inputType.textInput": "文本输入框", "core.workflow.inputType.textarea": "多行输入框", "core.workflow.publish.OnRevert version": "点击回退到该版本", "core.workflow.publish.OnRevert version confirm": "确认回退至该版本?会为您保存编辑中版本的配置,并为回退版本创建一个新的发布版本。", diff --git a/packages/web/i18n/zh/workflow.json b/packages/web/i18n/zh/workflow.json index 4b5f5dc16..24d700465 100644 --- a/packages/web/i18n/zh/workflow.json +++ b/packages/web/i18n/zh/workflow.json @@ -2,8 +2,8 @@ "Array_element": "数组元素", "Code": "代码", "Confirm_sync_node": "将会更新至最新的节点配置,不存在模板中的字段将会被删除(包括所有自定义字段)。\n如果字段较为复杂,建议您先复制一份节点,再更新原来的节点,便于参数复制。", - "Node_variables": "节点变量", "Node.Open_Node_Course": "查看节点教程", + "Node_variables": "节点变量", "Quote_prompt_setting": "引用提示词配置", "Variable.Variable type": "变量类型", "Variable_name": "变量名", @@ -55,6 +55,7 @@ "field_description_placeholder": "描述该输入字段的功能,如果为工具调用参数,则该描述会影响模型生成的质量", "field_name_already_exists": "字段名已经存在", "field_required": "必填", + "field_used_as_reference": "支持变量引用", "field_used_as_tool_input": "作为工具调用参数", "filter_description": "目前支持标签和创建时间过滤,需按照以下格式填写:\n{\n \"tags\": {\n \"$and\": [\"标签 1\",\"标签 2\"],\n \"$or\": [\"有 $and 标签时,and 生效,or 不生效\"]\n },\n \"createTime\": {\n \"$gte\": \"YYYY-MM-DD HH:mm 格式即可,集合的创建时间大于该时间\",\n \"$lte\": \"YYYY-MM-DD HH:mm 格式即可,集合的创建时间小于该时间,可和 $gte 共同使用\"\n }\n}", "form_input_result": "用户完整输入结果", diff --git a/projects/app/src/components/core/app/VariableEdit.tsx b/projects/app/src/components/core/app/VariableEdit.tsx index 58a18c706..c3c8068b5 100644 --- a/projects/app/src/components/core/app/VariableEdit.tsx +++ b/projects/app/src/components/core/app/VariableEdit.tsx @@ -36,7 +36,7 @@ export const defaultVariable: VariableItemType = { id: nanoid(), key: '', label: '', - type: VariableInputEnum.input, + type: VariableInputEnum.textInput, description: '', required: true, valueType: WorkflowIOValueTypeEnum.string @@ -72,13 +72,18 @@ const VariableEdit = ({ const inputTypeList = useMemo( () => - Object.values(variableMap).map((item) => ({ - icon: item.icon, - label: t(item.label as any), - value: item.value, - defaultValueType: item.defaultValueType, - description: item.description ? t(item.description as any) : '' - })), + Object.values(variableMap) + .filter( + (item) => + item.value !== VariableInputEnum.input && item.value !== VariableInputEnum.textarea + ) + .map((item) => ({ + icon: item.icon, + label: t(item.label as any), + value: item.value, + defaultValueType: item.defaultValueType, + description: item.description ? t(item.description as any) : '' + })), [t] ); diff --git a/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/VariableInput.tsx b/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/VariableInput.tsx index ab3e8d70b..764861b42 100644 --- a/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/VariableInput.tsx +++ b/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/VariableInput.tsx @@ -24,6 +24,7 @@ import { ChatBoxContext } from '../Provider'; import QuestionTip from '@fastgpt/web/components/common/MyTooltip/QuestionTip'; import { useDeepCompareEffect } from 'ahooks'; import { VariableItemType } from '@fastgpt/global/core/app/type'; +import PromptEditor from '@fastgpt/web/components/common/Textarea/PromptEditor'; export const VariableInputItem = ({ item, @@ -77,6 +78,16 @@ export const VariableInputItem = ({ maxLength={item.maxLength || 4000} /> )} + {item.type === VariableInputEnum.textInput && ( + setValue(item.key, e)} + bg={'myGray.50'} + minH={50} + maxH={150} + showOpenModal={false} + /> + )} {item.type === VariableInputEnum.select && ( )} + {input.type === FlowNodeInputTypeEnum.textInput && ( + setValue(input.label, e)} + minH={40} + maxH={100} + showOpenModal={false} + /> + )} {input.type === FlowNodeInputTypeEnum.numberInput && ( import('@fastgpt/web/components/common/MyDrawer/MyRightDrawer') @@ -270,10 +270,14 @@ export const useDebug = () => { const RenderInput = (() => { if (input.valueType === WorkflowIOValueTypeEnum.string) { return ( -