rewrite-node.tsx


Overview

rewrite-node.tsx defines a React functional component named RewriteNode which represents a specialized node within a visual flow or graph-based editor (likely part of a workflow or automation UI). This node visually encapsulates rewrite logic or configuration data (IRewriteNode) and integrates with the XYFlow React library for node-based workflows. It supports theming, connection handles for graph edges, and displays metadata such as the node's name, label, and a linked LLM (Large Language Model) identifier.

This file's primary purpose is to render the UI and interaction points of a "rewrite" node, making it visually distinct, selectable, and connectable within a larger flow diagram.


Detailed Explanation

Imports


Component: InnerRewriteNode

Declaration

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

Props

Returns

A React element representing the node UI.

Description

Usage Example

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

const exampleNodeData = {
  name: 'Rewrite Step',
  label: 'Rewrite Logic',
  form: { llm_id: 'llm-1234' },
};

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

Exported Component: RewriteNode

This is a memoized version of InnerRewriteNode to prevent unnecessary re-renders when props have not changed.

export const RewriteNode = memo(InnerRewriteNode);

Implementation Details


System Interaction


Visual Diagram

componentDiagram
    RewriteNode <|-- InnerRewriteNode
    InnerRewriteNode o-- Handle : leftHandle("c")
    InnerRewriteNode o-- Handle : rightHandle("b")
    InnerRewriteNode o-- NodeHeader
    InnerRewriteNode o-- LLMLabel
    InnerRewriteNode ..> useTheme
    InnerRewriteNode ..> classNames
    Handle <|-- @xyflow/react
    NodeHeader <|-- ./node-header
    LLMLabel <|-- @/components/llm-select/llm-label

Summary

rewrite-node.tsx provides a memoized React component designed for rendering a "rewrite" node within a workflow graph. It supports connection handles on both sides, adapts to dark/light themes, displays key node metadata, and integrates smoothly with the XYFlow node ecosystem. Its main role is UI representation and interaction points for rewrite logic nodes in a larger flow editor application.