Implementation:Infiniflow Ragflow Canvas Util
| Knowledge Sources | |
|---|---|
| Domains | Frontend, Agent_System, Graph_Algorithms |
| Last Updated | 2026-02-12 06:00 GMT |
Overview
Concrete utility functions for graph traversal and output option building in the agent canvas workflow system of the RAGFlow frontend.
Description
The utils/canvas-util.tsx module provides functions for traversing the agent workflow graph to build output options for downstream operators, finding ancestor/descendant nodes, and validating connection paths between nodes. These are the core graph algorithms powering the agent canvas editor.
Usage
Import these utilities in agent canvas components when building operator connection UIs, validating workflow graphs, or computing available input sources for an operator.
Code Reference
Source Location
- Repository: Infiniflow_Ragflow
- File: web/src/utils/canvas-util.tsx
- Lines: 1-133
Signature
export function buildOutputOptions(nodes: Node[], edges: Edge[], currentNodeId: string): OptionType[];
export function getAncestorNodes(nodes: Node[], edges: Edge[], nodeId: string): Node[];
export function getDescendantNodes(nodes: Node[], edges: Edge[], nodeId: string): Node[];
Import
import { buildOutputOptions, getAncestorNodes } from '@/utils/canvas-util';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| nodes | Node[] | Yes | All nodes in the workflow graph |
| edges | Edge[] | Yes | All edges in the workflow graph |
| currentNodeId | string | Yes | Node to compute options for |
Outputs
| Name | Type | Description |
|---|---|---|
| buildOutputOptions() | OptionType[] | Available output options from upstream nodes |
| getAncestorNodes() | Node[] | All ancestor nodes via incoming edges |
Usage Examples
import { buildOutputOptions } from '@/utils/canvas-util';
const options = buildOutputOptions(nodes, edges, currentNode.id);
// Returns options like [{ label: 'Retrieval Output', value: 'node-1:output' }]