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 UploadPropsonUploadChange: Callback when file upload changesplaceholder: Placeholder for the input boxdefaultContent: Default content for the input boxonContentChange: 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
Configurecomponents such asSelect,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.skillssample 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
| Prop | Description | Type | Default |
|---|---|---|---|
| canSend | Whether sending is allowed. If not set, sending depends on input, uploads, and references | boolean | true |
| className | Custom class name | string | - |
| defaultContent | Default input content, supports html string or Tiptap content | TiptapContent | - |
| dropdownMatchTriggerWidth | Should dropdown width match input? | boolean | true |
| extensions | Custom editor extensions | Extension[] | - |
| generating | Is it generating? | boolean | false |
| onContentChange | Callback when input content changes | (content: OnContentChangeProps | - |
| onMessageSend | Callback for sending message | (content: OnMessageSendProps | - |
| onReferenceClick | Callback for clicking a reference | (reference: Reference) => void | - |
| onReferenceDelete | Callback for deleting a reference | (reference: Reference) => void | - |
| onSkillChange | Callback for switching skills | (skill: Skill) => void | - |
| onStopGenerate | Callback for stop generate | () => void | - |
| onSuggestClick | Callback for clicking a suggestion | (suggestion: Suggestion) => void | - |
| onTemplateVisibleChange | Callback for template's visibility change | (visible: boolean) => void | - |
| onUploadChange | Callback for file upload | (props: OnChangeProps) => void | - |
| popoverProps | Popup configuration | PopoverProps | - |
| placeholder | Input placeholder | string | - |
| references | Reference list | Reference[] | - |
| renderActionArea | Custom bottom-right operation area | () => React.ReactNode | - |
| renderConfigureArea | Custom configuration area | () => React.ReactNode | - |
| renderReference | Custom render reference | (reference: Reference) => ReactNode | - |
| renderSkillItem | Custom skill list item renderer | (props: RenderSkillItemProps | - |
| renderSuggestionItem | Custom suggestion item renderer | (props: RenderSkillItemProps | - |
| renderTemplate | Custom template renderer | (skill: Skill, onTemplateClick: (content: string) => void) => React.ReactNode | - |
| renderTopSlot | Custom top slot renderer | () => React.ReactNode | - |
| round | Whether config/action areas have rounded style | boolean | true |
| onBlur | Callback when input blurs | (event: React.FocusEvent) => void | - |
| onConfigureChange | Callback for configuration area changes | (value: LeftMenuChangeProps, changedValue: LeftMenuChangeProps) => void | - |
| onFocus | Callback when input focused | (event: React.FocusEvent) => void | - |
| showReference | Show reference area | boolean | true |
| showTemplateButton | Show template button | boolean | false |
| showUploadFile | Show upload file area | boolean | true |
| skillHotKey | Skill panel trigger shortcut | string | - |
| skills | Skill list | Skill[] | - |
| style | Custom style | React.CSSProperties | - |
| suggestions | Suggestions list | Suggestion[] | - |
| templatesCls | The template's style class name | string | - |
| templatesStyle | Template style | React.CSSProperties | - |
| topSlotPosition | Top slot position: relative to reference and uploads | 'top' | 'bottom' | 'middle' | - |
| transformer | Customizing the conversion rules for extensions | Map<string, (obj: any) => any> | |
| uploadProps | Upload configuration | UploadProps | - |
| uploadTipProps | Upload tip configuration | UploadTipProps | - |
Methods
| Method | Description | Type | Default |
|---|---|---|---|
| changeTemplateVisible | Toggle visibility of the template popup | (visible: boolean) => void | - |
| deleteContent | Delete an item in the rich text. The deletion logic depends on the uniqueKey in the content. | (content: Content) => void | - |
| deleteUploadFile | Delete an item in the uploaded file | (item: Attachment) => void | - |
| focusEditor | Focus the input box. By default, the focus is on the end of the input box. | (pos?: string) => void | - |
| getEditor | Get the current tiptap editor instance | () => Editor | - |
| setContent | Set input box content | (content: TiptapContent) => void | - |
| setContentWhileSaveTool | Set the input box content while retaining the skill item | (content: TiptapContent) => void | - |