fIx: smaller nits

This commit is contained in:
2026-03-20 00:04:46 +01:00
parent bc67d01bc2
commit c3cbe35883
21 changed files with 2093 additions and 116 deletions

View File

@@ -2,6 +2,57 @@
* runs the resolve → render pipeline, manages streaming/cache,
* and exposes derived state for the dumb UI. See lib/graph/rendering.ts for the
* pipeline interface.
*
* ## Auto vs Manual Mode Decision Tree
*
* The hook supports two update modes: 'auto' and 'manual'. The mode is determined by:
*
* 1. **Node data override**: Check `data?.updateMode` first
* 2. **Source logic default**: Fall back to `sourceLogic?.defaultUpdateMode`
* 3. **Hardcoded default**: Default to 'auto' if neither is set
*
* ### Auto Mode Behavior
* - Runs automatically when upstream data changes (sourceSignature changes)
* - Debounces runs by 250ms to avoid excessive computation
* - Skips runs when node becomes visible with cache (visibility grace period: 400ms)
* - Updates path trigger on each run
*
* ### Manual Mode Behavior
* - Only runs when `runTrigger` increments (user clicks "Run")
* - Requires explicit user action to update output
* - Caches last run signature to prevent re-runs on unrelated changes
*
* ## Effect Dependencies
*
* The main effect depends on:
* - `id`: Node ID (re-run when node changes)
* - `srcId`: Source node ID (re-run when connection changes)
* - `srcNode?.type`: Source node type (re-run when source type changes)
* - `effectiveUpdateMode`: Auto vs manual mode
* - `runTrigger`: Run trigger counter (for manual mode)
* - `sourceSignature`: Combined signature of all upstream nodes
* - `viewportWidth/Height`: Viewport dimensions (affects rendering)
* - `retryCount`: Retry counter (for error recovery)
* - `incomingIds.length`: Number of incoming connections
*
* ## Rendering Pipeline
*
* 1. **Resolve**: Source node (config/agent) produces resolved content
* 2. **Render**: Output type renderer (plantuml/markdown/wireframe) produces HTML/SVG
* 3. **Cache**: Results are cached in node data for persistence
* 4. **Display**: UI consumes the rendered content
*
* ## Streaming Support
*
* When the source node supports streaming (e.g., agent nodes):
* - `onStreamingStart`: Called when streaming begins
* - `onStreamingChunk`: Called for each chunk of markdown content
* - Streaming content is parsed with marked.js for preview
*
* ## Error Handling
*
* Errors during resolve or render are caught and stored in the `error` state.
* The error includes a `kind` (e.g., 'render', 'no-content') and `message`.
*/
import { useCallback, useDeferredValue, useEffect, useMemo, useRef, useState } from 'react'