mirror of https://github.com/langgenius/dify.git
feat: workflow use common last run
This commit is contained in:
parent
928751a856
commit
7a9faf909e
|
|
@ -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`,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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<void>
|
||||
invalidateConversationVarValues: () => void
|
||||
configsMap?: {
|
||||
flowId: string
|
||||
flowType: FlowType
|
||||
conversationVarsUrl: string
|
||||
systemVarsUrl: string
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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[]) => {
|
||||
|
|
|
|||
|
|
@ -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<BasePanelProps> = ({
|
|||
nodesMap,
|
||||
} = useNodesMetaData()
|
||||
|
||||
const configsMap = useHooksStore(s => s.configsMap)
|
||||
const {
|
||||
isShowSingleRun,
|
||||
hideSingleRun,
|
||||
|
|
@ -205,6 +208,8 @@ const BasePanel: FC<BasePanelProps> = ({
|
|||
getFilteredExistVarForms,
|
||||
} = useLastRun<typeof data>({
|
||||
id,
|
||||
flowId: configsMap?.flowId || '',
|
||||
flowType: configsMap?.flowType || FlowType.appFlow,
|
||||
data,
|
||||
defaultRunInputData: nodesMap?.[data.type]?.defaultRunInputData || {},
|
||||
isPaused,
|
||||
|
|
|
|||
|
|
@ -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<Props> = ({
|
|||
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<Props> = ({
|
|||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -57,6 +57,8 @@ const singleRunFormParamsHooks: Record<BlockEnum, any> = {
|
|||
[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, any> = {
|
|||
[BlockEnum.Assigner]: undefined,
|
||||
[BlockEnum.LoopStart]: undefined,
|
||||
[BlockEnum.LoopEnd]: undefined,
|
||||
[BlockEnum.DataSource]: undefined,
|
||||
[BlockEnum.KnowledgeBase]: undefined,
|
||||
}
|
||||
|
||||
const useGetDataForCheckMoreHooks = <T>(nodeType: BlockEnum) => {
|
||||
|
|
@ -119,6 +123,8 @@ const useLastRun = <T>({
|
|||
|
||||
const {
|
||||
id,
|
||||
flowId,
|
||||
flowType,
|
||||
data,
|
||||
} = oneStepRunParams
|
||||
const oneStepRunRes = useOneStepRun({
|
||||
|
|
@ -129,7 +135,6 @@ const useLastRun = <T>({
|
|||
})
|
||||
|
||||
const {
|
||||
appId,
|
||||
hideSingleRun,
|
||||
handleRun: doCallRunApi,
|
||||
getInputVars,
|
||||
|
|
@ -199,7 +204,7 @@ const useLastRun = <T>({
|
|||
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<string, any>) => {
|
||||
const { isValid } = checkValid()
|
||||
|
|
|
|||
|
|
@ -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, Function> = {
|
||||
[BlockEnum.LLM]: checkLLMValid,
|
||||
|
|
@ -72,6 +72,8 @@ const checkValidFns: Record<BlockEnum, Function> = {
|
|||
|
||||
export type Params<T> = {
|
||||
id: string
|
||||
flowId: string
|
||||
flowType: FlowType
|
||||
data: CommonNodeType<T>
|
||||
defaultRunInputData: Record<string, any>
|
||||
moreDataForCheckValid?: any
|
||||
|
|
@ -106,6 +108,8 @@ const varTypeToInputVarType = (type: VarType, {
|
|||
|
||||
const useOneStepRun = <T>({
|
||||
id,
|
||||
flowId,
|
||||
flowType,
|
||||
data,
|
||||
defaultRunInputData,
|
||||
moreDataForCheckValid,
|
||||
|
|
@ -153,7 +157,6 @@ const useOneStepRun = <T>({
|
|||
|
||||
const checkValid = checkValidFns[data.type]
|
||||
|
||||
const appId = useAppStore.getState().appDetail?.id
|
||||
const [runInputData, setRunInputData] = useState<Record<string, any>>(defaultRunInputData || {})
|
||||
const runInputDataRef = useRef(runInputData)
|
||||
const handleSetRunInputData = useCallback((data: Record<string, any>) => {
|
||||
|
|
@ -168,7 +171,7 @@ const useOneStepRun = <T>({
|
|||
const {
|
||||
setShowSingleRunPanel,
|
||||
} = workflowStore.getState()
|
||||
const invalidLastRun = useInvalidLastRun(appId!, id)
|
||||
const invalidLastRun = useInvalidLastRun(flowType, flowId!, id)
|
||||
const [runResult, doSetRunResult] = useState<NodeRunResult | null>(null)
|
||||
const {
|
||||
appendNodeInspectVars,
|
||||
|
|
@ -195,7 +198,7 @@ const useOneStepRun = <T>({
|
|||
}
|
||||
|
||||
// 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 = <T>({
|
|||
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 = <T>({
|
|||
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 = <T>({
|
|||
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 = <T>({
|
|||
}
|
||||
|
||||
return {
|
||||
appId,
|
||||
isShowSingleRun,
|
||||
hideSingleRun,
|
||||
showSingleRun,
|
||||
|
|
|
|||
|
|
@ -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<string[]>([])
|
||||
const suggestedQuestionsAbortControllerRef = useRef<AbortController | null>(null)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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<NodeTracing>({
|
||||
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,
|
||||
})
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
}
|
||||
|
|
@ -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<FetchWorkflowDraftResponse>
|
||||
|
|
@ -78,13 +80,13 @@ export const fetchCurrentValueOfConversationVariable: Fetcher<ConversationVariab
|
|||
return get<ConversationVariableResponse>(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<VarInInspect[]> => {
|
||||
const res = await fetchAllInspectVarsOnePage(appId, 1)
|
||||
export const fetchAllInspectVars = async (flowType: FlowType, flowId: string): Promise<VarInInspect[]> => {
|
||||
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<VarInInspect[]
|
|||
const pageCount = Math.ceil(total / 100)
|
||||
const promises = []
|
||||
for (let i = 2; i <= pageCount; i++)
|
||||
promises.push(fetchAllInspectVarsOnePage(appId, i))
|
||||
promises.push(fetchAllInspectVarsOnePage(flowType, flowId, i))
|
||||
|
||||
const restData = await Promise.all(promises)
|
||||
restData.forEach(({ items: item }) => {
|
||||
|
|
@ -101,7 +103,7 @@ export const fetchAllInspectVars = async (appId: string): Promise<VarInInspect[]
|
|||
return items
|
||||
}
|
||||
|
||||
export const fetchNodeInspectVars = async (appId: string, nodeId: string): Promise<VarInInspect[]> => {
|
||||
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<VarInInspect[]> => {
|
||||
const { items } = (await get(`${getFlowPrefix(flowType)}/${flowId}/workflows/draft/nodes/${nodeId}/variables`)) as { items: VarInInspect[] }
|
||||
return items
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
export enum FlowType {
|
||||
appFlow = 'appFlow',
|
||||
ragFlow = 'ragFlow',
|
||||
}
|
||||
Loading…
Reference in New Issue