Skip to content

Commit 371da23

Browse files
authored
Bugfix/Node ID Replacing Existing One (#3643)
fix node is replacing
1 parent 20e0938 commit 371da23

File tree

2 files changed

+45
-35
lines changed

2 files changed

+45
-35
lines changed

packages/ui/src/utils/genericHelper.js

+10-17
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,18 @@ import { uniq } from 'lodash'
22
import moment from 'moment'
33

44
export const getUniqueNodeId = (nodeData, nodes) => {
5-
// Get amount of same nodes
6-
let totalSameNodes = 0
7-
for (let i = 0; i < nodes.length; i += 1) {
8-
const node = nodes[i]
9-
if (node.data.name === nodeData.name) {
10-
totalSameNodes += 1
11-
}
12-
}
5+
let suffix = 0
136

14-
// Get unique id
15-
let nodeId = `${nodeData.name}_${totalSameNodes}`
16-
for (let i = 0; i < nodes.length; i += 1) {
17-
const node = nodes[i]
18-
if (node.id === nodeId) {
19-
totalSameNodes += 1
20-
nodeId = `${nodeData.name}_${totalSameNodes}`
21-
}
7+
// Construct base ID
8+
let baseId = `${nodeData.name}_${suffix}`
9+
10+
// Increment suffix until a unique ID is found
11+
while (nodes.some((node) => node.id === baseId)) {
12+
suffix += 1
13+
baseId = `${nodeData.name}_${suffix}`
2214
}
23-
return nodeId
15+
16+
return baseId
2417
}
2518

2619
export const initializeDefaultNodeData = (nodeParams) => {

packages/ui/src/views/canvas/AddNodes.jsx

+35-18
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,16 @@ function a11yProps(index) {
5454
}
5555
}
5656

57-
const blacklistCategoriesForAgentCanvas = ['Agents', 'Memory', 'Record Manager']
58-
const allowedAgentModel = {}
59-
const exceptions = {
57+
const blacklistCategoriesForAgentCanvas = ['Agents', 'Memory', 'Record Manager', 'Utilities']
58+
59+
// Show blacklisted nodes (exceptions) for agent canvas
60+
const exceptionsForAgentCanvas = {
61+
Memory: ['agentMemory'],
62+
Utilities: ['getVariable', 'setVariable', 'stickyNote']
63+
}
64+
65+
// Hide some nodes from the chatflow canvas
66+
const blacklistForChatflowCanvas = {
6067
Memory: ['agentMemory']
6168
}
6269

@@ -87,11 +94,16 @@ const AddNodes = ({ nodesData, node, isAgentCanvas }) => {
8794
filterSearch(searchValue, newValue)
8895
}
8996

90-
const addException = () => {
97+
const addException = (category) => {
9198
let nodes = []
92-
for (const category in exceptions) {
93-
const nodeNames = exceptions[category]
94-
nodes.push(...nodesData.filter((nd) => nd.category === category && nodeNames.includes(nd.name)))
99+
if (category) {
100+
const nodeNames = exceptionsForAgentCanvas[category] || []
101+
nodes = nodesData.filter((nd) => nd.category === category && nodeNames.includes(nd.name))
102+
} else {
103+
for (const category in exceptionsForAgentCanvas) {
104+
const nodeNames = exceptionsForAgentCanvas[category]
105+
nodes.push(...nodesData.filter((nd) => nd.category === category && nodeNames.includes(nd.name)))
106+
}
95107
}
96108
return nodes
97109
}
@@ -108,7 +120,13 @@ const AddNodes = ({ nodesData, node, isAgentCanvas }) => {
108120
})
109121
return passed
110122
}
111-
const nodes = nodesData.filter((nd) => nd.category !== 'Multi Agents' && nd.category !== 'Sequential Agents')
123+
let nodes = nodesData.filter((nd) => nd.category !== 'Multi Agents' && nd.category !== 'Sequential Agents')
124+
125+
for (const category in blacklistForChatflowCanvas) {
126+
const nodeNames = blacklistForChatflowCanvas[category]
127+
nodes = nodes.filter((nd) => !nodeNames.includes(nd.name))
128+
}
129+
112130
const passed = nodes.filter((nd) => {
113131
const passesName = nd.name.toLowerCase().includes(value.toLowerCase())
114132
const passesLabel = nd.label.toLowerCase().includes(value.toLowerCase())
@@ -163,18 +181,12 @@ const AddNodes = ({ nodesData, node, isAgentCanvas }) => {
163181
const nodes = result[category].filter((nd) => !nd.tags || !nd.tags.includes('LlamaIndex'))
164182
if (!nodes.length) continue
165183

166-
// Only allow specific models for specific categories
167-
if (Object.keys(allowedAgentModel).includes(category)) {
168-
const allowedModels = allowedAgentModel[category]
169-
filteredResult[category] = nodes.filter((nd) => allowedModels.includes(nd.name))
170-
} else {
171-
filteredResult[category] = nodes
172-
}
184+
filteredResult[category] = nodes
173185
}
174186

175-
// Allow exceptions
176-
if (Object.keys(exceptions).includes(category)) {
177-
filteredResult[category] = addException()
187+
// Allow exceptionsForAgentCanvas
188+
if (Object.keys(exceptionsForAgentCanvas).includes(category)) {
189+
filteredResult[category] = addException(category)
178190
}
179191
}
180192
setNodes(filteredResult)
@@ -197,8 +209,13 @@ const AddNodes = ({ nodesData, node, isAgentCanvas }) => {
197209
if (category === 'Multi Agents' || category === 'Sequential Agents') {
198210
continue
199211
}
212+
if (Object.keys(blacklistForChatflowCanvas).includes(category)) {
213+
const nodes = blacklistForChatflowCanvas[category]
214+
result[category] = result[category].filter((nd) => !nodes.includes(nd.name))
215+
}
200216
filteredResult[category] = result[category]
201217
}
218+
202219
setNodes(filteredResult)
203220
setCategoryExpanded(accordianCategories)
204221
}

0 commit comments

Comments
 (0)