Skip to content

Commit a88337c

Browse files
authored
Bugfix/config input for multiple same fields (#4548)
* fix config input for multiple same fields * fix custom tool not selected
1 parent eb69b23 commit a88337c

File tree

3 files changed

+43
-32
lines changed

3 files changed

+43
-32
lines changed

packages/components/nodes/agentflow/Tool/Tool.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Tool_Agentflow implements INode {
2828
constructor() {
2929
this.label = 'Tool'
3030
this.name = 'toolAgentflow'
31-
this.version = 1.0
31+
this.version = 1.1
3232
this.type = 'Tool'
3333
this.category = 'Agent Flows'
3434
this.description = 'Tools allow LLM to interact with external systems'
@@ -37,7 +37,7 @@ class Tool_Agentflow implements INode {
3737
this.inputs = [
3838
{
3939
label: 'Tool',
40-
name: 'selectedTool',
40+
name: 'toolAgentflowSelectedTool',
4141
type: 'asyncOptions',
4242
loadMethod: 'listTools',
4343
loadConfig: true
@@ -64,7 +64,7 @@ class Tool_Agentflow implements INode {
6464
}
6565
],
6666
show: {
67-
selectedTool: '.+'
67+
toolAgentflowSelectedTool: '.+'
6868
}
6969
},
7070
{
@@ -124,7 +124,7 @@ class Tool_Agentflow implements INode {
124124
},
125125
async listToolInputArgs(nodeData: INodeData, options: ICommonObject): Promise<INodeOptionsValue[]> {
126126
const currentNode = options.currentNode as ICommonObject
127-
const selectedTool = currentNode?.inputs?.selectedTool as string
127+
const selectedTool = (currentNode?.inputs?.selectedTool as string) || (currentNode?.inputs?.toolAgentflowSelectedTool as string)
128128
const selectedToolConfig = currentNode?.inputs?.selectedToolConfig as ICommonObject
129129

130130
const nodeInstanceFilePath = options.componentNodes[selectedTool].filePath as string
@@ -183,7 +183,7 @@ class Tool_Agentflow implements INode {
183183
}
184184

185185
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<any> {
186-
const selectedTool = nodeData.inputs?.selectedTool as string
186+
const selectedTool = (nodeData.inputs?.selectedTool as string) || (nodeData.inputs?.toolAgentflowSelectedTool as string)
187187
const selectedToolConfig = nodeData.inputs?.selectedToolConfig as ICommonObject
188188

189189
const toolInputArgs = nodeData.inputs?.toolInputArgs as IToolInputArgs[]

packages/server/marketplaces/agentflowsv2/Slack Agent.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@
526526
"data": {
527527
"id": "toolAgentflow_0",
528528
"label": "Slack Reply",
529-
"version": 1,
529+
"version": 1.1,
530530
"name": "toolAgentflow",
531531
"type": "Tool",
532532
"color": "#d4a373",
@@ -536,11 +536,11 @@
536536
"inputParams": [
537537
{
538538
"label": "Tool",
539-
"name": "selectedTool",
539+
"name": "toolAgentflowSelectedTool",
540540
"type": "asyncOptions",
541541
"loadMethod": "listTools",
542542
"loadConfig": true,
543-
"id": "toolAgentflow_0-input-selectedTool-asyncOptions",
543+
"id": "toolAgentflow_0-input-toolAgentflowSelectedTool-asyncOptions",
544544
"display": true
545545
},
546546
{
@@ -565,7 +565,7 @@
565565
}
566566
],
567567
"show": {
568-
"selectedTool": ".+"
568+
"toolAgentflowSelectedTool": ".+"
569569
},
570570
"id": "toolAgentflow_0-input-toolInputArgs-array",
571571
"display": true
@@ -599,7 +599,7 @@
599599
],
600600
"inputAnchors": [],
601601
"inputs": {
602-
"selectedTool": "slackMCP",
602+
"toolAgentflowSelectedTool": "slackMCP",
603603
"toolInputArgs": [
604604
{
605605
"inputArgName": "channel_id",
@@ -611,9 +611,9 @@
611611
}
612612
],
613613
"toolUpdateState": "",
614-
"selectedToolConfig": {
614+
"toolAgentflowSelectedToolConfig": {
615615
"mcpActions": "[\"slack_post_message\"]",
616-
"selectedTool": "slackMCP"
616+
"toolAgentflowSelectedTool": "slackMCP"
617617
}
618618
},
619619
"outputAnchors": [

packages/ui/src/views/agentflowsv2/ConfigInput.jsx

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useContext, useState, useEffect, useRef } from 'react'
1+
import { useContext, useState, useEffect, useMemo } from 'react'
22
import PropTypes from 'prop-types'
33
import { cloneDeep } from 'lodash'
44

@@ -26,8 +26,12 @@ export const ConfigInput = ({ data, inputParam, disabled = false, arrayIndex = n
2626
const [expanded, setExpanded] = useState(false)
2727
const [selectedComponentNodeData, setSelectedComponentNodeData] = useState({})
2828

29-
// Track the last processed input values to prevent infinite loops
30-
const lastProcessedInputsRef = useRef({})
29+
// Track the last processed input values to prevent infinite loops using useState
30+
const [lastProcessedInputs, setLastProcessedInputs] = useState({
31+
mainValue: null,
32+
configValue: null,
33+
arrayValue: null
34+
})
3135

3236
const handleAccordionChange = (event, isExpanded) => {
3337
setExpanded(isExpanded)
@@ -64,6 +68,18 @@ export const ConfigInput = ({ data, inputParam, disabled = false, arrayIndex = n
6468
setSelectedComponentNodeData(nodeData)
6569
}
6670

71+
// Memoize current input values for reliable comparison
72+
const currentInputValues = useMemo(
73+
() => ({
74+
mainValue: data.inputs[inputParam.name],
75+
configValue: data.inputs[`${inputParam.name}Config`],
76+
arrayValue: parentParamForArray ? data.inputs[parentParamForArray.name] : null
77+
}),
78+
79+
// eslint-disable-next-line react-hooks/exhaustive-deps
80+
[data.inputs, inputParam.name, parentParamForArray?.name]
81+
)
82+
6783
// Load initial component data when the component mounts
6884
useEffect(() => {
6985
const loadComponentData = async () => {
@@ -138,11 +154,11 @@ export const ConfigInput = ({ data, inputParam, disabled = false, arrayIndex = n
138154
setSelectedComponentNodeData(componentNodeData)
139155

140156
// Store the processed inputs to track changes
141-
lastProcessedInputsRef.current = {
157+
setLastProcessedInputs({
142158
mainValue: data.inputs[inputParam.name],
143159
configValue: data.inputs[`${inputParam.name}Config`],
144160
arrayValue: parentParamForArray ? data.inputs[parentParamForArray.name] : null
145-
}
161+
})
146162
}
147163

148164
loadComponentData()
@@ -154,15 +170,10 @@ export const ConfigInput = ({ data, inputParam, disabled = false, arrayIndex = n
154170
useEffect(() => {
155171
if (!selectedComponentNodeData.inputParams) return
156172

157-
// Get current input values
158-
const currentMainValue = data.inputs[inputParam.name]
159-
const currentConfigValue = data.inputs[`${inputParam.name}Config`]
160-
const currentArrayValue = parentParamForArray ? data.inputs[parentParamForArray.name] : null
161-
162-
// Check if relevant inputs have changed
163-
const hasMainValueChanged = lastProcessedInputsRef.current.mainValue !== currentMainValue
164-
const hasConfigValueChanged = lastProcessedInputsRef.current.configValue !== currentConfigValue
165-
const hasArrayValueChanged = lastProcessedInputsRef.current.arrayValue !== currentArrayValue
173+
// Check if relevant inputs have changed using strict equality comparison
174+
const hasMainValueChanged = lastProcessedInputs.mainValue !== currentInputValues.mainValue
175+
const hasConfigValueChanged = lastProcessedInputs.configValue !== currentInputValues.configValue
176+
const hasArrayValueChanged = lastProcessedInputs.arrayValue !== currentInputValues.arrayValue
166177

167178
if (!hasMainValueChanged && !hasConfigValueChanged && !hasArrayValueChanged) {
168179
return // No relevant changes
@@ -224,17 +235,17 @@ export const ConfigInput = ({ data, inputParam, disabled = false, arrayIndex = n
224235
setSelectedComponentNodeData(updatedComponentData)
225236

226237
// Update the tracked values
227-
lastProcessedInputsRef.current = {
228-
mainValue: currentMainValue,
229-
configValue: currentConfigValue,
230-
arrayValue: currentArrayValue
231-
}
238+
setLastProcessedInputs({
239+
mainValue: currentInputValues.mainValue,
240+
configValue: currentInputValues.configValue,
241+
arrayValue: currentInputValues.arrayValue
242+
})
232243
}
233244

234245
updateComponentData()
235246

236247
// eslint-disable-next-line react-hooks/exhaustive-deps
237-
}, [data.inputs, inputParam.name, parentParamForArray?.name, arrayIndex])
248+
}, [currentInputValues, selectedComponentNodeData.inputParams, inputParam.name, parentParamForArray?.name, arrayIndex])
238249

239250
// Update node configuration when selected component data changes
240251
useEffect(() => {

0 commit comments

Comments
 (0)