Graph Serialization
lib/graph-serializer.ts handles converting between React Flow’s internal node format and the compact SimpleNode/SimpleEdge format used for storage, AI editing, and agent config conversion.
Types
SimpleNode
SimpleEdge
ExportFormat
Key functions
serializeGraph(nodes, edges)
Converts React Flow nodes toSimpleNode[]. Strips all UI metadata (label, category, handles, icon, position) and keeps only user-configured parameter values.
deserializeGraphFromExport(data)
Reconstructs a React Flow graph from an exported JSON file. CallsenrichNewNode() to restore template metadata (label, subtitle, handles) from nodeTemplates.ts.
applyOperations(nodes, edges, operations)
Applies a list ofEditOperation[] (from the AI generator) to the current graph state:
{ nodes, edges, needsArrange } — needsArrange: true signals the canvas to auto-layout after node additions or deletions.
enrichNewNode(node)
Converts aSimpleNode into a full React Flow Node by:
- Looking up the template in
nodeTemplates.ts - Filling in default parameter values
- Attaching template metadata (label, subtitle, handles, category, icon)
- Setting the initial position to
{ x: 0, y: 0 }