mirror of https://github.com/langgenius/dify.git
chore: use flow type instead of whole url
This commit is contained in:
parent
7a9faf909e
commit
82f4b35d52
|
|
@ -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<WorkflowProps, 'nodes' | 'edges' | 'viewport'>
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -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])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,8 +64,6 @@ export type CommonHooksFnMap = {
|
|||
configsMap?: {
|
||||
flowId: string
|
||||
flowType: FlowType
|
||||
conversationVarsUrl: string
|
||||
systemVarsUrl: string
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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[]) => {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue