feat: init has value vars
parent
10dd237ec0
commit
ff9c36a244
@ -0,0 +1,52 @@
|
||||
import type { NodeWithVar, VarInInspect } from '@/types/workflow'
|
||||
import { useWorkflowStore } from '../../workflow/store'
|
||||
import { useWorkflowVars as useDoFetchWorkflowVars } from '@/service/use-workflow'
|
||||
import { useStoreApi } from 'reactflow'
|
||||
import type { Node } from '@/app/components/workflow/types'
|
||||
|
||||
const useWorkflowVars = () => {
|
||||
const workflowStore = useWorkflowStore()
|
||||
const { setNodesWithInspectVars, appId } = workflowStore.getState()
|
||||
const store = useStoreApi()
|
||||
|
||||
const addNodeInfo = (inspectVars: VarInInspect[]) => {
|
||||
const { getNodes } = store.getState()
|
||||
const nodeArr = getNodes()
|
||||
const nodesKeyValue: Record<string, Node> = {}
|
||||
nodeArr.forEach((node) => {
|
||||
nodesKeyValue[node.id] = node
|
||||
})
|
||||
|
||||
const withValueNodeIds: Record<string, boolean> = {}
|
||||
inspectVars.forEach((varItem) => {
|
||||
const nodeId = varItem.selector[0]
|
||||
|
||||
const node = nodesKeyValue[nodeId]
|
||||
if (!node)
|
||||
return
|
||||
withValueNodeIds[nodeId] = true
|
||||
})
|
||||
const withValueNodes = Object.keys(withValueNodeIds).map((nodeId) => {
|
||||
return nodesKeyValue[nodeId]
|
||||
})
|
||||
|
||||
const res: NodeWithVar[] = withValueNodes.map((node) => {
|
||||
const nodeId = node.id
|
||||
const varsUnderTheNode = inspectVars.filter((varItem) => {
|
||||
return varItem.selector[0] === nodeId
|
||||
})
|
||||
const nodeWithVar = {
|
||||
nodeId,
|
||||
nodeType: node.data.type,
|
||||
title: node.data.title,
|
||||
vars: varsUnderTheNode,
|
||||
}
|
||||
return nodeWithVar
|
||||
})
|
||||
setNodesWithInspectVars(res)
|
||||
console.log(res)
|
||||
}
|
||||
useDoFetchWorkflowVars(appId, 1, addNodeInfo)
|
||||
}
|
||||
|
||||
export default useWorkflowVars
|
||||
@ -0,0 +1,16 @@
|
||||
import { VarType } from '../../../types'
|
||||
import type { VarInInspect } from '@/types/workflow'
|
||||
import { VarInInspectType } from '@/types/workflow'
|
||||
|
||||
export const vars: VarInInspect[] = [
|
||||
{
|
||||
id: 'xxx',
|
||||
type: VarInInspectType.node,
|
||||
name: 'llm 2',
|
||||
description: '',
|
||||
selector: ['1745476079387', 'text'],
|
||||
value_type: VarType.string,
|
||||
value: 'text value...',
|
||||
edited: false,
|
||||
},
|
||||
]
|
||||
Loading…
Reference in New Issue