fix(web): workflow's variables bugfix
This commit is contained in:
@@ -24,7 +24,7 @@ import AssignmentList from './AssignmentList'
|
||||
import ToolConfig from './ToolConfig'
|
||||
import MemoryConfig from './MemoryConfig'
|
||||
import VariableList from './VariableList'
|
||||
import { useVariableList, getCurrentNodeVariables } from './hooks/useVariableList'
|
||||
import { useVariableList, getCurrentNodeVariables, getChildNodeVariables } from './hooks/useVariableList'
|
||||
import styles from './properties.module.css'
|
||||
import Editor from "../Editor";
|
||||
import RbSlider from './RbSlider'
|
||||
@@ -290,141 +290,26 @@ const Properties: FC<PropertiesProps> = ({
|
||||
let filteredList = addParentIterationVars(variableList).filter(variable => variable.dataType === 'string' || variable.dataType === 'number');
|
||||
return filteredList;
|
||||
}
|
||||
if (nodeType === 'iteration' && key === 'output') {
|
||||
let filteredList = variableList.filter(variable => variable.value.includes('sys.'));
|
||||
// Add child node output variables for loop nodes
|
||||
if (selectedNode) {
|
||||
const graph = graphRef.current;
|
||||
if (graph) {
|
||||
const nodes = graph.getNodes();
|
||||
const childNodes = nodes.filter(node => {
|
||||
const nodeData = node.getData();
|
||||
return nodeData?.cycle === selectedNode.id;
|
||||
});
|
||||
|
||||
// Add output variables from child nodes
|
||||
childNodes.forEach(childNode => {
|
||||
const childData = childNode.getData();
|
||||
const childNodeId = childData.id;
|
||||
|
||||
// Add child node output variables based on their type
|
||||
switch (childData.type) {
|
||||
case 'llm':
|
||||
case 'jinja-render':
|
||||
case 'tool':
|
||||
const outputKey = `${childNodeId}_output`;
|
||||
const existingOutput = filteredList.find(v => v.key === outputKey);
|
||||
if (!existingOutput) {
|
||||
filteredList.push({
|
||||
key: outputKey,
|
||||
label: 'output',
|
||||
type: 'variable',
|
||||
dataType: 'string',
|
||||
value: `${childNodeId}.output`,
|
||||
nodeData: childData,
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 'http-request':
|
||||
const bodyKey = `${childNodeId}_body`;
|
||||
const statusKey = `${childNodeId}_status_code`;
|
||||
if (!filteredList.find(v => v.key === bodyKey)) {
|
||||
filteredList.push({
|
||||
key: bodyKey,
|
||||
label: 'body',
|
||||
type: 'variable',
|
||||
dataType: 'string',
|
||||
value: `${childNodeId}.body`,
|
||||
nodeData: childData,
|
||||
});
|
||||
}
|
||||
if (!filteredList.find(v => v.key === statusKey)) {
|
||||
filteredList.push({
|
||||
key: statusKey,
|
||||
label: 'status_code',
|
||||
type: 'variable',
|
||||
dataType: 'number',
|
||||
value: `${childNodeId}.status_code`,
|
||||
nodeData: childData,
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
if (nodeType === 'iteration' && key === 'output' || nodeType === 'loop' && key === 'condition') {
|
||||
if (!selectedNode) return [];
|
||||
let filteredList = nodeType === 'iteration'
|
||||
? variableList.filter(variable => variable.value.includes('sys.'))
|
||||
: addParentIterationVars(variableList).filter(variable => variable.nodeData.type !== 'loop');
|
||||
|
||||
const childVariables = getChildNodeVariables(selectedNode, graphRef);
|
||||
const existingKeys = new Set(filteredList.map(v => v.key));
|
||||
childVariables.forEach(v => {
|
||||
if (!existingKeys.has(v.key)) {
|
||||
filteredList.push(v);
|
||||
existingKeys.add(v.key);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return filteredList;
|
||||
}
|
||||
if (nodeType === 'iteration') {
|
||||
return variableList.filter(variable => variable.dataType.includes('array'));
|
||||
}
|
||||
if (nodeType === 'loop' && key === 'condition') {
|
||||
let filteredList = addParentIterationVars(variableList).filter(variable => variable.nodeData.type !== 'loop');
|
||||
|
||||
// Add child node output variables for loop nodes
|
||||
if (selectedNode) {
|
||||
const graph = graphRef.current;
|
||||
if (graph) {
|
||||
const nodes = graph.getNodes();
|
||||
const childNodes = nodes.filter(node => {
|
||||
const nodeData = node.getData();
|
||||
return nodeData?.cycle === selectedNode.id;
|
||||
});
|
||||
|
||||
// Add output variables from child nodes
|
||||
childNodes.forEach(childNode => {
|
||||
const childData = childNode.getData();
|
||||
const childNodeId = childData.id;
|
||||
|
||||
// Add child node output variables based on their type
|
||||
switch(childData.type) {
|
||||
case 'llm':
|
||||
case 'jinja-render':
|
||||
case 'tool':
|
||||
const outputKey = `${childNodeId}_output`;
|
||||
const existingOutput = filteredList.find(v => v.key === outputKey);
|
||||
if (!existingOutput) {
|
||||
filteredList.push({
|
||||
key: outputKey,
|
||||
label: 'output',
|
||||
type: 'variable',
|
||||
dataType: 'string',
|
||||
value: `${childNodeId}.output`,
|
||||
nodeData: childData,
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 'http-request':
|
||||
const bodyKey = `${childNodeId}_body`;
|
||||
const statusKey = `${childNodeId}_status_code`;
|
||||
if (!filteredList.find(v => v.key === bodyKey)) {
|
||||
filteredList.push({
|
||||
key: bodyKey,
|
||||
label: 'body',
|
||||
type: 'variable',
|
||||
dataType: 'string',
|
||||
value: `${childNodeId}.body`,
|
||||
nodeData: childData,
|
||||
});
|
||||
}
|
||||
if (!filteredList.find(v => v.key === statusKey)) {
|
||||
filteredList.push({
|
||||
key: statusKey,
|
||||
label: 'status_code',
|
||||
type: 'variable',
|
||||
dataType: 'number',
|
||||
value: `${childNodeId}.status_code`,
|
||||
nodeData: childData,
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return filteredList;
|
||||
}
|
||||
|
||||
// For all other node types, add parent iteration variables if applicable
|
||||
let baseList = variableList;
|
||||
|
||||
Reference in New Issue
Block a user