create-agent-form.tsx


Overview

The create-agent-form.tsx file defines a React component responsible for rendering a form interface to create or configure an "Agent" or related flow entity in the application. It leverages React Hook Form combined with Zod for schema validation to ensure user inputs meet expected criteria. The form supports selecting a flow type (Agent or Router) and entering metadata such as name, description, and tags.

This file primarily manages user input collection and validation, providing UI controls for flow type selection via custom cards and a standardized form input for the agent's name. It integrates internationalization for labels and supports conditional rendering based on props.


Exports

Types


Components and Functions

FlowTypeCards

A presentational component rendering selectable cards for each flow type defined in the FlowType enum. It allows users to pick between available flow types visually.

Props:

Name

Type

Description

value

FlowType (optional)

The currently selected flow type

onChange

(value: FlowType) => void (optional)

Callback function invoked when a flow type is selected

Behavior:

Usage example:

<FlowTypeCards
  value={FlowType.Agent}
  onChange={(newType) => console.log('Selected flow type:', newType)}
/>

FormSchema

A Zod schema defining validation rules for the form inputs:

Purpose: Ensures form data adheres to expected structure and constraints before submission.


CreateAgentForm

The main exported React component rendering the complete form for creating an agent or flow.

Props:

Name

Type

Description

hideModal

() => void (optional)

Function to close/hide the modal containing this form

onOk

`(data: FormSchemaType) => Promise<boolean

void>` (optional)

shouldChooseAgent

boolean (optional)

Whether to show the flow type selection cards

Internal Details:

Rendered Form Structure:

Usage example:

<CreateAgentForm
  shouldChooseAgent={true}
  onOk={async (data) => {
    console.log('Form submitted:', data);
    return true; // close modal
  }}
  hideModal={() => console.log('Modal closed')}
/>

Important Implementation Details


Interaction with Other System Parts


Visual Diagram

componentDiagram
    direction LR
    CreateAgentForm -- uses --> Form
    CreateAgentForm -- uses --> FlowTypeCards
    CreateAgentForm -- uses --> NameFormField
    FlowTypeCards -- renders --> Card
    FlowTypeCards -- renders --> CardContent
    CardContent -- onClick --> onChange (FlowTypeCards callback)
    CreateAgentForm -- manages --> FormSchema (Zod validation)
    CreateAgentForm -- triggers --> onOk (prop callback)
    CreateAgentForm -- triggers --> hideModal (prop callback)

Summary

The create-agent-form.tsx file provides a modular, validated, and localized form interface for creating flow agents in the system. It combines UI components, form validation, and user interaction patterns to deliver a clean experience for selecting flow types and entering agent metadata. Its design promotes reusability and maintainability by leveraging shared schemas and components.

This component fits into a larger modal/dialog system and relies on external props for controlling visibility and handling form submission side effects. It emphasizes user-friendly selection and input entry with real-time validation feedback.


Appendix: Key Types and Interfaces

export type CreateAgentFormProps = IModalProps<any> & {
  shouldChooseAgent?: boolean;
};

export type FormSchemaType = z.infer<typeof FormSchema>;

Appendix: Main Enums (from ./constant)

export enum FlowType {
  Agent = 'Agent',
  Router = 'Router',
}

End of Documentation for create-agent-form.tsx