### What problem does this PR solve? Fix: Fixed the issue that variables defined in the begin operator cannot be referenced in the switch operator. #3221 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)tags/v0.20.0
| } from '@/components/ui/tooltip'; | } from '@/components/ui/tooltip'; | ||||
| import { cn } from '@/lib/utils'; | import { cn } from '@/lib/utils'; | ||||
| import { | import { | ||||
| Background, | |||||
| ConnectionMode, | ConnectionMode, | ||||
| ControlButton, | ControlButton, | ||||
| Controls, | Controls, | ||||
| import { useCallback, useEffect } from 'react'; | import { useCallback, useEffect } from 'react'; | ||||
| import { useTranslation } from 'react-i18next'; | import { useTranslation } from 'react-i18next'; | ||||
| import { ChatSheet } from '../chat/chat-sheet'; | import { ChatSheet } from '../chat/chat-sheet'; | ||||
| import { AgentBackground } from '../components/background'; | |||||
| import { | import { | ||||
| AgentChatContext, | AgentChatContext, | ||||
| AgentChatLogContext, | AgentChatLogContext, | ||||
| deleteKeyCode={['Delete', 'Backspace']} | deleteKeyCode={['Delete', 'Backspace']} | ||||
| onBeforeDelete={handleBeforeDelete} | onBeforeDelete={handleBeforeDelete} | ||||
| > | > | ||||
| <Background /> | |||||
| <AgentBackground></AgentBackground> | |||||
| <Controls position={'bottom-center'} orientation="horizontal"> | <Controls position={'bottom-center'} orientation="horizontal"> | ||||
| <ControlButton> | <ControlButton> | ||||
| <Tooltip> | <Tooltip> |
| import { BeginId } from '../constant'; | import { BeginId } from '../constant'; | ||||
| import { AgentChatLogContext } from '../context'; | import { AgentChatLogContext } from '../context'; | ||||
| import { transferInputsArrayToObject } from '../form/begin-form/use-watch-change'; | import { transferInputsArrayToObject } from '../form/begin-form/use-watch-change'; | ||||
| import { useGetBeginNodeDataQuery } from '../hooks/use-get-begin-query'; | |||||
| import { useSelectBeginNodeDataInputs } from '../hooks/use-get-begin-query'; | |||||
| import { BeginQuery } from '../interface'; | import { BeginQuery } from '../interface'; | ||||
| import useGraphStore from '../store'; | import useGraphStore from '../store'; | ||||
| import { receiveMessageError } from '../utils'; | import { receiveMessageError } from '../utils'; | ||||
| const { handleInputChange, value, setValue } = useHandleMessageInputChange(); | const { handleInputChange, value, setValue } = useHandleMessageInputChange(); | ||||
| const { refetch } = useFetchAgent(); | const { refetch } = useFetchAgent(); | ||||
| const { addEventList } = useContext(AgentChatLogContext); | const { addEventList } = useContext(AgentChatLogContext); | ||||
| const getBeginNodeDataQuery = useGetBeginNodeDataQuery(); | |||||
| const inputs = useSelectBeginNodeDataInputs(); | |||||
| const [messageEndEventList, setMessageEndEventList] = useState< | const [messageEndEventList, setMessageEndEventList] = useState< | ||||
| IMessageEndEvent[] | IMessageEndEvent[] | ||||
| >([]); | >([]); | ||||
| defaultValue: 'is running...🕞', | defaultValue: 'is running...🕞', | ||||
| }); | }); | ||||
| if (message.content) { | if (message.content) { | ||||
| const query = getBeginNodeDataQuery(); | |||||
| const query = inputs; | |||||
| params.query = message.content; | params.query = message.content; | ||||
| // params.message_id = message.id; | // params.message_id = message.id; | ||||
| refetch(); // pull the message list after sending the message successfully | refetch(); // pull the message list after sending the message successfully | ||||
| } | } | ||||
| }, | }, | ||||
| [ | |||||
| agentId, | |||||
| send, | |||||
| getBeginNodeDataQuery, | |||||
| setValue, | |||||
| removeLatestMessage, | |||||
| refetch, | |||||
| ], | |||||
| [agentId, send, inputs, setValue, removeLatestMessage, refetch], | |||||
| ); | ); | ||||
| const handleSendMessage = useCallback( | const handleSendMessage = useCallback( |
| import { Background } from '@xyflow/react'; | |||||
| export function AgentBackground() { | |||||
| return ( | |||||
| <Background color="rgba(255,255,255,0.15)" bgColor="rgba(22, 22, 24, 1)" /> | |||||
| ); | |||||
| } |
| import { BeginQuery } from '../interface'; | import { BeginQuery } from '../interface'; | ||||
| import useGraphStore from '../store'; | import useGraphStore from '../store'; | ||||
| export function useSelectBeginNodeDataInputs() { | |||||
| const getNode = useGraphStore((state) => state.getNode); | |||||
| return buildBeginInputListFromObject( | |||||
| getNode(BeginId)?.data?.form?.inputs ?? {}, | |||||
| ); | |||||
| } | |||||
| export const useGetBeginNodeDataQuery = () => { | export const useGetBeginNodeDataQuery = () => { | ||||
| const getNode = useGraphStore((state) => state.getNode); | const getNode = useGraphStore((state) => state.getNode); | ||||
| export const useGetBeginNodeDataQueryIsSafe = () => { | export const useGetBeginNodeDataQueryIsSafe = () => { | ||||
| const [isBeginNodeDataQuerySafe, setIsBeginNodeDataQuerySafe] = | const [isBeginNodeDataQuerySafe, setIsBeginNodeDataQuerySafe] = | ||||
| useState(false); | useState(false); | ||||
| const getBeginNodeDataQuery = useGetBeginNodeDataQuery(); | |||||
| const inputs = useSelectBeginNodeDataInputs(); | |||||
| const nodes = useGraphStore((state) => state.nodes); | const nodes = useGraphStore((state) => state.nodes); | ||||
| useEffect(() => { | useEffect(() => { | ||||
| const query: BeginQuery[] = getBeginNodeDataQuery(); | |||||
| const query: BeginQuery[] = inputs; | |||||
| const isSafe = !query.some((q) => !q.optional && q.type === 'file'); | const isSafe = !query.some((q) => !q.optional && q.type === 'file'); | ||||
| setIsBeginNodeDataQuerySafe(isSafe); | setIsBeginNodeDataQuerySafe(isSafe); | ||||
| }, [getBeginNodeDataQuery, nodes]); | |||||
| }, [inputs, nodes]); | |||||
| return isBeginNodeDataQuerySafe; | return isBeginNodeDataQuerySafe; | ||||
| }; | }; | ||||
| } | } | ||||
| export function useBuildBeginVariableOptions() { | export function useBuildBeginVariableOptions() { | ||||
| const getBeginNodeDataQuery = useGetBeginNodeDataQuery(); | |||||
| const inputs = useSelectBeginNodeDataInputs(); | |||||
| const options = useMemo(() => { | const options = useMemo(() => { | ||||
| const query: BeginQuery[] = getBeginNodeDataQuery(); | |||||
| return [ | return [ | ||||
| { | { | ||||
| label: <span>Begin Input</span>, | label: <span>Begin Input</span>, | ||||
| title: 'Begin Input', | title: 'Begin Input', | ||||
| options: query.map((x) => ({ | |||||
| options: inputs.map((x) => ({ | |||||
| label: x.name, | label: x.name, | ||||
| value: `begin@${x.key}`, | value: `begin@${x.key}`, | ||||
| type: transferToVariableType(x.type), | type: transferToVariableType(x.type), | ||||
| })), | })), | ||||
| }, | }, | ||||
| ]; | ]; | ||||
| }, [getBeginNodeDataQuery]); | |||||
| }, [inputs]); | |||||
| return options; | return options; | ||||
| } | } |
| import get from 'lodash/get'; | import get from 'lodash/get'; | ||||
| import { useCallback, useEffect } from 'react'; | import { useCallback, useEffect } from 'react'; | ||||
| import { Operator } from '../constant'; | import { Operator } from '../constant'; | ||||
| import { BeginQuery } from '../interface'; | |||||
| import useGraphStore from '../store'; | import useGraphStore from '../store'; | ||||
| import { useCacheChatLog } from './use-cache-chat-log'; | import { useCacheChatLog } from './use-cache-chat-log'; | ||||
| import { useGetBeginNodeDataQuery } from './use-get-begin-query'; | |||||
| import { useGetBeginNodeDataInputs } from './use-get-begin-query'; | |||||
| import { useSaveGraph } from './use-save-graph'; | import { useSaveGraph } from './use-save-graph'; | ||||
| export const useShowFormDrawer = () => { | export const useShowFormDrawer = () => { | ||||
| } = useShowSingleDebugDrawer(); | } = useShowSingleDebugDrawer(); | ||||
| const { formDrawerVisible, hideFormDrawer, showFormDrawer, clickedNode } = | const { formDrawerVisible, hideFormDrawer, showFormDrawer, clickedNode } = | ||||
| useShowFormDrawer(); | useShowFormDrawer(); | ||||
| const getBeginNodeDataQuery = useGetBeginNodeDataQuery(); | |||||
| const inputs = useGetBeginNodeDataInputs(); | |||||
| useEffect(() => { | useEffect(() => { | ||||
| if (drawerVisible) { | if (drawerVisible) { | ||||
| const query: BeginQuery[] = getBeginNodeDataQuery(); | |||||
| if (query.length > 0) { | |||||
| if (inputs.length > 0) { | |||||
| showRunModal(); | showRunModal(); | ||||
| hideChatModal(); | hideChatModal(); | ||||
| } else { | } else { | ||||
| showChatModal, | showChatModal, | ||||
| showRunModal, | showRunModal, | ||||
| drawerVisible, | drawerVisible, | ||||
| getBeginNodeDataQuery, | |||||
| inputs, | |||||
| ]); | ]); | ||||
| const hideRunOrChatDrawer = useCallback(() => { | const hideRunOrChatDrawer = useCallback(() => { |
| import EmbedDialog from './embed-dialog'; | import EmbedDialog from './embed-dialog'; | ||||
| import { useHandleExportOrImportJsonFile } from './hooks/use-export-json'; | import { useHandleExportOrImportJsonFile } from './hooks/use-export-json'; | ||||
| import { useFetchDataOnMount } from './hooks/use-fetch-data'; | import { useFetchDataOnMount } from './hooks/use-fetch-data'; | ||||
| import { useGetBeginNodeDataQuery } from './hooks/use-get-begin-query'; | |||||
| import { useGetBeginNodeDataInputs } from './hooks/use-get-begin-query'; | |||||
| import { useOpenDocument } from './hooks/use-open-document'; | import { useOpenDocument } from './hooks/use-open-document'; | ||||
| import { | import { | ||||
| useSaveGraph, | useSaveGraph, | ||||
| useSaveGraphBeforeOpeningDebugDrawer, | useSaveGraphBeforeOpeningDebugDrawer, | ||||
| } from './hooks/use-save-graph'; | } from './hooks/use-save-graph'; | ||||
| import { useShowEmbedModal } from './hooks/use-show-dialog'; | import { useShowEmbedModal } from './hooks/use-show-dialog'; | ||||
| import { BeginQuery } from './interface'; | |||||
| import { UploadAgentDialog } from './upload-agent-dialog'; | import { UploadAgentDialog } from './upload-agent-dialog'; | ||||
| import { VersionDialog } from './version-dialog'; | import { VersionDialog } from './version-dialog'; | ||||
| } = useHandleExportOrImportJsonFile(); | } = useHandleExportOrImportJsonFile(); | ||||
| const { saveGraph, loading } = useSaveGraph(); | const { saveGraph, loading } = useSaveGraph(); | ||||
| const { flowDetail } = useFetchDataOnMount(); | const { flowDetail } = useFetchDataOnMount(); | ||||
| const getBeginNodeDataQuery = useGetBeginNodeDataQuery(); | |||||
| const inputs = useGetBeginNodeDataInputs(); | |||||
| const { handleRun } = useSaveGraphBeforeOpeningDebugDrawer(showChatDrawer); | const { handleRun } = useSaveGraphBeforeOpeningDebugDrawer(showChatDrawer); | ||||
| const handleRunAgent = useCallback(() => { | const handleRunAgent = useCallback(() => { | ||||
| const query: BeginQuery[] = getBeginNodeDataQuery(); | |||||
| if (query.length > 0) { | |||||
| if (inputs.length > 0) { | |||||
| showChatDrawer(); | showChatDrawer(); | ||||
| } else { | } else { | ||||
| handleRun(); | handleRun(); | ||||
| } | } | ||||
| }, [getBeginNodeDataQuery, handleRun, showChatDrawer]); | |||||
| }, [handleRun, inputs, showChatDrawer]); | |||||
| const { | const { | ||||
| visible: versionDialogVisible, | visible: versionDialogVisible, | ||||
| hideModal: hideVersionDialog, | hideModal: hideVersionDialog, |
| import { useTranslation } from 'react-i18next'; | import { useTranslation } from 'react-i18next'; | ||||
| import { BeginId } from '../constant'; | import { BeginId } from '../constant'; | ||||
| import DebugContent from '../debug-content'; | import DebugContent from '../debug-content'; | ||||
| import { useGetBeginNodeDataQuery } from '../hooks/use-get-begin-query'; | |||||
| import { useGetBeginNodeDataInputs } from '../hooks/use-get-begin-query'; | |||||
| import { useSaveGraphBeforeOpeningDebugDrawer } from '../hooks/use-save-graph'; | import { useSaveGraphBeforeOpeningDebugDrawer } from '../hooks/use-save-graph'; | ||||
| import { BeginQuery } from '../interface'; | import { BeginQuery } from '../interface'; | ||||
| import useGraphStore from '../store'; | import useGraphStore from '../store'; | ||||
| const { t } = useTranslation(); | const { t } = useTranslation(); | ||||
| const { updateNodeForm, getNode } = useGraphStore((state) => state); | const { updateNodeForm, getNode } = useGraphStore((state) => state); | ||||
| const getBeginNodeDataQuery = useGetBeginNodeDataQuery(); | |||||
| const query: BeginQuery[] = getBeginNodeDataQuery(); | |||||
| const inputs = useGetBeginNodeDataInputs(); | |||||
| const { handleRun, loading } = useSaveGraphBeforeOpeningDebugDrawer( | const { handleRun, loading } = useSaveGraphBeforeOpeningDebugDrawer( | ||||
| showChatModal!, | showChatModal!, | ||||
| <SheetTitle>{t('flow.testRun')}</SheetTitle> | <SheetTitle>{t('flow.testRun')}</SheetTitle> | ||||
| <DebugContent | <DebugContent | ||||
| ok={onOk} | ok={onOk} | ||||
| parameters={query} | |||||
| parameters={inputs} | |||||
| loading={loading} | loading={loading} | ||||
| ></DebugContent> | ></DebugContent> | ||||
| </SheetHeader> | </SheetHeader> |
| import { cn } from '@/lib/utils'; | import { cn } from '@/lib/utils'; | ||||
| import { formatDate } from '@/utils/date'; | import { formatDate } from '@/utils/date'; | ||||
| import { downloadJsonFile } from '@/utils/file-util'; | import { downloadJsonFile } from '@/utils/file-util'; | ||||
| import { | |||||
| Background, | |||||
| ConnectionMode, | |||||
| ReactFlow, | |||||
| ReactFlowProvider, | |||||
| } from '@xyflow/react'; | |||||
| import { ConnectionMode, ReactFlow, ReactFlowProvider } from '@xyflow/react'; | |||||
| import { ArrowDownToLine } from 'lucide-react'; | import { ArrowDownToLine } from 'lucide-react'; | ||||
| import { ReactNode, useCallback, useEffect, useState } from 'react'; | import { ReactNode, useCallback, useEffect, useState } from 'react'; | ||||
| import { useTranslation } from 'react-i18next'; | import { useTranslation } from 'react-i18next'; | ||||
| import { nodeTypes } from '../canvas'; | import { nodeTypes } from '../canvas'; | ||||
| import { AgentBackground } from '../components/background'; | |||||
| export function VersionDialog({ | export function VersionDialog({ | ||||
| hideModal, | hideModal, | ||||
| zoomOnDoubleClick={false} | zoomOnDoubleClick={false} | ||||
| preventScrolling={true} | preventScrolling={true} | ||||
| minZoom={0.1} | minZoom={0.1} | ||||
| className="!bg-background-agent" | |||||
| > | > | ||||
| <Background /> | |||||
| <AgentBackground></AgentBackground> | |||||
| </ReactFlow> | </ReactFlow> | ||||
| </ReactFlowProvider> | </ReactFlowProvider> | ||||
| </section> | </section> |