index.tsx

Overview

The index.tsx file defines a React functional component named BedrockModal. This component renders a modal dialog form that collects configuration details required to add a new Bedrock Large Language Model (LLM) connection. It is part of a UI settings module that allows users to input necessary credentials and parameters for integrating Bedrock LLMs into the application.

The modal form includes fields such as model type, model name, AWS Bedrock access keys, region selection, and token limits. It uses Ant Design (antd) components for UI elements and form management, along with a custom translation hook for internationalization. The component validates user inputs, handles form submission, and displays external links for user guidance.


Detailed Documentation

Component: BedrockModal

A React functional component that renders a modal dialog containing a form to add or configure a Bedrock LLM integration.

Props

interface IModalProps<T> {
  visible: boolean;                      // Controls modal visibility
  hideModal: () => void;                 // Callback to close the modal
  onOk?: (data: T) => void;              // Callback fired on successful form submission
  loading?: boolean;                     // Loading state for the OK button
}

interface BedrockModalProps extends IModalProps<IAddLlmRequestBody> {
  llmFactory: string;                    // Identifier for the LLM factory type
}

Internal Types

type FieldType = IAddLlmRequestBody & {
  bedrock_ak: string;           // AWS access key
  bedrock_sk: string;           // AWS secret key
  bedrock_region: string;       // AWS region
};

This type extends the base interface IAddLlmRequestBody by adding Bedrock-specific credentials and region information.

Hooks and State

Methods

handleOk(): Promise<void>
const handleOk = async () => {
  const values = await form.validateFields();
  const data = {
    ...values,
    llm_factory: llmFactory,
    max_tokens: values.max_tokens,
  };
  onOk?.(data);
};

Rendered Elements

Each field uses validation rules including required checks and custom validators (e.g., max_tokens must be a non-negative number).

Usage Example

<BedrockModal
  visible={isModalVisible}
  hideModal={() => setModalVisible(false)}
  onOk={(data) => console.log('Submitted data:', data)}
  loading={isSubmitting}
  llmFactory="Bedrock"
/>

Important Implementation Details


Interaction with Other Parts of the System


Visual Diagram

componentDiagram
    component BedrockModal {
        +visible: boolean
        +hideModal(): void
        +onOk(data: IAddLlmRequestBody): void
        +loading: boolean
        +llmFactory: string
        +handleOk(): Promise<void>
    }

    component Form {
        +model_type: Select ("chat" | "embedding")
        +llm_name: Input (string)
        +bedrock_ak: Input (string)
        +bedrock_sk: Input (string)
        +bedrock_region: Select (string)
        +max_tokens: InputNumber (number)
        +validateFields(): Promise<FieldType>
    }

    BedrockModal --> Form : renders
    BedrockModal --> useTranslate : uses for i18n
    BedrockModal --> BedrockRegionList : uses for region options
    BedrockModal --> Modal : container dialog

Summary

The index.tsx file implements the BedrockModal React component, a user interface modal dialog for adding Bedrock LLM configurations. It features a form with validation, internationalized labels, and integration with AWS Bedrock regions and credentials. The component is designed to be reusable and composable within a broader settings UI, allowing users to safely input and submit LLM connection details. The code leverages Ant Design for UI consistency and React hooks for state and performance optimizations.