dynamic-prompt.tsx


Overview

dynamic-prompt.tsx defines a React functional component named DynamicPrompt that provides a dynamic form interface for managing a list of conversational prompts. Each prompt comprises a role (either "User" or "Assistant") and associated content, editable via a rich text editor component.

This component leverages React Hook Form (react-hook-form) for form state management, allowing users to add, edit, and remove prompt entries dynamically. It integrates with UI components from the project’s design system for consistent styling and accessibility.

This file is primarily used in contexts where users need to configure or edit a sequence of message prompts, such as in a chatbot workflow or conversational AI setup.


Detailed Description

Imports and Dependencies


Constants

const options = [
  { label: 'User', value: PromptRole.User },
  { label: 'Assistant', value: PromptRole.Assistant },
];

Component: DynamicPrompt

const DynamicPrompt = () => { ... }

Purpose

Renders a dynamic list of prompt entries, each with:

Also provides an "Add" button to append a new prompt with default values.

Usage Example

import DynamicPrompt from './dynamic-prompt';

function MyForm() {
  // Assume react-hook-form provider is wrapped at a higher level
  return (
    <form>
      <DynamicPrompt />
      {/* other form fields */}
    </form>
  );
}

Internal Logic and Hooks

JSX Structure

Props and Bindings

Return Value


Methods and Functions

The file contains only one main React component function:

DynamicPrompt()

Aspect

Description

Parameters

None

Returns

JSX Element

Side Effects

Uses hooks (useFormContext, useFieldArray, useTranslation)

Usage

Used inside a form managed by react-hook-form


Important Implementation Details


Interactions with Other System Parts

This file likely interacts with a larger conversational AI or chatbot workflow editor where users define messages that drive interactions.


Mermaid Component Diagram

componentDiagram
    component DynamicPrompt {
        +render()
        -fields: array
        -append(prompt)
        -remove(index)
    }
    component FormField {
        +render({field})
    }
    component RAGFlowSelect
    component PromptEditor
    component Button
    component FormItem
    component FormLabel
    component FormMessage

    DynamicPrompt --> FormField : manages prompt role & content fields
    FormField --> RAGFlowSelect : renders role select dropdown
    FormField --> PromptEditor : renders prompt content editor
    DynamicPrompt --> Button : remove prompt button
    DynamicPrompt --> Button : add prompt button
    DynamicPrompt --> FormItem : main form container
    FormItem --> FormLabel
    FormItem --> FormMessage

Summary

dynamic-prompt.tsx is a reusable React component that provides a dynamic, localized, and well-structured UI for editing a list of conversational prompts with roles and content. It integrates tightly with react-hook-form for form state management and uses project-specific UI components for a consistent look and feel. The component supports adding and removing prompt entries interactively and uses memoization for performance optimization. It is a core building block for workflows involving message prompt configuration.