Skip to content

Commit 97a182c

Browse files
committed
perf: custom varialbe (#4225)
1 parent a0ad450 commit 97a182c

File tree

13 files changed

+23
-42
lines changed

13 files changed

+23
-42
lines changed

docSite/content/zh-cn/docs/development/upgrading/492.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ weight: 799
1111
## 🚀 新增内容
1212

1313
1. 知识库分块增加自定义分隔符预设值,同时支持自定义换行符分割。
14+
2. 外部变量改名:自定义变量。 并且支持在测试时调试,在分享链接中,该变量直接隐藏。
1415

1516
## ⚙️ 优化
1617

packages/web/i18n/en/chat.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"to_dataset": "Go to the Knowledge Base",
6060
"unsupported_file_type": "Unsupported file types",
6161
"upload": "Upload",
62+
"variable_invisable_in_share": "Custom variables are not visible in login-free links",
6263
"view_citations": "View References",
6364
"web_site_sync": "Web Site Sync"
6465
}

packages/web/i18n/en/common.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,6 @@
430430
"core.chat.Start Chat": "Start Chat",
431431
"core.chat.Type a message": "Enter a Question, Press [Enter] to Send / Press [Ctrl(Alt/Shift) + Enter] for New Line",
432432
"core.chat.Unpin": "Unpin",
433-
"core.chat.Variable_Visiable_in_test": "This variable is not visible in the login-free link",
434-
"core.chat.Visiable_in_test": "Custom variables are not visible in login-free links",
435433
"core.chat.You need to a chat app": "You Do Not Have an Available App",
436434
"core.chat.error.Chat error": "Chat Error",
437435
"core.chat.error.Messages empty": "API Content is Empty, Possibly Due to Text Being Too Long",

packages/web/i18n/zh-CN/chat.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"to_dataset": "前往知识库",
6060
"unsupported_file_type": "不支持的文件类型",
6161
"upload": "上传",
62+
"variable_invisable_in_share": "自定义变量在免登录链接中不可见",
6263
"view_citations": "查看引用",
6364
"web_site_sync": "Web站点同步"
6465
}

packages/web/i18n/zh-CN/common.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,6 @@
433433
"core.chat.Start Chat": "开始对话",
434434
"core.chat.Type a message": "输入问题,发送 [Enter]/换行 [Ctrl(Alt/Shift) + Enter]",
435435
"core.chat.Unpin": "取消置顶",
436-
"core.chat.Variable_Visiable_in_test": "该变量在免登录链接中不可见",
437-
"core.chat.Visiable_in_test": "自定义变量在免登录链接中不可见",
438436
"core.chat.You need to a chat app": "你没有可用的应用",
439437
"core.chat.error.Chat error": "对话出现异常",
440438
"core.chat.error.Messages empty": "接口内容为空,可能文本超长了~",

packages/web/i18n/zh-Hant/chat.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"to_dataset": "前往知識庫",
5959
"unsupported_file_type": "不支援的檔案類型",
6060
"upload": "上傳",
61+
"variable_invisable_in_share": "自定義變量在免登錄鏈接中不可見",
6162
"view_citations": "檢視引用",
6263
"web_site_sync": "網站同步"
6364
}

packages/web/i18n/zh-Hant/common.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,6 @@
429429
"core.chat.Start Chat": "開始對話",
430430
"core.chat.Type a message": "輸入問題,按 [Enter] 傳送 / 按 [Ctrl(Alt/Shift) + Enter] 換行",
431431
"core.chat.Unpin": "取消釘選",
432-
"core.chat.Variable_Visiable_in_test": "該變量在免登錄鏈接中不可見",
433-
"core.chat.Visiable_in_test": "自定義變量在免登錄鏈接中不可見",
434432
"core.chat.You need to a chat app": "您沒有可用的應用程式",
435433
"core.chat.error.Chat error": "對話發生錯誤",
436434
"core.chat.error.Messages empty": "API 內容為空,可能是文字過長",

projects/app/src/components/core/chat/ChatContainer/ChatBox/components/VariableInput.tsx

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,10 @@ export const ExternalVariableInputItem = ({
126126
const { t } = useTranslation();
127127
const { register, control } = variablesForm;
128128

129-
return (
130-
<Box key={item.id} mb={4} pl={1}>
131-
<Box
132-
as={'label'}
133-
display={'flex'}
134-
position={'relative'}
135-
mb={1}
136-
alignItems={'center'}
137-
w={'full'}
138-
>
129+
const Label = useMemo(() => {
130+
return (
131+
<Box display={'flex'} position={'relative'} mb={1} alignItems={'center'} w={'full'}>
139132
{item.label}
140-
{item.required && (
141-
<Box position={'absolute'} top={'-2px'} left={'-8px'} color={'red.500'}>
142-
*
143-
</Box>
144-
)}
145133
{item.description && <QuestionTip ml={1} label={item.description} />}
146134
{showTag && (
147135
<Flex
@@ -155,22 +143,19 @@ export const ExternalVariableInputItem = ({
155143
rounded={'sm'}
156144
>
157145
<MyIcon name={'common/info'} color={'primary.600'} w={4} />
158-
{t('common:core.chat.Variable_Visiable_in_test')}
146+
{t('chat:variable_invisable_in_share')}
159147
</Flex>
160148
)}
161149
</Box>
150+
);
151+
}, [item.description, item.label, showTag, t]);
152+
153+
return (
154+
<Box key={item.id} mb={4} pl={1}>
155+
{Label}
162156
<Controller
163157
control={control}
164158
name={`variables.${item.key}`}
165-
rules={{
166-
required: item.required,
167-
validate: (value) => {
168-
if (item.valueType === WorkflowIOValueTypeEnum.boolean) {
169-
return value !== undefined;
170-
}
171-
return !!value;
172-
}
173-
}}
174159
render={({ field: { onChange, value } }) => {
175160
if (item.valueType === WorkflowIOValueTypeEnum.string) {
176161
return (
@@ -179,9 +164,7 @@ export const ExternalVariableInputItem = ({
179164
minH={40}
180165
maxH={160}
181166
bg={'myGray.50'}
182-
{...register(`variables.${item.key}`, {
183-
required: item.required
184-
})}
167+
{...register(`variables.${item.key}`)}
185168
/>
186169
);
187170
}
@@ -231,7 +214,7 @@ const VariableInput = ({
231214
setValue(`variables.${item.key}`, item.defaultValue);
232215
}
233216
});
234-
}, [variableList]);
217+
}, [allVariableList, getValues, setValue, variableList]);
235218

236219
return (
237220
<Box py={3}>
@@ -257,7 +240,7 @@ const VariableInput = ({
257240
rounded={'sm'}
258241
>
259242
<MyIcon name={'common/info'} color={'primary.600'} w={4} />
260-
{t('common:core.chat.Visiable_in_test')}
243+
{t('chat:variable_invisable_in_share')}
261244
</Flex>
262245
{externalVariableList.map((item) => (
263246
<ExternalVariableInputItem key={item.id} item={item} variablesForm={variablesForm} />

projects/app/src/components/core/chat/ChatContainer/ChatBox/components/VariablePopover.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const VariablePopover = ({
6565
rounded={'sm'}
6666
>
6767
<MyIcon name={'common/info'} color={'primary.600'} w={4} />
68-
{t('common:core.chat.Visiable_in_test')}
68+
{t('chat:variable_invisable_in_share')}
6969
</Flex>
7070
{externalVariableList.map((item) => (
7171
<ExternalVariableInputItem

projects/app/src/components/core/chat/ChatContainer/ChatBox/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -921,14 +921,14 @@ const ChatBox = ({
921921

922922
const container = ScrollContainerRef.current;
923923
if (container) {
924-
container.addEventListener('scroll', checkVariableVisibility);
925924
checkVariableVisibility();
925+
container.addEventListener('scroll', checkVariableVisibility);
926926

927927
return () => {
928928
container.removeEventListener('scroll', checkVariableVisibility);
929929
};
930930
}
931-
}, [setIsVariableVisible]);
931+
}, [chatType, setIsVariableVisible]);
932932

933933
const RenderRecords = useMemo(() => {
934934
return (

0 commit comments

Comments
 (0)