mirror of
https://github.com/labring/FastGPT.git
synced 2025-08-03 05:19:51 +00:00
Global variables support external variable; Extract module support default value (#921)
This commit is contained in:
@@ -186,6 +186,10 @@ const ChatBox = (
|
||||
() => splitGuideModule(userGuideModule),
|
||||
[userGuideModule]
|
||||
);
|
||||
const filterVariableModules = useMemo(
|
||||
() => variableModules.filter((item) => item.type !== VariableInputEnum.external),
|
||||
[variableModules]
|
||||
);
|
||||
|
||||
// compute variable input is finish.
|
||||
const chatForm = useForm<{
|
||||
@@ -200,17 +204,18 @@ const ChatBox = (
|
||||
|
||||
const [variableInputFinish, setVariableInputFinish] = useState(false); // clicked start chat button
|
||||
const variableIsFinish = useMemo(() => {
|
||||
if (!variableModules || variableModules.length === 0 || chatHistory.length > 0) return true;
|
||||
if (!filterVariableModules || filterVariableModules.length === 0 || chatHistory.length > 0)
|
||||
return true;
|
||||
|
||||
for (let i = 0; i < variableModules.length; i++) {
|
||||
const item = variableModules[i];
|
||||
for (let i = 0; i < filterVariableModules.length; i++) {
|
||||
const item = filterVariableModules[i];
|
||||
if (item.required && !variables[item.key]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return variableInputFinish;
|
||||
}, [chatHistory.length, variableInputFinish, variableModules, variables]);
|
||||
}, [chatHistory.length, variableInputFinish, filterVariableModules, variables]);
|
||||
|
||||
// 滚动到底部
|
||||
const scrollToBottom = (behavior: 'smooth' | 'auto' = 'smooth') => {
|
||||
@@ -495,7 +500,7 @@ const ChatBox = (
|
||||
getChatHistories: () => chatHistory,
|
||||
resetVariables(e) {
|
||||
const defaultVal: Record<string, any> = {};
|
||||
variableModules?.forEach((item) => {
|
||||
filterVariableModules?.forEach((item) => {
|
||||
defaultVal[item.key] = '';
|
||||
});
|
||||
|
||||
@@ -519,13 +524,13 @@ const ChatBox = (
|
||||
feConfigs?.show_emptyChat &&
|
||||
showEmptyIntro &&
|
||||
chatHistory.length === 0 &&
|
||||
!variableModules?.length &&
|
||||
!filterVariableModules?.length &&
|
||||
!welcomeText,
|
||||
[
|
||||
chatHistory.length,
|
||||
feConfigs?.show_emptyChat,
|
||||
showEmptyIntro,
|
||||
variableModules?.length,
|
||||
filterVariableModules?.length,
|
||||
welcomeText
|
||||
]
|
||||
);
|
||||
@@ -604,10 +609,10 @@ const ChatBox = (
|
||||
{showEmpty && <Empty />}
|
||||
{!!welcomeText && <WelcomeText appAvatar={appAvatar} welcomeText={welcomeText} />}
|
||||
{/* variable input */}
|
||||
{!!variableModules?.length && (
|
||||
{!!filterVariableModules?.length && (
|
||||
<VariableInput
|
||||
appAvatar={appAvatar}
|
||||
variableModules={variableModules}
|
||||
variableModules={filterVariableModules}
|
||||
variableIsFinish={variableIsFinish}
|
||||
chatForm={chatForm}
|
||||
onSubmitVariables={onSubmitVariables}
|
||||
|
Reference in New Issue
Block a user