feat(workflow): 更新消息队列节点 (MqNode) 的配置,添加到错误处理节点类型列表
parent
12ab5efa42
commit
bd3f3e7b26
@ -0,0 +1,5 @@
|
|||||||
|
from .entities import MqNodeData
|
||||||
|
from .mq_node import MqNode
|
||||||
|
from .rabbitmq_client import RabbitMQClient
|
||||||
|
|
||||||
|
__all__ = ["MqNode", "MqNodeData", "RabbitMQClient"]
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
from core.workflow.nodes.base import BaseNodeData
|
||||||
|
|
||||||
|
|
||||||
|
class MqNodeData(BaseNodeData):
|
||||||
|
"""
|
||||||
|
Mq Node Data.
|
||||||
|
"""
|
||||||
|
|
||||||
|
class Case(BaseModel):
|
||||||
|
"""
|
||||||
|
Case entity representing a single logical condition group
|
||||||
|
"""
|
||||||
|
|
||||||
|
channel: str
|
||||||
|
message: str
|
||||||
|
|
||||||
|
channel: Optional[str] = "abc"
|
||||||
|
message: Optional[str] = "message"
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
|
||||||
|
|
||||||
|
from core.workflow.entities.node_entities import NodeRunResult
|
||||||
|
from core.workflow.entities.workflow_node_execution import WorkflowNodeExecutionStatus
|
||||||
|
from core.workflow.nodes.base import BaseNode
|
||||||
|
from core.workflow.nodes.enums import NodeType
|
||||||
|
from core.workflow.nodes.mq.entities import MqNodeData
|
||||||
|
from core.workflow.nodes.mq.rabbitmq_client import RabbitMQClient
|
||||||
|
|
||||||
|
# 创建全局RabbitMQ客户端实例
|
||||||
|
rabbitmq_client = RabbitMQClient("dify_node")
|
||||||
|
|
||||||
|
class MqNode(BaseNode[MqNodeData]):
|
||||||
|
_node_data_cls = MqNodeData
|
||||||
|
_node_type = NodeType.MqNode
|
||||||
|
|
||||||
|
def _run(self) -> NodeRunResult:
|
||||||
|
"""
|
||||||
|
Run mq node
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
print("go go go execute execute execute")
|
||||||
|
node_inputs: dict[str, list] = {"conditions": []}
|
||||||
|
|
||||||
|
process_data: dict[str, list] = {"condition_results": []}
|
||||||
|
|
||||||
|
input_conditions = []
|
||||||
|
final_result = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
rabbitmq_client.publish_json({
|
||||||
|
"action": "downloadImage",
|
||||||
|
"msg": '你好'
|
||||||
|
})
|
||||||
|
except Exception:
|
||||||
|
print("err")
|
||||||
|
pass
|
||||||
|
outputs = {"result": True, "message": 'xxx'}
|
||||||
|
|
||||||
|
data = NodeRunResult(
|
||||||
|
status=WorkflowNodeExecutionStatus.SUCCEEDED,
|
||||||
|
inputs=node_inputs,
|
||||||
|
process_data=process_data,
|
||||||
|
edge_source_handle="false", # Use case ID or 'default'
|
||||||
|
outputs=outputs,
|
||||||
|
)
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
import { BlockEnum } from '../../types'
|
||||||
|
import type { NodeDefault } from '../../types'
|
||||||
|
import {
|
||||||
|
ALL_CHAT_AVAILABLE_BLOCKS,
|
||||||
|
ALL_COMPLETION_AVAILABLE_BLOCKS,
|
||||||
|
} from '@/app/components/workflow/blocks'
|
||||||
|
|
||||||
|
const nodeDefault: NodeDefault<any> = {
|
||||||
|
defaultValue: {
|
||||||
|
channelName: '',
|
||||||
|
message: '',
|
||||||
|
},
|
||||||
|
getAvailablePrevNodes(isChatMode: boolean) {
|
||||||
|
const nodes = isChatMode
|
||||||
|
? ALL_CHAT_AVAILABLE_BLOCKS
|
||||||
|
: ALL_COMPLETION_AVAILABLE_BLOCKS.filter(type => type !== BlockEnum.End)
|
||||||
|
return nodes
|
||||||
|
},
|
||||||
|
getAvailableNextNodes(isChatMode: boolean) {
|
||||||
|
const nodes = isChatMode ? ALL_CHAT_AVAILABLE_BLOCKS : ALL_COMPLETION_AVAILABLE_BLOCKS
|
||||||
|
return nodes
|
||||||
|
},
|
||||||
|
checkValid(payload: any, t: any) {
|
||||||
|
const errorMessages = ''
|
||||||
|
return {
|
||||||
|
isValid: !errorMessages,
|
||||||
|
errorMessage: errorMessages,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
export default nodeDefault
|
||||||
Loading…
Reference in New Issue