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

View File

@@ -40,7 +40,7 @@ const AddChatVariable = forwardRef<AddChatVariableRef, AddChatVariableProps>(({
} }
const handleSave = (value: ChatVariable, index?: number) => { const handleSave = (value: ChatVariable, index?: number) => {
const list = [...variables] const list = [...variables]
if (index && index > -1) { if (typeof index === 'number' && index > -1) {
list[index] = value list[index] = value
} else { } else {
list.push(value) list.push(value)
@@ -75,17 +75,15 @@ const AddChatVariable = forwardRef<AddChatVariableRef, AddChatVariableProps>(({
dataSource={variables} dataSource={variables}
renderItem={(item, index) => ( renderItem={(item, index) => (
<List.Item> <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:flex rb:items-center rb:justify-between">
<div className="rb:leading-4"> <div className="rb:leading-4">
<span className="rb:font-medium">{item.name}</span> <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> <span className="rb:text-[12px] rb:text-[#5B6167] rb:font-regular"> ({t(`workflow.config.parameter-extractor.${item.type}`)})</span>
</div> </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>
<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> <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 <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')]" 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)} onClick={() => handleEdit(index)}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -117,7 +117,12 @@ const KnowledgeConfigModal = forwardRef<KnowledgeConfigModalRef, KnowledgeConfig
extra={t('application.top_k_desc')} extra={t('application.top_k_desc')}
initialValue={5} 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> </FormItem>
{/* 语义相似度阈值 similarity_threshold */} {/* 语义相似度阈值 similarity_threshold */}
{values?.retrieve_type === 'semantic' && ( {values?.retrieve_type === 'semantic' && (

View File

@@ -110,7 +110,12 @@ const KnowledgeGlobalConfigModal = forwardRef<KnowledgeGlobalConfigModalRef, Kno
rules={[{ required: true, message: t('common.pleaseEnter') }]} rules={[{ required: true, message: t('common.pleaseEnter') }]}
extra={t('application.reranker_top_k_desc')} 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> </FormItem>
</>} </>}
</Form> </Form>

View File

@@ -197,7 +197,14 @@ const ToolConfig: FC<{ options: Suggestion[]; }> = ({
: parameter.type === 'boolean' : parameter.type === 'boolean'
? <Switch /> ? <Switch />
: parameter.type === 'integer' || parameter.type === 'number' : 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 : <Editor
height={32} height={32}
variant="outlined" variant="outlined"

View File

@@ -141,7 +141,11 @@ const VariableEditModal = forwardRef<VariableEditModalRef, VariableEditModalProp
name="max_length" name="max_length"
label={t('workflow.config.start.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> </FormItem>
)} )}
{/* 默认值 */} {/* 默认值 */}
@@ -151,7 +155,13 @@ const VariableEditModal = forwardRef<VariableEditModalRef, VariableEditModalProp
label={t('workflow.config.start.default')} label={t('workflow.config.start.default')}
> >
{['string'].includes(values.type) && <Input placeholder={t('common.enter')} />} {['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') }]} />} {['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> </FormItem>
)} )}

View File

@@ -72,7 +72,10 @@ const VariableSelect: FC<VariableSelectProps> = ({
const groupedOptions = Object.entries(groupedSuggestions).map(([_nodeId, suggestions]) => ({ const groupedOptions = Object.entries(groupedSuggestions).map(([_nodeId, suggestions]) => ({
label: suggestions[0].nodeData.name, 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 ( return (

View File

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

View File

@@ -63,7 +63,17 @@ export const useWorkflowGraph = ({
if (!id) return if (!id) return
getWorkflowConfig(id) getWorkflowConfig(id)
.then(res => { .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 return edgeConfig
@@ -906,6 +917,13 @@ export const useWorkflowGraph = ({
const params = { const params = {
...config, ...config,
variables: config.variables.map(v => {
const { defaultValue, ...cleanV } = v
return {
...cleanV,
default: defaultValue ?? ''
}
}),
nodes: nodes.map((node: Node) => { nodes: nodes.map((node: Node) => {
const data = node.getData(); const data = node.getData();
const position = node.getPosition(); const position = node.getPosition();

View File

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