(result: Record<string, any>, config: Record<string, any>)
| 410 | } |
| 411 | |
| 412 | const generateNodesData = (result: Record<string, any>, config: Record<string, any>) => { |
| 413 | try { |
| 414 | if (result.error) { |
| 415 | return result |
| 416 | } |
| 417 | |
| 418 | let nodes = result.nodes |
| 419 | |
| 420 | for (let i = 0; i < nodes.length; i += 1) { |
| 421 | const node = nodes[i] |
| 422 | let nodeName = node.data.name |
| 423 | |
| 424 | // If nodeName is not found in data.name, try extracting from node.id |
| 425 | if (!nodeName || !config.componentNodes[nodeName]) { |
| 426 | nodeName = node.id.split('_')[0] |
| 427 | } |
| 428 | |
| 429 | const componentNode = config.componentNodes[nodeName] |
| 430 | if (!componentNode) { |
| 431 | continue |
| 432 | } |
| 433 | |
| 434 | const initializedNodeData = initNode(cloneDeep(componentNode), node.id) |
| 435 | nodes[i].data = { |
| 436 | ...initializedNodeData, |
| 437 | label: node.data?.label |
| 438 | } |
| 439 | |
| 440 | if (nodes[i].data.name === 'iterationAgentflow') { |
| 441 | nodes[i].type = 'iteration' |
| 442 | } |
| 443 | |
| 444 | if (nodes[i].parentNode) { |
| 445 | nodes[i].extent = 'parent' |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | return { nodes, edges: result.edges } |
| 450 | } catch (error) { |
| 451 | console.error('Error generating AgentflowV2:', error) |
| 452 | return { error: error.message || 'Unknown error occurred' } |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | const initNode = (nodeData: Record<string, any>, newNodeId: string): NodeData => { |
| 457 | const inputParams = [] |
no test coverage detected