Skip to content
Open
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
6 changes: 6 additions & 0 deletions framework/elsa/fit-elsa-react/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ function App({i18n}) {
testCodeUrl: '',
},
});
configs.push({
node: 'replyNodeState', urls: {
testCodeUrl: '',
},
});
configs.push({
node: 'evaluationAlgorithmsNodeState', urls: {
evaluationAlgorithmsUrl: '',
Expand Down Expand Up @@ -282,6 +287,7 @@ function App({i18n}) {
<Button onClick={() => window.agent.createNodeByPosition('queryOptimizationNodeState', {x:100, y:100}, {uniqueName : ''})}>创建问题优化节点</Button>
<Button onClick={() => window.agent.createNodeByPosition('codeNodeState', {x:100, y:100}, {uniqueName : ''})}>创建code节点</Button>
<Button onClick={() => window.agent.createNodeByPosition('textConcatenateNodeState', {x:100, y:100}, {uniqueName : ''})}>创建文本拼接节点</Button>
<Button onClick={() => window.agent.createNodeByPosition('replyNodeState', {x:100, y:100}, {uniqueName : ''})}>创建直接回复节点</Button>
<Button onClick={() => {
const nodeTypes = ['endNodeEnd',
'retrievalNodeState',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React from 'react';
import PropTypes from 'prop-types';
import {JadeInputForm} from '../common/JadeInputForm.jsx';
import {useDispatch, useShapeContext} from '@/components/DefaultRoot.jsx';
import {TemplatePanel} from "@/components/common/TemplatePanel.jsx";
import {Trans, useTranslation} from "react-i18next";

ReplyWrapper.propTypes = {
data: PropTypes.object.isRequired,
shapeStatus: PropTypes.object,
};

export default function ReplyWrapper({data, shapeStatus}) {
const dispatch = useDispatch();
const shape = useShapeContext();
const {t} = useTranslation();
const template = data.inputParams.find(item => item.name === 'template');

/**
* 初始化数据
*
* @return {*}
*/
const initItems = () => {
return data.inputParams.find(item => item.name === "variables").value
};

/**
* 添加输入的变量
*
* @param id id 数据id
*/
const addItem = (id) => {
// 代码节点入参最大数量为20
if (data.inputParams.find(item => item.name === 'variables').value.length < 20) {
dispatch({type: 'addInputParam', id: id});
}
};

/**
* 更新入参变量属性名或者类型
*
* @param id 数据id
* @param value 新值
*/
const updateItem = (id, value) => {
dispatch({type: 'editInputParam', id: id, newValue: value});
};

/**
* 删除input
*
* @param id 需要删除的数据id
*/
const deleteItem = (id) => {
dispatch({type: 'deleteInputParam', id: id});
};

return (
<div>
<JadeInputForm
shapeStatus={shapeStatus}
items={initItems()}
addItem={addItem}
updateItem={updateItem}
deleteItem={deleteItem}
content={
(<div className={'jade-font-size'} style={{lineHeight: '1.2'}}>
<Trans i18nKey='templateInputPopover' components={{p: <p/>}}/>
</div>)}
maxInputLength={1000}
/>
<TemplatePanel
disabled={shapeStatus.disabled}
template={template}
title={t("replyTextLabel")}
placeHolder={t("promptPlaceHolder")}
name={"reply"}
onChange={(templateText) => {
dispatch({type: 'changeTemplate', id: template.id, value: templateText});
}}
labelName={t("replyTextLabel")}
/>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
* This file is a part of the ModelEngine Project.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

/**
* changeTemplate 事件处理器.
*
* @return {{}} 处理器对象.
* @constructor
*/
export const ChangeTemplateReducer = () => {
const self = {};
self.type = 'changeTemplate';

/**
* 处理方法.
*
* @param config 配置数据.
* @param action 事件对象.
* @return {*} 处理之后的数据.
*/
self.reduce = (config, action) => {
const newConfig = {};
Object.entries(config).forEach(([key, value]) => {
if (key === 'inputParams') {
newConfig[key] = value.map(item => {
if (item.id === action.id) {
return {
...item, value: action.value,
};
} else {
return item;
}
});
} else {
newConfig[key] = value;
}
});
return newConfig;
};

return self;
};

/**
* addInputParam 事件处理器.
*
* @return {{}} 处理器对象.
* @constructor
*/
export const AddInputParamReducer = () => {
const self = {};
self.type = 'addInputParam';

/**
* 处理方法.
*
* @param config 配置数据.
* @param action 事件对象.
* @return {*} 处理之后的数据.
*/
self.reduce = (config, action) => {
const newConfig = {};
Object.entries(config).forEach(([key, value]) => {
if (key === 'inputParams') {
newConfig[key] = value.map(item => {
if (item.name === 'variables') {
return {
...item,
value: [
...item.value,
{
id: action.id,
name: undefined,
type: 'String',
from: 'Reference',
value: '',
referenceNode: '',
referenceId: '',
referenceKey: '',
}
]
};
} else {
return item;
}
});
} else {
newConfig[key] = value;
}
});
return newConfig;
};


return self;
};

/**
* deleteInputParam 事件处理器.
*
* @return {{}} 处理器对象.
* @constructor
*/
export const DeleteInputParamReducer = () => {
const self = {};
self.type = 'deleteInputParam';

/**
* 处理方法.
*
* @param config 配置数据.
* @param action 事件对象.
* @return {*} 处理之后的数据.
*/
self.reduce = (config, action) => {
const newConfig = {};
Object.entries(config).forEach(([key, value]) => {
if (key === 'inputParams') {
newConfig[key] = value.map(item => {
if (item.name === 'variables') {
return {
...item,
value: item.value.filter((item) => item.id !== action.id),
};
} else {
return item;
}
});
} else {
newConfig[key] = value;
}
});
return newConfig;
};

return self;
};

/**
* deleteInputParam 事件处理器.
*
* @return {{}} 处理器对象.
* @constructor
*/
export const EditInputParamReducer = () => {
const self = {};
self.type = 'editInputParam';

/**
* 处理方法.
*
* @param config 配置数据.
* @param action 事件对象.
* @return {*} 处理之后的数据.
*/
self.reduce = (config, action) => {
const newConfig = {};
Object.entries(config).forEach(([key, value]) => {
if (key === 'inputParams') {
newConfig[key] = value.map(item => {
if (item.name === 'variables') {
return {
...item,
value: item.value.map(inputItem => {
if (inputItem.id === action.id) {
let updatedInputItem = {...inputItem};
action.newValue.map((param) => {
updatedInputItem[param.key] = param.value;
});
return updatedInputItem;
} else {
return inputItem;
}
}),
};
} else {
return item;
}
});
} else {
newConfig[key] = value;
}
});
return newConfig;
};

return self;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
* This file is a part of the ModelEngine Project.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import ReplyWrapper from './ReplyWrapper.jsx';
import {v4 as uuidv4} from 'uuid';
import {defaultComponent} from '@/components/defaultComponent.js';
import {
AddInputParamReducer,
ChangeTemplateReducer,
DeleteInputParamReducer,
EditInputParamReducer
} from "@/components/replyNode/reducers/reducer.js";

/**
* 直接回复节点组件
*
* @param jadeConfig
* @param shape 图形对象.
*/
export const replyNodeComponent = (jadeConfig, shape) => {
const self = defaultComponent(jadeConfig);
const addReducer = (map, reducer) => map.set(reducer.type, reducer);
const builtInReducers = new Map();
addReducer(builtInReducers, AddInputParamReducer());
addReducer(builtInReducers, EditInputParamReducer());
addReducer(builtInReducers, ChangeTemplateReducer());
addReducer(builtInReducers, DeleteInputParamReducer());

/**
* 必须.
*/
self.getJadeConfig = () => {
return jadeConfig ? jadeConfig : {
inputParams: [
{
id: uuidv4(), name: 'variables', type: 'Object', from: 'Expand', value: [
{
id: uuidv4(),
name: undefined,
type: 'String',
from: 'Reference',
value: '',
referenceNode: '',
referenceId: '',
referenceKey: '',
}
],
},
{
id: uuidv4(),
name: 'template',
type: 'String',
from: 'Input',
value: ''
},
],
outputParams: [],
tempReference: {},
};
};

/**
* 必须.
*
* @param shapeStatus 图形状态集合.
* @param data 数据.
*/
self.getReactComponents = (shapeStatus, data) => {
return (<><ReplyWrapper shapeStatus={shapeStatus} data={data}/></>);
};

/**
* 必须.
*/
const reducers = self.reducers;
self.reducers = (data, action) => {
const reducer = builtInReducers.get(action.type);
return reducer ? reducer.reduce(data, action) : reducers.apply(self, [data, action]);
};

return self;
};
Loading