Prompt Input
Prompt Input is a message field with attachments and a send button.
The person types into Prompt Input to send a message to the agent. It is an Input Group with a textarea, an attach button, the Model Selector menus, and a send button. Attached files show as Attachment chips above the text.
Installation#
Prompt Input is built with the Input Group, Attachment, and Dropdown Menu components.
npx shadcn@latest add @formance/input-group @formance/attachment @formance/dropdown-menuUsage#
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupTextarea,} from '@/components/ui/input-group';<form ref={formRef} onSubmit={onSubmit}> <InputGroup> <InputGroupTextarea value={text} onChange={(event) => setText(event.target.value)} placeholder="Ask the agent to change your schema…" className="p-3" /> <InputGroupAddon align="block-end"> <InputGroupButton size="icon-sm" variant="outline" aria-label="Attach files" onClick={() => inputRef.current?.click()} > <PlusIcon /> </InputGroupButton> <InputGroupButton type="submit" size="icon-sm" variant="primary" className="ml-auto" disabled={!canSend} aria-label="Send" > <ArrowUpIcon /> </InputGroupButton> </InputGroupAddon> </InputGroup></form>Attachments#
The attach button opens a hidden file input. Show each file as an Attachment in an addon with align="block-start". Give each attachment a button to remove it.
Model and effort#
Put the two Model Selector menus in the block-end addon, between the attach button and the send button. Move ml-auto from the send button to the first menu trigger. The two menus then sit next to the send button.
Keyboard#
Enter sends the message. Shift+Enter adds a new line.
onKeyDown={(event) => { if (event.key === 'Enter' && !event.shiftKey) { event.preventDefault(); formRef.current?.requestSubmit(); }}}AI SDK#
Send the text and the FileList of the file input.
sendMessage({ text, files });The route streams the reply with result.toUIMessageStreamResponse().