interface.ts

Overview

This file interface.ts defines TypeScript interfaces and types used to standardize data structures related to form handling, parameter generation, and query definition within the application. The interfaces encapsulate shapes of objects passed around components, especially those dealing with UI forms (using antd library) and flow nodes (likely representing workflow or graph nodes).

The file primarily serves as a shared set of contracts to ensure consistency and type safety across various parts of the system that handle operator forms, parameter generation, variable invocation, UI positioning, and query beginnings.


Interfaces and Types

1. IOperatorForm

Represents the props or data related to an operator form component in the UI, including callbacks and references to form and node data.

export interface IOperatorForm {
  onValuesChange?(changedValues: any, values: any): void;
  form?: FormInstance;
  node?: RAGFlowNodeType;
  nodeId?: string;
}

Properties

Usage Example

const MyOperatorForm: React.FC<IOperatorForm> = ({ form, node, onValuesChange }) => {
  return (
    <Form form={form} onValuesChange={onValuesChange}>
      {/* form fields based on node */}
    </Form>
  );
};

2. IGenerateParameter

Defines the shape for generated parameters used in the system, likely for dynamic components or invocation.

export interface IGenerateParameter {
  id?: string;
  key: string;
  component_id?: string;
}

Properties

Usage Example

Used to define parameters passed when generating or configuring components dynamically.

const param: IGenerateParameter = {
  key: 'timeout',
  component_id: 'timer-component',
};

3. IInvokeVariable

Extends IGenerateParameter by adding an optional value field. Used when invoking or binding variables.

export interface IInvokeVariable extends IGenerateParameter {
  value?: string;
}

Properties

Usage Example

Represents variable parameters with their assigned values during invocation or runtime.

const variable: IInvokeVariable = {
  key: 'username',
  value: 'john_doe',
};

4. IPosition

A simple type alias for UI positioning, describing coordinates and an index.

export type IPosition = { top: number; right: number; idx: number };

Properties

Usage Example

Used for positioning UI elements such as nodes or components on a canvas.

const position: IPosition = { top: 100, right: 50, idx: 2 };

5. BeginQuery

Describes the parameters required to begin a query, including type, key, value, and options.

export interface BeginQuery {
  key: string;
  type: string;
  value: string;
  optional: boolean;
  name: string;
  options: (number | string | boolean)[];
}

Properties

Usage Example

Used to define the schema or parameters for starting a query operation.

const queryParam: BeginQuery = {
  key: 'limit',
  type: 'number',
  value: '10',
  optional: false,
  name: 'Result Limit',
  options: [10, 20, 50, 100],
};

Important Implementation Details


Interaction with Other System Parts


Mermaid Class Diagram

classDiagram
    class IOperatorForm {
        +onValuesChange?(changedValues: any, values: any): void
        +form?: FormInstance
        +node?: RAGFlowNodeType
        +nodeId?: string
    }

    class IGenerateParameter {
        +id?: string
        +key: string
        +component_id?: string
    }

    class IInvokeVariable {
        +value?: string
    }

    class BeginQuery {
        +key: string
        +type: string
        +value: string
        +optional: boolean
        +name: string
        +options: (number | string | boolean)[]
    }

    IInvokeVariable --|> IGenerateParameter : extends

Summary

This file interface.ts provides foundational data contracts for form handling, parameter generation, and query initiation within a system that integrates UI forms (Ant Design) and workflow nodes. It enhances type safety and clarity for developers working on operator forms and parameter-driven components. The interfaces are designed to interact closely with the system's flow nodes and UI elements, ensuring consistent and maintainable data structures throughout the application.