rewrite-node.tsx

Overview

rewrite-node.tsx defines a React functional component called RewriteNode, which represents a custom node within a flowchart or workflow editor UI built using the @xyflow/react library. This component visually renders a node with two connection handles (input/output points), a header, and a label indicating the selected language model (LLM).

The node is styled dynamically based on the current UI theme (light or dark) and selection state. It integrates with the wider flow-based interface by exposing connection points and rendering data-driven labels and headers.


Component: RewriteNode

Description

RewriteNode is a React component designed to be used within a flow editor UI. It displays a node with:

The component supports theming and selection highlighting, making it visually consistent with the rest of the application.

Import Dependencies

Props

The component receives props typed as NodeProps<IRewriteNode>, which extend the generic node props from @xyflow/react with data typed as IRewriteNode.

Prop

Type

Default

Description

id

string

required

Unique identifier for the node instance.

data

IRewriteNode

required

Object containing node-specific data (name, label, form, etc.).

isConnectable

boolean

true

Enables or disables the ability to create connections from this node.

selected

boolean

false

Indicates if this node is currently selected in the UI.

Return Value

Returns JSX markup representing the node UI.

Usage Example

import { RewriteNode } from './rewrite-node';

// Example node data conforming to IRewriteNode interface
const exampleNodeData = {
  name: 'Rewrite',
  label: 'Text Rewriter',
  form: {
    llm_id: 'gpt-4',
  },
};

<RewriteNode
  id="node-1"
  data={exampleNodeData}
  isConnectable={true}
  selected={false}
/>;

Implementation Details


Interaction with Other Parts of the System


Mermaid Component Diagram

componentDiagram
    component RewriteNode {
      +id: string
      +data: IRewriteNode
      +isConnectable: boolean
      +selected: boolean
      --
      +Render handles (Left & Right)
      +Render NodeHeader
      +Render LLMLabel
      +Apply theme styles
    }
    component NodeHeader {
      +id: string
      +name: string
      +label: string
    }
    component LLMLabel {
      +value: string
    }
    component Handle {
      +id: string
      +type: "source"
      +position: Position.Left | Position.Right
      +isConnectable: boolean
      +style: CSSProperties
    }
    RewriteNode --> Handle : uses (2 instances)
    RewriteNode --> NodeHeader : uses
    RewriteNode --> LLMLabel : uses
    RewriteNode --> useTheme : uses

Summary

The rewrite-node.tsx file provides a reusable React component tailored for a visual flow editor. It encapsulates node UI logic, including connection handles, theming, and displaying relevant node metadata such as name, label, and associated language model. By leveraging modular components and styles, it integrates seamlessly into the broader system supporting visual flow construction and management.