refactoring: graph state

This commit is contained in:
2026-03-12 17:40:05 +01:00
parent bfd1a40332
commit 4bd2f1b458
9 changed files with 176 additions and 58 deletions

View File

@@ -2,30 +2,21 @@
* Node lifecycle: contract that nodes implement so the graph can show the right
* connection status (edge colors) and path animation.
*
* ## State flow
*
* Nodes report lifecycle (updating / error / paused) via useSyncConnectionStatus(id, state).
* This hook updates FlowContext sets; edges read them via getConnectionStatus() in connectionStatus.ts.
* See lib/graph/state.ts for the overall state flow (graph state, connection path state).
*
* ## Lifecycle phases (conceptual)
*
* - **Idle** Node is not on an active path; edges to/from it use default style.
* - **Trigger** Node's output changed (e.g. config content, variable value). Reported
* automatically when the node calls `updateData()` from useAbstractNode. Downstream
* path is computed from triggers + updating nodes.
* - **Updating** Node is doing async work (e.g. renderer loading, agent run triggered by renderer).
* Report `updating: true` at start, `updating: false` when done. Incoming/outgoing
* edges on the path show "updating" (blue).
* - **Paused** Node is on hold (e.g. renderer in manual mode waiting for Run after inputs changed).
* Report `paused: true` when waiting, `paused: false` when not. Edges in the paused
* segment show "paused" (yellow).
* - **Error** Node has an error to show. Report `error: true` when error is set,
* `error: false` when cleared. Incoming edges to this node show "error" (red).
* - **Idle** Node is not on an active path; edges use default style.
* - **Trigger** Node's output changed; path is computed from triggers + updating nodes.
* - **Updating** Node is doing async work. Report `updating: true` → false. Path edges show blue.
* - **Paused** Node is on hold (e.g. manual mode waiting for Run). Report `paused: true` → false. Segment shows yellow.
* - **Error** Node has an error. Report `error: true` → false. Incoming edges show red.
*
* ## Connection status integration
*
* Edge status is derived in getConnectionStatus() from the sets that this lifecycle
* feeds: connectionPathUpdatingNodeIds, connectionPathPausedNodeIds,
* connectionPathErrorNodeIds (plus path/paused segment from graphPath). Priority:
* error > paused > updating > default.
*
* Nodes that can be updating, paused, or in error should call useSyncConnectionStatus()
* with their current state so edges update correctly.
* Priority for edge status: error > paused > updating > default.
*/
import { useContext, useEffect, useRef } from 'react'