Ai · AIChatInput
AIChatInput
Input box used in AI chat scenarios

Usage Scenarios

In AI chat scenarios, users can use AIChatInput to achieve rich text input, uploading, quoting, suggestions, templates, feature configuration, and rich custom display.
AIChatInput's rich text input is based on tiptap (https://tiptap.dev/docs/editor/getting-started/overview), a modern rich text editor development framework that supports mainstream front-end frameworks such as React and Vue, and boasts strong customizability and extensibility. Its componentization capabilities are excellent, performance is high, it has many built-in commonly used extensions, and it supports user-defined nodes, commands, plugins, and menus, enabling flexible adaptation and expansion of rich text input capabilities in complex AI scenarios. Semi's AIChatInput component encapsulates tiptap, allowing developers to use it out of the box or extend it as needed according to business requirements.

Demos

How to import

Basic Usage

Supports text input and file upload. You can configure the following parameters as needed:
  • uploadProps: Configure parameters related to file upload. See UploadProps
  • onUploadChange: Callback when file upload changes
  • placeholder: Placeholder for the input box
  • defaultContent: Default content for the input box
  • onContentChange: Callback when the content of the input box changes; the parameter is the current content

Message Sending

When there is content in the input box (including text entry, uploaded content, reference content), sending messages is allowed. Clicking the send message button triggers the onMessageSend callback; the argument is the input content, including text, reference content, uploaded files, and configuration area content.
You can manage generating status with generating. If generating is true, AIChatInput will show a stop-generating button instead of the send button and clear the input area as well as uploaded files. References require manual handling.
Clicking the stop button triggers onStopGenerate, where you can handle logic such as setting generating to false.

Rich Text Input

AIChatInput uses tiptap for its rich text editor. You can enter text, use built-in extensions (including input-slot, select-slot, skill-slot), or extend with your own.
  • input-slot: Supports text input and placeholder display.
  • select-slot: Supports in-box option selection with string options.
  • skill-slot: For skill display blocks.
You can set input content with the setContent ref method and focus the editor with focusEditor.

Reference

You can pass in references via the references, which will display at the top of the input box.
  • renderReference: Custom renderer for an individual reference.
  • onReferenceDelete: Callback for deleting a reference.
  • onReferenceClick: Callback for clicking a reference.

Configuration Area

You can configure options such as model parameters, web search, and critical thinking through the configuration area, or display/view MCP tools.
  • renderConfigureArea: Custom renderer for config area buttons.
  • Use Configure components such as Select, Button, Mcp, RadioButton, etc.
The Configure component manages the state and provides a callback via onConfigureChange (make sure to set the unique field). For initial values, use initValue.
You can also use getConfigureItem to adapt your custom components.
You can extend any custom component for configuration using getConfigureItem.
Demo:

Action Area

The lower right corner is the action area. Use renderActionArea to customize buttons (e.g. for deleting or other operations).

Button Shape

You can use the round API to configure the button shape at the bottom. The default is true (rounded). Set it to false for square buttons.

Suggestions

Configure suggestions with the suggestion API. This works similarly to the AutoComplete component. Users can dynamically show suggestions based on input.
Use up/down keys to navigate suggestions. Pressing ESC or clicking outside the suggestion/input area will close the suggestions. You can customize rendering using renderSuggestionItem.

Skills & Templates

Configure a skill list with skills, and use skillHotKey to set the shortcut for skill panel.
  • skills sample format:
Because templates can be displayed in a variety of ways, we don't provide a default display method. Users can customize the template display through the renderTemplate API. The template panel can be displayed and closed by clicking the template button.

Custom Top Slot

Users can customize the top rendering area using the renderTopSlot API, rendering references, uploaded content, and configuration items. This can be combined with the showReference and showUploadFile APIs to control whether references and uploaded files are displayed. Additionally, the topSlotPosition API allows you to configure the relative position of customized rendered content relative to the reference and upload display areas.
Usage examples are as follows:

Custom Extensions

Rich text areas support custom extensions. For implementation details, see Tiptap Custom Extensions. Custom extensions can be added to the AIChatInput component using the extensions API. If you add a custom extension, you must configure the corresponding transformation rules in transformer to ensure that the data returned in onContentChange matches your expectations.

API Reference

AIChatInput

PropDescriptionTypeDefault
canSendWhether sending is allowed. If not set, sending depends on input, uploads, and referencesbooleantrue
classNameCustom class namestring-
defaultContentDefault input content, supports html string or Tiptap contentTiptapContent-
dropdownMatchTriggerWidthShould dropdown width match input?booleantrue
extensionsCustom editor extensionsExtension[]-
generatingIs it generating?booleanfalse
onContentChangeCallback when input content changes(content:
OnContentChangeProps
) => void
-
onMessageSendCallback for sending message(content:
OnMessageSendProps
) => void
-
onReferenceClickCallback for clicking a reference(reference: Reference) => void-
onReferenceDeleteCallback for deleting a reference(reference: Reference) => void-
onSkillChangeCallback for switching skills(skill: Skill) => void-
onStopGenerateCallback for stop generate() => void-
onSuggestClickCallback for clicking a suggestion(suggestion: Suggestion) => void-
onTemplateVisibleChangeCallback for template's visibility change(visible: boolean) => void-
onUploadChangeCallback for file upload(props: OnChangeProps) => void-
popoverPropsPopup configurationPopoverProps-
placeholderInput placeholderstring-
referencesReference listReference[]-
renderActionAreaCustom bottom-right operation area() => React.ReactNode-
renderConfigureAreaCustom configuration area() => React.ReactNode-
renderReferenceCustom render reference(reference: Reference) => ReactNode-
renderSkillItemCustom skill list item renderer(props:
RenderSkillItemProps
) => React.ReactNode
-
renderSuggestionItemCustom suggestion item renderer(props:
RenderSkillItemProps
) => React.ReactNode
-
renderTemplateCustom template renderer(skill: Skill, onTemplateClick: (content: string) => void) => React.ReactNode-
renderTopSlotCustom top slot renderer() => React.ReactNode-
roundWhether config/action areas have rounded stylebooleantrue
onBlurCallback when input blurs(event: React.FocusEvent) => void-
onConfigureChangeCallback for configuration area changes(value: LeftMenuChangeProps, changedValue: LeftMenuChangeProps) => void-
onFocusCallback when input focused(event: React.FocusEvent) => void-
showReferenceShow reference areabooleantrue
showTemplateButtonShow template buttonbooleanfalse
showUploadFileShow upload file areabooleantrue
skillHotKeySkill panel trigger shortcutstring-
skillsSkill listSkill[]-
styleCustom styleReact.CSSProperties-
suggestionsSuggestions listSuggestion[]-
templatesClsThe template's style class namestring-
templatesStyleTemplate styleReact.CSSProperties-
topSlotPositionTop slot position: relative to reference and uploads'top' | 'bottom' | 'middle'-
transformerCustomizing the conversion rules for extensionsMap<string, (obj: any) => any>
uploadPropsUpload configurationUploadProps-
uploadTipPropsUpload tip configurationUploadTipProps-

Methods

MethodDescriptionTypeDefault
changeTemplateVisibleToggle visibility of the template popup(visible: boolean) => void-
deleteContentDelete an item in the rich text. The deletion logic depends on the uniqueKey in the content.(content: Content) => void-
deleteUploadFileDelete an item in the uploaded file(item: Attachment) => void-
focusEditorFocus the input box. By default, the focus is on the end of the input box.(pos?: string) => void-
getEditorGet the current tiptap editor instance() => Editor-
setContentSet input box content(content: TiptapContent) => void-
setContentWhileSaveToolSet the input box content while retaining the skill item(content: TiptapContent) => void-

Design Tokens