Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/Node ID Replacing Existing One #3643

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions packages/ui/src/utils/genericHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,18 @@ import { uniq } from 'lodash'
import moment from 'moment'

export const getUniqueNodeId = (nodeData, nodes) => {
// Get amount of same nodes
let totalSameNodes = 0
for (let i = 0; i < nodes.length; i += 1) {
const node = nodes[i]
if (node.data.name === nodeData.name) {
totalSameNodes += 1
}
}
let suffix = 0

// Get unique id
let nodeId = `${nodeData.name}_${totalSameNodes}`
for (let i = 0; i < nodes.length; i += 1) {
const node = nodes[i]
if (node.id === nodeId) {
totalSameNodes += 1
nodeId = `${nodeData.name}_${totalSameNodes}`
}
// Construct base ID
let baseId = `${nodeData.name}_${suffix}`

// Increment suffix until a unique ID is found
while (nodes.some((node) => node.id === baseId)) {
suffix += 1
baseId = `${nodeData.name}_${suffix}`
}
return nodeId

return baseId
}

export const initializeDefaultNodeData = (nodeParams) => {
Expand Down
53 changes: 35 additions & 18 deletions packages/ui/src/views/canvas/AddNodes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,16 @@ function a11yProps(index) {
}
}

const blacklistCategoriesForAgentCanvas = ['Agents', 'Memory', 'Record Manager']
const allowedAgentModel = {}
const exceptions = {
const blacklistCategoriesForAgentCanvas = ['Agents', 'Memory', 'Record Manager', 'Utilities']

// Show blacklisted nodes (exceptions) for agent canvas
const exceptionsForAgentCanvas = {
Memory: ['agentMemory'],
Utilities: ['getVariable', 'setVariable', 'stickyNote']
}

// Hide some nodes from the chatflow canvas
const blacklistForChatflowCanvas = {
Memory: ['agentMemory']
}

Expand Down Expand Up @@ -87,11 +94,16 @@ const AddNodes = ({ nodesData, node, isAgentCanvas }) => {
filterSearch(searchValue, newValue)
}

const addException = () => {
const addException = (category) => {
let nodes = []
for (const category in exceptions) {
const nodeNames = exceptions[category]
nodes.push(...nodesData.filter((nd) => nd.category === category && nodeNames.includes(nd.name)))
if (category) {
const nodeNames = exceptionsForAgentCanvas[category] || []
nodes = nodesData.filter((nd) => nd.category === category && nodeNames.includes(nd.name))
} else {
for (const category in exceptionsForAgentCanvas) {
const nodeNames = exceptionsForAgentCanvas[category]
nodes.push(...nodesData.filter((nd) => nd.category === category && nodeNames.includes(nd.name)))
}
}
return nodes
}
Expand All @@ -108,7 +120,13 @@ const AddNodes = ({ nodesData, node, isAgentCanvas }) => {
})
return passed
}
const nodes = nodesData.filter((nd) => nd.category !== 'Multi Agents' && nd.category !== 'Sequential Agents')
let nodes = nodesData.filter((nd) => nd.category !== 'Multi Agents' && nd.category !== 'Sequential Agents')

for (const category in blacklistForChatflowCanvas) {
const nodeNames = blacklistForChatflowCanvas[category]
nodes = nodes.filter((nd) => !nodeNames.includes(nd.name))
}

const passed = nodes.filter((nd) => {
const passesName = nd.name.toLowerCase().includes(value.toLowerCase())
const passesLabel = nd.label.toLowerCase().includes(value.toLowerCase())
Expand Down Expand Up @@ -163,18 +181,12 @@ const AddNodes = ({ nodesData, node, isAgentCanvas }) => {
const nodes = result[category].filter((nd) => !nd.tags || !nd.tags.includes('LlamaIndex'))
if (!nodes.length) continue

// Only allow specific models for specific categories
if (Object.keys(allowedAgentModel).includes(category)) {
const allowedModels = allowedAgentModel[category]
filteredResult[category] = nodes.filter((nd) => allowedModels.includes(nd.name))
} else {
filteredResult[category] = nodes
}
filteredResult[category] = nodes
}

// Allow exceptions
if (Object.keys(exceptions).includes(category)) {
filteredResult[category] = addException()
// Allow exceptionsForAgentCanvas
if (Object.keys(exceptionsForAgentCanvas).includes(category)) {
filteredResult[category] = addException(category)
}
}
setNodes(filteredResult)
Expand All @@ -197,8 +209,13 @@ const AddNodes = ({ nodesData, node, isAgentCanvas }) => {
if (category === 'Multi Agents' || category === 'Sequential Agents') {
continue
}
if (Object.keys(blacklistForChatflowCanvas).includes(category)) {
const nodes = blacklistForChatflowCanvas[category]
result[category] = result[category].filter((nd) => !nodes.includes(nd.name))
}
filteredResult[category] = result[category]
}

setNodes(filteredResult)
setCategoryExpanded(accordianCategories)
}
Expand Down
Loading