dynamic-input-variable.tsx


Overview

The dynamic-input-variable.tsx file provides a React component for dynamically managing input variables in a form, specifically within the context of a RAG (Retrieval-Augmented Generation) flow node. It allows users to add, remove, and configure variables that can either be references to other components or direct text inputs. The component leverages Ant Design's Form.List to handle dynamic lists, Select and Input components for user input, and supports internationalization via react-i18next.

This file is primarily responsible for the UI and logic around dynamically adding and configuring query variables that will be used elsewhere in the application flow, possibly to build queries or parameters for the RAG nodes.


Detailed Explanation

Interfaces and Enums

IProps

interface IProps {
  node?: RAGFlowNodeType;
}

VariableType (Enum)

enum VariableType {
  Reference = 'reference',
  Input = 'input',
}

Utility Function

getVariableName

const getVariableName = (type: string) =>
  type === VariableType.Reference ? 'component_id' : 'value';

Components

DynamicVariableForm

const DynamicVariableForm = ({ node }: IProps) => { ... }

FormCollapse

export function FormCollapse({
  children,
  title,
}: PropsWithChildren<{ title: string }>) { ... }

DynamicInputVariable (Default Export)

const DynamicInputVariable = ({ node }: IProps) => { ... }

Important Implementation Details


Interaction with Other Parts of the System


Visual Diagram

componentDiagram
    component DynamicInputVariable {
        +node: RAGFlowNodeType (optional)
        - uses FormCollapse
        - uses DynamicVariableForm
    }
    component FormCollapse {
        +title: string
        +children: ReactNode
        - renders Collapse (AntD)
    }
    component DynamicVariableForm {
        +node: RAGFlowNodeType (optional)
        - uses Form.List
        - uses Select (for type and references)
        - uses Input (for text input)
        - uses useBuildVariableOptions (hook)
        - handles dynamic add/remove
        - handles type change resetting fields
    }
    DynamicInputVariable --> FormCollapse : wraps
    DynamicInputVariable --> DynamicVariableForm : renders inside
    DynamicVariableForm --> useBuildVariableOptions : fetch options
    DynamicVariableForm --> Form.List : manages dynamic list
    FormCollapse --> Collapse (AntD)

Summary

The dynamic-input-variable.tsx file is a React component module designed to provide a flexible UI for managing dynamic input variables, which can either be references to other components or manual text inputs. It integrates tightly with Ant Design's form system and the RAG flow node data model, supporting internationalization and styled via CSS modules. This component is intended to be embedded within larger forms to support configuring queries or parameters dynamically in a flow-based application.


End of Documentation for dynamic-input-variable.tsx