fix node variable update render (#5251)

* fix node variable update render

* editor value formatted

* fix
This commit is contained in:
heheer
2025-07-18 15:48:26 +08:00
committed by GitHub
parent 530f30e3e8
commit 6f75c1b80e
12 changed files with 59 additions and 33 deletions

View File

@@ -1,6 +1,6 @@
import type { BoxProps } from '@chakra-ui/react'; import type { BoxProps } from '@chakra-ui/react';
import { Box, Button, ModalBody, ModalFooter, useDisclosure } from '@chakra-ui/react'; import { Box, Button, ModalBody, ModalFooter, useDisclosure } from '@chakra-ui/react';
import React from 'react'; import React, { useMemo } from 'react';
import { editorStateToText } from './utils'; import { editorStateToText } from './utils';
import Editor from './Editor'; import Editor from './Editor';
import MyModal from '../../MyModal'; import MyModal from '../../MyModal';
@@ -58,6 +58,12 @@ const PromptEditor = ({
}, },
[onBlur] [onBlur]
); );
const formattedValue = useMemo(() => {
if (typeof value === 'object') {
return JSON.stringify(value);
}
return value;
}, [value]);
return ( return (
<> <>
@@ -70,7 +76,7 @@ const PromptEditor = ({
minH={minH} minH={minH}
maxH={maxH} maxH={maxH}
maxLength={maxLength} maxLength={maxLength}
value={value} value={formattedValue}
onChange={onChangeInput} onChange={onChangeInput}
onBlur={onBlurInput} onBlur={onBlurInput}
placeholder={placeholder} placeholder={placeholder}

View File

@@ -6,11 +6,15 @@ import { InputTypeEnum } from './constant';
import { FlowNodeInputTypeEnum } from '@fastgpt/global/core/workflow/node/constant'; import { FlowNodeInputTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
import type { InputConfigType } from '@fastgpt/global/core/workflow/type/io'; import type { InputConfigType } from '@fastgpt/global/core/workflow/type/io';
export const variableInputTypeToInputType = (inputType: VariableInputEnum) => { export const variableInputTypeToInputType = (
inputType: VariableInputEnum,
valueType?: WorkflowIOValueTypeEnum
) => {
if (inputType === VariableInputEnum.input) return InputTypeEnum.input; if (inputType === VariableInputEnum.input) return InputTypeEnum.input;
if (inputType === VariableInputEnum.textarea) return InputTypeEnum.textarea; if (inputType === VariableInputEnum.textarea) return InputTypeEnum.textarea;
if (inputType === VariableInputEnum.numberInput) return InputTypeEnum.numberInput; if (inputType === VariableInputEnum.numberInput) return InputTypeEnum.numberInput;
if (inputType === VariableInputEnum.select) return InputTypeEnum.select; if (inputType === VariableInputEnum.select) return InputTypeEnum.select;
if (inputType === VariableInputEnum.custom) return valueTypeToInputType(valueType);
return InputTypeEnum.JSONEditor; return InputTypeEnum.JSONEditor;
}; };

View File

@@ -23,13 +23,14 @@ import { getChatResData } from '@/web/core/chat/api';
import { ChatItemContext } from '@/web/core/chat/context/chatItemContext'; import { ChatItemContext } from '@/web/core/chat/context/chatItemContext';
import { ChatRecordContext } from '@/web/core/chat/context/chatRecordContext'; import { ChatRecordContext } from '@/web/core/chat/context/chatRecordContext';
import { useCreation } from 'ahooks'; import { useCreation } from 'ahooks';
import type { ChatTypeEnum } from './constants';
export type ChatProviderProps = { export type ChatProviderProps = {
appId: string; appId: string;
chatId: string; chatId: string;
outLinkAuthData?: OutLinkChatAuthProps; outLinkAuthData?: OutLinkChatAuthProps;
chatType: 'log' | 'chat' | 'share' | 'team'; chatType: ChatTypeEnum;
}; };
type useChatStoreType = ChatProviderProps & { type useChatStoreType = ChatProviderProps & {
@@ -130,7 +131,7 @@ const Provider = ({
appId, appId,
chatId, chatId,
outLinkAuthData, outLinkAuthData,
chatType = 'chat', chatType,
children, children,
...props ...props
}: ChatProviderProps & { }: ChatProviderProps & {

View File

@@ -79,17 +79,19 @@ const VariableInput = ({
<MyIcon name={'common/info'} color={'primary.600'} w={4} /> <MyIcon name={'common/info'} color={'primary.600'} w={4} />
{t('chat:variable_invisable_in_share')} {t('chat:variable_invisable_in_share')}
</Flex> </Flex>
{externalVariableList.map((item) => ( {externalVariableList.map((item) => {
<LabelAndFormRender return (
{...item} <LabelAndFormRender
key={item.key} {...item}
formKey={`variables.${item.key}`} key={item.key}
placeholder={item.description} formKey={`variables.${item.key}`}
inputType={variableInputTypeToInputType(item.type)} placeholder={item.description}
variablesForm={variablesForm} inputType={variableInputTypeToInputType(item.type, item.valueType)}
bg={'myGray.50'} variablesForm={variablesForm}
/> bg={'myGray.50'}
))} />
);
})}
{variableList.length === 0 && !chatStarted && ( {variableList.length === 0 && !chatStarted && (
<Button <Button
leftIcon={<MyIcon name={'core/chat/chatFill'} w={'16px'} />} leftIcon={<MyIcon name={'core/chat/chatFill'} w={'16px'} />}

View File

@@ -17,3 +17,10 @@ export enum FeedbackTypeEnum {
admin = 'admin', admin = 'admin',
hidden = 'hidden' hidden = 'hidden'
} }
export enum ChatTypeEnum {
chat = 'chat',
log = 'log',
share = 'share',
team = 'team'
}

View File

@@ -47,7 +47,7 @@ import {
formatChatValue2InputType, formatChatValue2InputType,
setUserSelectResultToHistories setUserSelectResultToHistories
} from './utils'; } from './utils';
import { textareaMinH } from './constants'; import { ChatTypeEnum, textareaMinH } from './constants';
import { SseResponseEventEnum } from '@fastgpt/global/core/workflow/runtime/constants'; import { SseResponseEventEnum } from '@fastgpt/global/core/workflow/runtime/constants';
import ChatProvider, { ChatBoxContext, type ChatProviderProps } from './Provider'; import ChatProvider, { ChatBoxContext, type ChatProviderProps } from './Provider';
@@ -155,7 +155,7 @@ const ChatBox = ({
const isInteractive = useMemo(() => checkIsInteractiveByHistories(chatRecords), [chatRecords]); const isInteractive = useMemo(() => checkIsInteractiveByHistories(chatRecords), [chatRecords]);
const externalVariableList = useMemo(() => { const externalVariableList = useMemo(() => {
if (chatType === 'chat') { if ([ChatTypeEnum.log, ChatTypeEnum.chat].includes(chatType)) {
return allVariableList.filter((item) => item.type === VariableInputEnum.custom); return allVariableList.filter((item) => item.type === VariableInputEnum.custom);
} }
return []; return [];
@@ -972,7 +972,7 @@ const ChatBox = ({
<VariableInputForm <VariableInputForm
chatStarted={chatStarted} chatStarted={chatStarted}
chatForm={chatForm} chatForm={chatForm}
showExternalVariables={chatType === 'chat'} showExternalVariables={[ChatTypeEnum.log, ChatTypeEnum.chat].includes(chatType)}
/> />
</Box> </Box>
)} )}

View File

@@ -20,6 +20,7 @@ import ChatRecordContextProvider, {
import { useRequest2 } from '@fastgpt/web/hooks/useRequest'; import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
import { useContextSelector } from 'use-context-selector'; import { useContextSelector } from 'use-context-selector';
import ChatQuoteList from '@/pageComponents/chat/ChatQuoteList'; import ChatQuoteList from '@/pageComponents/chat/ChatQuoteList';
import { ChatTypeEnum } from '@/components/core/chat/ChatContainer/ChatBox/constants';
const PluginRunBox = dynamic(() => import('@/components/core/chat/ChatContainer/PluginRunBox')); const PluginRunBox = dynamic(() => import('@/components/core/chat/ChatContainer/PluginRunBox'));
const ChatBox = dynamic(() => import('@/components/core/chat/ChatContainer/ChatBox')); const ChatBox = dynamic(() => import('@/components/core/chat/ChatContainer/ChatBox'));
@@ -164,7 +165,7 @@ const DetailLogsModal = ({ appId, chatId, onClose }: Props) => {
feedbackType={'admin'} feedbackType={'admin'}
showMarkIcon showMarkIcon
showVoiceIcon={false} showVoiceIcon={false}
chatType="log" chatType={ChatTypeEnum.log}
/> />
)} )}
</Box> </Box>

View File

@@ -31,6 +31,7 @@ import { WorkflowNodeEdgeContext } from '../../context/workflowInitContext';
import { useSystemStore } from '@/web/common/system/useSystemStore'; import { useSystemStore } from '@/web/common/system/useSystemStore';
import InputRender from '@/components/core/app/formRender'; import InputRender from '@/components/core/app/formRender';
import { valueTypeToInputType } from '@/components/core/app/formRender/utils'; import { valueTypeToInputType } from '@/components/core/app/formRender/utils';
import { isValidReferenceValueFormat } from '@fastgpt/global/core/workflow/utils';
const NodeVariableUpdate = ({ data, selected }: NodeProps<FlowNodeItemType>) => { const NodeVariableUpdate = ({ data, selected }: NodeProps<FlowNodeItemType>) => {
const { inputs = [], nodeId } = data; const { inputs = [], nodeId } = data;
@@ -110,19 +111,19 @@ const NodeVariableUpdate = ({ data, selected }: NodeProps<FlowNodeItemType>) =>
(item) => item.renderType === updateItem.renderType (item) => item.renderType === updateItem.renderType
); );
const onUpdateNewValue = (newValue?: ReferenceValueType | string) => { const onUpdateNewValue = (newValue: any) => {
if (typeof newValue === 'string') { if (isValidReferenceValueFormat(newValue)) {
onUpdateList(
updateList.map((update, i) =>
i === index ? { ...update, value: ['', newValue] } : update
)
);
} else if (newValue) {
onUpdateList( onUpdateList(
updateList.map((update, i) => updateList.map((update, i) =>
i === index ? { ...update, value: newValue as ReferenceItemValueType } : update i === index ? { ...update, value: newValue as ReferenceItemValueType } : update
) )
); );
} else {
onUpdateList(
updateList.map((update, i) =>
i === index ? { ...update, value: ['', newValue] } : update
)
);
} }
}; };
@@ -224,7 +225,7 @@ const NodeVariableUpdate = ({ data, selected }: NodeProps<FlowNodeItemType>) =>
const inputValue = isArray(updateItem.value?.[1]) ? '' : updateItem.value?.[1]; const inputValue = isArray(updateItem.value?.[1]) ? '' : updateItem.value?.[1];
return ( return (
<Box w={'300px'} bg={'white'} borderRadius={'sm'}> <Box w={'300px'} borderRadius={'sm'}>
<InputRender <InputRender
inputType={valueTypeToInputType(valueType)} inputType={valueTypeToInputType(valueType)}
value={inputValue || ''} value={inputValue || ''}

View File

@@ -18,6 +18,7 @@ import { ChatItemContext } from '@/web/core/chat/context/chatItemContext';
import { useRequest2 } from '@fastgpt/web/hooks/useRequest'; import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
import { getInitChatInfo } from '@/web/core/chat/api'; import { getInitChatInfo } from '@/web/core/chat/api';
import { useTranslation } from 'next-i18next'; import { useTranslation } from 'next-i18next';
import { ChatTypeEnum } from '@/components/core/chat/ChatContainer/ChatBox/constants';
const PluginRunBox = dynamic(() => import('@/components/core/chat/ChatContainer/PluginRunBox')); const PluginRunBox = dynamic(() => import('@/components/core/chat/ChatContainer/PluginRunBox'));
@@ -140,7 +141,7 @@ export const useChatTest = ({
appId={appId} appId={appId}
chatId={chatId} chatId={chatId}
showMarkIcon showMarkIcon
chatType={'chat'} chatType={ChatTypeEnum.chat}
onStartChat={startChat} onStartChat={startChat}
/> />
) )

View File

@@ -37,6 +37,7 @@ import ChatRecordContextProvider, {
ChatRecordContext ChatRecordContext
} from '@/web/core/chat/context/chatRecordContext'; } from '@/web/core/chat/context/chatRecordContext';
import ChatQuoteList from '@/pageComponents/chat/ChatQuoteList'; import ChatQuoteList from '@/pageComponents/chat/ChatQuoteList';
import { ChatTypeEnum } from '@/components/core/chat/ChatContainer/ChatBox/constants';
const CustomPluginRunBox = dynamic(() => import('@/pageComponents/chat/CustomPluginRunBox')); const CustomPluginRunBox = dynamic(() => import('@/pageComponents/chat/CustomPluginRunBox'));
@@ -212,7 +213,7 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
showEmptyIntro showEmptyIntro
feedbackType={'user'} feedbackType={'user'}
onStartChat={onStartChat} onStartChat={onStartChat}
chatType={'chat'} chatType={ChatTypeEnum.chat}
isReady={!loading} isReady={!loading}
/> />
)} )}

View File

@@ -39,6 +39,7 @@ import { useI18nLng } from '@fastgpt/web/hooks/useI18n';
import { type AppSchema } from '@fastgpt/global/core/app/type'; import { type AppSchema } from '@fastgpt/global/core/app/type';
import ChatQuoteList from '@/pageComponents/chat/ChatQuoteList'; import ChatQuoteList from '@/pageComponents/chat/ChatQuoteList';
import { useToast } from '@fastgpt/web/hooks/useToast'; import { useToast } from '@fastgpt/web/hooks/useToast';
import { ChatTypeEnum } from '@/components/core/chat/ChatContainer/ChatBox/constants';
const CustomPluginRunBox = dynamic(() => import('@/pageComponents/chat/CustomPluginRunBox')); const CustomPluginRunBox = dynamic(() => import('@/pageComponents/chat/CustomPluginRunBox'));
@@ -294,7 +295,7 @@ const OutLink = (props: Props) => {
outLinkAuthData={outLinkAuthData} outLinkAuthData={outLinkAuthData}
feedbackType={'user'} feedbackType={'user'}
onStartChat={startChat} onStartChat={startChat}
chatType="share" chatType={ChatTypeEnum.share}
/> />
)} )}
</Box> </Box>

View File

@@ -34,6 +34,7 @@ import { useChatStore } from '@/web/core/chat/context/useChatStore';
import { useMount } from 'ahooks'; import { useMount } from 'ahooks';
import { ChatSourceEnum } from '@fastgpt/global/core/chat/constants'; import { ChatSourceEnum } from '@fastgpt/global/core/chat/constants';
import ChatQuoteList from '@/pageComponents/chat/ChatQuoteList'; import ChatQuoteList from '@/pageComponents/chat/ChatQuoteList';
import { ChatTypeEnum } from '@/components/core/chat/ChatContainer/ChatBox/constants';
const CustomPluginRunBox = dynamic(() => import('@/pageComponents/chat/CustomPluginRunBox')); const CustomPluginRunBox = dynamic(() => import('@/pageComponents/chat/CustomPluginRunBox'));
type Props = { appId: string; chatId: string; teamId: string; teamToken: string }; type Props = { appId: string; chatId: string; teamId: string; teamToken: string };
@@ -228,7 +229,7 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
outLinkAuthData={outLinkAuthData} outLinkAuthData={outLinkAuthData}
feedbackType={'user'} feedbackType={'user'}
onStartChat={startChat} onStartChat={startChat}
chatType="team" chatType={ChatTypeEnum.team}
/> />
)} )}
</Box> </Box>