import type { RouteNode } from '@cameleer/design-system'; // Map NodeType strings to RouteNode types function mapNodeType(type: string): RouteNode['type'] { const lower = type?.toLowerCase() || ''; if (lower.includes('from') || lower === 'endpoint') return 'from'; if (lower.includes('to')) return 'to'; if (lower.includes('choice') || lower.includes('when') || lower.includes('otherwise')) return 'choice'; if (lower.includes('error') || lower.includes('dead')) return 'error-handler'; return 'process'; } function mapStatus(status: string | undefined): RouteNode['status'] { if (!status) return 'ok'; const s = status.toUpperCase(); if (s === 'FAILED') return 'fail'; if (s === 'RUNNING') return 'slow'; return 'ok'; } /** * Maps diagram PositionedNodes + execution ProcessorNodes to RouteFlow RouteNode[] format. * Joins on diagramNodeId → node.id. */ export function mapDiagramToRouteNodes( diagramNodes: Array<{ id?: string; label?: string; type?: string }>, processors: Array<{ diagramNodeId?: string; processorId?: string; status?: string; durationMs?: number; children?: any[] }> ): RouteNode[] { // Flatten processor tree const flatProcessors: typeof processors = []; function flatten(nodes: typeof processors) { for (const n of nodes) { flatProcessors.push(n); if (n.children) flatten(n.children); } } flatten(processors || []); // Build lookup: diagramNodeId → processor const procMap = new Map(); for (const p of flatProcessors) { if (p.diagramNodeId) procMap.set(p.diagramNodeId, p); } return diagramNodes.map(node => { const proc = procMap.get(node.id ?? ''); return { name: node.label || node.id || '', type: mapNodeType(node.type ?? ''), durationMs: proc?.durationMs ?? 0, status: mapStatus(proc?.status), isBottleneck: false, }; }); }