Skip to content

Commit f5afa15

Browse files
committed
feat: Add nodes to the workflow canvas
1 parent 80f121d commit f5afa15

4 files changed

Lines changed: 34 additions & 15 deletions

File tree

‎ui/src/views/workflow/AgentWorkflowView.vue‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
import type LogicFlow from '@logicflow/core'
33
import WorkflowCanvas from '@/workflow-canvas/index.vue'
44
import { WorkflowNodeType } from '@/workflow-canvas/types.ts'
5+
import {nodeDict} from "@/workflow-canvas/config/node-mapping.ts"
56
import WorkflowComponentMenu from './components/WorkflowComponentMenu.vue'
6-
7+
import {type ShapeItem} from "@/workflow-canvas/types"
78
defineOptions({ name: 'AgentWorkflowView' })
89
910
defineProps<{
@@ -17,9 +18,24 @@ const emit = defineEmits<{
1718
const workflowRef = useTemplateRef<InstanceType<typeof WorkflowCanvas>>('workflowRef')
1819
1920
const handleAddNode = (nodeType: WorkflowNodeType) => {
20-
workflowRef.value?.addNode(nodeType)
21-
}
21+
const shapeItem=toShapeItem(nodeType)
22+
if(!shapeItem){
23+
return
24+
}
25+
workflowRef.value?.addNode(shapeItem)
26+
}
2227
28+
const toShapeItem=(nodeType: WorkflowNodeType)=>{
29+
const node=nodeDict[nodeType]
30+
if(node){
31+
const shapeItem:ShapeItem={
32+
type: node.type,
33+
properties:node.properties,
34+
text:node.text
35+
}
36+
return shapeItem;
37+
}
38+
}
2339
const handleSave = () => {
2440
const graphData = workflowRef.value?.getGraphData()
2541
if (graphData) emit('save', graphData)

‎ui/src/workflow-canvas/config/node-mapping.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const workflowModelDict: Record<WorkflowMode, WorkflowNodeMatcher> = {
5757
)
5858
},
5959
}
60-
export const nodeDict: Partial<Record<WorkflowNodeType, unknown>> = {
60+
export const nodeDict: Partial<Record<WorkflowNodeType, Record<string,any>>> = {
6161
[WorkflowNodeType.AiChat]: NodeData.aiChatNode,
6262
[WorkflowNodeType.SearchKnowledge]: NodeData.searchKnowledgeNode,
6363
[WorkflowNodeType.SearchDocument]: NodeData.searchDocumentNode,

‎ui/src/workflow-canvas/index.vue‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,14 @@ import { disconnectAll, getTeleport } from '@/workflow-canvas/core/teleport'
99
import type { WorkflowNodeModel } from '@/workflow-canvas/core/workflow-node'
1010
import Dagre from '@/workflow-canvas/plugins/dagre'
1111
import { WorkflowMode, WorkflowNodeType } from '@/workflow-canvas/types'
12-
12+
import {type ShapeItem} from "@/workflow-canvas/types"
1313
defineOptions({ name: 'MkWorkflow' })
1414
1515
type CanvasWorkflowNodeModel = WorkflowNodeModel & {
1616
set_loop_body?: () => void
1717
}
1818
19-
type ShapeItem = {
20-
callback?: (logicFlow: LogicFlow, container?: HTMLElement) => void
21-
className?: string
22-
disabled?: boolean
23-
icon?: string
24-
label?: string
25-
properties?: LogicFlow.PropertiesType
26-
text?: string
27-
type?: string
28-
}
19+
2920
3021
const props = withDefaults(
3122
defineProps<{
@@ -78,6 +69,7 @@ function renderGraphData(data: LogicFlow.GraphConfigData = props.data ?? {}) {
7869
})
7970
8071
initDefaultShortcut(lf.value, lf.value.graphModel)
72+
console.log(Object.values(nodeModules).map(({ default: node }) => node))
8173
lf.value.batchRegister([...Object.values(nodeModules).map(({ default: node }) => node), AppEdge])
8274
lf.value.setDefaultEdgeType('app-edge')
8375
lf.value.render(data ? data : {})

‎ui/src/workflow-canvas/types.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import LogicFlow from '@logicflow/core'
12
/** LogicFlow 节点类型,作为工作流图数据中的稳定协议值。 */
23
export enum WorkflowNodeType {
34
Base = 'base-node',
@@ -66,3 +67,13 @@ export interface WorkflowNodeField {
6667
type?: string
6768
value: string
6869
}
70+
export type ShapeItem = {
71+
callback?: (logicFlow: LogicFlow, container?: HTMLElement) => void
72+
className?: string
73+
disabled?: boolean
74+
icon?: string
75+
label?: string
76+
properties?: LogicFlow.PropertiesType
77+
text?: string
78+
type?: string
79+
}

0 commit comments

Comments
 (0)