rewrite-node.tsx


Overview

The rewrite-node.tsx file defines a React functional component called RewriteNode used to render a specialized node within a graphical flow editor interface. This node visually represents a "rewrite" operation or entity in the flow and integrates with the XYFlow library for node-based UIs. The component supports theming, connection handles for graph edges, and dynamic labeling based on node data.

Key features include:

This file is a UI component primarily responsible for displaying a rewrite node within a larger flow or graph editor application.


Detailed Explanation

Imports


InnerRewriteNode Component

function InnerRewriteNode({
  id,
  data,
  isConnectable = true,
  selected,
}: NodeProps<IRewriteNode>) { ... }

Purpose

Renders the UI for a single rewrite node in the flow graph, including connection handles, header, and LLM label.

Parameters

Return Value

Returns a JSX element representing the node structure with two handles (left and right), a header, and an LLM label.

Usage Example

<RewriteNode
  id="node-123"
  data={{
    name: "Rewrite Step",
    label: "Rewrite",
    form: { llm_id: "llm-456" }
  }}
  isConnectable={true}
  selected={false}
/>

Implementation Details


Exported Component

export const RewriteNode = memo(InnerRewriteNode);

Interaction with Other Parts of the System


Important Implementation Notes


Visual Diagram

componentDiagram
    direction TB
    component RewriteNode {
        +id: string
        +data: IRewriteNode
        +isConnectable?: boolean
        +selected?: boolean
        +Render()
    }

    RewriteNode --> HandleLeft: position=Left, id="c"
    RewriteNode --> HandleRight: position=Right, id="b"
    RewriteNode --> NodeHeader
    RewriteNode --> LLMLabel
    RewriteNode --> useTheme

Summary

The rewrite-node.tsx file defines a React component that visually represents a rewrite operation node within a flow editor. Its key responsibilities are rendering connection handles, displaying node metadata, adapting to UI themes, and showing associated LLM labels. It integrates tightly with XYFlow for graph interactions and uses modular components and styles for maintainability and clarity. The component is optimized for performance through memoization.

This component serves as a building block in a larger flow-based application, enabling users to construct, view, and interact with rewrite nodes as part of complex workflows.