fix: multi loop nodes remove children error
This commit is contained in:
parent
c6c388fbda
commit
55aad3718d
@ -1,5 +1,4 @@
|
|||||||
import { BlockEnum } from '@/app/components/workflow/types'
|
import { BlockEnum } from '@/app/components/workflow/types'
|
||||||
import { has } from 'immer/dist/internal'
|
|
||||||
|
|
||||||
export const agentNodeData = (() => {
|
export const agentNodeData = (() => {
|
||||||
const node = {
|
const node = {
|
||||||
@ -120,7 +119,6 @@ export const oneStepCircle = (() => {
|
|||||||
],
|
],
|
||||||
}],
|
}],
|
||||||
}
|
}
|
||||||
|
|
||||||
})()
|
})()
|
||||||
|
|
||||||
export const multiStepsCircle = (() => {
|
export const multiStepsCircle = (() => {
|
||||||
@ -138,13 +136,13 @@ export const multiStepsCircle = (() => {
|
|||||||
{ id: '1', parent_id: '4', label: 'Node 1' },
|
{ id: '1', parent_id: '4', label: 'Node 1' },
|
||||||
{ id: '2', parent_id: '1', label: 'Node 2' },
|
{ id: '2', parent_id: '1', label: 'Node 2' },
|
||||||
{ id: '4', parent_id: '2', label: 'Node 4' },
|
{ id: '4', parent_id: '2', label: 'Node 4' },
|
||||||
// { id: '1', parent_id: '4', label: 'Node 1' },
|
{ id: '1', parent_id: '4', label: 'Node 1' },
|
||||||
// { id: '2', parent_id: '1', label: 'Node 2' },
|
{ id: '2', parent_id: '1', label: 'Node 2' },
|
||||||
// { id: '4', parent_id: '2', label: 'Node 4' },
|
{ id: '4', parent_id: '2', label: 'Node 4' },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
// 1 -> [2(4(1(2(4...)))), 3]
|
||||||
return {
|
return {
|
||||||
in: [node],
|
in: [node],
|
||||||
expect: [{
|
expect: [{
|
||||||
@ -165,7 +163,7 @@ export const multiStepsCircle = (() => {
|
|||||||
label: 'Node 4',
|
label: 'Node 4',
|
||||||
children: [],
|
children: [],
|
||||||
hasCircle: true,
|
hasCircle: true,
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -5,24 +5,26 @@ import { cloneDeep } from 'lodash-es'
|
|||||||
const supportedAgentLogNodes = [BlockEnum.Agent, BlockEnum.Tool]
|
const supportedAgentLogNodes = [BlockEnum.Agent, BlockEnum.Tool]
|
||||||
|
|
||||||
const remove = (node: AgentLogItemWithChildren, removeId: string) => {
|
const remove = (node: AgentLogItemWithChildren, removeId: string) => {
|
||||||
const { children } = node
|
let { children } = node
|
||||||
if (!children || children.length === 0) {
|
if (!children || children.length === 0)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
const hasCircle = !!children.find(c => c.id === removeId)
|
||||||
|
if (hasCircle) {
|
||||||
|
node.hasCircle = true
|
||||||
|
node.children = node.children.filter(c => c.id !== removeId)
|
||||||
|
children = node.children
|
||||||
}
|
}
|
||||||
children.forEach((child, index) => {
|
|
||||||
if (child.id === removeId) {
|
children.forEach((child) => {
|
||||||
node.hasCircle = true
|
|
||||||
children.splice(index, 1)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
remove(child, removeId)
|
remove(child, removeId)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const removeRepeatedSiblings = (list: AgentLogItemWithChildren[]) => {
|
const removeRepeatedSiblings = (list: AgentLogItemWithChildren[]) => {
|
||||||
if (!list || list.length === 0) {
|
if (!list || list.length === 0)
|
||||||
return []
|
return []
|
||||||
}
|
|
||||||
const result: AgentLogItemWithChildren[] = []
|
const result: AgentLogItemWithChildren[] = []
|
||||||
const addedItemIds: string[] = []
|
const addedItemIds: string[] = []
|
||||||
list.forEach((item) => {
|
list.forEach((item) => {
|
||||||
@ -35,19 +37,18 @@ const removeRepeatedSiblings = (list: AgentLogItemWithChildren[]) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const removeCircleLogItem = (log: AgentLogItemWithChildren) => {
|
const removeCircleLogItem = (log: AgentLogItemWithChildren) => {
|
||||||
let newLog = cloneDeep(log)
|
const newLog = cloneDeep(log)
|
||||||
newLog.children = removeRepeatedSiblings(newLog.children)
|
newLog.children = removeRepeatedSiblings(newLog.children)
|
||||||
let { id, children } = newLog
|
let { id, children } = newLog
|
||||||
if (!children || children.length === 0) {
|
if (!children || children.length === 0)
|
||||||
return log
|
return log
|
||||||
}
|
|
||||||
// check one step circle
|
// check one step circle
|
||||||
const hasOneStepCircle = !!children.find(c => c.id === id)
|
const hasOneStepCircle = !!children.find(c => c.id === id)
|
||||||
if (hasOneStepCircle) {
|
if (hasOneStepCircle) {
|
||||||
newLog.hasCircle = true
|
newLog.hasCircle = true
|
||||||
newLog.children = newLog.children.filter(c => c.id !== id)
|
newLog.children = newLog.children.filter(c => c.id !== id)
|
||||||
children = newLog.children
|
children = newLog.children
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
children.forEach((child, index) => {
|
children.forEach((child, index) => {
|
||||||
@ -85,6 +86,7 @@ const format = (list: NodeTracing[]): NodeTracing[] => {
|
|||||||
let removedCircleTree: AgentLogItemWithChildren[] = []
|
let removedCircleTree: AgentLogItemWithChildren[] = []
|
||||||
if (supportedAgentLogNodes.includes(item.node_type) && item.execution_metadata?.agent_log && item.execution_metadata?.agent_log.length > 0)
|
if (supportedAgentLogNodes.includes(item.node_type) && item.execution_metadata?.agent_log && item.execution_metadata?.agent_log.length > 0)
|
||||||
treeList = listToTree(item.execution_metadata.agent_log)
|
treeList = listToTree(item.execution_metadata.agent_log)
|
||||||
|
// console.log(JSON.stringify(treeList))
|
||||||
removedCircleTree = treeList.length > 0 ? treeList.map(t => removeCircleLogItem(t)) : []
|
removedCircleTree = treeList.length > 0 ? treeList.map(t => removeCircleLogItem(t)) : []
|
||||||
item.agentLog = removedCircleTree
|
item.agentLog = removedCircleTree
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user