From 077350e651450f647528f3bad0e96f098288c0ae Mon Sep 17 00:00:00 2001 From: Archer <545436317@qq.com> Date: Wed, 19 Mar 2025 12:35:09 +0800 Subject: [PATCH] perf: custom varialbe (#4225) --- .../zh-cn/docs/development/upgrading/492.md | 1 + packages/web/i18n/en/chat.json | 1 + packages/web/i18n/en/common.json | 2 - packages/web/i18n/zh-CN/chat.json | 1 + packages/web/i18n/zh-CN/common.json | 2 - packages/web/i18n/zh-Hant/chat.json | 1 + packages/web/i18n/zh-Hant/common.json | 2 - .../ChatBox/components/VariableInput.tsx | 43 ++++++------------- .../ChatBox/components/VariablePopover.tsx | 2 +- .../core/chat/ChatContainer/ChatBox/index.tsx | 4 +- .../components/renderPluginInput.tsx | 2 +- .../app/detail/SimpleApp/ChatTest.tsx | 2 +- .../WorkflowComponents/Flow/ChatTest.tsx | 2 +- 13 files changed, 23 insertions(+), 42 deletions(-) diff --git a/docSite/content/zh-cn/docs/development/upgrading/492.md b/docSite/content/zh-cn/docs/development/upgrading/492.md index fb98bd53a..3a7f9bd79 100644 --- a/docSite/content/zh-cn/docs/development/upgrading/492.md +++ b/docSite/content/zh-cn/docs/development/upgrading/492.md @@ -11,6 +11,7 @@ weight: 799 ## 🚀 新增内容 1. 知识库分块增加自定义分隔符预设值,同时支持自定义换行符分割。 +2. 外部变量改名:自定义变量。 并且支持在测试时调试,在分享链接中,该变量直接隐藏。 ## ⚙️ 优化 diff --git a/packages/web/i18n/en/chat.json b/packages/web/i18n/en/chat.json index c46326eaf..280b57410 100644 --- a/packages/web/i18n/en/chat.json +++ b/packages/web/i18n/en/chat.json @@ -59,6 +59,7 @@ "to_dataset": "Go to the Knowledge Base", "unsupported_file_type": "Unsupported file types", "upload": "Upload", + "variable_invisable_in_share": "Custom variables are not visible in login-free links", "view_citations": "View References", "web_site_sync": "Web Site Sync" } diff --git a/packages/web/i18n/en/common.json b/packages/web/i18n/en/common.json index 9ec8e914b..cd36d6a6a 100644 --- a/packages/web/i18n/en/common.json +++ b/packages/web/i18n/en/common.json @@ -430,8 +430,6 @@ "core.chat.Start Chat": "Start Chat", "core.chat.Type a message": "Enter a Question, Press [Enter] to Send / Press [Ctrl(Alt/Shift) + Enter] for New Line", "core.chat.Unpin": "Unpin", - "core.chat.Variable_Visiable_in_test": "This variable is not visible in the login-free link", - "core.chat.Visiable_in_test": "Custom variables are not visible in login-free links", "core.chat.You need to a chat app": "You Do Not Have an Available App", "core.chat.error.Chat error": "Chat Error", "core.chat.error.Messages empty": "API Content is Empty, Possibly Due to Text Being Too Long", diff --git a/packages/web/i18n/zh-CN/chat.json b/packages/web/i18n/zh-CN/chat.json index 6d5ab76ed..5250c44d6 100644 --- a/packages/web/i18n/zh-CN/chat.json +++ b/packages/web/i18n/zh-CN/chat.json @@ -59,6 +59,7 @@ "to_dataset": "前往知识库", "unsupported_file_type": "不支持的文件类型", "upload": "上传", + "variable_invisable_in_share": "自定义变量在免登录链接中不可见", "view_citations": "查看引用", "web_site_sync": "Web站点同步" } diff --git a/packages/web/i18n/zh-CN/common.json b/packages/web/i18n/zh-CN/common.json index 451ccf4cd..52445499c 100644 --- a/packages/web/i18n/zh-CN/common.json +++ b/packages/web/i18n/zh-CN/common.json @@ -433,8 +433,6 @@ "core.chat.Start Chat": "开始对话", "core.chat.Type a message": "输入问题,发送 [Enter]/换行 [Ctrl(Alt/Shift) + Enter]", "core.chat.Unpin": "取消置顶", - "core.chat.Variable_Visiable_in_test": "该变量在免登录链接中不可见", - "core.chat.Visiable_in_test": "自定义变量在免登录链接中不可见", "core.chat.You need to a chat app": "你没有可用的应用", "core.chat.error.Chat error": "对话出现异常", "core.chat.error.Messages empty": "接口内容为空,可能文本超长了~", diff --git a/packages/web/i18n/zh-Hant/chat.json b/packages/web/i18n/zh-Hant/chat.json index a688e4674..8026afe8d 100644 --- a/packages/web/i18n/zh-Hant/chat.json +++ b/packages/web/i18n/zh-Hant/chat.json @@ -58,6 +58,7 @@ "to_dataset": "前往知識庫", "unsupported_file_type": "不支援的檔案類型", "upload": "上傳", + "variable_invisable_in_share": "自定義變量在免登錄鏈接中不可見", "view_citations": "檢視引用", "web_site_sync": "網站同步" } diff --git a/packages/web/i18n/zh-Hant/common.json b/packages/web/i18n/zh-Hant/common.json index 53c122b7e..fff2a0c78 100644 --- a/packages/web/i18n/zh-Hant/common.json +++ b/packages/web/i18n/zh-Hant/common.json @@ -429,8 +429,6 @@ "core.chat.Start Chat": "開始對話", "core.chat.Type a message": "輸入問題,按 [Enter] 傳送 / 按 [Ctrl(Alt/Shift) + Enter] 換行", "core.chat.Unpin": "取消釘選", - "core.chat.Variable_Visiable_in_test": "該變量在免登錄鏈接中不可見", - "core.chat.Visiable_in_test": "自定義變量在免登錄鏈接中不可見", "core.chat.You need to a chat app": "您沒有可用的應用程式", "core.chat.error.Chat error": "對話發生錯誤", "core.chat.error.Messages empty": "API 內容為空,可能是文字過長", 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 5d06bdd5f..7d52fc992 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 @@ -126,22 +126,10 @@ export const ExternalVariableInputItem = ({ const { t } = useTranslation(); const { register, control } = variablesForm; - return ( - - + const Label = useMemo(() => { + return ( + {item.label} - {item.required && ( - - * - - )} {item.description && } {showTag && ( - {t('common:core.chat.Variable_Visiable_in_test')} + {t('chat:variable_invisable_in_share')} )} + ); + }, [item.description, item.label, showTag, t]); + + return ( + + {Label} { - if (item.valueType === WorkflowIOValueTypeEnum.boolean) { - return value !== undefined; - } - return !!value; - } - }} render={({ field: { onChange, value } }) => { if (item.valueType === WorkflowIOValueTypeEnum.string) { return ( @@ -179,9 +164,7 @@ export const ExternalVariableInputItem = ({ minH={40} maxH={160} bg={'myGray.50'} - {...register(`variables.${item.key}`, { - required: item.required - })} + {...register(`variables.${item.key}`)} /> ); } @@ -231,7 +214,7 @@ const VariableInput = ({ setValue(`variables.${item.key}`, item.defaultValue); } }); - }, [variableList]); + }, [allVariableList, getValues, setValue, variableList]); return ( @@ -257,7 +240,7 @@ const VariableInput = ({ rounded={'sm'} > - {t('common:core.chat.Visiable_in_test')} + {t('chat:variable_invisable_in_share')} {externalVariableList.map((item) => ( diff --git a/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/VariablePopover.tsx b/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/VariablePopover.tsx index d75ada0ab..2e54c5815 100644 --- a/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/VariablePopover.tsx +++ b/projects/app/src/components/core/chat/ChatContainer/ChatBox/components/VariablePopover.tsx @@ -65,7 +65,7 @@ const VariablePopover = ({ rounded={'sm'} > - {t('common:core.chat.Visiable_in_test')} + {t('chat:variable_invisable_in_share')} {externalVariableList.map((item) => ( { container.removeEventListener('scroll', checkVariableVisibility); }; } - }, [setIsVariableVisible]); + }, [chatType, setIsVariableVisible]); const RenderRecords = useMemo(() => { return ( diff --git a/projects/app/src/components/core/chat/ChatContainer/PluginRunBox/components/renderPluginInput.tsx b/projects/app/src/components/core/chat/ChatContainer/PluginRunBox/components/renderPluginInput.tsx index ba28be3ef..879de95dd 100644 --- a/projects/app/src/components/core/chat/ChatContainer/PluginRunBox/components/renderPluginInput.tsx +++ b/projects/app/src/components/core/chat/ChatContainer/PluginRunBox/components/renderPluginInput.tsx @@ -255,7 +255,7 @@ const RenderPluginInput = ({ rounded={'sm'} > - {t('common:core.chat.Variable_Visiable_in_test')} + {t('chat:variable_invisable_in_share')} )} diff --git a/projects/app/src/pageComponents/app/detail/SimpleApp/ChatTest.tsx b/projects/app/src/pageComponents/app/detail/SimpleApp/ChatTest.tsx index a1611b7a8..e03edb08b 100644 --- a/projects/app/src/pageComponents/app/detail/SimpleApp/ChatTest.tsx +++ b/projects/app/src/pageComponents/app/detail/SimpleApp/ChatTest.tsx @@ -70,7 +70,7 @@ const ChatTest = ({ appForm, setRenderEdit }: Props) => { {t('app:chat_debug')} - {!isVariableVisible && } + {!isVariableVisible && } { {t('common:core.chat.Run test')} - {!isVariableVisible && } + {!isVariableVisible && }