From f5afa156697377c5c72a244eaf1125aed54bfd77 Mon Sep 17 00:00:00 2001 From: shaohuzhang1 Date: Wed, 19 Aug 2026 18:05:37 +0800 Subject: [PATCH] feat: Add nodes to the workflow canvas --- ui/src/views/workflow/AgentWorkflowView.vue | 22 ++++++++++++++++--- ui/src/workflow-canvas/config/node-mapping.ts | 2 +- ui/src/workflow-canvas/index.vue | 14 +++--------- ui/src/workflow-canvas/types.ts | 11 ++++++++++ 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/ui/src/views/workflow/AgentWorkflowView.vue b/ui/src/views/workflow/AgentWorkflowView.vue index 892fadef9e9..eaed55201d2 100644 --- a/ui/src/views/workflow/AgentWorkflowView.vue +++ b/ui/src/views/workflow/AgentWorkflowView.vue @@ -2,8 +2,9 @@ import type LogicFlow from '@logicflow/core' import WorkflowCanvas from '@/workflow-canvas/index.vue' import { WorkflowNodeType } from '@/workflow-canvas/types.ts' +import {nodeDict} from "@/workflow-canvas/config/node-mapping.ts" import WorkflowComponentMenu from './components/WorkflowComponentMenu.vue' - +import {type ShapeItem} from "@/workflow-canvas/types" defineOptions({ name: 'AgentWorkflowView' }) defineProps<{ @@ -17,9 +18,24 @@ const emit = defineEmits<{ const workflowRef = useTemplateRef>('workflowRef') const handleAddNode = (nodeType: WorkflowNodeType) => { - workflowRef.value?.addNode(nodeType) -} + const shapeItem=toShapeItem(nodeType) + if(!shapeItem){ + return + } + workflowRef.value?.addNode(shapeItem) + } +const toShapeItem=(nodeType: WorkflowNodeType)=>{ + const node=nodeDict[nodeType] + if(node){ + const shapeItem:ShapeItem={ + type: node.type, + properties:node.properties, + text:node.text + } + return shapeItem; +} +} const handleSave = () => { const graphData = workflowRef.value?.getGraphData() if (graphData) emit('save', graphData) diff --git a/ui/src/workflow-canvas/config/node-mapping.ts b/ui/src/workflow-canvas/config/node-mapping.ts index ea3f069b145..8545dd5bbbb 100644 --- a/ui/src/workflow-canvas/config/node-mapping.ts +++ b/ui/src/workflow-canvas/config/node-mapping.ts @@ -57,7 +57,7 @@ export const workflowModelDict: Record = { ) }, } -export const nodeDict: Partial> = { +export const nodeDict: Partial>> = { [WorkflowNodeType.AiChat]: NodeData.aiChatNode, [WorkflowNodeType.SearchKnowledge]: NodeData.searchKnowledgeNode, [WorkflowNodeType.SearchDocument]: NodeData.searchDocumentNode, diff --git a/ui/src/workflow-canvas/index.vue b/ui/src/workflow-canvas/index.vue index 7a57932e4bc..6010c2be4e3 100644 --- a/ui/src/workflow-canvas/index.vue +++ b/ui/src/workflow-canvas/index.vue @@ -9,23 +9,14 @@ import { disconnectAll, getTeleport } from '@/workflow-canvas/core/teleport' import type { WorkflowNodeModel } from '@/workflow-canvas/core/workflow-node' import Dagre from '@/workflow-canvas/plugins/dagre' import { WorkflowMode, WorkflowNodeType } from '@/workflow-canvas/types' - +import {type ShapeItem} from "@/workflow-canvas/types" defineOptions({ name: 'MkWorkflow' }) type CanvasWorkflowNodeModel = WorkflowNodeModel & { set_loop_body?: () => void } -type ShapeItem = { - callback?: (logicFlow: LogicFlow, container?: HTMLElement) => void - className?: string - disabled?: boolean - icon?: string - label?: string - properties?: LogicFlow.PropertiesType - text?: string - type?: string -} + const props = withDefaults( defineProps<{ @@ -78,6 +69,7 @@ function renderGraphData(data: LogicFlow.GraphConfigData = props.data ?? {}) { }) initDefaultShortcut(lf.value, lf.value.graphModel) + console.log(Object.values(nodeModules).map(({ default: node }) => node)) lf.value.batchRegister([...Object.values(nodeModules).map(({ default: node }) => node), AppEdge]) lf.value.setDefaultEdgeType('app-edge') lf.value.render(data ? data : {}) diff --git a/ui/src/workflow-canvas/types.ts b/ui/src/workflow-canvas/types.ts index 54db159984e..8a5cd5fd280 100644 --- a/ui/src/workflow-canvas/types.ts +++ b/ui/src/workflow-canvas/types.ts @@ -1,3 +1,4 @@ +import LogicFlow from '@logicflow/core' /** LogicFlow 节点类型,作为工作流图数据中的稳定协议值。 */ export enum WorkflowNodeType { Base = 'base-node', @@ -66,3 +67,13 @@ export interface WorkflowNodeField { type?: string value: string } +export type ShapeItem = { + callback?: (logicFlow: LogicFlow, container?: HTMLElement) => void + className?: string + disabled?: boolean + icon?: string + label?: string + properties?: LogicFlow.PropertiesType + text?: string + type?: string +} \ No newline at end of file