keyword-node.tsx

Overview

keyword-node.tsx defines a React functional component that renders a specialized node UI element, called KeywordNode, for a flow-based interface. This node visually represents a keyword entity within a graph or flow editor, displaying its name, label, and associated language model (LLM) information. It supports interactive connection handles to link with other nodes, and dynamically adapts its styling based on theme and selection state.

The component leverages hooks and utilities from the surrounding application ecosystem and a third-party flow library (@xyflow/react) to integrate seamlessly into a node-based workflow editor.


Detailed Explanation

Exports


InnerKeywordNode Component

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

Purpose

Renders the visual structure of a keyword node, including:

Parameters

Return Value

A React element representing the keyword node UI.

Usage Example

import { KeywordNode } from './keyword-node';

const nodeData = {
  name: 'Keyword Node 1',
  label: 'Important',
  form: { llm_id: 'llm-123' },
};

<KeywordNode
  id="node-1"
  data={nodeData}
  isConnectable={true}
  selected={false}
/>

Implementation Details


Imported Modules and Their Roles

Import

Purpose

LLMLabel

Displays language model label based on llm_id.

useTheme

Provides current UI theme to apply conditional styling.

IKeywordNode

Type interface for the keyword node data.

{ Handle, NodeProps, Position } from @xyflow/react

Core building blocks for node handles and props typing.

classNames

Utility to conditionally join CSS class names.

get from lodash

Safe getter for nested properties (data.form.llm_id).

memo from react

Optimization to memoize the component.

LeftHandleStyle, RightHandleStyle

Inline styles for left and right handles respectively.

styles from ./index.less

CSS module for scoped styling.

NodeHeader

Subcomponent rendering the node's header information.


Interaction with Other Parts of the System


Visual Diagram

classDiagram
    class InnerKeywordNode {
        +id: string
        +data: IKeywordNode
        +isConnectable: boolean
        +selected: boolean
        +render(): JSX.Element
    }

    class KeywordNode {
        +InnerKeywordNode
        +memoizedRender(): JSX.Element
    }

    InnerKeywordNode <|-- KeywordNode

    class Handle {
        +id: string
        +type: "source" | "target"
        +position: Position
        +isConnectable: boolean
        +className: string
        +style: React.CSSProperties
    }

    class NodeHeader {
        +id: string
        +name: string
        +label: string
        +render(): JSX.Element
    }

    class LLMLabel {
        +value: string
        +render(): JSX.Element
    }

    InnerKeywordNode o-- Handle : "2 instances (left and right)"
    InnerKeywordNode o-- NodeHeader : "1 instance"
    InnerKeywordNode o-- LLMLabel : "1 instance"

Summary

This file is a key UI building block for constructing interactive and visually consistent node-based workflows involving keyword data and language models.