|
|
|
@ -1,20 +1,36 @@
|
|
|
|
import { useWorkflowStore } from '../store'
|
|
|
|
import { useWorkflowStore } from '../store'
|
|
|
|
import { BlockEnum, type ValueSelector, type VarType } from '../types'
|
|
|
|
import type { ValueSelector, VarType } from '../types'
|
|
|
|
const useCurrentVars = () => {
|
|
|
|
import {
|
|
|
|
|
|
|
|
useConversationVarValues,
|
|
|
|
|
|
|
|
useDeleteAllInspectorVars,
|
|
|
|
|
|
|
|
useDeleteInspectVar,
|
|
|
|
|
|
|
|
useDeleteNodeInspectorVars,
|
|
|
|
|
|
|
|
useInvalidateConversationVarValues,
|
|
|
|
|
|
|
|
useInvalidateSysVarValues,
|
|
|
|
|
|
|
|
useSysVarValues,
|
|
|
|
|
|
|
|
} from '@/service/use-workflow'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const useInspectVarsCrud = () => {
|
|
|
|
const workflowStore = useWorkflowStore()
|
|
|
|
const workflowStore = useWorkflowStore()
|
|
|
|
const {
|
|
|
|
const {
|
|
|
|
conversationVars,
|
|
|
|
appId,
|
|
|
|
nodesWithInspectVars,
|
|
|
|
nodesWithInspectVars,
|
|
|
|
getInspectVar,
|
|
|
|
getInspectVar,
|
|
|
|
setInspectVar,
|
|
|
|
setInspectVar,
|
|
|
|
deleteAllInspectVars: deleteAllInspectVarsInStore,
|
|
|
|
deleteAllInspectVars: deleteAllInspectVarsInStore,
|
|
|
|
deleteNodeInspectVars: deleteNodeInspectVarsInStore,
|
|
|
|
deleteNodeInspectVars: deleteNodeInspectVarsInStore,
|
|
|
|
|
|
|
|
deleteInspectVar: deleteInspectVarInStore,
|
|
|
|
getLastRunVar,
|
|
|
|
getLastRunVar,
|
|
|
|
} = workflowStore.getState()
|
|
|
|
} = workflowStore.getState()
|
|
|
|
|
|
|
|
|
|
|
|
// rag flow don't have start node
|
|
|
|
const { data: conversationVars } = useConversationVarValues(appId)
|
|
|
|
const startNode = nodesWithInspectVars.find(node => node.nodeType === BlockEnum.Start)
|
|
|
|
const invalidateConversationVarValues = useInvalidateConversationVarValues(appId)
|
|
|
|
const systemVars = startNode?.vars.filter(varItem => varItem.selector[0] === 'sys')
|
|
|
|
const { data: systemVars } = useSysVarValues(appId)
|
|
|
|
|
|
|
|
const invalidateSysVarValues = useInvalidateSysVarValues(appId)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { mutate: doDeleteAllInspectorVars } = useDeleteAllInspectorVars(appId)
|
|
|
|
|
|
|
|
const { mutate: doDeleteNodeInspectorVars } = useDeleteNodeInspectorVars(appId)
|
|
|
|
|
|
|
|
const { mutate: doDeleteInspectVar } = useDeleteInspectVar(appId)
|
|
|
|
|
|
|
|
|
|
|
|
const fetchInspectVarValue = (selector: ValueSelector) => {
|
|
|
|
const fetchInspectVarValue = (selector: ValueSelector) => {
|
|
|
|
const nodeId = selector[0]
|
|
|
|
const nodeId = selector[0]
|
|
|
|
@ -26,6 +42,7 @@ const useCurrentVars = () => {
|
|
|
|
|
|
|
|
|
|
|
|
const editInspectVarValue = (varId: string, value: any) => {
|
|
|
|
const editInspectVarValue = (varId: string, value: any) => {
|
|
|
|
console.log('edit var', varId, value)
|
|
|
|
console.log('edit var', varId, value)
|
|
|
|
|
|
|
|
|
|
|
|
// call api and update store
|
|
|
|
// call api and update store
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -38,17 +55,20 @@ const useCurrentVars = () => {
|
|
|
|
console.log('edit var value type', varId, valueType)
|
|
|
|
console.log('edit var value type', varId, valueType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const deleteInspectVar = async (varId: string) => {
|
|
|
|
const deleteInspectVar = async (nodeId: string, varId: string) => {
|
|
|
|
console.log('delete var', varId)
|
|
|
|
await doDeleteInspectVar(varId)
|
|
|
|
|
|
|
|
deleteInspectVarInStore(nodeId, varId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const deleteNodeInspectorVars = async (nodeId: string) => {
|
|
|
|
const deleteNodeInspectorVars = async (nodeId: string) => {
|
|
|
|
// todo fetch api
|
|
|
|
await doDeleteNodeInspectorVars(nodeId)
|
|
|
|
deleteNodeInspectVarsInStore(nodeId)
|
|
|
|
deleteNodeInspectVarsInStore(nodeId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const deleteAllInspectorVars = async () => {
|
|
|
|
const deleteAllInspectorVars = async () => {
|
|
|
|
// todo fetch api
|
|
|
|
await doDeleteAllInspectorVars()
|
|
|
|
|
|
|
|
await invalidateConversationVarValues()
|
|
|
|
|
|
|
|
await invalidateSysVarValues()
|
|
|
|
deleteAllInspectVarsInStore()
|
|
|
|
deleteAllInspectVarsInStore()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -62,9 +82,11 @@ const useCurrentVars = () => {
|
|
|
|
setInspectVar(nodeId, key, lastRunVar)
|
|
|
|
setInspectVar(nodeId, key, lastRunVar)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(conversationVars, systemVars)
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
conversationVars,
|
|
|
|
conversationVars: conversationVars || [],
|
|
|
|
systemVars,
|
|
|
|
systemVars: systemVars || [],
|
|
|
|
nodesWithInspectVars,
|
|
|
|
nodesWithInspectVars,
|
|
|
|
fetchInspectVarValue,
|
|
|
|
fetchInspectVarValue,
|
|
|
|
editInspectVarValue,
|
|
|
|
editInspectVarValue,
|
|
|
|
@ -78,4 +100,4 @@ const useCurrentVars = () => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default useCurrentVars
|
|
|
|
export default useInspectVarsCrud
|
|
|
|
|