From 928751a856fbab13dddb02556c1696e4c263d928 Mon Sep 17 00:00:00 2001 From: jyong <718720800@qq.com> Date: Mon, 14 Jul 2025 14:11:58 +0800 Subject: [PATCH 1/6] r2 --- .../variables/manager.py | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/api/core/app/app_config/workflow_ui_based_app/variables/manager.py b/api/core/app/app_config/workflow_ui_based_app/variables/manager.py index 5be87a3bb6..76139c4ebe 100644 --- a/api/core/app/app_config/workflow_ui_based_app/variables/manager.py +++ b/api/core/app/app_config/workflow_ui_based_app/variables/manager.py @@ -1,3 +1,4 @@ +import re from core.app.app_config.entities import RagPipelineVariableEntity, VariableEntity from models.workflow import Workflow @@ -30,10 +31,34 @@ class WorkflowVariablesConfigManager: """ variables = [] - user_input_form = workflow.rag_pipeline_user_input_form() - # filter variables by start_node_id - for variable in user_input_form: - if variable.get("belong_to_node_id") == start_node_id or variable.get("belong_to_node_id") == "shared": - variables.append(RagPipelineVariableEntity.model_validate(variable)) + # get second step node + rag_pipeline_variables = workflow.rag_pipeline_variables + if not rag_pipeline_variables: + return [] + variables_map = {item["variable"]: item for item in rag_pipeline_variables} + + # get datasource node data + datasource_node_data = None + datasource_nodes = workflow.graph_dict.get("nodes", []) + for datasource_node in datasource_nodes: + if datasource_node.get("id") == start_node_id: + datasource_node_data = datasource_node.get("data", {}) + break + if datasource_node_data: + datasource_parameters = datasource_node_data.get("datasource_parameters", {}) + + for key, value in datasource_parameters.items(): + if value.get("value") and isinstance(value.get("value"), str): + pattern = r"\{\{#([a-zA-Z0-9_]{1,50}(?:\.[a-zA-Z0-9_][a-zA-Z0-9_]{0,29}){1,10})#\}\}" + match = re.match(pattern, value["value"]) + if match: + full_path = match.group(1) + last_part = full_path.split(".")[-1] + variables_map.pop(last_part) + all_second_step_variables = list(variables_map.values()) + + for item in all_second_step_variables: + if item.get("belong_to_node_id") == start_node_id or item.get("belong_to_node_id") == "shared": + variables.append(RagPipelineVariableEntity.model_validate(item)) return variables From 7a9faf909ea666a45bd5dc92f4b9c16c3487808a Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 14 Jul 2025 15:10:21 +0800 Subject: [PATCH 2/6] feat: workflow use common last run --- .../workflow-app/hooks/use-configs-map.ts | 3 ++ .../hooks/use-inspect-vars-crud.ts | 3 -- .../workflow-app/hooks/use-workflow-run.ts | 6 +-- .../workflow/header/header-in-restoring.tsx | 7 ++- .../components/workflow/hooks-store/store.ts | 3 ++ .../hooks/use-fetch-workflow-inspect-vars.ts | 7 ++- .../hooks/use-inspect-vars-crud-common.ts | 23 ++++---- .../_base/components/workflow-panel/index.tsx | 5 ++ .../workflow-panel/last-run/index.tsx | 5 +- .../workflow-panel/last-run/use-last-run.ts | 9 +++- .../nodes/_base/hooks/use-one-step-run.ts | 20 +++---- .../workflow/panel/debug-and-preview/hooks.ts | 6 +-- .../panel/version-history-panel/index.tsx | 6 +-- web/service/use-flow.ts | 29 +++++++++++ web/service/use-workflow.ts | 52 ++++++++++--------- web/service/utils.ts | 10 ++++ web/service/workflow.ts | 16 +++--- web/types/common.ts | 4 ++ 18 files changed, 143 insertions(+), 71 deletions(-) create mode 100644 web/service/use-flow.ts create mode 100644 web/service/utils.ts create mode 100644 web/types/common.ts diff --git a/web/app/components/workflow-app/hooks/use-configs-map.ts b/web/app/components/workflow-app/hooks/use-configs-map.ts index 0db4f77856..d2de9b8f43 100644 --- a/web/app/components/workflow-app/hooks/use-configs-map.ts +++ b/web/app/components/workflow-app/hooks/use-configs-map.ts @@ -1,10 +1,13 @@ import { useMemo } from 'react' import { useStore } from '@/app/components/workflow/store' +import { FlowType } from '@/types/common' export const useConfigsMap = () => { const appId = useStore(s => s.appId) return useMemo(() => { return { + flowId: appId!, + flowType: FlowType.appFlow, conversationVarsUrl: `apps/${appId}/workflows/draft/conversation-variables`, systemVarsUrl: `apps/${appId}/workflows/draft/system-variables`, } diff --git a/web/app/components/workflow-app/hooks/use-inspect-vars-crud.ts b/web/app/components/workflow-app/hooks/use-inspect-vars-crud.ts index 109ee85f96..48c65e6b30 100644 --- a/web/app/components/workflow-app/hooks/use-inspect-vars-crud.ts +++ b/web/app/components/workflow-app/hooks/use-inspect-vars-crud.ts @@ -1,12 +1,9 @@ -import { useStore } from '@/app/components/workflow/store' import { useInspectVarsCrudCommon } from '../../workflow/hooks/use-inspect-vars-crud-common' import { useConfigsMap } from './use-configs-map' export const useInspectVarsCrud = () => { - const appId = useStore(s => s.appId) const configsMap = useConfigsMap() const apis = useInspectVarsCrudCommon({ - flowId: appId, ...configsMap, }) diff --git a/web/app/components/workflow-app/hooks/use-workflow-run.ts b/web/app/components/workflow-app/hooks/use-workflow-run.ts index c303211715..15a4857ee6 100644 --- a/web/app/components/workflow-app/hooks/use-workflow-run.ts +++ b/web/app/components/workflow-app/hooks/use-workflow-run.ts @@ -31,11 +31,11 @@ export const useWorkflowRun = () => { const { doSyncWorkflowDraft } = useNodesSyncDraft() const { handleUpdateWorkflowCanvas } = useWorkflowUpdate() const pathname = usePathname() - const appId = useAppStore.getState().appDetail?.id - const invalidAllLastRun = useInvalidAllLastRun(appId as string) const configsMap = useConfigsMap() + const { flowId, flowType } = configsMap + const invalidAllLastRun = useInvalidAllLastRun(flowType, flowId) + const { fetchInspectVars } = useSetWorkflowVarsWithValue({ - flowId: appId as string, ...configsMap, }) diff --git a/web/app/components/workflow/header/header-in-restoring.tsx b/web/app/components/workflow/header/header-in-restoring.tsx index afa4e62099..edf9c603ce 100644 --- a/web/app/components/workflow/header/header-in-restoring.tsx +++ b/web/app/components/workflow/header/header-in-restoring.tsx @@ -17,8 +17,8 @@ import { import Toast from '../../base/toast' import RestoringTitle from './restoring-title' import Button from '@/app/components/base/button' -import { useStore as useAppStore } from '@/app/components/app/store' import { useInvalidAllLastRun } from '@/service/use-workflow' +import { useHooksStore } from '../hooks-store' export type HeaderInRestoringProps = { onRestoreSettled?: () => void @@ -28,9 +28,8 @@ const HeaderInRestoring = ({ }: HeaderInRestoringProps) => { const { t } = useTranslation() const workflowStore = useWorkflowStore() - const appDetail = useAppStore.getState().appDetail - - const invalidAllLastRun = useInvalidAllLastRun(appDetail!.id) + const configsMap = useHooksStore(s => s.configsMap) + const invalidAllLastRun = useInvalidAllLastRun(configsMap?.flowType, configsMap?.flowId) const { deleteAllInspectVars, } = workflowStore.getState() diff --git a/web/app/components/workflow/hooks-store/store.ts b/web/app/components/workflow/hooks-store/store.ts index d9a35cd36d..45892714e6 100644 --- a/web/app/components/workflow/hooks-store/store.ts +++ b/web/app/components/workflow/hooks-store/store.ts @@ -17,6 +17,7 @@ import type { Node, ValueSelector, } from '@/app/components/workflow/types' +import type { FlowType } from '@/types/common' export type AvailableNodesMetaData = { nodes: NodeDefault[] @@ -61,6 +62,8 @@ export type CommonHooksFnMap = { resetConversationVar: (varId: string) => Promise invalidateConversationVarValues: () => void configsMap?: { + flowId: string + flowType: FlowType conversationVarsUrl: string systemVarsUrl: string } diff --git a/web/app/components/workflow/hooks/use-fetch-workflow-inspect-vars.ts b/web/app/components/workflow/hooks/use-fetch-workflow-inspect-vars.ts index 27a9ea9d2d..09a106affe 100644 --- a/web/app/components/workflow/hooks/use-fetch-workflow-inspect-vars.ts +++ b/web/app/components/workflow/hooks/use-fetch-workflow-inspect-vars.ts @@ -6,14 +6,17 @@ import type { Node } from '@/app/components/workflow/types' import { fetchAllInspectVars } from '@/service/workflow' import { useInvalidateConversationVarValues, useInvalidateSysVarValues } from '@/service/use-workflow' import { useNodesInteractionsWithoutSync } from '@/app/components/workflow/hooks/use-nodes-interactions-without-sync' +import type { FlowType } from '@/types/common' type Params = { + flowType: FlowType flowId: string conversationVarsUrl: string systemVarsUrl: string } export const useSetWorkflowVarsWithValue = ({ + flowType, flowId, conversationVarsUrl, systemVarsUrl, @@ -68,10 +71,10 @@ export const useSetWorkflowVarsWithValue = ({ const fetchInspectVars = useCallback(async () => { invalidateConversationVarValues() invalidateSysVarValues() - const data = await fetchAllInspectVars(flowId) + const data = await fetchAllInspectVars(flowType, flowId) setInspectVarsToStore(data) handleCancelAllNodeSuccessStatus() // to make sure clear node output show the unset status - }, [invalidateConversationVarValues, invalidateSysVarValues, flowId, setInspectVarsToStore, handleCancelAllNodeSuccessStatus]) + }, [invalidateConversationVarValues, invalidateSysVarValues, flowType, flowId, setInspectVarsToStore, handleCancelAllNodeSuccessStatus]) return { fetchInspectVars, } diff --git a/web/app/components/workflow/hooks/use-inspect-vars-crud-common.ts b/web/app/components/workflow/hooks/use-inspect-vars-crud-common.ts index ffcfd81666..5c9851829d 100644 --- a/web/app/components/workflow/hooks/use-inspect-vars-crud-common.ts +++ b/web/app/components/workflow/hooks/use-inspect-vars-crud-common.ts @@ -4,14 +4,8 @@ import type { ValueSelector } from '@/app/components/workflow/types' import type { VarInInspect } from '@/types/workflow' import { VarInInspectType } from '@/types/workflow' import { - useDeleteAllInspectorVars, - useDeleteInspectVar, - useDeleteNodeInspectorVars, - useEditInspectorVar, useInvalidateConversationVarValues, useInvalidateSysVarValues, - useResetConversationVar, - useResetToLastRunValue, } from '@/service/use-workflow' import { useCallback } from 'react' import { isConversationVar, isENV, isSystemVar } from '@/app/components/workflow/nodes/_base/components/variable/utils' @@ -19,18 +13,30 @@ import produce from 'immer' import type { Node } from '@/app/components/workflow/types' import { useNodesInteractionsWithoutSync } from '@/app/components/workflow/hooks/use-nodes-interactions-without-sync' import { useEdgesInteractionsWithoutSync } from '@/app/components/workflow/hooks/use-edges-interactions-without-sync' +import type { FlowType } from '@/types/common' +import useFLow from '@/service/use-flow' type Params = { flowId: string + flowType: FlowType conversationVarsUrl: string systemVarsUrl: string } export const useInspectVarsCrudCommon = ({ flowId, + flowType, conversationVarsUrl, systemVarsUrl, }: Params) => { const workflowStore = useWorkflowStore() + const { + useResetConversationVar, + useResetToLastRunValue, + useDeleteAllInspectorVars, + useDeleteNodeInspectorVars, + useDeleteInspectVar, + useEditInspectorVar, + } = useFLow({ flowType }) const invalidateConversationVarValues = useInvalidateConversationVarValues(conversationVarsUrl!) const { mutateAsync: doResetConversationVar } = useResetConversationVar(flowId) const { mutateAsync: doResetToLastRunValue } = useResetToLastRunValue(flowId) @@ -89,7 +95,6 @@ export const useInspectVarsCrudCommon = ({ const fetchInspectVarValue = useCallback(async (selector: ValueSelector) => { const { - appId, setNodeInspectVars, } = workflowStore.getState() const nodeId = selector[0] @@ -103,9 +108,9 @@ export const useInspectVarsCrudCommon = ({ invalidateConversationVarValues() return } - const vars = await fetchNodeInspectVars(appId, nodeId) + const vars = await fetchNodeInspectVars(flowType, flowId, nodeId) setNodeInspectVars(nodeId, vars) - }, [workflowStore, invalidateSysVarValues, invalidateConversationVarValues]) + }, [workflowStore, flowType, flowId, invalidateSysVarValues, invalidateConversationVarValues]) // after last run would call this const appendNodeInspectVars = useCallback((nodeId: string, payload: VarInInspect[], allNodes: Node[]) => { diff --git a/web/app/components/workflow/nodes/_base/components/workflow-panel/index.tsx b/web/app/components/workflow/nodes/_base/components/workflow-panel/index.tsx index 51badaee0f..3f035dea7d 100644 --- a/web/app/components/workflow/nodes/_base/components/workflow-panel/index.tsx +++ b/web/app/components/workflow/nodes/_base/components/workflow-panel/index.tsx @@ -59,6 +59,8 @@ import { useLogs } from '@/app/components/workflow/run/hooks' import PanelWrap from '../before-run-form/panel-wrap' import SpecialResultPanel from '@/app/components/workflow/run/special-result-panel' import { Stop } from '@/app/components/base/icons/src/vender/line/mediaAndDevices' +import { useHooksStore } from '@/app/components/workflow/hooks-store' +import { FlowType } from '@/types/common' type BasePanelProps = { children: ReactNode @@ -184,6 +186,7 @@ const BasePanel: FC = ({ nodesMap, } = useNodesMetaData() + const configsMap = useHooksStore(s => s.configsMap) const { isShowSingleRun, hideSingleRun, @@ -205,6 +208,8 @@ const BasePanel: FC = ({ getFilteredExistVarForms, } = useLastRun({ id, + flowId: configsMap?.flowId || '', + flowType: configsMap?.flowType || FlowType.appFlow, data, defaultRunInputData: nodesMap?.[data.type]?.defaultRunInputData || {}, isPaused, diff --git a/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/index.tsx b/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/index.tsx index a029987818..07ea5d354f 100644 --- a/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/index.tsx +++ b/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/index.tsx @@ -8,6 +8,8 @@ import NoData from './no-data' import { useLastRun } from '@/service/use-workflow' import { RiLoader2Line } from '@remixicon/react' import type { NodeTracing } from '@/types/workflow' +import { useHooksStore } from '@/app/components/workflow/hooks-store' +import { FlowType } from '@/types/common' type Props = { appId: string @@ -35,6 +37,7 @@ const LastRun: FC = ({ isPaused, ...otherResultPanelProps }) => { + const configsMap = useHooksStore(s => s.configsMap) const isOneStepRunSucceed = oneStepRunRunningStatus === NodeRunningStatus.Succeeded const isOneStepRunFailed = oneStepRunRunningStatus === NodeRunningStatus.Failed // hide page and return to page would lost the oneStepRunRunningStatus @@ -44,7 +47,7 @@ const LastRun: FC = ({ const hidePageOneStepRunFinished = [NodeRunningStatus.Succeeded, NodeRunningStatus.Failed].includes(hidePageOneStepFinishedStatus!) const canRunLastRun = !isRunAfterSingleRun || isOneStepRunSucceed || isOneStepRunFailed || (pageHasHide && hidePageOneStepRunFinished) - const { data: lastRunResult, isFetching, error } = useLastRun(appId, nodeId, canRunLastRun) + const { data: lastRunResult, isFetching, error } = useLastRun(configsMap?.flowType || FlowType.appFlow, configsMap?.flowId || '', nodeId, canRunLastRun) const isRunning = useMemo(() => { if(isPaused) return false diff --git a/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/use-last-run.ts b/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/use-last-run.ts index 014707cdfb..9854f99dcd 100644 --- a/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/use-last-run.ts +++ b/web/app/components/workflow/nodes/_base/components/workflow-panel/last-run/use-last-run.ts @@ -57,6 +57,8 @@ const singleRunFormParamsHooks: Record = { [BlockEnum.IterationStart]: undefined, [BlockEnum.LoopStart]: undefined, [BlockEnum.LoopEnd]: undefined, + [BlockEnum.DataSource]: undefined, + [BlockEnum.KnowledgeBase]: undefined, } const useSingleRunFormParamsHooks = (nodeType: BlockEnum) => { @@ -89,6 +91,8 @@ const getDataForCheckMoreHooks: Record = { [BlockEnum.Assigner]: undefined, [BlockEnum.LoopStart]: undefined, [BlockEnum.LoopEnd]: undefined, + [BlockEnum.DataSource]: undefined, + [BlockEnum.KnowledgeBase]: undefined, } const useGetDataForCheckMoreHooks = (nodeType: BlockEnum) => { @@ -119,6 +123,8 @@ const useLastRun = ({ const { id, + flowId, + flowType, data, } = oneStepRunParams const oneStepRunRes = useOneStepRun({ @@ -129,7 +135,6 @@ const useLastRun = ({ }) const { - appId, hideSingleRun, handleRun: doCallRunApi, getInputVars, @@ -199,7 +204,7 @@ const useLastRun = ({ setInitShowLastRunTab(false) // eslint-disable-next-line react-hooks/exhaustive-deps }, [initShowLastRunTab]) - const invalidLastRun = useInvalidLastRun(appId!, id) + const invalidLastRun = useInvalidLastRun(flowType, flowId, id) const handleRunWithParams = async (data: Record) => { const { isValid } = checkValid() diff --git a/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts b/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts index 769804a20b..10e269084f 100644 --- a/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts +++ b/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts @@ -11,7 +11,6 @@ import { getNodeInfoById, isConversationVar, isENV, isSystemVar, toNodeOutputVar import type { CommonNodeType, InputVar, ValueSelector, Var, Variable } from '@/app/components/workflow/types' import { BlockEnum, InputVarType, NodeRunningStatus, VarType } from '@/app/components/workflow/types' -import { useStore as useAppStore } from '@/app/components/app/store' import { useStore, useWorkflowStore } from '@/app/components/workflow/store' import { fetchNodeInspectVars, getIterationSingleNodeRunUrl, getLoopSingleNodeRunUrl, singleNodeRun } from '@/service/workflow' import Toast from '@/app/components/base/toast' @@ -52,6 +51,7 @@ import { } from 'reactflow' import { useInvalidLastRun } from '@/service/use-workflow' import useInspectVarsCrud from '../../../hooks/use-inspect-vars-crud' +import type { FlowType } from '@/types/common' // eslint-disable-next-line ts/no-unsafe-function-type const checkValidFns: Record = { [BlockEnum.LLM]: checkLLMValid, @@ -72,6 +72,8 @@ const checkValidFns: Record = { export type Params = { id: string + flowId: string + flowType: FlowType data: CommonNodeType defaultRunInputData: Record moreDataForCheckValid?: any @@ -106,6 +108,8 @@ const varTypeToInputVarType = (type: VarType, { const useOneStepRun = ({ id, + flowId, + flowType, data, defaultRunInputData, moreDataForCheckValid, @@ -153,7 +157,6 @@ const useOneStepRun = ({ const checkValid = checkValidFns[data.type] - const appId = useAppStore.getState().appDetail?.id const [runInputData, setRunInputData] = useState>(defaultRunInputData || {}) const runInputDataRef = useRef(runInputData) const handleSetRunInputData = useCallback((data: Record) => { @@ -168,7 +171,7 @@ const useOneStepRun = ({ const { setShowSingleRunPanel, } = workflowStore.getState() - const invalidLastRun = useInvalidLastRun(appId!, id) + const invalidLastRun = useInvalidLastRun(flowType, flowId!, id) const [runResult, doSetRunResult] = useState(null) const { appendNodeInspectVars, @@ -195,7 +198,7 @@ const useOneStepRun = ({ } // run fail may also update the inspect vars when the node set the error default output. - const vars = await fetchNodeInspectVars(appId!, id) + const vars = await fetchNodeInspectVars(flowType, flowId!, id) const { getNodes } = store.getState() const nodes = getNodes() appendNodeInspectVars(id, vars, nodes) @@ -205,7 +208,7 @@ const useOneStepRun = ({ invalidateSysVarValues() invalidateConversationVarValues() // loop, iteration, variable assigner node can update the conversation variables, but to simple the logic(some nodes may also can update in the future), all nodes refresh. } - }, [isRunAfterSingleRun, runningStatus, appId, id, store, appendNodeInspectVars, invalidLastRun, isStartNode, invalidateSysVarValues, invalidateConversationVarValues]) + }, [isRunAfterSingleRun, runningStatus, flowId, id, store, appendNodeInspectVars, invalidLastRun, isStartNode, invalidateSysVarValues, invalidateConversationVarValues]) const { handleNodeDataUpdate }: { handleNodeDataUpdate: (data: any) => void } = useNodeDataUpdate() const setNodeRunning = () => { @@ -305,14 +308,14 @@ const useOneStepRun = ({ else { postData.inputs = submitData } - res = await singleNodeRun(appId!, id, postData) as any + res = await singleNodeRun(flowId!, id, postData) as any } else if (isIteration) { setIterationRunResult([]) let _iterationResult: NodeTracing[] = [] let _runResult: any = null ssePost( - getIterationSingleNodeRunUrl(isChatMode, appId!, id), + getIterationSingleNodeRunUrl(isChatMode, flowId!, id), { body: { inputs: submitData } }, { onWorkflowStarted: noop, @@ -415,7 +418,7 @@ const useOneStepRun = ({ let _loopResult: NodeTracing[] = [] let _runResult: any = null ssePost( - getLoopSingleNodeRunUrl(isChatMode, appId!, id), + getLoopSingleNodeRunUrl(isChatMode, flowId!, id), { body: { inputs: submitData } }, { onWorkflowStarted: noop, @@ -633,7 +636,6 @@ const useOneStepRun = ({ } return { - appId, isShowSingleRun, hideSingleRun, showSingleRun, diff --git a/web/app/components/workflow/panel/debug-and-preview/hooks.ts b/web/app/components/workflow/panel/debug-and-preview/hooks.ts index d98cf49812..c82a5598f0 100644 --- a/web/app/components/workflow/panel/debug-and-preview/hooks.ts +++ b/web/app/components/workflow/panel/debug-and-preview/hooks.ts @@ -34,7 +34,7 @@ import { import type { FileEntity } from '@/app/components/base/file-uploader/types' import { getThreadMessages } from '@/app/components/base/chat/utils' import { useInvalidAllLastRun } from '@/service/use-workflow' -import { useParams } from 'next/navigation' +import { useHooksStore } from '../../hooks-store' type GetAbortController = (abortController: AbortController) => void type SendCallback = { @@ -58,8 +58,8 @@ export const useChat = ( const taskIdRef = useRef('') const [isResponding, setIsResponding] = useState(false) const isRespondingRef = useRef(false) - const { appId } = useParams() - const invalidAllLastRun = useInvalidAllLastRun(appId as string) + const configsMap = useHooksStore(s => s.configsMap) + const invalidAllLastRun = useInvalidAllLastRun(configsMap?.flowType, configsMap?.flowId) const { fetchInspectVars } = useSetWorkflowVarsWithValue() const [suggestedQuestions, setSuggestQuestions] = useState([]) const suggestedQuestionsAbortControllerRef = useRef(null) diff --git a/web/app/components/workflow/panel/version-history-panel/index.tsx b/web/app/components/workflow/panel/version-history-panel/index.tsx index 7e070a56ea..662b7bb1ff 100644 --- a/web/app/components/workflow/panel/version-history-panel/index.tsx +++ b/web/app/components/workflow/panel/version-history-panel/index.tsx @@ -17,6 +17,7 @@ import RestoreConfirmModal from './restore-confirm-modal' import DeleteConfirmModal from './delete-confirm-modal' import VersionInfoModal from '@/app/components/app/app-publisher/version-info-modal' import Toast from '@/app/components/base/toast' +import { useHooksStore } from '../../hooks-store' const HISTORY_PER_PAGE = 10 const INITIAL_PAGE = 1 @@ -46,9 +47,8 @@ export const VersionHistoryPanel = ({ const currentVersion = useStore(s => s.currentVersion) const setCurrentVersion = useStore(s => s.setCurrentVersion) const userProfile = useAppContextSelector(s => s.userProfile) - const appId = useStore(s => s.appId) - const pipelineId = useStore(s => s.pipelineId) - const invalidAllLastRun = useInvalidAllLastRun(appId || pipelineId || '') + const configsMap = useHooksStore(s => s.configsMap) + const invalidAllLastRun = useInvalidAllLastRun(configsMap?.flowType, configsMap?.flowId) const { deleteAllInspectVars, } = workflowStore.getState() diff --git a/web/service/use-flow.ts b/web/service/use-flow.ts new file mode 100644 index 0000000000..380ad5ba6d --- /dev/null +++ b/web/service/use-flow.ts @@ -0,0 +1,29 @@ +import type { FlowType } from '@/types/common' +import { + useDeleteAllInspectorVars as useDeleteAllInspectorVarsInner, + useDeleteInspectVar as useDeleteInspectVarInner, + useDeleteNodeInspectorVars as useDeleteNodeInspectorVarsInner, + useEditInspectorVar as useEditInspectorVarInner, + useResetConversationVar as useResetConversationVarInner, + useResetToLastRunValue as useResetToLastRunValueInner, +} from './use-workflow' +import { curry } from 'lodash-es' + +type Params = { + flowType: FlowType +} + +const useFLow = ({ + flowType, +}: Params) => { + return { + useResetConversationVar: curry(useResetConversationVarInner)(flowType), + useResetToLastRunValue: curry(useResetToLastRunValueInner)(flowType), + useDeleteAllInspectorVars: curry(useDeleteAllInspectorVarsInner)(flowType), + useDeleteNodeInspectorVars: curry(useDeleteNodeInspectorVarsInner)(flowType), + useDeleteInspectVar: curry(useDeleteInspectVarInner)(flowType), + useEditInspectorVar: curry(useEditInspectorVarInner)(flowType), + } +} + +export default useFLow diff --git a/web/service/use-workflow.ts b/web/service/use-workflow.ts index 09761b07f5..15cc2014d5 100644 --- a/web/service/use-workflow.ts +++ b/web/service/use-workflow.ts @@ -12,6 +12,8 @@ import type { } from '@/types/workflow' import type { CommonResponse } from '@/models/common' import { useInvalid, useReset } from './use-base' +import type { FlowType } from '@/types/common' +import { getFlowPrefix } from './utils' const NAME_SPACE = 'workflow' @@ -102,12 +104,12 @@ export const usePublishWorkflow = () => { } const useLastRunKey = [NAME_SPACE, 'last-run'] -export const useLastRun = (appID: string, nodeId: string, enabled: boolean) => { +export const useLastRun = (flowType: FlowType, flowId: string, nodeId: string, enabled: boolean) => { return useQuery({ enabled, - queryKey: [...useLastRunKey, appID, nodeId], + queryKey: [...useLastRunKey, flowType, flowId, nodeId], queryFn: async () => { - return get(`apps/${appID}/workflows/draft/nodes/${nodeId}/last-run`, {}, { + return get(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/nodes/${nodeId}/last-run`, {}, { silent: true, }) }, @@ -115,13 +117,13 @@ export const useLastRun = (appID: string, nodeId: string, enabled: boolean) => { }) } -export const useInvalidLastRun = (appId: string, nodeId: string) => { - return useInvalid([NAME_SPACE, 'last-run', appId, nodeId]) +export const useInvalidLastRun = (flowType: FlowType, flowId: string, nodeId: string) => { + return useInvalid([NAME_SPACE, flowType, 'last-run', flowId, nodeId]) } // Rerun workflow or change the version of workflow -export const useInvalidAllLastRun = (appId: string) => { - return useInvalid([NAME_SPACE, 'last-run', appId]) +export const useInvalidAllLastRun = (flowType?: FlowType, flowId?: string) => { + return useInvalid([NAME_SPACE, flowType, 'last-run', flowId]) } const useConversationVarValuesKey = [NAME_SPACE, 'conversation-variable'] @@ -141,20 +143,20 @@ export const useInvalidateConversationVarValues = (url: string) => { return useInvalid([...useConversationVarValuesKey, url]) } -export const useResetConversationVar = (appId: string) => { +export const useResetConversationVar = (flowType: FlowType, flowId: string) => { return useMutation({ - mutationKey: [NAME_SPACE, 'reset conversation var', appId], + mutationKey: [NAME_SPACE, flowType, 'reset conversation var', flowId], mutationFn: async (varId: string) => { - return put(`apps/${appId}/workflows/draft/variables/${varId}/reset`) + return put(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/variables/${varId}/reset`) }, }) } -export const useResetToLastRunValue = (appId: string) => { +export const useResetToLastRunValue = (flowType: FlowType, flowId: string) => { return useMutation({ - mutationKey: [NAME_SPACE, 'reset to last run value', appId], + mutationKey: [NAME_SPACE, flowType, 'reset to last run value', flowId], mutationFn: async (varId: string): Promise<{ value: any }> => { - return put(`apps/${appId}/workflows/draft/variables/${varId}/reset`) + return put(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/variables/${varId}/reset`) }, }) } @@ -175,43 +177,43 @@ export const useInvalidateSysVarValues = (url: string) => { return useInvalid([...useSysVarValuesKey, url]) } -export const useDeleteAllInspectorVars = (appId: string) => { +export const useDeleteAllInspectorVars = (flowType: FlowType, flowId: string) => { return useMutation({ - mutationKey: [NAME_SPACE, 'delete all inspector vars', appId], + mutationKey: [NAME_SPACE, flowType, 'delete all inspector vars', flowId], mutationFn: async () => { - return del(`apps/${appId}/workflows/draft/variables`) + return del(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/variables`) }, }) } -export const useDeleteNodeInspectorVars = (appId: string) => { +export const useDeleteNodeInspectorVars = (flowType: FlowType, flowId: string) => { return useMutation({ - mutationKey: [NAME_SPACE, 'delete node inspector vars', appId], + mutationKey: [NAME_SPACE, flowType, 'delete node inspector vars', flowId], mutationFn: async (nodeId: string) => { - return del(`apps/${appId}/workflows/draft/nodes/${nodeId}/variables`) + return del(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/nodes/${nodeId}/variables`) }, }) } -export const useDeleteInspectVar = (appId: string) => { +export const useDeleteInspectVar = (flowType: FlowType, flowId: string) => { return useMutation({ - mutationKey: [NAME_SPACE, 'delete inspector var', appId], + mutationKey: [NAME_SPACE, flowType, 'delete inspector var', flowId], mutationFn: async (varId: string) => { - return del(`apps/${appId}/workflows/draft/variables/${varId}`) + return del(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/variables/${varId}`) }, }) } // edit the name or value of the inspector var -export const useEditInspectorVar = (appId: string) => { +export const useEditInspectorVar = (flowType: FlowType, flowId: string) => { return useMutation({ - mutationKey: [NAME_SPACE, 'edit inspector var', appId], + mutationKey: [NAME_SPACE, flowType, 'edit inspector var', flowId], mutationFn: async ({ varId, ...rest }: { varId: string name?: string value?: any }) => { - return patch(`apps/${appId}/workflows/draft/variables/${varId}`, { + return patch(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/variables/${varId}`, { body: rest, }) }, diff --git a/web/service/utils.ts b/web/service/utils.ts new file mode 100644 index 0000000000..fe26257dc6 --- /dev/null +++ b/web/service/utils.ts @@ -0,0 +1,10 @@ +import { FlowType } from '@/types/common' + +export const flowPrefixMap = { + [FlowType.appFlow]: 'apps', + [FlowType.ragFlow]: 'rag/pipelines', +} + +export const getFlowPrefix = (type: FlowType) => { + return flowPrefixMap[type] || flowPrefixMap[FlowType.appFlow] +} diff --git a/web/service/workflow.ts b/web/service/workflow.ts index edb04f292f..3311d7a205 100644 --- a/web/service/workflow.ts +++ b/web/service/workflow.ts @@ -10,6 +10,8 @@ import type { } from '@/types/workflow' import type { BlockEnum } from '@/app/components/workflow/types' import type { VarInInspect } from '@/types/workflow' +import type { FlowType } from '@/types/common' +import { getFlowPrefix } from './utils' export const fetchWorkflowDraft = (url: string) => { return get(url, {}, { silent: true }) as Promise @@ -78,13 +80,13 @@ export const fetchCurrentValueOfConversationVariable: Fetcher(url, { params }) } -const fetchAllInspectVarsOnePage = async (appId: string, page: number): Promise<{ total: number, items: VarInInspect[] }> => { - return get(`apps/${appId}/workflows/draft/variables`, { +const fetchAllInspectVarsOnePage = async (flowType: FlowType, flowId: string, page: number): Promise<{ total: number, items: VarInInspect[] }> => { + return get(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/variables`, { params: { page, limit: 100 }, }) } -export const fetchAllInspectVars = async (appId: string): Promise => { - const res = await fetchAllInspectVarsOnePage(appId, 1) +export const fetchAllInspectVars = async (flowType: FlowType, flowId: string): Promise => { + const res = await fetchAllInspectVarsOnePage(flowType, flowId, 1) const { items, total } = res if (total <= 100) return items @@ -92,7 +94,7 @@ export const fetchAllInspectVars = async (appId: string): Promise { @@ -101,7 +103,7 @@ export const fetchAllInspectVars = async (appId: string): Promise => { - const { items } = (await get(`apps/${appId}/workflows/draft/nodes/${nodeId}/variables`)) as { items: VarInInspect[] } +export const fetchNodeInspectVars = async (flowType: FlowType, flowId: string, nodeId: string): Promise => { + const { items } = (await get(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/nodes/${nodeId}/variables`)) as { items: VarInInspect[] } return items } diff --git a/web/types/common.ts b/web/types/common.ts new file mode 100644 index 0000000000..9f55b740a8 --- /dev/null +++ b/web/types/common.ts @@ -0,0 +1,4 @@ +export enum FlowType { + appFlow = 'appFlow', + ragFlow = 'ragFlow', +} From 82f4b35d520ce5af050f51ab0ea63cacf7e9f627 Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 14 Jul 2025 15:30:04 +0800 Subject: [PATCH 3/6] chore: use flow type instead of whole url --- .../workflow-app/components/workflow-main.tsx | 4 +-- .../workflow-app/hooks/use-configs-map.ts | 2 -- .../components/workflow/hooks-store/store.ts | 2 -- .../hooks/use-fetch-workflow-inspect-vars.ts | 8 ++---- .../hooks/use-inspect-vars-crud-common.ts | 15 ++++------- .../workflow/hooks/use-inspect-vars-crud.ts | 4 +-- web/service/use-flow.ts | 4 +++ web/service/use-workflow.ts | 26 +++++++++---------- web/service/utils.ts | 4 +-- 9 files changed, 28 insertions(+), 41 deletions(-) diff --git a/web/app/components/workflow-app/components/workflow-main.tsx b/web/app/components/workflow-app/components/workflow-main.tsx index 534c60c73a..af8488e640 100644 --- a/web/app/components/workflow-app/components/workflow-main.tsx +++ b/web/app/components/workflow-app/components/workflow-main.tsx @@ -18,7 +18,7 @@ import { useWorkflowRun, useWorkflowStartRun, } from '../hooks' -import { useStore, useWorkflowStore } from '@/app/components/workflow/store' +import { useWorkflowStore } from '@/app/components/workflow/store' type WorkflowMainProps = Pick const WorkflowMain = ({ @@ -67,7 +67,6 @@ const WorkflowMain = ({ handleWorkflowStartRunInChatflow, handleWorkflowStartRunInWorkflow, } = useWorkflowStartRun() - const appId = useStore(s => s.appId) const availableNodesMetaData = useAvailableNodesMetaData() const { getWorkflowRunAndTraceUrl } = useGetRunAndTraceUrl() const { @@ -75,7 +74,6 @@ const WorkflowMain = ({ handleExportDSL, } = useDSL() const { fetchInspectVars } = useSetWorkflowVarsWithValue({ - flowId: appId, ...useConfigsMap(), }) const { diff --git a/web/app/components/workflow-app/hooks/use-configs-map.ts b/web/app/components/workflow-app/hooks/use-configs-map.ts index d2de9b8f43..6d98b87e91 100644 --- a/web/app/components/workflow-app/hooks/use-configs-map.ts +++ b/web/app/components/workflow-app/hooks/use-configs-map.ts @@ -8,8 +8,6 @@ export const useConfigsMap = () => { return { flowId: appId!, flowType: FlowType.appFlow, - conversationVarsUrl: `apps/${appId}/workflows/draft/conversation-variables`, - systemVarsUrl: `apps/${appId}/workflows/draft/system-variables`, } }, [appId]) } diff --git a/web/app/components/workflow/hooks-store/store.ts b/web/app/components/workflow/hooks-store/store.ts index 45892714e6..783b42d861 100644 --- a/web/app/components/workflow/hooks-store/store.ts +++ b/web/app/components/workflow/hooks-store/store.ts @@ -64,8 +64,6 @@ export type CommonHooksFnMap = { configsMap?: { flowId: string flowType: FlowType - conversationVarsUrl: string - systemVarsUrl: string } } diff --git a/web/app/components/workflow/hooks/use-fetch-workflow-inspect-vars.ts b/web/app/components/workflow/hooks/use-fetch-workflow-inspect-vars.ts index 09a106affe..463611a7e1 100644 --- a/web/app/components/workflow/hooks/use-fetch-workflow-inspect-vars.ts +++ b/web/app/components/workflow/hooks/use-fetch-workflow-inspect-vars.ts @@ -11,20 +11,16 @@ import type { FlowType } from '@/types/common' type Params = { flowType: FlowType flowId: string - conversationVarsUrl: string - systemVarsUrl: string } export const useSetWorkflowVarsWithValue = ({ flowType, flowId, - conversationVarsUrl, - systemVarsUrl, }: Params) => { const workflowStore = useWorkflowStore() const store = useStoreApi() - const invalidateConversationVarValues = useInvalidateConversationVarValues(conversationVarsUrl) - const invalidateSysVarValues = useInvalidateSysVarValues(systemVarsUrl) + const invalidateConversationVarValues = useInvalidateConversationVarValues(flowType, flowId) + const invalidateSysVarValues = useInvalidateSysVarValues(flowType, flowId) const { handleCancelAllNodeSuccessStatus } = useNodesInteractionsWithoutSync() const setInspectVarsToStore = useCallback((inspectVars: VarInInspect[]) => { diff --git a/web/app/components/workflow/hooks/use-inspect-vars-crud-common.ts b/web/app/components/workflow/hooks/use-inspect-vars-crud-common.ts index 5c9851829d..6391fdfec6 100644 --- a/web/app/components/workflow/hooks/use-inspect-vars-crud-common.ts +++ b/web/app/components/workflow/hooks/use-inspect-vars-crud-common.ts @@ -3,10 +3,7 @@ import { useWorkflowStore } from '@/app/components/workflow/store' import type { ValueSelector } from '@/app/components/workflow/types' import type { VarInInspect } from '@/types/workflow' import { VarInInspectType } from '@/types/workflow' -import { - useInvalidateConversationVarValues, - useInvalidateSysVarValues, -} from '@/service/use-workflow' + import { useCallback } from 'react' import { isConversationVar, isENV, isSystemVar } from '@/app/components/workflow/nodes/_base/components/variable/utils' import produce from 'immer' @@ -19,17 +16,15 @@ import useFLow from '@/service/use-flow' type Params = { flowId: string flowType: FlowType - conversationVarsUrl: string - systemVarsUrl: string } export const useInspectVarsCrudCommon = ({ flowId, flowType, - conversationVarsUrl, - systemVarsUrl, }: Params) => { const workflowStore = useWorkflowStore() const { + useInvalidateConversationVarValues, + useInvalidateSysVarValues, useResetConversationVar, useResetToLastRunValue, useDeleteAllInspectorVars, @@ -37,10 +32,10 @@ export const useInspectVarsCrudCommon = ({ useDeleteInspectVar, useEditInspectorVar, } = useFLow({ flowType }) - const invalidateConversationVarValues = useInvalidateConversationVarValues(conversationVarsUrl!) + const invalidateConversationVarValues = useInvalidateConversationVarValues(flowId) const { mutateAsync: doResetConversationVar } = useResetConversationVar(flowId) const { mutateAsync: doResetToLastRunValue } = useResetToLastRunValue(flowId) - const invalidateSysVarValues = useInvalidateSysVarValues(systemVarsUrl!) + const invalidateSysVarValues = useInvalidateSysVarValues(flowId) const { mutateAsync: doDeleteAllInspectorVars } = useDeleteAllInspectorVars(flowId) const { mutate: doDeleteNodeInspectorVars } = useDeleteNodeInspectorVars(flowId) diff --git a/web/app/components/workflow/hooks/use-inspect-vars-crud.ts b/web/app/components/workflow/hooks/use-inspect-vars-crud.ts index 50188185c2..ab38bf0446 100644 --- a/web/app/components/workflow/hooks/use-inspect-vars-crud.ts +++ b/web/app/components/workflow/hooks/use-inspect-vars-crud.ts @@ -8,8 +8,8 @@ import { const useInspectVarsCrud = () => { const nodesWithInspectVars = useStore(s => s.nodesWithInspectVars) const configsMap = useHooksStore(s => s.configsMap) - const { data: conversationVars } = useConversationVarValues(configsMap?.conversationVarsUrl) - const { data: systemVars } = useSysVarValues(configsMap?.systemVarsUrl) + const { data: conversationVars } = useConversationVarValues(configsMap?.flowType, configsMap?.flowId) + const { data: systemVars } = useSysVarValues(configsMap?.flowType, configsMap?.flowId) const hasNodeInspectVars = useHooksStore(s => s.hasNodeInspectVars) const hasSetInspectVar = useHooksStore(s => s.hasSetInspectVar) const fetchInspectVarValue = useHooksStore(s => s.fetchInspectVarValue) diff --git a/web/service/use-flow.ts b/web/service/use-flow.ts index 380ad5ba6d..54820a8d1d 100644 --- a/web/service/use-flow.ts +++ b/web/service/use-flow.ts @@ -4,6 +4,8 @@ import { useDeleteInspectVar as useDeleteInspectVarInner, useDeleteNodeInspectorVars as useDeleteNodeInspectorVarsInner, useEditInspectorVar as useEditInspectorVarInner, + useInvalidateConversationVarValues as useInvalidateConversationVarValuesInner, + useInvalidateSysVarValues as useInvalidateSysVarValuesInner, useResetConversationVar as useResetConversationVarInner, useResetToLastRunValue as useResetToLastRunValueInner, } from './use-workflow' @@ -17,6 +19,8 @@ const useFLow = ({ flowType, }: Params) => { return { + useInvalidateConversationVarValues: curry(useInvalidateConversationVarValuesInner)(flowType), + useInvalidateSysVarValues: curry(useInvalidateSysVarValuesInner)(flowType), useResetConversationVar: curry(useResetConversationVarInner)(flowType), useResetToLastRunValue: curry(useResetToLastRunValueInner)(flowType), useDeleteAllInspectorVars: curry(useDeleteAllInspectorVarsInner)(flowType), diff --git a/web/service/use-workflow.ts b/web/service/use-workflow.ts index 15cc2014d5..2d4148e6da 100644 --- a/web/service/use-workflow.ts +++ b/web/service/use-workflow.ts @@ -126,21 +126,19 @@ export const useInvalidAllLastRun = (flowType?: FlowType, flowId?: string) => { return useInvalid([NAME_SPACE, flowType, 'last-run', flowId]) } -const useConversationVarValuesKey = [NAME_SPACE, 'conversation-variable'] - -export const useConversationVarValues = (url?: string) => { +export const useConversationVarValues = (flowType?: FlowType, flowId?: string) => { return useQuery({ - enabled: !!url, - queryKey: [...useConversationVarValuesKey, url], + enabled: !!flowId, + queryKey: [NAME_SPACE, flowType, 'conversation var values', flowId], queryFn: async () => { - const { items } = (await get(url || '')) as { items: VarInInspect[] } + const { items } = (await get(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/conversation-variables`)) as { items: VarInInspect[] } return items }, }) } -export const useInvalidateConversationVarValues = (url: string) => { - return useInvalid([...useConversationVarValuesKey, url]) +export const useInvalidateConversationVarValues = (flowType: FlowType, flowId: string) => { + return useInvalid([NAME_SPACE, flowType, 'conversation var values', flowId]) } export const useResetConversationVar = (flowType: FlowType, flowId: string) => { @@ -162,19 +160,19 @@ export const useResetToLastRunValue = (flowType: FlowType, flowId: string) => { } export const useSysVarValuesKey = [NAME_SPACE, 'sys-variable'] -export const useSysVarValues = (url?: string) => { +export const useSysVarValues = (flowType?: FlowType, flowId?: string) => { return useQuery({ - enabled: !!url, - queryKey: [...useSysVarValuesKey, url], + enabled: !!flowId, + queryKey: [NAME_SPACE, flowType, 'sys var values', flowId], queryFn: async () => { - const { items } = (await get(url || '')) as { items: VarInInspect[] } + const { items } = (await get(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/system-variables`)) as { items: VarInInspect[] } return items }, }) } -export const useInvalidateSysVarValues = (url: string) => { - return useInvalid([...useSysVarValuesKey, url]) +export const useInvalidateSysVarValues = (flowType: FlowType, flowId: string) => { + return useInvalid([NAME_SPACE, flowType, 'sys var values', flowId]) } export const useDeleteAllInspectorVars = (flowType: FlowType, flowId: string) => { diff --git a/web/service/utils.ts b/web/service/utils.ts index fe26257dc6..7700f62582 100644 --- a/web/service/utils.ts +++ b/web/service/utils.ts @@ -5,6 +5,6 @@ export const flowPrefixMap = { [FlowType.ragFlow]: 'rag/pipelines', } -export const getFlowPrefix = (type: FlowType) => { - return flowPrefixMap[type] || flowPrefixMap[FlowType.appFlow] +export const getFlowPrefix = (type?: FlowType) => { + return flowPrefixMap[type!] || flowPrefixMap[FlowType.appFlow] } From e095de05c5270b7f9e7008d5e768ac09a4db94d4 Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 14 Jul 2025 16:04:43 +0800 Subject: [PATCH 4/6] feat: pipeline run --- .../components/rag-pipeline-main.tsx | 56 +++++++++++++++++++ .../rag-pipeline/hooks/use-configs-map.ts | 13 +++++ .../hooks/use-inspect-vars-crud.ts | 13 +++++ .../workflow-app/components/workflow-main.tsx | 5 +- .../workflow/hooks/use-inspect-vars-crud.ts | 6 +- web/service/utils.ts | 2 +- web/types/common.ts | 2 +- 7 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 web/app/components/rag-pipeline/hooks/use-configs-map.ts create mode 100644 web/app/components/rag-pipeline/hooks/use-inspect-vars-crud.ts diff --git a/web/app/components/rag-pipeline/components/rag-pipeline-main.tsx b/web/app/components/rag-pipeline/components/rag-pipeline-main.tsx index 82c80684b8..5daf1f2ceb 100644 --- a/web/app/components/rag-pipeline/components/rag-pipeline-main.tsx +++ b/web/app/components/rag-pipeline/components/rag-pipeline-main.tsx @@ -15,6 +15,9 @@ import { usePipelineStartRun, } from '../hooks' import { useWorkflowStore } from '@/app/components/workflow/store' +import { useConfigsMap } from '../hooks/use-configs-map' +import { useSetWorkflowVarsWithValue } from '@/app/components/workflow/hooks/use-fetch-workflow-inspect-vars' +import { useInspectVarsCrud } from '../hooks/use-inspect-vars-crud' type RagPipelineMainProps = Pick const RagPipelineMain = ({ @@ -62,6 +65,27 @@ const RagPipelineMain = ({ handleExportDSL, } = useDSL() + const configsMap = useConfigsMap() + const { fetchInspectVars } = useSetWorkflowVarsWithValue({ + ...configsMap, + }) + const { + hasNodeInspectVars, + hasSetInspectVar, + fetchInspectVarValue, + editInspectVarValue, + renameInspectVarName, + appendNodeInspectVars, + deleteInspectVar, + deleteNodeInspectorVars, + deleteAllInspectorVars, + isInspectVarEdited, + resetToLastRunVar, + invalidateSysVarValues, + resetConversationVar, + invalidateConversationVarValues, + } = useInspectVarsCrud() + const hooksStore = useMemo(() => { return { availableNodesMetaData, @@ -78,6 +102,22 @@ const RagPipelineMain = ({ getWorkflowRunAndTraceUrl, exportCheck, handleExportDSL, + fetchInspectVars, + hasNodeInspectVars, + hasSetInspectVar, + fetchInspectVarValue, + editInspectVarValue, + renameInspectVarName, + appendNodeInspectVars, + deleteInspectVar, + deleteNodeInspectorVars, + deleteAllInspectorVars, + isInspectVarEdited, + resetToLastRunVar, + invalidateSysVarValues, + resetConversationVar, + invalidateConversationVarValues, + configsMap, } }, [ availableNodesMetaData, @@ -94,6 +134,22 @@ const RagPipelineMain = ({ getWorkflowRunAndTraceUrl, exportCheck, handleExportDSL, + fetchInspectVars, + hasNodeInspectVars, + hasSetInspectVar, + fetchInspectVarValue, + editInspectVarValue, + renameInspectVarName, + appendNodeInspectVars, + deleteInspectVar, + deleteNodeInspectorVars, + deleteAllInspectorVars, + isInspectVarEdited, + resetToLastRunVar, + invalidateSysVarValues, + resetConversationVar, + invalidateConversationVarValues, + configsMap, ]) return ( diff --git a/web/app/components/rag-pipeline/hooks/use-configs-map.ts b/web/app/components/rag-pipeline/hooks/use-configs-map.ts new file mode 100644 index 0000000000..537d6f253a --- /dev/null +++ b/web/app/components/rag-pipeline/hooks/use-configs-map.ts @@ -0,0 +1,13 @@ +import { useMemo } from 'react' +import { useStore } from '@/app/components/workflow/store' +import { FlowType } from '@/types/common' + +export const useConfigsMap = () => { + const pipelineId = useStore(s => s.pipelineId) + return useMemo(() => { + return { + flowId: pipelineId!, + flowType: FlowType.ragPipeline, + } + }, [pipelineId]) +} diff --git a/web/app/components/rag-pipeline/hooks/use-inspect-vars-crud.ts b/web/app/components/rag-pipeline/hooks/use-inspect-vars-crud.ts new file mode 100644 index 0000000000..48c65e6b30 --- /dev/null +++ b/web/app/components/rag-pipeline/hooks/use-inspect-vars-crud.ts @@ -0,0 +1,13 @@ +import { useInspectVarsCrudCommon } from '../../workflow/hooks/use-inspect-vars-crud-common' +import { useConfigsMap } from './use-configs-map' + +export const useInspectVarsCrud = () => { + const configsMap = useConfigsMap() + const apis = useInspectVarsCrudCommon({ + ...configsMap, + }) + + return { + ...apis, + } +} diff --git a/web/app/components/workflow-app/components/workflow-main.tsx b/web/app/components/workflow-app/components/workflow-main.tsx index af8488e640..f979a12f26 100644 --- a/web/app/components/workflow-app/components/workflow-main.tsx +++ b/web/app/components/workflow-app/components/workflow-main.tsx @@ -73,8 +73,10 @@ const WorkflowMain = ({ exportCheck, handleExportDSL, } = useDSL() + + const configsMap = useConfigsMap() const { fetchInspectVars } = useSetWorkflowVarsWithValue({ - ...useConfigsMap(), + ...configsMap, }) const { hasNodeInspectVars, @@ -92,7 +94,6 @@ const WorkflowMain = ({ resetConversationVar, invalidateConversationVarValues, } = useInspectVarsCrud() - const configsMap = useConfigsMap() const hooksStore = useMemo(() => { return { diff --git a/web/app/components/workflow/hooks/use-inspect-vars-crud.ts b/web/app/components/workflow/hooks/use-inspect-vars-crud.ts index ab38bf0446..c922192267 100644 --- a/web/app/components/workflow/hooks/use-inspect-vars-crud.ts +++ b/web/app/components/workflow/hooks/use-inspect-vars-crud.ts @@ -4,12 +4,14 @@ import { useConversationVarValues, useSysVarValues, } from '@/service/use-workflow' +import { FlowType } from '@/types/common' const useInspectVarsCrud = () => { const nodesWithInspectVars = useStore(s => s.nodesWithInspectVars) const configsMap = useHooksStore(s => s.configsMap) - const { data: conversationVars } = useConversationVarValues(configsMap?.flowType, configsMap?.flowId) - const { data: systemVars } = useSysVarValues(configsMap?.flowType, configsMap?.flowId) + const isRagPipeline = configsMap?.flowType === FlowType.ragPipeline + const { data: conversationVars } = useConversationVarValues(configsMap?.flowType, !isRagPipeline ? configsMap?.flowId : '') + const { data: systemVars } = useSysVarValues(configsMap?.flowType, !isRagPipeline ? configsMap?.flowId : '') const hasNodeInspectVars = useHooksStore(s => s.hasNodeInspectVars) const hasSetInspectVar = useHooksStore(s => s.hasSetInspectVar) const fetchInspectVarValue = useHooksStore(s => s.fetchInspectVarValue) diff --git a/web/service/utils.ts b/web/service/utils.ts index 7700f62582..6d0c3ca88e 100644 --- a/web/service/utils.ts +++ b/web/service/utils.ts @@ -2,7 +2,7 @@ import { FlowType } from '@/types/common' export const flowPrefixMap = { [FlowType.appFlow]: 'apps', - [FlowType.ragFlow]: 'rag/pipelines', + [FlowType.ragPipeline]: 'rag/pipelines', } export const getFlowPrefix = (type?: FlowType) => { diff --git a/web/types/common.ts b/web/types/common.ts index 9f55b740a8..19bc8acc8d 100644 --- a/web/types/common.ts +++ b/web/types/common.ts @@ -1,4 +1,4 @@ export enum FlowType { appFlow = 'appFlow', - ragFlow = 'ragFlow', + ragPipeline = 'ragPipeline', } From 4b9a5a66c16411d7e9ffe80cb3ebcf960242f449 Mon Sep 17 00:00:00 2001 From: jyong <718720800@qq.com> Date: Mon, 14 Jul 2025 16:14:27 +0800 Subject: [PATCH 5/6] r2 --- api/controllers/console/__init__.py | 1 + .../console/datasets/rag_pipeline/rag_pipeline_import.py | 1 + api/services/rag_pipeline/rag_pipeline_dsl_service.py | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/api/controllers/console/__init__.py b/api/controllers/console/__init__.py index 2b95938cb6..a497ff14ac 100644 --- a/api/controllers/console/__init__.py +++ b/api/controllers/console/__init__.py @@ -90,6 +90,7 @@ from .datasets.rag_pipeline import ( datasource_content_preview, rag_pipeline, rag_pipeline_datasets, + rag_pipeline_draft_variable, rag_pipeline_import, rag_pipeline_workflow, ) diff --git a/api/controllers/console/datasets/rag_pipeline/rag_pipeline_import.py b/api/controllers/console/datasets/rag_pipeline/rag_pipeline_import.py index e5c211be93..485a73e517 100644 --- a/api/controllers/console/datasets/rag_pipeline/rag_pipeline_import.py +++ b/api/controllers/console/datasets/rag_pipeline/rag_pipeline_import.py @@ -53,6 +53,7 @@ class RagPipelineImportApi(Resource): yaml_content=args.get("yaml_content"), yaml_url=args.get("yaml_url"), pipeline_id=args.get("pipeline_id"), + dataset_name=args.get("name"), ) session.commit() diff --git a/api/services/rag_pipeline/rag_pipeline_dsl_service.py b/api/services/rag_pipeline/rag_pipeline_dsl_service.py index fb311482d8..e2908d83aa 100644 --- a/api/services/rag_pipeline/rag_pipeline_dsl_service.py +++ b/api/services/rag_pipeline/rag_pipeline_dsl_service.py @@ -123,6 +123,7 @@ class RagPipelineDslService: yaml_url: Optional[str] = None, pipeline_id: Optional[str] = None, dataset: Optional[Dataset] = None, + dataset_name: Optional[str] = None, ) -> RagPipelineImportInfo: """Import an app from YAML content or URL.""" import_id = str(uuid.uuid4()) @@ -265,7 +266,7 @@ class RagPipelineDslService: dependencies=check_dependencies_pending_data, ) # create dataset - name = pipeline.name + name = dataset_name or pipeline.name description = pipeline.description icon_type = data.get("rag_pipeline", {}).get("icon_type") icon = data.get("rag_pipeline", {}).get("icon") @@ -883,6 +884,7 @@ class RagPipelineDslService: import_mode=ImportMode.YAML_CONTENT.value, yaml_content=rag_pipeline_dataset_create_entity.yaml_content, dataset=None, + dataset_name=rag_pipeline_dataset_create_entity.name, ) return { "id": rag_pipeline_import_info.id, From cf89d060237e7bdd0e89b3a993902dd0de03626f Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 14 Jul 2025 16:15:41 +0800 Subject: [PATCH 6/6] fix: single run url error in pipeline --- .../workflow/nodes/_base/hooks/use-one-step-run.ts | 6 +++--- web/service/workflow.ts | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts b/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts index 10e269084f..9f77e66d12 100644 --- a/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts +++ b/web/app/components/workflow/nodes/_base/hooks/use-one-step-run.ts @@ -308,14 +308,14 @@ const useOneStepRun = ({ else { postData.inputs = submitData } - res = await singleNodeRun(flowId!, id, postData) as any + res = await singleNodeRun(flowType, flowId!, id, postData) as any } else if (isIteration) { setIterationRunResult([]) let _iterationResult: NodeTracing[] = [] let _runResult: any = null ssePost( - getIterationSingleNodeRunUrl(isChatMode, flowId!, id), + getIterationSingleNodeRunUrl(flowType, isChatMode, flowId!, id), { body: { inputs: submitData } }, { onWorkflowStarted: noop, @@ -418,7 +418,7 @@ const useOneStepRun = ({ let _loopResult: NodeTracing[] = [] let _runResult: any = null ssePost( - getLoopSingleNodeRunUrl(isChatMode, flowId!, id), + getLoopSingleNodeRunUrl(flowType, isChatMode, flowId!, id), { body: { inputs: submitData } }, { onWorkflowStarted: noop, diff --git a/web/service/workflow.ts b/web/service/workflow.ts index 3311d7a205..654fe3d01a 100644 --- a/web/service/workflow.ts +++ b/web/service/workflow.ts @@ -36,16 +36,16 @@ export const fetchChatRunHistory: Fetcher = (url return get(url) } -export const singleNodeRun = (appId: string, nodeId: string, params: object) => { - return post(`apps/${appId}/workflows/draft/nodes/${nodeId}/run`, { body: params }) +export const singleNodeRun = (flowType: FlowType, flowId: string, nodeId: string, params: object) => { + return post(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/nodes/${nodeId}/run`, { body: params }) } -export const getIterationSingleNodeRunUrl = (isChatFlow: boolean, appId: string, nodeId: string) => { - return `apps/${appId}/${isChatFlow ? 'advanced-chat/' : ''}workflows/draft/iteration/nodes/${nodeId}/run` +export const getIterationSingleNodeRunUrl = (flowType: FlowType, isChatFlow: boolean, flowId: string, nodeId: string) => { + return `${getFlowPrefix(flowType)}/${flowId}/${isChatFlow ? 'advanced-chat/' : ''}workflows/draft/iteration/nodes/${nodeId}/run` } -export const getLoopSingleNodeRunUrl = (isChatFlow: boolean, appId: string, nodeId: string) => { - return `apps/${appId}/${isChatFlow ? 'advanced-chat/' : ''}workflows/draft/loop/nodes/${nodeId}/run` +export const getLoopSingleNodeRunUrl = (flowType: FlowType, isChatFlow: boolean, flowId: string, nodeId: string) => { + return `${getFlowPrefix(flowType)}/${flowId}/${isChatFlow ? 'advanced-chat/' : ''}workflows/draft/loop/nodes/${nodeId}/run` } export const fetchPublishedWorkflow: Fetcher = (url) => {