|
|
@@ -94,8 +94,8 @@ import EditorFooter from '@/features/editorFooter/index.vue'
|
|
|
import Toolbar from '@/features/toolbar/index.vue'
|
|
|
|
|
|
import { IconButton, Input } from '@repo/ui'
|
|
|
+import { nodeMap } from '@repo/nodes'
|
|
|
|
|
|
-import type { SourceType } from '@repo/nodes'
|
|
|
import { dayjs, ElMessage, ElMessageBox } from 'element-plus'
|
|
|
|
|
|
const layout = inject<{ setMainStyle: (style: CSSProperties) => void }>('layout')
|
|
|
@@ -132,37 +132,9 @@ const saveVarsTimer = ref<number | undefined>(undefined)
|
|
|
const isHydrating = ref(false)
|
|
|
const notifyTimestamps = new Map<string, number>()
|
|
|
|
|
|
-const nodeTypeMap: Record<string, string> = {
|
|
|
- 'http-request': 'http-request',
|
|
|
- 'if-else': 'condition',
|
|
|
- condition: 'condition',
|
|
|
- code: 'code',
|
|
|
- database: 'database',
|
|
|
- start: 'start',
|
|
|
- end: 'end'
|
|
|
-}
|
|
|
-
|
|
|
-const nodeSchemaMap: Record<string, any> = {
|
|
|
- start: startNode.schema,
|
|
|
- end: endNode.schema,
|
|
|
- 'http-request': httpNode.schema,
|
|
|
- condition: conditionNode.schema,
|
|
|
- code: codeNode.schema,
|
|
|
- database: databaseNode.schema
|
|
|
-}
|
|
|
-
|
|
|
const normalizeNodeType = (node: any) => {
|
|
|
const sourceNodeType = node?.nodeType || node?.data?.nodeType || node?.data?.type || node?.type
|
|
|
- return nodeTypeMap[sourceNodeType] || sourceNodeType || 'code'
|
|
|
-}
|
|
|
-
|
|
|
-type AgentNodeType = 'custom' | 'start' | 'end' | 'condition' | 'task' | 'http-request'
|
|
|
-
|
|
|
-const toApiNodeType = (nodeType?: string): AgentNodeType => {
|
|
|
- if (!nodeType) return 'custom'
|
|
|
- return ['start', 'end', 'condition', 'http-request'].includes(nodeType)
|
|
|
- ? (nodeType as AgentNodeType)
|
|
|
- : 'custom'
|
|
|
+ return sourceNodeType || 'code'
|
|
|
}
|
|
|
|
|
|
const toApiNodeData = (nodeData: any) => {
|
|
|
@@ -243,7 +215,7 @@ const buildUpdateNodePayload = (node: any) => {
|
|
|
width: node.width ?? node.data?.width ?? 96,
|
|
|
height: node.height ?? node.data?.height ?? 96,
|
|
|
selected: !!node.selected,
|
|
|
- nodeType: toApiNodeType(node.data?.nodeType || node.nodeType),
|
|
|
+ nodeType: node.data?.nodeType || node.nodeType,
|
|
|
zIndex: node.zIndex ?? 1,
|
|
|
data: toApiNodeData(node.data)
|
|
|
}
|
|
|
@@ -251,10 +223,10 @@ const buildUpdateNodePayload = (node: any) => {
|
|
|
|
|
|
const toWorkflowNode = (node: any) => {
|
|
|
const normalizedNodeType = normalizeNodeType(node)
|
|
|
- const schema = nodeSchemaMap[normalizedNodeType] || codeNode.schema
|
|
|
- const position = node?.position || schema.position || { x: 20, y: 30 }
|
|
|
- const width = node?.width ?? schema.width ?? 96
|
|
|
- const height = node?.height ?? schema.height ?? 96
|
|
|
+ const schema = nodeMap[normalizedNodeType]?.schema
|
|
|
+ const position = node?.position || schema?.position || { x: 20, y: 30 }
|
|
|
+ const width = node?.width ?? schema?.width ?? 96
|
|
|
+ const height = node?.height ?? schema?.height ?? 96
|
|
|
|
|
|
return {
|
|
|
...schema,
|
|
|
@@ -264,10 +236,10 @@ const toWorkflowNode = (node: any) => {
|
|
|
position,
|
|
|
width,
|
|
|
height,
|
|
|
- zIndex: node?.zIndex ?? schema.zIndex ?? 1,
|
|
|
+ zIndex: node?.zIndex ?? schema?.zIndex ?? 1,
|
|
|
selected: !!node?.selected,
|
|
|
data: {
|
|
|
- ...(schema.data || {}),
|
|
|
+ ...(schema?.data || {}),
|
|
|
...(node?.data || {}),
|
|
|
id: node.id,
|
|
|
position,
|
|
|
@@ -342,7 +314,7 @@ const loadAgentWorkflow = async (agentId: string) => {
|
|
|
isHydrating.value = true
|
|
|
|
|
|
try {
|
|
|
- const response = await agent.postGetAgentInfo({ id: agentId })
|
|
|
+ const response = await agent.postAgentGetAgentInfo({ id: agentId })
|
|
|
const result = response?.result
|
|
|
if (!response?.isSuccess || !result) {
|
|
|
throw new Error('获取智能体信息失败')
|
|
|
@@ -376,7 +348,7 @@ const saveAgentMeta = async () => {
|
|
|
if (!workflow.value?.id) return
|
|
|
|
|
|
try {
|
|
|
- const response = await agent.postDoEditAgent({
|
|
|
+ const response = await agent.postAgentDoEditAgent({
|
|
|
data: {
|
|
|
id: workflow.value.id,
|
|
|
name: workflow.value.name,
|
|
|
@@ -398,7 +370,7 @@ const saveAgentVariables = async () => {
|
|
|
if (!workflow.value?.id) return
|
|
|
|
|
|
try {
|
|
|
- const response = await agent.postDoSaveAgentVariables({
|
|
|
+ const response = await agent.postAgentDoSaveAgentVariables({
|
|
|
appAgentId: workflow.value.id,
|
|
|
conversation_variables: workflow.value.conversation_variables || [],
|
|
|
env_variables: (workflow.value.env_variables || []).map((item: any) => ({
|
|
|
@@ -464,9 +436,9 @@ watch(
|
|
|
*/
|
|
|
watch(
|
|
|
() => route.params?.id,
|
|
|
- async (newId) => {
|
|
|
- if (newId) {
|
|
|
- await loadAgentWorkflow('b3a4aabb-a6b8-47f3-8a32-f45930f7d7b8' as string)
|
|
|
+ async (id) => {
|
|
|
+ if (id) {
|
|
|
+ await loadAgentWorkflow(id as string)
|
|
|
}
|
|
|
},
|
|
|
{ immediate: true }
|
|
|
@@ -508,9 +480,9 @@ const handleRunSelectedNode = async () => {
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- const response = await agent.postDoTestNodeRunner({
|
|
|
+ const response = await agent.postAgentDoTestNodeRunner({
|
|
|
appAgentId: workflow.value.id,
|
|
|
- nodeIds: [nodeID.value]
|
|
|
+ id: nodeID.value
|
|
|
})
|
|
|
runVisible.value = false
|
|
|
handleApiResult(response, '已提交节点测试', '节点测试失败')
|
|
|
@@ -527,9 +499,9 @@ const handleRunNode = async (id: string) => {
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- const response = await agent.postDoTestNodeRunner({
|
|
|
+ const response = await agent.postAgentDoTestNodeRunner({
|
|
|
appAgentId: workflow.value.id,
|
|
|
- nodeIds: [id]
|
|
|
+ id
|
|
|
})
|
|
|
handleApiResult(response, '已提交节点测试', '节点测试失败')
|
|
|
} catch (error) {
|
|
|
@@ -537,7 +509,7 @@ const handleRunNode = async (id: string) => {
|
|
|
ElMessage.error('节点测试失败')
|
|
|
}
|
|
|
}
|
|
|
-const handleNodeCreate = (value: SourceType | string) => {
|
|
|
+const handleNodeCreate = (value: { type: string } | string) => {
|
|
|
const id = uuid()
|
|
|
if (typeof value === 'string') {
|
|
|
if (value === 'stickyNote') {
|
|
|
@@ -563,14 +535,6 @@ const handleNodeCreate = (value: SourceType | string) => {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- const nodeMap: Record<string, any> = {
|
|
|
- start: startNode,
|
|
|
- end: endNode,
|
|
|
- http: httpNode,
|
|
|
- condition: conditionNode,
|
|
|
- code: codeNode,
|
|
|
- database: databaseNode
|
|
|
- }
|
|
|
const nodeToAdd = nodeMap[value.type]?.schema
|
|
|
|
|
|
// 如果存在对应节点则添加
|
|
|
@@ -585,16 +549,15 @@ const handleNodeCreate = (value: SourceType | string) => {
|
|
|
__pendingCreate: true,
|
|
|
id
|
|
|
}
|
|
|
- workflow.value?.nodes.push(newNode)
|
|
|
|
|
|
agent
|
|
|
- .postDoNewAgentNode({
|
|
|
+ .postAgentDoNewAgentNode({
|
|
|
appAgentId: workflow.value.id,
|
|
|
position: newNode.position,
|
|
|
width: newNode.width,
|
|
|
height: newNode.height,
|
|
|
selected: !!newNode.selected,
|
|
|
- nodeType: toApiNodeType(newNode.data?.nodeType),
|
|
|
+ nodeType: newNode.data?.nodeType,
|
|
|
zIndex: newNode.zIndex ?? 1,
|
|
|
parentId: newNode.parentId || ''
|
|
|
})
|
|
|
@@ -646,17 +609,21 @@ const handleDelete = () => {
|
|
|
/**
|
|
|
* 创建连线
|
|
|
*/
|
|
|
-const onCreateConnection = (connection: Connection) => {
|
|
|
- const { source, target } = connection
|
|
|
+const onCreateConnection = async (connection: Connection) => {
|
|
|
+ const { source, target, sourceHandle } = connection
|
|
|
|
|
|
if (!workflow.value?.edges.some((edge) => edge.source === source && edge.target === target)) {
|
|
|
- workflow.value?.edges.push({
|
|
|
- id: `edge-${source}-${target}`,
|
|
|
+ const response = await agent.postAgentDoNewEdge({
|
|
|
+ appAgentId: workflow.value.id,
|
|
|
source,
|
|
|
target,
|
|
|
- type: 'canvas-edge',
|
|
|
- data: {}
|
|
|
+ sourceHandle: sourceHandle!,
|
|
|
+ zIndex: 1
|
|
|
})
|
|
|
+
|
|
|
+ if (handleApiResult(response, '节点已添加', '新增节点失败')) {
|
|
|
+ await loadAgentWorkflow(workflow.value.id)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -672,7 +639,7 @@ const handleUpdateNodesPosition = (events: { id: string; position: XYPosition }[
|
|
|
}
|
|
|
node.position = position
|
|
|
agent
|
|
|
- .postDoUpdateAgentNode(buildUpdateNodePayload(node))
|
|
|
+ .postAgentDoUpdateAgentNode(buildUpdateNodePayload(node))
|
|
|
.then((response) => {
|
|
|
handleApiResult(response, undefined, '更新节点失败')
|
|
|
})
|
|
|
@@ -702,7 +669,7 @@ const hangleUpdateNodeData = (id: string, data: any) => {
|
|
|
}
|
|
|
node.data = nextData
|
|
|
agent
|
|
|
- .postDoUpdateAgentNode(buildUpdateNodePayload(node))
|
|
|
+ .postAgentDoUpdateAgentNode(buildUpdateNodePayload(node))
|
|
|
.then((response) => {
|
|
|
handleApiResult(response, undefined, '更新节点失败')
|
|
|
})
|
|
|
@@ -735,24 +702,26 @@ const handleUpdateNodeProps = (id: string, attrs: Record<string, unknown>) => {
|
|
|
/**
|
|
|
* 删除节点
|
|
|
*/
|
|
|
-const handleDeleteNode = (id: string) => {
|
|
|
+const handleDeleteNode = async (id: string) => {
|
|
|
console.log('del node', id)
|
|
|
const index = workflow.value.nodes.findIndex((node) => node.id === id)
|
|
|
if (index != -1) {
|
|
|
- workflow.value.nodes.splice(index, 1)
|
|
|
+ await agent.postAgentDoDeleteAgentNode({
|
|
|
+ id: id
|
|
|
+ })
|
|
|
+ await loadAgentWorkflow(workflow.value.id)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除连线
|
|
|
*/
|
|
|
-const handleDeleteEdge = (connection: Connection) => {
|
|
|
- console.log('del edge', connection)
|
|
|
- const index = workflow.value.edges.findIndex(
|
|
|
- (edge) => edge.id === `edge-${connection.source}-${connection.target}`
|
|
|
- )
|
|
|
- if (index != -1) {
|
|
|
- workflow.value.edges.splice(index, 1)
|
|
|
+const handleDeleteEdge = async (connection: Connection) => {
|
|
|
+ if (connection.id) {
|
|
|
+ // await agent.postAgentDoDeleteEdge({
|
|
|
+ // id: connection.id
|
|
|
+ // })
|
|
|
+ await loadAgentWorkflow(workflow.value.id)
|
|
|
}
|
|
|
}
|
|
|
|