|
|
@@ -4,6 +4,7 @@ import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.TimeoutException;
|
|
|
|
|
|
import com.agentsflex.core.chain.Chain;
|
|
|
import com.agentsflex.core.chain.ChainEvent;
|
|
|
@@ -11,6 +12,7 @@ import com.agentsflex.core.chain.ChainNode;
|
|
|
import com.agentsflex.core.chain.event.NodeEndEvent;
|
|
|
import com.agentsflex.core.chain.event.NodeStartEvent;
|
|
|
import com.agentsflex.core.chain.listener.ChainEventListener;
|
|
|
+import com.agentsflex.core.chain.listener.NodeErrorListener;
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
import com.ruoyi.common.utils.JsonUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
@@ -19,6 +21,7 @@ import com.ruoyi.interfaces.domain.vo.MdAppFlowVo;
|
|
|
import com.ruoyi.interfaces.tinyflow.TinyflowUtil;
|
|
|
import com.ruoyi.interfaces.tinyflow.parser.PrintNodeParser;
|
|
|
import dev.tinyflow.core.Tinyflow;
|
|
|
+import dev.tinyflow.core.node.HttpNode;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.ruoyi.interfaces.mapper.MdAppFlowMapper;
|
|
|
@@ -122,6 +125,7 @@ public class MdAppFlowServiceImpl implements IMdAppFlowService {
|
|
|
chain.addEventListener(new ChainEventListener() {
|
|
|
@Override
|
|
|
public void onEvent(ChainEvent event, Chain chain) {
|
|
|
+
|
|
|
if (event instanceof NodeStartEvent) {
|
|
|
if (StringUtils.isNotNull(session)) {
|
|
|
NodeStartEvent nodeEndEvent = (NodeStartEvent) event;
|
|
|
@@ -149,6 +153,42 @@ public class MdAppFlowServiceImpl implements IMdAppFlowService {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ chain.addNodeErrorListener(new NodeErrorListener(){
|
|
|
+ @Override
|
|
|
+ public void onError(Throwable error, ChainNode node, Map<String, Object> nodeResult, Chain chain) {
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.isNotNull(session)) {
|
|
|
+ HashMap<String, Object> nodeMap = new HashMap<>();
|
|
|
+ nodeMap.put("id", node.getId());
|
|
|
+ nodeMap.put("name", node.getName());
|
|
|
+ nodeMap.put("nodeState", "ERROR");
|
|
|
+ nodeMap.put("timestamp", System.currentTimeMillis());
|
|
|
+ // 根据错误类型分类处理
|
|
|
+ if (error instanceof TimeoutException) {
|
|
|
+ nodeMap.put("errorType", "TIMEOUT");
|
|
|
+ nodeMap.put("errorMessage", "节点执行超时");
|
|
|
+ nodeMap.put("suggestion", "请检查网络连接或增加超时时间");
|
|
|
+ } else if (error instanceof IllegalArgumentException) {
|
|
|
+ nodeMap.put("errorType", "INVALID_PARAMETER");
|
|
|
+ nodeMap.put("errorMessage", "参数错误: " + error.getMessage());
|
|
|
+ nodeMap.put("suggestion", "请检查输入参数格式");
|
|
|
+ } else if (error instanceof NullPointerException) {
|
|
|
+ nodeMap.put("errorType", "NULL_POINTER");
|
|
|
+ nodeMap.put("errorMessage", "空指针异常");
|
|
|
+ nodeMap.put("suggestion", "请检查数据完整性");
|
|
|
+ } else {
|
|
|
+ nodeMap.put("errorType", "UNKNOWN_ERROR");
|
|
|
+ nodeMap.put("errorMessage", error.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ WebSocketUsers.sendMessageToUserByText(session, JsonUtils.objectToJson(nodeMap));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
return chain.executeForResult(appFlow.getParams());
|
|
|
}
|
|
|
}
|