import type { NodeTracing } from '@/types/workflow' import { NodeRunningStatus } from '../types' const isNestedTracingNode = (trace: Pick) => { return Boolean(trace.iteration_id || trace.loop_id) } export const upsertTopLevelTracingNodeOnStart = ( tracing: NodeTracing[], startedNode: NodeTracing, options?: { reuseRunningNodeId?: boolean }, ) => { if (isNestedTracingNode(startedNode)) return false const currentIndex = tracing.findIndex((item) => { if (item.id === startedNode.id) return true if (!options?.reuseRunningNodeId) return false return item.node_id === startedNode.node_id && item.status === NodeRunningStatus.Running }) if (currentIndex > -1) // Started events are the authoritative snapshot for an execution; merging would retain stale client-side fields. tracing[currentIndex] = startedNode else tracing.push(startedNode) return true }