mirror of
https://github.com/langgenius/dify.git
synced 2026-05-13 08:57:28 +08:00
35 lines
965 B
TypeScript
35 lines
965 B
TypeScript
import type { NodeTracing } from '@/types/workflow'
|
|
import { NodeRunningStatus } from '../types'
|
|
|
|
const isNestedTracingNode = (trace: Pick<NodeTracing, 'iteration_id' | 'loop_id'>) => {
|
|
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
|
|
}
|