Files
dify/web/app/components/workflow/workflow-generator/graph-diff.ts
Crazywoola 8809cc036d feat(workflow-generator): enhance the AI auto-creation flow end-to-end (#38175)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
2026-07-01 02:28:58 +00:00

40 lines
1.4 KiB
TypeScript

import type { GeneratedGraph } from './types'
export type GraphDiff = {
/** Node ids present in the new graph but not the base. */
added: string[]
/** Node ids present in the base graph but dropped from the new one. */
removed: string[]
/** Node ids present in both whose ``data`` changed. */
changed: string[]
}
/**
* Shallow node-level diff between a refine base graph and the generated result.
*
* Used by the `/refine` flow to tell the user what an "apply" would actually
* change before they overwrite their draft — far less scary than a bare "this
* cannot be undone". Comparison is by node ``id`` with a JSON equality check on
* ``data``; edges and layout (which the generator always rewrites) are ignored
* so cosmetic re-layouts don't read as changes.
*/
export const diffGraphs = (base: GeneratedGraph, next: GeneratedGraph): GraphDiff => {
const baseById = new Map(base.nodes.map(node => [node.id, node]))
const nextById = new Map(next.nodes.map(node => [node.id, node]))
const added: string[] = []
const changed: string[] = []
for (const [id, node] of nextById) {
const prev = baseById.get(id)
if (!prev) {
added.push(id)
continue
}
if (JSON.stringify(prev.data) !== JSON.stringify(node.data))
changed.push(id)
}
const removed = [...baseById.keys()].filter(id => !nextById.has(id))
return { added, removed, changed }
}