bugfix: workflow bugfix

This commit is contained in:
zhaoying
2026-01-10 17:44:06 +08:00
parent 177d514d13
commit 24ace52e27
15 changed files with 242 additions and 176 deletions

View File

@@ -1,5 +1,5 @@
import { forwardRef, useImperativeHandle, useState } from 'react';
import { Form, Input, Select, Checkbox, InputNumber } from 'antd';
import { Form, Input, Select, InputNumber } from 'antd';
import { useTranslation } from 'react-i18next';
import type { ChatVariableModalRef } from './types'
@@ -26,6 +26,7 @@ const ChatVariableModal = forwardRef<ChatVariableModalRef, ChatVariableModalProp
const [form] = Form.useForm<ChatVariable>();
const [loading, setLoading] = useState(false)
const [editIndex, setEditIndex] = useState<number | undefined>(undefined)
const type = Form.useWatch('type', form);
// 封装取消方法,添加关闭弹窗逻辑
const handleClose = () => {
@@ -38,7 +39,8 @@ const ChatVariableModal = forwardRef<ChatVariableModalRef, ChatVariableModalProp
const handleOpen = (variable?: ChatVariable, index?: number) => {
setVisible(true);
if (variable) {
form.setFieldsValue(variable)
const { default: _, ...rest } = variable
form.setFieldsValue({ ...rest })
setEditIndex(index)
} else {
form.resetFields();
@@ -48,7 +50,7 @@ const ChatVariableModal = forwardRef<ChatVariableModalRef, ChatVariableModalProp
// 封装保存方法,添加提交逻辑
const handleSave = () => {
form.validateFields().then((values) => {
refresh({ ...values }, editIndex)
refresh({ ...values, default: values.defaultValue }, editIndex)
handleClose()
})
}
@@ -89,52 +91,36 @@ const ChatVariableModal = forwardRef<ChatVariableModalRef, ChatVariableModalProp
>
<Select
placeholder={t('common.pleaseSelect')}
onChange={() => form.setFieldValue('default', undefined)}
onChange={() => form.setFieldValue('defaultValue', undefined)}
options={types.map(key => ({
value: key,
label: t(`workflow.config.parameter-extractor.${key}`),
}))}
/>
</FormItem>
<FormItem
name="default"
<Form.Item
name="defaultValue"
label={t('workflow.config.parameter-extractor.default')}
>
<Form.Item noStyle shouldUpdate={(prevValues, currentValues) => prevValues.type !== currentValues.type}>
{({ getFieldValue }) => {
const type = getFieldValue('type');
if (type === 'number') {
return <InputNumber placeholder={t('common.enter')} style={{ width: '100%' }} />;
}
if (type === 'boolean') {
return (
<Select
placeholder={t('common.pleaseSelect')}
options={[
{ value: true, label: 'true' },
{ value: false, label: 'false' }
]}
/>
);
}
return <Input placeholder={t('common.enter')} />;
}}
</Form.Item>
</FormItem>
{type === 'number'
? <InputNumber placeholder={t('common.enter')} style={{ width: '100%' }} />
: type === 'boolean'
? <Select
placeholder={t('common.pleaseSelect')}
options={[
{ value: true, label: 'true' },
{ value: false, label: 'false' }
]}
/>
: <Input placeholder={t('common.enter')} />
}
</Form.Item>
<FormItem
name="description"
label={t('workflow.config.parameter-extractor.desc')}
>
<Input.TextArea placeholder={t('common.enter')} />
</FormItem>
<FormItem
name="required"
valuePropName="checked"
>
<Checkbox>{t('workflow.config.parameter-extractor.required')}</Checkbox>
</FormItem>
</Form>
</RbModal>
);

View File

@@ -40,7 +40,7 @@ const AddChatVariable = forwardRef<AddChatVariableRef, AddChatVariableProps>(({
}
const handleSave = (value: ChatVariable, index?: number) => {
const list = [...variables]
if (index && index > -1) {
if (typeof index === 'number' && index > -1) {
list[index] = value
} else {
list.push(value)
@@ -75,17 +75,15 @@ const AddChatVariable = forwardRef<AddChatVariableRef, AddChatVariableProps>(({
dataSource={variables}
renderItem={(item, index) => (
<List.Item>
<div key={index} className="rb:group rb:relative rb:p-[12px_16px] rb:bg-[#FBFDFF] rb:cursor-pointer rb:border rb:border-[#DFE4ED] rb:rounded-lg">
<div key={index} className="rb:relative rb:p-[12px_16px] rb:bg-[#FBFDFF] rb:cursor-pointer rb:border rb:border-[#DFE4ED] rb:rounded-lg">
<div className="rb:flex rb:items-center rb:justify-between">
<div className="rb:leading-4">
<span className="rb:font-medium">{item.name}</span>
<span className="rb:text-[12px] rb:text-[#5B6167] rb:font-regular"> ({t(`workflow.config.parameter-extractor.${item.type}`)})</span>
</div>
<span className="rb:block rb:group-hover:hidden rb:text-[12px] rb:text-[#5B6167] rb:font-regular">{item.required ? t('workflow.config.parameter-extractor.required') : ''}</span>
</div>
<div className="rb:mt-1 rb:text-[12px] rb:text-[#5B6167] rb:font-regular rb:leading-5 rb:wrap-break-word rb:line-clamp-1">{item.description}</div>
<Space size={12} className="rb:hidden! rb:group-hover:flex! rb:absolute rb:right-4 rb:top-[50%] rb:transform-[translateY(-50%)] rb:bg-white">
<Space size={12} className="rb:flex rb:absolute rb:right-4 rb:top-[50%] rb:transform-[translateY(-50%)] rb:bg-white">
<div
className="rb:size-5 rb:cursor-pointer rb:bg-cover rb:bg-[url('@/assets/images/editBorder.svg')] rb:hover:bg-[url('@/assets/images/editBg.svg')]"
onClick={() => handleEdit(index)}

View File

@@ -11,8 +11,8 @@ export interface VariableFormData {
name: string;
type: ChatVariable['type'];
description?: string;
required?: boolean;
defaultValue?: any;
defaultValue?: string;
default?: string;
}
export interface ChatVariableModalRef {

View File

@@ -114,6 +114,7 @@ const AssignmentList: FC<AssignmentListProps> = ({
? <InputNumber
placeholder={t('common.pleaseEnter')}
className="rb:w-full!"
onChange={(value) => form.setFieldValue([name, 'value'], value)}
/>
: operation === 'assign'
? <>

View File

@@ -348,8 +348,12 @@ const CaseList: FC<CaseListProps> = ({
popupMatchSelectWidth={false}
variant="borderless"
/>
: <InputNumber placeholder={t('common.pleaseEnter')}
variant="borderless" className="rb:w-full!" />
: <InputNumber
placeholder={t('common.pleaseEnter')}
variant="borderless"
className="rb:w-full!"
onChange={(value) => form.setFieldValue([name, caseIndex, 'expressions', conditionIndex, 'right'], value)}
/>
}
</Form.Item>
</Col>

View File

@@ -169,8 +169,12 @@ const ConditionList: FC<CaseListProps> = ({
variant="borderless"
className="rb:w-full!"
/>
: <InputNumber placeholder={t('common.pleaseEnter')}
variant="borderless" className="rb:w-full!" />
: <InputNumber
placeholder={t('common.pleaseEnter')}
variant="borderless"
className="rb:w-full!"
onChange={(value) => form.setFieldValue([parentName, 'expressions', index, 'right'], value)}
/>
}
</Form.Item>
</Col>

View File

@@ -194,19 +194,31 @@ const HttpRequest: FC<{ options: Suggestion[]; selectedNode?: any; graphRef?: an
name={['timeouts', 'connect_timeout']}
label={t('workflow.config.http-request.connect_timeout')}
>
<InputNumber placeholder={t('common.pleaseEnter')} className="rb:w-full!" />
<InputNumber
placeholder={t('common.pleaseEnter')}
className="rb:w-full!"
onChange={(value) => form.setFieldValue(['timeouts', 'connect_timeout'], value)}
/>
</Form.Item>
<Form.Item
name={['timeouts', 'read_timeout']}
label={t('workflow.config.http-request.read_timeout')}
>
<InputNumber placeholder={t('common.pleaseEnter')} className="rb:w-full!" />
<InputNumber
placeholder={t('common.pleaseEnter')}
className="rb:w-full!"
onChange={(value) => form.setFieldValue(['timeouts', 'read_timeout'], value)}
/>
</Form.Item>
<Form.Item
name={['timeouts', 'write_timeout']}
label={t('workflow.config.http-request.write_timeout')}
>
<InputNumber placeholder={t('common.pleaseEnter')} className="rb:w-full!" />
<InputNumber
placeholder={t('common.pleaseEnter')}
className="rb:w-full!"
onChange={(value) => form.setFieldValue(['timeouts', 'write_timeout'], value)}
/>
</Form.Item>
<Divider />
@@ -219,13 +231,21 @@ const HttpRequest: FC<{ options: Suggestion[]; selectedNode?: any; graphRef?: an
name={['retry', 'max_attempts']}
label={t('workflow.config.http-request.max_attempts')}
>
<InputNumber placeholder={t('common.pleaseEnter')} className="rb:w-full!" />
<InputNumber
placeholder={t('common.pleaseEnter')}
className="rb:w-full!"
onChange={(value) => form.setFieldValue(['retry', 'max_attempts'], value)}
/>
</Form.Item>
<Form.Item
name={['retry', 'retry_interval']}
label={<>{t('workflow.config.http-request.retry_interval')} <span className="rb:text-[#5B6167]">(ms)</span></>}
>
<InputNumber placeholder={t('common.pleaseEnter')} className="rb:w-full!" />
<InputNumber
placeholder={t('common.pleaseEnter')}
className="rb:w-full!"
onChange={(value) => form.setFieldValue(['retry', 'retry_interval'], value)}
/>
</Form.Item>
</>
}
@@ -254,7 +274,11 @@ const HttpRequest: FC<{ options: Suggestion[]; selectedNode?: any; graphRef?: an
name={['error_handle', 'status_code']}
label={<>status_code <span className="rb:text-[#5B6167] rb:ml-1">number</span></>}
>
<InputNumber placeholder={t('common.pleaseEnter')} className="rb:w-full!" />
<InputNumber
placeholder={t('common.pleaseEnter')}
className="rb:w-full!"
onChange={(value) => form.setFieldValue(['error_handle', 'status_code'], value)}
/>
</Form.Item>
<Form.Item
name={['error_handle', 'headers']}

View File

@@ -117,7 +117,12 @@ const KnowledgeConfigModal = forwardRef<KnowledgeConfigModalRef, KnowledgeConfig
extra={t('application.top_k_desc')}
initialValue={5}
>
<InputNumber style={{ width: '100%' }} min={1} max={20} />
<InputNumber
style={{ width: '100%' }}
min={1}
max={20}
onChange={(value) => form.setFieldValue('top_k', value)}
/>
</FormItem>
{/* 语义相似度阈值 similarity_threshold */}
{values?.retrieve_type === 'semantic' && (

View File

@@ -110,7 +110,12 @@ const KnowledgeGlobalConfigModal = forwardRef<KnowledgeGlobalConfigModalRef, Kno
rules={[{ required: true, message: t('common.pleaseEnter') }]}
extra={t('application.reranker_top_k_desc')}
>
<InputNumber style={{ width: '100%' }} min={1} max={20} />
<InputNumber
style={{ width: '100%' }}
min={1}
max={20}
onChange={(value) => form.setFieldValue('reranker_top_k', value)}
/>
</FormItem>
</>}
</Form>

View File

@@ -197,7 +197,14 @@ const ToolConfig: FC<{ options: Suggestion[]; }> = ({
: parameter.type === 'boolean'
? <Switch />
: parameter.type === 'integer' || parameter.type === 'number'
? <InputNumber min={parameter.minimum} max={parameter.maximum} step={parameter.type === 'integer' ? 1 : 0.01} placeholder={t('common.pleaseEnter')} className="rb:w-full!" />
? <InputNumber
min={parameter.minimum}
max={parameter.maximum}
step={parameter.type === 'integer' ? 1 : 0.01}
placeholder={t('common.pleaseEnter')}
className="rb:w-full!"
onChange={(value) => form.setFieldValue(['tool_parameters', parameter.name], value)}
/>
: <Editor
height={32}
variant="outlined"

View File

@@ -141,7 +141,11 @@ const VariableEditModal = forwardRef<VariableEditModalRef, VariableEditModalProp
name="max_length"
label={t('workflow.config.start.max_length')}
>
<InputNumber placeholder={t('common.enter')} style={{ width: '100%' }} />
<InputNumber
placeholder={t('common.enter')}
style={{ width: '100%' }}
onChange={(value) => form.setFieldValue('max_length', value)}
/>
</FormItem>
)}
{/* 默认值 */}
@@ -151,7 +155,13 @@ const VariableEditModal = forwardRef<VariableEditModalRef, VariableEditModalProp
label={t('workflow.config.start.default')}
>
{['string'].includes(values.type) && <Input placeholder={t('common.enter')} />}
{['number'].includes(values.type) && <InputNumber placeholder={t('common.enter')} style={{ width: '100%' }} />}
{['number'].includes(values.type) && (
<InputNumber
placeholder={t('common.enter')}
style={{ width: '100%' }}
onChange={(value) => form.setFieldValue('default', value)}
/>
)}
{['boolean'].includes(values.type) && <Select placeholder={t('common.pleaseSelect')} options={[{ value: true, label: t('workflow.config.start.defaultChecked') }, { value: false, label: t('workflow.config.start.notDefaultChecked') }]} />}
</FormItem>
)}

View File

@@ -72,7 +72,10 @@ const VariableSelect: FC<VariableSelectProps> = ({
const groupedOptions = Object.entries(groupedSuggestions).map(([_nodeId, suggestions]) => ({
label: suggestions[0].nodeData.name,
options: suggestions.map(s => ({ label: s.label, value: `{{${s.value}}}` }))
options: suggestions.map(s => ({
label: <div className="rb:flex rb:items-center rb:gap-1 rb:justify-between"> { s.label } <span>{s.dataType}</span></div>,
value: `{{${s.value}}}`
}))
}));
return (

View File

@@ -36,7 +36,7 @@ interface PropertiesProps {
const Properties: FC<PropertiesProps> = ({
selectedNode,
graphRef,
config,
config: workflowConfig,
}) => {
const { t } = useTranslation()
const { modal } = App.useApp()
@@ -47,7 +47,7 @@ const Properties: FC<PropertiesProps> = ({
const [editIndex, setEditIndex] = useState<number | null>(null)
const prevMappingNamesRef = useRef<string[]>([])
const prevTemplateVarsRef = useRef<string[]>([])
const syncTimeoutRef = useRef<NodeJS.Timeout | null>(null)
const syncTimeoutRef = useRef<number | null>(null)
const isSyncingRef = useRef(false)
const lastSyncSourceRef = useRef<'mapping' | 'template' | null>(null)
@@ -64,7 +64,7 @@ const Properties: FC<PropertiesProps> = ({
useEffect(() => {
if (isSyncingRef.current || lastSyncSourceRef.current === 'mapping' || selectedNode?.data?.type !== 'jinja-render' || !values?.mapping || !values?.template) return
const currentMappingNames = values.mapping.map((item: any) => item.name).filter(Boolean)
const currentMappingNames = Array.isArray(values.mapping) ? values.mapping.map((item: any) => item.name).filter(Boolean) : []
const prevNames = prevMappingNamesRef.current
if (prevNames.length === 0) {
@@ -121,7 +121,7 @@ const Properties: FC<PropertiesProps> = ({
return
}
const updatedMapping = [...values.mapping]
const updatedMapping = Array.isArray(values.mapping) ? [...values.mapping] : []
const existingNames = updatedMapping.map(item => item.name)
let updatedTemplate = String(values.template)
@@ -343,11 +343,12 @@ const Properties: FC<PropertiesProps> = ({
// Add parent loop/iteration node variables if current node is a child
if (parentLoopNode) {
const parentData = parentLoopNode.getData();
const parentNodeId = parentLoopNode.getData().id;
if (parentData.type === 'loop') {
const cycleVars = parentData.cycle_vars || [];
cycleVars.forEach((cycleVar: any) => {
const key = `${parentLoopNode.getData().id}_cycle_${cycleVar.name}`;
const key = `${parentNodeId}_cycle_${cycleVar.name}`;
if (!addedKeys.has(key)) {
addedKeys.add(key);
variableList.push({
@@ -355,15 +356,15 @@ const Properties: FC<PropertiesProps> = ({
label: cycleVar.name,
type: 'variable',
dataType: cycleVar.type || 'String',
value: `${parentLoopNode.getData().id}.${cycleVar.name}`,
value: `${parentNodeId}.${cycleVar.name}`,
nodeData: parentData,
});
}
});
} else if (parentData.type === 'iteration') {
// Add item and index variables for iteration parent
const itemKey = `${parentLoopNode.getData().id}_item`;
const indexKey = `${parentLoopNode.getData().id}_index`;
const itemKey = `${parentNodeId}_item`;
const indexKey = `${parentNodeId}_index`;
if (!addedKeys.has(itemKey)) {
addedKeys.add(itemKey);
@@ -372,7 +373,7 @@ const Properties: FC<PropertiesProps> = ({
label: 'item',
type: 'variable',
dataType: 'Object',
value: `${parentLoopNode.getData().id}.item`,
value: `${parentNodeId}.item`,
nodeData: parentData,
});
}
@@ -384,7 +385,7 @@ const Properties: FC<PropertiesProps> = ({
label: 'index',
type: 'variable',
dataType: 'Number',
value: `${parentLoopNode.getData().id}.index`,
value: `${parentNodeId}.index`,
nodeData: parentData,
});
}
@@ -400,6 +401,7 @@ const Properties: FC<PropertiesProps> = ({
if (!node) return;
const nodeData = node.getData();
const dataNodeId = nodeData.id; // Use the data.id instead of node.id for consistency
switch(nodeData.type) {
case 'start':
@@ -409,7 +411,7 @@ const Properties: FC<PropertiesProps> = ({
]
list.forEach((variable: any) => {
if (!variable || !variable?.name) return;
const key = `${nodeId}_${variable.name}`;
const key = `${dataNodeId}_${variable.name}`;
if (!addedKeys.has(key)) {
addedKeys.add(key);
variableList.push({
@@ -417,14 +419,14 @@ const Properties: FC<PropertiesProps> = ({
label: variable.name,
type: 'variable',
dataType: variable.type,
value: `${node.getData().id}.${variable.name}`,
value: `${dataNodeId}.${variable.name}`,
nodeData: nodeData,
});
}
});
nodeData.config?.variables?.sys?.forEach((variable: any) => {
if (!variable || !variable?.name) return;
const key = `${nodeId}_sys_${variable.name}`;
const key = `${dataNodeId}_sys_${variable.name}`;
if (!addedKeys.has(key)) {
addedKeys.add(key);
variableList.push({
@@ -439,7 +441,7 @@ const Properties: FC<PropertiesProps> = ({
});
break
case 'llm':
const llmKey = `${nodeId}_output`;
const llmKey = `${dataNodeId}_output`;
if (!addedKeys.has(llmKey)) {
addedKeys.add(llmKey);
variableList.push({
@@ -447,13 +449,13 @@ const Properties: FC<PropertiesProps> = ({
label: 'output',
type: 'variable',
dataType: 'String',
value: `${node.getData().id}.output`,
value: `${dataNodeId}.output`,
nodeData: nodeData,
});
}
break
case 'knowledge-retrieval':
const knowledgeKey = `${nodeId}_message`;
const knowledgeKey = `${dataNodeId}_message`;
if (!addedKeys.has(knowledgeKey)) {
addedKeys.add(knowledgeKey);
variableList.push({
@@ -461,14 +463,14 @@ const Properties: FC<PropertiesProps> = ({
label: 'message',
type: 'variable',
dataType: 'array[object]',
value: `${node.getData().id}.message`,
value: `${dataNodeId}.message`,
nodeData: nodeData,
});
}
break
case 'parameter-extractor':
const successKey = `${nodeId}___is_success`;
const reasonKey = `${nodeId}___reason`;
const successKey = `${dataNodeId}___is_success`;
const reasonKey = `${dataNodeId}___reason`;
if (!addedKeys.has(successKey)) {
addedKeys.add(successKey);
variableList.push({
@@ -476,7 +478,7 @@ const Properties: FC<PropertiesProps> = ({
label: '__is_success',
type: 'variable',
dataType: 'number',
value: `${node.getData().id}.__is_success`,
value: `${dataNodeId}.__is_success`,
nodeData: nodeData,
});
}
@@ -487,7 +489,7 @@ const Properties: FC<PropertiesProps> = ({
label: '__reason',
type: 'variable',
dataType: 'string',
value: `${node.getData().id}.__reason`,
value: `${dataNodeId}.__reason`,
nodeData: nodeData,
});
}
@@ -495,7 +497,7 @@ const Properties: FC<PropertiesProps> = ({
const paramsList = nodeData.config?.params?.defaultValue || [];
paramsList.forEach((param: any) => {
if (!param || !param?.name) return;
const paramKey = `${nodeId}_${param.name}`;
const paramKey = `${dataNodeId}_${param.name}`;
if (!addedKeys.has(paramKey)) {
addedKeys.add(paramKey);
variableList.push({
@@ -503,29 +505,50 @@ const Properties: FC<PropertiesProps> = ({
label: param.name,
type: 'variable',
dataType: param.type || 'string',
value: `${node.getData().id}.${param.name}`,
value: `${dataNodeId}.${param.name}`,
nodeData: nodeData,
});
}
});
break
case 'var-aggregator':
const varAggregatorKey = `${nodeId}_output`;
if (!addedKeys.has(varAggregatorKey)) {
addedKeys.add(varAggregatorKey);
variableList.push({
key: varAggregatorKey,
label: 'output',
type: 'variable',
dataType: 'string',
value: `${node.getData().id}.output`,
nodeData: nodeData,
if (nodeData.config.group.defaultValue) {
// If group=true, add variables from group_variables with key as variable name
const groupVariables = nodeData.config.group_variables.defaultValue || [];
groupVariables?.forEach((groupVar: any) => {
if (!groupVar || !groupVar.key) return;
const groupVarKey = `${dataNodeId}_${groupVar.key}`;
if (!addedKeys.has(groupVarKey)) {
addedKeys.add(groupVarKey);
variableList.push({
key: groupVarKey,
label: groupVar.key,
type: 'variable',
dataType: 'string',
value: `${dataNodeId}.${groupVar.key}`,
nodeData: nodeData,
});
}
});
} else {
// If group=false, add output variable
const varAggregatorKey = `${dataNodeId}_output`;
if (!addedKeys.has(varAggregatorKey)) {
addedKeys.add(varAggregatorKey);
variableList.push({
key: varAggregatorKey,
label: 'output',
type: 'variable',
dataType: 'string',
value: `${dataNodeId}.output`,
nodeData: nodeData,
});
}
}
break
case 'http-request':
const httpBodyKey = `${nodeId}_body`;
const httpStatusKey = `${nodeId}_status_code`;
const httpBodyKey = `${dataNodeId}_body`;
const httpStatusKey = `${dataNodeId}_status_code`;
if (!addedKeys.has(httpBodyKey)) {
addedKeys.add(httpBodyKey);
variableList.push({
@@ -533,7 +556,7 @@ const Properties: FC<PropertiesProps> = ({
label: 'body',
type: 'variable',
dataType: 'string',
value: `${node.getData().id}.body`,
value: `${dataNodeId}.body`,
nodeData: nodeData,
});
}
@@ -544,13 +567,13 @@ const Properties: FC<PropertiesProps> = ({
label: 'status_code',
type: 'variable',
dataType: 'number',
value: `${node.getData().id}.status_code`,
value: `${dataNodeId}.status_code`,
nodeData: nodeData,
});
}
break
case 'jinja-render':
const jinjaOutputKey = `${nodeId}_output`;
const jinjaOutputKey = `${dataNodeId}_output`;
if (!addedKeys.has(jinjaOutputKey)) {
addedKeys.add(jinjaOutputKey);
variableList.push({
@@ -558,14 +581,14 @@ const Properties: FC<PropertiesProps> = ({
label: 'output',
type: 'variable',
dataType: 'string',
value: `${node.getData().id}.output`,
value: `${dataNodeId}.output`,
nodeData: nodeData,
});
}
break
case 'question-classifier':
const classNameKey = `${nodeId}_class_name`;
const outputKey = `${nodeId}_output`;
const classNameKey = `${dataNodeId}_class_name`;
const outputKey = `${dataNodeId}_output`;
if (!addedKeys.has(classNameKey)) {
addedKeys.add(classNameKey);
variableList.push({
@@ -573,7 +596,7 @@ const Properties: FC<PropertiesProps> = ({
label: 'class_name',
type: 'variable',
dataType: 'string',
value: `${node.getData().id}.class_name`,
value: `${dataNodeId}.class_name`,
nodeData: nodeData,
});
}
@@ -584,13 +607,15 @@ const Properties: FC<PropertiesProps> = ({
label: 'output',
type: 'variable',
dataType: 'string',
value: `${node.getData().id}.output`,
value: `${dataNodeId}.output`,
nodeData: nodeData,
});
}
break
case 'iteration':
const iterationOutputKey = `${nodeId}_output`;
console.log('iteration addedKeys', addedKeys)
const iterationOutputKey = `${dataNodeId}_output`;
const iterationItemKey = `${dataNodeId}_item`;
if (!addedKeys.has(iterationOutputKey)) {
addedKeys.add(iterationOutputKey);
// Get the data type from the output configuration, default to string
@@ -608,15 +633,26 @@ const Properties: FC<PropertiesProps> = ({
label: 'output',
type: 'variable',
dataType: outputDataType,
value: `${node.getData().id}.output`,
value: `${dataNodeId}.output`,
nodeData: nodeData,
});
}
if (!addedKeys.has(iterationItemKey)) {
addedKeys.add(iterationItemKey);
variableList.push({
key: iterationItemKey,
label: 'item',
type: 'variable',
dataType: 'string',
value: `${dataNodeId}.item`,
nodeData: nodeData,
});
}
break
case 'loop':
const cycleVars = nodeData.cycle_vars || [];
const cycleVars = nodeData.config.cycle_vars.defaultValue || [];
cycleVars.forEach((cycleVar: any) => {
const cycleVarKey = `${nodeId}_cycle_${cycleVar.name}`;
const cycleVarKey = `${dataNodeId}_cycle_${cycleVar.name}`;
if (!addedKeys.has(cycleVarKey)) {
addedKeys.add(cycleVarKey);
variableList.push({
@@ -624,14 +660,14 @@ const Properties: FC<PropertiesProps> = ({
label: cycleVar.name,
type: 'variable',
dataType: cycleVar.type || 'string',
value: `${node.getData().id}.${cycleVar.name}`,
value: `${dataNodeId}.${cycleVar.name}`,
nodeData: nodeData,
});
}
});
break
case 'tool':
const toolDataKey = `${nodeId}_data`;
const toolDataKey = `${dataNodeId}_data`;
if (!addedKeys.has(toolDataKey)) {
addedKeys.add(toolDataKey);
variableList.push({
@@ -639,7 +675,7 @@ const Properties: FC<PropertiesProps> = ({
label: 'data',
type: 'variable',
dataType: 'object',
value: `${node.getData().id}.data`,
value: `${dataNodeId}.data`,
nodeData: nodeData,
});
}
@@ -648,7 +684,7 @@ const Properties: FC<PropertiesProps> = ({
});
// Add conversation variables from global config
const conversationVariables = config?.variables || [];
const conversationVariables = workflowConfig?.variables || [];
conversationVariables.forEach((variable: any) => {
const key = `CONVERSATION_${variable.name}`;
@@ -667,7 +703,7 @@ const Properties: FC<PropertiesProps> = ({
});
return variableList;
}, [selectedNode, graphRef]);
}, [selectedNode, graphRef, workflowConfig?.variables]);
// Filter out boolean type variables for loop and llm nodes
const getFilteredVariableList = (nodeType?: string) => {
@@ -885,67 +921,7 @@ const Properties: FC<PropertiesProps> = ({
parentName={key}
options={(() => {
if (config.filterLoopIterationVars) {
// Add loop cycle variables and iteration item/index variables
const loopIterationVars: Suggestion[] = [];
const graph = graphRef.current;
if (graph && selectedNode) {
const nodes = graph.getNodes();
// Find parent loop/iteration nodes
const findParentLoopIteration = (nodeId: string): string[] => {
const node = nodes.find(n => n.id === nodeId);
if (!node) return [];
const nodeData = node.getData();
const cycle = nodeData?.cycle;
if (cycle) {
const parentNode = nodes.find(n => n.getData().id === cycle);
if (parentNode) {
const parentData = parentNode.getData();
if (parentData?.type === 'loop') {
console.log('parentData', parentData)
// Add cycle variables from loop node
const cycleVars = parentData.cycle_vars || [];
cycleVars.forEach((cycleVar: any) => {
loopIterationVars.push({
key: `${cycle}_cycle_${cycleVar.name}`,
label: cycleVar.name,
type: 'variable',
dataType: 'String',
value: `${cycle}.${cycleVar.name}`,
nodeData: parentData,
});
});
} else if (parentData?.type === 'iteration') {
// Add item and index variables from iteration node
loopIterationVars.push(
{
key: `${cycle}_item`,
label: 'item',
type: 'variable',
dataType: 'Object',
value: `${cycle}.item`,
nodeData: parentData,
},
{
key: `${cycle}_index`,
label: 'index',
type: 'variable',
dataType: 'Number',
value: `${cycle}.index`,
nodeData: parentData,
}
);
}
return [cycle, ...findParentLoopIteration(cycle)];
}
}
return [];
};
findParentLoopIteration(selectedNode.id);
}
return [...getFilteredVariableList(selectedNode?.data?.type), ...loopIterationVars];
}
@@ -974,7 +950,11 @@ const Properties: FC<PropertiesProps> = ({
placeholder={t('common.pleaseSelect')}
/>
: config.type === 'inputNumber'
? <InputNumber />
? <InputNumber
placeholder={t('common.pleaseEnter')}
className="rb:w-full!"
onChange={(value) => form.setFieldValue(key, value)}
/>
: config.type === 'slider'
? <Slider min={config.min} max={config.max} step={config.step} />
: config.type === 'customSelect'
@@ -1041,9 +1021,28 @@ const Properties: FC<PropertiesProps> = ({
value: `${selectedNode.getData().id}.${cycleVar.name}`,
nodeData: selectedNode.getData(),
}));
return [...getFilteredVariableList(selectedNode?.data?.type), ...cycleVarSuggestions];
return [...getFilteredVariableList(selectedNode?.data?.type).filter(variable => {
// Keep conversation variables
if (variable.group === 'CONVERSATION') return true;
// Keep sys variables from start nodes
if (variable.nodeData?.type === 'start' && variable.value?.startsWith('sys.')) return true;
// Keep variables from non-start nodes
if (variable.nodeData?.type !== 'start') return true;
// Filter out custom variables from start nodes
return false;
}), ...cycleVarSuggestions];
}
return getFilteredVariableList(selectedNode?.data?.type);
// Filter options for condition list: only sys variables from start nodes and conversation variables
return getFilteredVariableList(selectedNode?.data?.type).filter(variable => {
// Keep conversation variables
if (variable.group === 'CONVERSATION') return true;
// Keep sys variables from start nodes
if (variable.nodeData?.type === 'start' && variable.value?.startsWith('sys.')) return true;
// Keep variables from non-start nodes
if (variable.nodeData?.type !== 'start') return true;
// Filter out custom variables from start nodes
return false;
});
})()
}
selectedNode={selectedNode}

View File

@@ -63,7 +63,17 @@ export const useWorkflowGraph = ({
if (!id) return
getWorkflowConfig(id)
.then(res => {
setConfig(res as WorkflowConfig)
const { variables, ...rest } = res as WorkflowConfig
setConfig({
...rest,
variables: variables.map(v => {
const { default: _, ...cleanV } = v
return {
...cleanV,
defaultValue: v.default ?? ''
}
})
})
})
}
@@ -332,6 +342,7 @@ export const useWorkflowGraph = ({
},
},
},
zIndex: 0
}
return edgeConfig
@@ -906,6 +917,13 @@ export const useWorkflowGraph = ({
const params = {
...config,
variables: config.variables.map(v => {
const { defaultValue, ...cleanV } = v
return {
...cleanV,
default: defaultValue ?? ''
}
}),
nodes: nodes.map((node: Node) => {
const data = node.getData();
const position = node.getPosition();

View File

@@ -74,7 +74,8 @@ export interface WorkflowConfig {
type: string;
required: boolean;
description: string;
default: string;
default?: string;
defaultValue: string;
}>,
execution_config: {
max_execution_time: number;
@@ -114,7 +115,8 @@ export interface ChatVariable {
type: string;
required: boolean;
description: string;
default: string;
default?: string;
defaultValue: string;
}
export interface AddChatVariableRef {
handleOpen: (value?: ChatVariable) => void;