MCPcopy Index your code
hub / github.com/FlowiseAI/Flowise / getSortedDepthNodes

Function getSortedDepthNodes

packages/server/src/utils/buildAgentGraph.ts:1060–1083  ·  view source on GitHub ↗
(depthQueue: IDepthQueue)

Source from the content-addressed store, hash-verified

1058}
1059
1060const getSortedDepthNodes = (depthQueue: IDepthQueue) => {
1061 // Step 1: Convert the object into an array of [key, value] pairs and sort them by the value
1062 const sortedEntries = Object.entries(depthQueue).sort((a, b) => a[1] - b[1])
1063
1064 // Step 2: Group keys by their depth values
1065 const groupedByDepth: Record<number, string[]> = {}
1066 sortedEntries.forEach(([key, value]) => {
1067 if (!groupedByDepth[value]) {
1068 groupedByDepth[value] = []
1069 }
1070 groupedByDepth[value].push(key)
1071 })
1072
1073 // Step 3: Create the final sorted array with grouped keys
1074 const sortedArray: (string | string[])[] = []
1075 Object.keys(groupedByDepth)
1076 .sort((a, b) => parseInt(a) - parseInt(b))
1077 .forEach((depth) => {
1078 const items = groupedByDepth[parseInt(depth)]
1079 sortedArray.push(...items)
1080 })
1081
1082 return sortedArray.flat()
1083}

Callers 1

compileSeqAgentsGraphFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected