feat: handle mq message

pull/21533/head
ziqiang 11 months ago
parent bd3f3e7b26
commit 2a4f9f0af9

@ -8,7 +8,7 @@ from core.workflow.nodes.mq.entities import MqNodeData
from core.workflow.nodes.mq.rabbitmq_client import RabbitMQClient from core.workflow.nodes.mq.rabbitmq_client import RabbitMQClient
# 创建全局RabbitMQ客户端实例 # 创建全局RabbitMQ客户端实例
rabbitmq_client = RabbitMQClient("dify_node") rabbitmq_client = RabbitMQClient("dify_node")
class MqNode(BaseNode[MqNodeData]): class MqNode(BaseNode[MqNodeData]):
_node_data_cls = MqNodeData _node_data_cls = MqNodeData
@ -20,8 +20,17 @@ class MqNode(BaseNode[MqNodeData]):
:return: :return:
""" """
print("go go go execute execute execute") print("go go go execute execute execute")
print("ddd:", self.node_data)
node_inputs: dict[str, list] = {"conditions": []} node_inputs: dict[str, list] = {"conditions": []}
newMessage = self.graph_runtime_state.variable_pool.convert_template(
self.node_data.message
).text
newChannel = self.graph_runtime_state.variable_pool.convert_template(
self.node_data.channel
).text
print("new message:", newMessage)
print("new newChannel:", newChannel)
process_data: dict[str, list] = {"condition_results": []} process_data: dict[str, list] = {"condition_results": []}
input_conditions = [] input_conditions = []
@ -30,7 +39,8 @@ class MqNode(BaseNode[MqNodeData]):
try: try:
rabbitmq_client.publish_json({ rabbitmq_client.publish_json({
"action": "downloadImage", "action": "downloadImage",
"msg": '你好' "msg": newMessage,
"channel": newChannel
}) })
except Exception: except Exception:
print("err") print("err")

@ -361,7 +361,7 @@ export const NODES_INITIAL_DATA = {
title: '', title: '',
desc: '', desc: '',
variables: [], variables: [],
...HttpRequestDefault.defaultValue, ...MqDefault.defaultValue,
}, },
[BlockEnum.ParameterExtractor]: { [BlockEnum.ParameterExtractor]: {
type: BlockEnum.ParameterExtractor, type: BlockEnum.ParameterExtractor,

@ -100,9 +100,9 @@ export const useChecklist = (nodes: Node[], edges: Edge[]) => {
if (node.type === CUSTOM_NODE) { if (node.type === CUSTOM_NODE) {
const checkData = getCheckData(node.data) const checkData = getCheckData(node.data)
console.log('node', node) // console.log('node', node)
console.log('checkData', checkData) // console.log('checkData', checkData)
console.log('nodesExtraData', nodesExtraData) // console.log('nodesExtraData', nodesExtraData)
const { errorMessage } = nodesExtraData[node.data.type].checkValid(checkData, t, moreDataForCheckValid) const { errorMessage } = nodesExtraData[node.data.type].checkValid(checkData, t, moreDataForCheckValid)
if (errorMessage || !validNodes.find(n => n.id === node.id)) { if (errorMessage || !validNodes.find(n => n.id === node.id)) {

@ -39,6 +39,7 @@ import ListFilterPanel from './list-operator/panel'
import AgentNode from './agent/node' import AgentNode from './agent/node'
import AgentPanel from './agent/panel' import AgentPanel from './agent/panel'
import MqNode from './mq/node' import MqNode from './mq/node'
import MqPanel from './mq/panel'
import { TransferMethod } from '@/types/app' import { TransferMethod } from '@/types/app'
export const NodeComponentMap: Record<string, ComponentType<any>> = { export const NodeComponentMap: Record<string, ComponentType<any>> = {
@ -86,7 +87,7 @@ export const PanelComponentMap: Record<string, ComponentType<any>> = {
[BlockEnum.DocExtractor]: DocExtractorPanel, [BlockEnum.DocExtractor]: DocExtractorPanel,
[BlockEnum.ListFilter]: ListFilterPanel, [BlockEnum.ListFilter]: ListFilterPanel,
[BlockEnum.Agent]: AgentPanel, [BlockEnum.Agent]: AgentPanel,
[BlockEnum.MqNode]: MqNode, [BlockEnum.MqNode]: MqPanel,
} }
export const CUSTOM_NODE_TYPE = 'custom' export const CUSTOM_NODE_TYPE = 'custom'

@ -14,7 +14,7 @@ import BasePanel from './_base/panel'
const CustomNode = (props: NodeProps) => { const CustomNode = (props: NodeProps) => {
const nodeData = props.data const nodeData = props.data
console.log('zzq see nodeData', props) // console.log('zzq see nodeData', props)
const NodeComponent = NodeComponentMap[nodeData.type] const NodeComponent = NodeComponentMap[nodeData.type]
return ( return (

@ -37,35 +37,35 @@ const MqNode: FC<NodeProps<any>> = ({ data }) => {
readOnly readOnly
/> />
</div> </div>
<div> {/* <div> */}
<label style={{ {/* <label style={{ */}
display: 'block', {/* display: 'block', */}
marginBottom: '4px', {/* marginBottom: '4px', */}
fontSize: '14px', {/* fontSize: '14px', */}
color: '#495057', {/* color: '#495057', */}
fontWeight: '500', {/* fontWeight: '500', */}
}}> {/* }}> */}
Message {/* Message */}
</label> {/* </label> */}
<textarea {/* <textarea */}
style={{ {/* style={{ */}
width: '100%', {/* width: '100%', */}
padding: '8px 12px', {/* padding: '8px 12px', */}
border: '1px solid #ced4da', {/* border: '1px solid #ced4da', */}
borderRadius: '4px', {/* borderRadius: '4px', */}
fontSize: '14px', {/* fontSize: '14px', */}
transition: 'border-color 0.15s ease-in-out', {/* transition: 'border-color 0.15s ease-in-out', */}
boxSizing: 'border-box', {/* boxSizing: 'border-box', */}
minHeight: '100px', {/* minHeight: '100px', */}
resize: 'vertical', {/* resize: 'vertical', */}
fontFamily: 'inherit', {/* fontFamily: 'inherit', */}
lineHeight: '1.5', {/* lineHeight: '1.5', */}
}} {/* }} */}
value={data.mqValue || ''} {/* value={data.mqValue || ''} */}
placeholder="请输入要发送的消息" {/* placeholder="请输入要发送的消息" */}
readOnly {/* readOnly */}
/> {/* /> */}
</div> {/* </div> */}
</div> </div>
) )
} }

@ -0,0 +1,58 @@
import type { FC } from 'react'
import React from 'react'
import { useTranslation } from 'react-i18next'
import useConfig from './use-config'
import type { MqNodeType } from './types'
import Editor from '@/app/components/workflow/nodes/_base/components/prompt/editor'
import type { NodePanelProps } from '@/app/components/workflow/types'
import useAvailableVarList from '@/app/components/workflow/nodes/_base/hooks/use-available-var-list'
import InputWithVar from '@/app/components/workflow/nodes/_base/components/prompt/editor'
const i18nPrefix = 'workflow.nodes.answer'
const Panel: FC<NodePanelProps<MqNodeType>> = ({
id,
data,
}) => {
const { t } = useTranslation()
const {
readOnly,
inputs,
handleMessageChange,
handleChannelNameChange,
filterVar,
} = useConfig(id, data)
const { availableVars, availableNodesWithParent } = useAvailableVarList(id, {
onlyLeafNodeVar: false,
hideChatVar: false,
hideEnv: false,
filterVar,
})
return (
<div className='mb-2 mt-2 space-y-4 px-4'>
<Editor
readOnly={readOnly}
justVar
title={'Channel'}
value={inputs.channelName}
onChange={handleChannelNameChange}
nodesOutputVars={availableVars}
availableNodes={availableNodesWithParent}
isSupportFileVar
/>
<div className='mt-1'></div>
<InputWithVar
title='数据'
value={inputs.message}
onChange={handleMessageChange}
justVar
nodesOutputVars={availableVars}
availableNodes={availableNodesWithParent}
/>
</div>
)
}
export default React.memo(Panel)

@ -0,0 +1,6 @@
import type { CommonNodeType } from '@/app/components/workflow/types'
export type MqNodeType = CommonNodeType & {
channelName: string
message: string
}

@ -0,0 +1,40 @@
import { useCallback } from 'react'
import produce from 'immer'
import { VarType } from '../../types'
import type { Var } from '../../types'
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
import {
useNodesReadOnly,
} from '@/app/components/workflow/hooks'
import type { MqNodeType } from '@/app/components/workflow/nodes/mq/types'
const useConfig = (id: string, payload: MqNodeType) => {
const { nodesReadOnly: readOnly } = useNodesReadOnly()
const { inputs, setInputs } = useNodeCrud<MqNodeType>(id, payload)
const handleChannelNameChange = useCallback((value: string) => {
const newInputs = produce(inputs, (draft) => {
draft.channelName = value
})
setInputs(newInputs)
}, [inputs, setInputs])
const handleMessageChange = useCallback((value: string) => {
const newInputs = produce(inputs, (draft) => {
draft.message = value
})
setInputs(newInputs)
}, [inputs, setInputs])
const filterVar = useCallback((varPayload: Var) => {
return varPayload.type !== VarType.arrayObject
}, [])
return {
readOnly,
inputs,
handleChannelNameChange,
handleMessageChange,
filterVar,
}
}
export default useConfig
Loading…
Cancel
Save