Chat Input
The message box of a chat. Type @ to tag an agent, /to add a skill, or # to add a file. Markdown and shortcuts format text. The bar holds attach and mode menus, a project picker, a model picker, and send.
Installation
pnpm dlx shadcn@latest add https://sprout.tulipfarm.ai/r/chat-input.jsonCopies Chat Input and the components it uses (Attachment, Button, Command, Dropdown Menu, File Viewer, Hover Card, Input Group, Mention List, Model Selector, Popover, Rich Text Editor, and Tooltip) into your app, installs the packages, and adds the styles. Then import it from @/components/ui/chat-input. Needs Tailwind CSS 4 and a components.json from shadcn init.
Install the following dependencies:
pnpm add clsx tailwind-merge @hugeicons/core-free-icons @hugeicons/react @tiptap/core @tiptap/pm @tiptap/suggestionAdd Sprout base once per app: the
cn()helper and the design tokens.lib/sprout/classes.ts- Design tokens, for your global CSS
Add the components it uses: Attachment, Button, Command, Dropdown Menu, File Viewer, Hover Card, Input Group, Mention List, Model Selector, Popover, Rich Text Editor, and Tooltip.
Copy and paste the following code into your project.
'use client'; import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode, } from 'react'; import { Extension, Node, mergeAttributes, type Extensions } from '@tiptap/core'; import { PluginKey } from '@tiptap/pm/state'; import Suggestion, { exitSuggestion, type SuggestionKeyDownProps, type SuggestionProps } from '@tiptap/suggestion'; import { AddIcon } from '@/lib/sprout/icons/add-icon'; import { ArrowUpIcon } from '@/lib/sprout/icons/arrow-up-icon'; import { ChevronDownIcon } from '@/lib/sprout/icons/chevron-down-icon'; import { CloseIcon } from '@/lib/sprout/icons/close-icon'; import { FolderIcon } from '@/lib/sprout/icons/folder-icon'; import { SlidersIcon } from '@/lib/sprout/icons/sliders-icon'; import { chatReferenceChars } from '@/lib/sprout/chat-reference'; import { cn } from '@/lib/sprout/classes'; import { ReferenceHintBody, ReferencePeek, referenceDetail, referenceHover, type ChatReferenceDetail, type ChatReferenceResolved, } from '@/lib/sprout/reference-hint'; import { FileAttachment, type AttachmentFile } from '@/components/ui/attachment'; import { FileViewer, type ViewableFile } from '@/components/ui/file-viewer'; import { HoverCard } from '@/components/ui/hover-card'; import { Button } from '@/components/ui/button'; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from '@/components/ui/command'; import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { InputGroup, InputGroupAddon, InputGroupButton } from '@/components/ui/input-group'; import { MentionList, MentionOption, MentionStatus } from '@/components/ui/mention-list'; import { ModelSelector, type ModelSelectorModel } from '@/components/ui/model-selector'; import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; import { RichTextEditor, type RichTextEditorHandle, type RichTextKeyword, type RichTextValue, } from '@/components/ui/rich-text-editor'; import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'; export const chatInputReferenceKindNames = ['agent', 'skill', 'file'] as const; export const chatInputStatusNames = ['idle', 'streaming'] as const; export type ChatInputReferenceKind = (typeof chatInputReferenceKindNames)[number]; export type ChatInputStatus = (typeof chatInputStatusNames)[number]; export type ChatInputReference = ChatReferenceDetail; export type ChatInputResolvedReference = ChatReferenceResolved; export interface ChatInputSuggestion { id: string; label: string; description?: string | undefined; media?: ReactNode; file?: ViewableFile | undefined; } export type ChatInputSource = (query: string) => ChatInputSuggestion[] | Promise<ChatInputSuggestion[]>; export interface ChatInputAction { id: string; label: string; description?: string | undefined; icon?: ReactNode; onSelect: () => void; } export interface ChatInputOption { id: string; label: string; description?: string | undefined; icon?: ReactNode; color?: string | undefined; } export type ChatInputIntegration = RichTextKeyword; export type ChatInputModel = ModelSelectorModel; export interface ChatInputPrompt { id: string; label: string; icon?: ReactNode; prompt?: string | undefined; } export interface ChatInputProps { value: RichTextValue; onValueChange: (value: RichTextValue) => void; onSend: () => void; onStop?: (() => void) | undefined; status?: ChatInputStatus | undefined; placeholder?: string | undefined; streamingPlaceholder?: string | undefined; minRows?: number | undefined; disabled?: boolean | undefined; label?: string | undefined; agents?: ChatInputSource | undefined; skills?: ChatInputSource | undefined; files?: ChatInputSource | undefined; integrations?: readonly ChatInputIntegration[] | undefined; resolveReference?: ((reference: ChatInputReference) => ChatInputResolvedReference | undefined) | undefined; onConnectIntegration?: ((integration: ChatInputIntegration) => void) | undefined; onIntegrationAccountChange?: | ((integration: ChatInputIntegration, accountId: string) => void | Promise<unknown>) | undefined; attachments?: AttachmentFile[] | undefined; onRemoveAttachment?: ((id: string) => void) | undefined; attachActions?: ChatInputAction[] | undefined; modes?: ChatInputOption[] | undefined; mode?: string | null | undefined; onModeChange?: ((mode: string | null) => void) | undefined; projects?: ChatInputOption[] | undefined; project?: string | undefined; onProjectChange?: ((project: string) => void) | undefined; models?: ChatInputModel[] | undefined; model?: string | undefined; onModelChange?: ((model: string) => void) | undefined; prompts?: ChatInputPrompt[] | undefined; onPromptSelect?: ((prompt: ChatInputPrompt) => void) | undefined; className?: string | undefined; } const triggers = { agent: { char: chatReferenceChars.agent, label: 'Agents', empty: 'No agents match.' }, skill: { char: chatReferenceChars.skill, label: 'Skills', empty: 'No skills match.' }, file: { char: chatReferenceChars.file, label: 'Files', empty: 'No files match.' }, } as const satisfies Record<ChatInputReferenceKind, { char: string; label: string; empty: string }>; type PanelState = { kind: ChatInputReferenceKind; items: ChatInputSuggestion[]; active: number; select: (index: number) => void; } | null; const referenceNode = Node.create({ name: 'chatReference', inline: true, group: 'inline', atom: true, selectable: true, addAttributes() { return { kind: { default: 'file', rendered: false, parseHTML: el => el.getAttribute('data-chat-reference'), }, id: { default: '', rendered: false, parseHTML: el => el.getAttribute('data-id'), }, label: { default: '', rendered: false, parseHTML: el => el.getAttribute('data-label'), }, description: { default: null, rendered: false, parseHTML: el => el.getAttribute('data-description'), }, }; }, parseHTML() { return [{ tag: 'span[data-chat-reference]' }]; }, renderHTML({ node, HTMLAttributes }) { const kind = node.attrs.kind as ChatInputReferenceKind; return [ 'span', mergeAttributes(HTMLAttributes, { 'data-chat-reference': kind, 'data-id': node.attrs.id, 'data-label': node.attrs.label, 'data-description': node.attrs.description ?? undefined, class: 'sprout-chat-input-reference', }), `${triggers[kind]?.char ?? ''}${node.attrs.label}`, ]; }, renderText({ node }) { const kind = node.attrs.kind as ChatInputReferenceKind; return `${triggers[kind]?.char ?? ''}${node.attrs.label}`; }, }); const linkShortcut = Extension.create({ name: 'chatInputLinkShortcut', addKeyboardShortcuts() { return { 'Mod-k': ({ editor }) => { if (editor.isActive('link')) return editor.chain().focus().unsetLink().run(); const { from, to } = editor.state.selection; const text = editor.state.doc.textBetween(from, to).trim(); const href = /^\S+@\S+\.\S+$/.test(text) ? `mailto:${text}` : /^(https?:\/\/|www\.)\S+$/i.test(text) ? text.startsWith('www.') ? `https://${text}` : text : null; if (!href) return false; return editor.chain().focus().setLink({ href }).run(); }, }; }, }); function triggerExtension( kind: ChatInputReferenceKind, source: { current: ChatInputSource | undefined }, onState: (state: PanelState) => void, picked: Map<string, ChatInputSuggestion>, ) { const key = new PluginKey(`chatInput-${kind}`); return Extension.create({ name: `chatInput-${kind}`, addProseMirrorPlugins() { return [ Suggestion<ChatInputSuggestion>({ editor: this.editor, pluginKey: key, char: triggers[kind].char, allowSpaces: false, items: async ({ query }) => (await source.current?.(query)) ?? [], command: ({ editor, range, props }) => { picked.set(`${kind}:${props.id}`, props); return editor .chain() .focus() .insertContentAt(range, [ { type: 'chatReference', attrs: { kind, id: props.id, label: props.label, description: props.description ?? null }, }, { type: 'text', text: ' ' }, ]) .run(); }, render: () => { let current: SuggestionProps<ChatInputSuggestion> | null = null; let active = 0; const publish = () => { if (!current) return; const items = current.items; onState({ kind, items, active: Math.min(active, Math.max(0, items.length - 1)), select: index => { const item = items[index]; if (item) current?.command(item); }, }); }; return { onStart: props => { current = props; active = 0; publish(); }, onUpdate: props => { current = props; active = 0; publish(); }, onKeyDown: ({ event, view }: SuggestionKeyDownProps) => { if (event.key === 'Escape') { exitSuggestion(view, key); return true; } const count = current?.items.length ?? 0; if (!count) return false; if (event.key === 'ArrowDown' || event.key === 'ArrowUp') { active = (active + (event.key === 'ArrowDown' ? 1 : count - 1)) % count; publish(); return true; } if ((event.key === 'Enter' && !event.shiftKey) || event.key === 'Tab') { current!.command(current!.items[active]!); return true; } return false; }, onExit: () => { current = null; onState(null); }, }; }, }), ]; }, }); } function firstLine(element: HTMLElement) { return { getBoundingClientRect: () => element.getClientRects()[0] ?? element.getBoundingClientRect() }; } function hasContent(node: RichTextValue): boolean { if (node.type === 'chatReference') return true; if (node.text?.trim()) return true; return node.content?.some(hasContent) ?? false; } function textDoc(text: string): RichTextValue { return { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text }] }], }; } function OptionPicker({ label, search, options, value, onChange, disabled, icon, align, }: { label: string; search: string; options: ChatInputOption[]; value: string | undefined; onChange: (id: string) => void; disabled: boolean; icon: (option: ChatInputOption | undefined) => ReactNode; align: 'start' | 'end'; }) { const [open, setOpen] = useState(false); const selected = options.find(option => option.id === value); return ( <Popover open={open} onOpenChange={setOpen}> <PopoverTrigger render={ <InputGroupButton aria-label={`${label}: ${selected?.label ?? 'None'}`} disabled={disabled} className="sprout-chat-input-picker" /> } > {icon(selected)} <span className="sprout-chat-input-picker-label">{selected?.label ?? label}</span> <ChevronDownIcon size="xs" aria-hidden="true" /> </PopoverTrigger> <PopoverContent size="picker" side="top" align={align} sideOffset={8} className="sprout-chat-input-menu"> <Command> <CommandInput aria-label={search} placeholder={`${search}…`} /> <CommandList> <CommandEmpty>No matches.</CommandEmpty> <CommandGroup heading={label}> {options.map(option => ( <CommandItem key={option.id} value={`${option.label} ${option.description ?? ''}`} data-checked={option.id === value} onSelect={() => { onChange(option.id); setOpen(false); }} > {icon(option)} <span className="sprout-chat-input-option-text"> <span>{option.label}</span> {option.description && ( <span className="sprout-chat-input-option-description">{option.description}</span> )} </span> </CommandItem> ))} </CommandGroup> </CommandList> </Command> </PopoverContent> </Popover> ); } export function ChatInput({ value, onValueChange, onSend, onStop, status = 'idle', placeholder = 'Ask anything, @agents, /skills, #files…', streamingPlaceholder = 'Working on your request…', minRows, disabled = false, label = 'Message', agents, skills, files, integrations, resolveReference, onConnectIntegration, onIntegrationAccountChange, attachments = [], onRemoveAttachment, attachActions, modes, mode = null, onModeChange, projects, project, onProjectChange, models, model, onModelChange, prompts, onPromptSelect, className, }: ChatInputProps) { const editor = useRef<RichTextEditorHandle>(null); const form = useRef<HTMLFormElement>(null); const listId = useId(); const [panel, setPanel] = useState<PanelState>(null); const [panelBelow, setPanelBelow] = useState(false); const picked = useRef(new Map<string, ChatInputSuggestion>()).current; type ReferenceHint = { anchor: HTMLElement; reference: ChatReferenceDetail; resolved: ChatReferenceResolved | undefined; }; const [referenceHint, setReferenceHint] = useState<ReferenceHint | null>(null); const [viewing, setViewing] = useState<{ file: ViewableFile; open: boolean } | null>(null); const referenceTimer = useRef<ReturnType<typeof setTimeout>>(undefined); useEffect(() => () => clearTimeout(referenceTimer.current), []); const referenceAt = (target: EventTarget | null): ReferenceHint | null => { const anchor = target instanceof Element ? target.closest<HTMLElement>('.sprout-rich-text-editor-content .sprout-chat-input-reference') : null; if (!anchor) return null; const reference = referenceDetail({ kind: anchor.dataset.chatReference, id: anchor.dataset.id, label: anchor.dataset.label, description: anchor.dataset.description, }); const resolved = picked.get(`${reference.kind}:${reference.id}`) ?? resolveReference?.(reference); if (reference.kind === 'file') anchor.toggleAttribute('data-openable', !!resolved?.file); return { anchor, reference, resolved }; }; const hoverReference = (target: EventTarget | null) => { const next = referenceAt(target); clearTimeout(referenceTimer.current); if (next && referenceHover(next.reference, next.resolved)) { const show = () => setReferenceHint(current => (current?.anchor === next.anchor ? current : next)); if (referenceHover(next.reference, next.resolved) === 'peek' && referenceHint?.anchor !== next.anchor) referenceTimer.current = setTimeout(show, 300); else show(); } else referenceTimer.current = setTimeout(() => setReferenceHint(null), 80); }; const openReference = (target: EventTarget | null) => { const file = referenceAt(target)?.resolved?.file; if (!file) return; clearTimeout(referenceTimer.current); setReferenceHint(null); setViewing({ file, open: true }); }; const sources = { agent: useRef(agents), skill: useRef(skills), file: useRef(files), }; sources.agent.current = agents; sources.skill.current = skills; sources.file.current = files; const enabled = `${!!agents}${!!skills}${!!files}`; const extensions = useMemo<Extensions>( () => [ referenceNode, linkShortcut, ...chatInputReferenceKindNames .filter(kind => sources[kind].current) .map(kind => triggerExtension(kind, sources[kind], setPanel, picked)), ], [enabled], ); const streaming = status === 'streaming'; const filled = hasContent(value) || attachments.length > 0; const canSend = filled && !disabled && !streaming; const activeMode = modes?.find(option => option.id === mode); const optionId = (index: number) => `${listId}-option-${index}`; const panelOpen = !!panel; useLayoutEffect(() => { const bounds = form.current?.getBoundingClientRect(); if (panel && bounds) setPanelBelow(bounds.top < 320 && window.innerHeight - bounds.bottom > bounds.top); }, [panelOpen]); const send = () => { if (canSend) onSend(); }; const fill = (prompt: ChatInputPrompt) => { editor.current?.setContent(textDoc(prompt.prompt ?? prompt.label)); editor.current?.editor()?.commands.focus('end'); onPromptSelect?.(prompt); }; return ( <div data-slot="chat-input" data-status={status} data-mode-color={activeMode?.color ? '' : undefined} style={ activeMode?.color ? ({ '--sprout-chat-input-mode': activeMode.color, } as CSSProperties) : undefined } className={cn('sprout-chat-input', className)} > <form ref={form} aria-label={label} className="sprout-chat-input-form" onPointerOver={event => hoverReference(event.target)} onClick={event => openReference(event.target)} onPointerLeave={() => hoverReference(null)} onSubmit={event => { event.preventDefault(); send(); }} > <InputGroup variant="composer" className="sprout-chat-input-box"> {attachments.length > 0 && ( <InputGroupAddon align="block-start" className="sprout-chat-input-attachments"> {attachments.map(file => ( <FileAttachment key={file.id} file={file} variant="chip" viewable preview onRemove={onRemoveAttachment && !disabled ? () => onRemoveAttachment(file.id) : undefined} /> ))} </InputGroupAddon> )} <RichTextEditor ref={editor} minRows={minRows} value={value} onChange={next => { setReferenceHint(null); onValueChange(next); }} onSend={send} extensions={extensions} keywords={integrations} onKeywordConnect={onConnectIntegration} onKeywordAccountChange={onIntegrationAccountChange} placeholder={streaming ? streamingPlaceholder : placeholder} disabled={disabled} ariaLabel={label} ariaExpanded={!!panel} ariaControls={panel ? listId : undefined} ariaActiveDescendant={panel?.items.length ? optionId(panel.active) : undefined} className="sprout-chat-input-editor" toolbarAddon={ <div className="sprout-chat-input-bar"> <div className="sprout-chat-input-bar-start"> {attachActions && attachActions.length > 0 && ( <DropdownMenu> <Tooltip> <TooltipTrigger render={ <DropdownMenuTrigger render={ <InputGroupButton size="icon" aria-label="Add files and more" disabled={disabled} /> } /> } > <AddIcon size="md" aria-hidden="true" /> </TooltipTrigger> <TooltipContent>Add files and more</TooltipContent> </Tooltip> <DropdownMenuContent size="menu" side="top" align="start" className="sprout-chat-input-menu"> <DropdownMenuGroup> <DropdownMenuLabel>Add</DropdownMenuLabel> {attachActions.map(action => ( <DropdownMenuItem key={action.id} onClick={action.onSelect}> {action.icon} <span className="sprout-chat-input-option-text"> <span>{action.label}</span> {action.description && ( <span className="sprout-chat-input-option-description">{action.description}</span> )} </span> </DropdownMenuItem> ))} </DropdownMenuGroup> </DropdownMenuContent> </DropdownMenu> )} {modes && modes.length > 0 && ( <DropdownMenu> <Tooltip> <TooltipTrigger render={ <DropdownMenuTrigger render={ <InputGroupButton size="icon" aria-label={`Mode: ${activeMode?.label ?? 'Default'}`} disabled={disabled} /> } /> } > <SlidersIcon size="md" aria-hidden="true" /> </TooltipTrigger> <TooltipContent>Modes</TooltipContent> </Tooltip> <DropdownMenuContent size="menu" side="top" align="start" className="sprout-chat-input-menu"> <DropdownMenuGroup> <DropdownMenuLabel>Mode</DropdownMenuLabel> <DropdownMenuRadioGroup value={mode ?? ''} onValueChange={next => onModeChange?.(next === mode || !next ? null : String(next))} > {modes.map(option => ( <DropdownMenuRadioItem key={option.id} value={option.id} closeOnClick style={ option.color ? ({ '--sprout-chat-input-mode': option.color, } as CSSProperties) : undefined } className={option.color ? 'sprout-chat-input-mode-option' : undefined} > {option.icon} <span className="sprout-chat-input-option-text"> <span>{option.label}</span> {option.description && ( <span className="sprout-chat-input-option-description">{option.description}</span> )} </span> </DropdownMenuRadioItem> ))} </DropdownMenuRadioGroup> </DropdownMenuGroup> </DropdownMenuContent> </DropdownMenu> )} {activeMode && ( <InputGroupButton variant="secondary" className="sprout-chat-input-mode" aria-label={`Turn off ${activeMode.label}`} disabled={disabled} onClick={() => onModeChange?.(null)} > {activeMode.icon} <span className="sprout-chat-input-picker-label">{activeMode.label}</span> <CloseIcon size="xs" aria-hidden="true" /> </InputGroupButton> )} {projects && projects.length > 0 && ( <> <span className="sprout-chat-input-divider" aria-hidden="true" /> <OptionPicker label="Project" search="Search projects" options={projects} value={project} onChange={id => onProjectChange?.(id)} disabled={disabled} icon={option => option?.icon ?? <FolderIcon size="md" aria-hidden="true" />} align="start" /> </> )} </div> <div className="sprout-chat-input-bar-end"> {models && models.length > 0 && ( <ModelSelector models={models} value={model} onValueChange={id => onModelChange?.(id)} disabled={disabled} side="top" align="end" render={<InputGroupButton className="sprout-chat-input-picker" />} /> )} {streaming ? ( <InputGroupButton size="icon" variant="default" className="sprout-chat-input-send" aria-label="Stop" onClick={onStop} > <span className="sprout-chat-input-stop" aria-hidden="true" /> </InputGroupButton> ) : ( <InputGroupButton type="submit" size="icon" variant={canSend ? 'default' : 'secondary'} className="sprout-chat-input-send" aria-label="Send message" disabled={!canSend} > <ArrowUpIcon size="md" aria-hidden="true" /> </InputGroupButton> )} </div> </div> } /> </InputGroup> {panel && ( <div className="sprout-chat-input-panel" data-side={panelBelow ? 'bottom' : 'top'}> <MentionList id={listId} label={triggers[panel.kind].label} announcement={ panel.items.length ? `${panel.items.length} ${triggers[panel.kind].label.toLowerCase()}. Use Up and Down to choose, Enter to add, Escape to close.` : triggers[panel.kind].empty } status={ panel.items.length ? undefined : ( <MentionStatus tone="empty">{triggers[panel.kind].empty}</MentionStatus> ) } > {panel.items.map((item, index) => ( <MentionOption key={item.id} id={optionId(index)} active={index === panel.active} onSelect={() => panel.select(index)} media={item.media} title={item.label} description={item.description} /> ))} </MentionList> </div> )} </form> <HoverCard open={ !!referenceHint?.resolved?.file && referenceHover(referenceHint.reference, referenceHint.resolved) === 'peek' } onOpenChange={open => !open && setReferenceHint(null)} > {referenceHint?.resolved?.file && ( <ReferencePeek file={referenceHint.resolved.file} anchor={firstLine(referenceHint.anchor)} onPointerEnter={() => clearTimeout(referenceTimer.current)} onPointerLeave={() => hoverReference(null)} /> )} </HoverCard> {viewing && ( <FileViewer file={viewing.file} open={viewing.open} onOpenChange={open => setViewing(current => current && { ...current, open })} /> )} <Tooltip open={!!referenceHint && referenceHover(referenceHint.reference, referenceHint.resolved) === 'hint'} onOpenChange={open => !open && setReferenceHint(null)} > {referenceHint && referenceHover(referenceHint.reference, referenceHint.resolved) === 'hint' && ( <TooltipContent anchor={referenceHint.anchor} className="sprout-message-rich-text-hint" data-slot="chat-input-reference-hint" onPointerEnter={() => clearTimeout(referenceTimer.current)} onPointerLeave={() => hoverReference(null)} > <ReferenceHintBody reference={referenceHint.reference} media={referenceHint.resolved?.media} /> </TooltipContent> )} </Tooltip> {prompts && prompts.length > 0 && !filled && !streaming && ( <div role="group" aria-label="Suggested prompts" className="sprout-chat-input-prompts"> {prompts.map(prompt => ( <Button key={prompt.id} size="sm" variant="outline" disabled={disabled} className="sprout-chat-input-prompt" onClick={() => fill(prompt)} > {prompt.icon} {prompt.label} </Button> ))} </div> )} </div> ); }And the files it imports:
lib/sprout/icons/add-icon.tsxlib/sprout/icons/arrow-up-icon.tsxlib/sprout/icons/book-open-icon.tsxlib/sprout/icons/chevron-down-icon.tsxlib/sprout/icons/close-icon.tsxlib/sprout/icons/create-icon.tsxlib/sprout/icons/document-text-icon.tsxlib/sprout/icons/folder-icon.tsxlib/sprout/icons/sliders-icon.tsxlib/sprout/icons/user-icon.tsxlib/sprout/chat-reference.tslib/sprout/reference-hint.tsx
Add the styles to your global CSS, after
@import "tailwindcss".@layer components { .sprout-chat-input { box-sizing: border-box; width: 100%; min-width: 0; font-family: var(--sprout-font); flex-direction: column; gap: 12px; display: flex; } .sprout-chat-input-form { min-width: 0; position: relative; } .sprout-chat-input-attachments.sprout-input-group-addon { overscroll-behavior-x: contain; scrollbar-width: none; cursor: default; flex-wrap: nowrap; justify-content: flex-start; gap: 6px; padding: 4px 4px 0; overflow-x: auto; } .sprout-chat-input-attachments::-webkit-scrollbar { display: none; } .sprout-chat-input-attachments > * { flex-shrink: 0; } .sprout-chat-input-editor .sprout-rich-text-editor-body { min-height: 4.5rem; } .sprout-chat-input-editor .sprout-rich-text-editor-content { font-size: var(--sprout-text-base); line-height: 1.625; } .sprout-chat-input-reference { border-radius: var(--sprout-radius-control); background: color-mix(in oklab, var(--sprout-text) 8%, transparent); color: var(--sprout-text); white-space: nowrap; -webkit-box-decoration-break: clone; box-decoration-break: clone; padding: 0 .4375em; font-weight: 500; } .sprout-chat-input-reference[data-openable] { cursor: pointer; } .sprout-chat-input-reference[data-chat-reference="agent"] { background: var(--sprout-info-subtle); color: var(--sprout-info); } .sprout-chat-input-reference.ProseMirror-selectednode { outline: var(--sprout-focus-width) solid var(--sprout-focus-ring); outline-offset: 0; } .sprout-chat-input-editor .sprout-rich-text-editor-content a { color: var(--sprout-info); text-underline-offset: 2px; text-decoration: underline; } .sprout-chat-input-bar { flex: 1; justify-content: space-between; align-items: center; gap: 8px; min-width: 0; display: flex; } .sprout-chat-input-bar-start, .sprout-chat-input-bar-end { align-items: center; gap: 2px; min-width: 0; display: flex; } .sprout-chat-input-bar-end { flex-shrink: 0; gap: 6px; } .sprout-chat-input-divider { background: var(--sprout-line); align-self: center; width: 1px; height: 20px; margin-inline: 6px; } .sprout-chat-input-bar .sprout-input-group-button[data-variant="ghost"] { color: var(--sprout-muted); } @media (hover: hover) { .sprout-chat-input-bar .sprout-input-group-button[data-variant="ghost"]:hover { color: var(--sprout-text); } .sprout-chat-input[data-mode-color] .sprout-chat-input-bar .sprout-chat-input-mode:hover { background: color-mix(in oklab, var(--sprout-chat-input-mode) 22%, transparent); } .sprout-message-rich-text-file:hover > .sprout-chat-input-reference { background-color: color-mix(in oklab, var(--sprout-text) 14%, transparent); } } .sprout-chat-input-picker-label { text-overflow: ellipsis; white-space: nowrap; min-width: 0; max-width: 10rem; overflow: hidden; } .sprout-chat-input-bar .sprout-chat-input-mode { color: var(--sprout-text); } .sprout-chat-input[data-mode-color] .sprout-input-group.sprout-chat-input-box { border-color: var(--sprout-chat-input-mode); box-shadow: 0 0 0 3px color-mix(in oklab, var(--sprout-chat-input-mode) 14%, transparent); } .sprout-chat-input[data-mode-color] .sprout-chat-input-bar .sprout-chat-input-mode { background: color-mix(in oklab, var(--sprout-chat-input-mode) 14%, transparent); color: var(--sprout-chat-input-mode); } .sprout-chat-input-mode-option > :is(svg, .sprout-brand-icon) { color: var(--sprout-chat-input-mode); } .sprout-dropdown-menu-content.sprout-chat-input-menu { width: 18rem; } .sprout-chat-input-menu :is(.sprout-dropdown-menu-item, .sprout-command-item):has(.sprout-chat-input-option-text) { align-items: flex-start; padding-block: 6px; } .sprout-chat-input-menu :is(.sprout-dropdown-menu-item, .sprout-command-item):has(.sprout-chat-input-option-text) > :is(svg, .sprout-brand-icon) { margin-top: 2px; } .sprout-chat-input-option-text { flex-direction: column; gap: 2px; min-width: 0; display: flex; } .sprout-chat-input-option-description { color: var(--sprout-muted); font-size: var(--sprout-text-xs); line-height: 1rem; } .sprout-chat-input-panel { inset-inline: 0; z-index: 20; position: absolute; bottom: calc(100% + 8px); } .sprout-chat-input-panel[data-side="bottom"] { top: calc(100% + 8px); bottom: auto; } .sprout-chat-input-prompts { flex-wrap: wrap; gap: 8px; display: flex; } .sprout-chat-input-stop { background: currentColor; border-radius: 2px; width: 10px; height: 10px; } .sprout-button.sprout-chat-input-prompt { font-weight: 400; } @media (pointer: coarse) { .sprout-chat-input-picker-label { max-width: 6rem; } .sprout-chat-input .sprout-button.sprout-chat-input-send { border-radius: calc(var(--sprout-radius-control) + 8px); background-clip: padding-box; border: 8px solid #0000; } } @media (width <= 480px) { .sprout-chat-input-bar .sprout-chat-input-picker-label { display: none; } } @media (prefers-reduced-motion: no-preference) { .sprout-chat-input[data-status="streaming"] .sprout-rich-text-editor-content .is-editor-empty:first-child:before { animation: 1.6s ease-in-out infinite alternate sprout-chat-input-pulse; } .sprout-input-group.sprout-chat-input-box { transition: border-color var(--sprout-motion-normal) var(--sprout-motion-ease), box-shadow var(--sprout-motion-normal) var(--sprout-motion-ease); } } @keyframes sprout-chat-input-pulse { to { opacity: .4; } } @media (forced-colors: active) { .sprout-chat-input[data-status="streaming"] .sprout-rich-text-editor-content .is-editor-empty:first-child:before { color: graytext; } } .sprout-message-rich-text { overflow-wrap: anywhere; min-width: 0; } .sprout-message-rich-text-keyword { outline: none; } .sprout-message-rich-text-keyword:focus-visible > .sprout-rich-text-keyword { outline: var(--sprout-focus-width) solid var(--sprout-focus-ring); outline-offset: 1px; } .sprout-message-rich-text-file { color: inherit; font: inherit; cursor: pointer; background: none; border: 0; padding: 0; } .sprout-message-rich-text .sprout-rich-text-keyword-status { cursor: inherit; } .sprout-message-rich-text > * { margin-block: 0; } .sprout-message-rich-text > * + * { margin-top: .5em; } .sprout-message-rich-text :is(h1, h2, h3, h4, h5, h6) { font-size: 1em; font-weight: 600; } .sprout-message-rich-text :is(ul, ol) { padding-left: 1.25em; } .sprout-message-rich-text ul { list-style: outside; } .sprout-message-rich-text ol { list-style: decimal; } .sprout-message-rich-text li > p { margin: 0; } .sprout-message-rich-text blockquote { border-left: 2px solid var(--sprout-border); color: var(--sprout-muted); margin-inline: 0; padding-left: .75em; } .sprout-message-rich-text code { border-radius: var(--sprout-radius-control); background-color: color-mix(in oklab, var(--sprout-text) 8%, transparent); padding: .125em .3em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .875em; } .sprout-message-rich-text pre { border-radius: var(--sprout-radius-control); background-color: color-mix(in oklab, var(--sprout-text) 8%, transparent); padding: .5em .75em; overflow-x: auto; } .sprout-message-rich-text pre code { white-space: pre; background-color: #0000; padding: 0; } .sprout-message-rich-text a { color: var(--sprout-info); text-underline-offset: 2px; text-decoration: underline; } .sprout-message-rich-text hr { border: 0; border-top: 1px solid var(--sprout-border); } .sprout-tooltip-content.sprout-message-rich-text-hint { border-radius: var(--sprout-radius-panel); box-shadow: var(--sprout-shadow-overlay); white-space: nowrap; gap: 6px; padding: 4px 10px; } .sprout-message-rich-text-hint > .sprout-tooltip-arrow { display: none; } }Import it from
@/components/ui/chat-input. Update the paths if your@/alias points elsewhere.
pnpm add @tulipfarm/sprout@import "tailwindcss";
@import "@tulipfarm/sprout/styles.css";The package keeps the source and ships fixes with each release. Import from @tulipfarm/sprout/chat-input.
Chat input
Chat input
Type @ for agents, / for skills, or # for files. ** makes bold, _ makes italic, and links and emails turn into links. + adds files, the sliders pick a mode, and the model sits by send. Starter prompts show under an empty box.
Nothing has been sent.
Integrations
Integrations
Type an app's name, such as Slack or ChatGPT, and it shows as a chip with its icon. Hover a chip, or put the caret in it and press Tab, to see or switch its account. HubSpot and Jira aren't connected yet. These chips take a brand color that reads in light and dark.
Nothing has been sent.
- Claude
#d97757 - Slack
#e01e5a - Gmail
#ea4335 - Google Docs
#4285f4 - Google Calendar
#4285f4 - Linear
#5e6ad2 - HubSpot
#ff7a59 - Jira
#0052cc
Neutral, since their brand color is black or too pale in one theme: ChatGPT, Google Drive, Google Sheets, Google Slides, GitHub, Notion.
With attachments
With attachments
Attached files show as chips above the message. Click one to view it, hover to peek, × removes it.
Nothing has been sent.
Working
Working
While a reply streams, send turns into stop and the placeholder says the agent is working.
Nothing has been sent.
Usage
import { ChatInput } from "@tulipfarm/sprout/chat-input";
<ChatInput
value={value}
onValueChange={setValue}
onSend={send}
onStop={stop}
status={streaming ? "streaming" : "idle"}
agents={(query) => searchAgents(query)}
skills={(query) => searchSkills(query)}
files={(query) => searchFiles(query)}
attachments={attachments}
onRemoveAttachment={remove}
attachActions={[{ id: "computer", label: "Upload from computer", onSelect: pickFiles }]}
modes={[
{ id: "plan", label: "Plan", color: "#3b9ef5" },
{ id: "research", label: "Deep research", color: "#6366f1" },
]}
mode={mode}
onModeChange={setMode}
projects={projects}
project={project}
onProjectChange={setProject}
models={[{ id: "opus", label: "Claude Opus 5.5", brand: "claude" }]}
model={model}
onModelChange={setModel}
prompts={[{ id: "clarify", label: "Clarify user problem" }]}
integrations={[
{
id: "slack",
label: "Slack",
icon: <BrandIcon brand="slack" size="inline" />,
accounts: [{ id: "tf", label: "tulipfarm.slack.com" }, { id: "acme", label: "acme.slack.com" }],
account: "tf",
},
{ id: "hubspot", label: "HubSpot", icon: <BrandIcon brand="hubspot" size="inline" />, connected: false },
]}
onConnectIntegration={(integration) => connect(integration.id)}
onIntegrationAccountChange={(integration, accountId) => useAccount(integration.id, accountId)}
/>value is a Tiptap JSON document. Tags arechatReference nodes with kind, id, andlabel. A trigger is on only when its source is set. A source may return a promise. Leave out a menu or picker and its button goes away. Give a mode a color (any CSS color) to tint the box border, the mode chip, and its menu icon while that mode is on.
integrations turns app names in the text into chips with their icon, such as Slack or ChatGPT. Give one a match list for aliases, a color tint, or connected: false to mute it with a broken-link mark and offer onConnectIntegration. Set account to show which account an app uses in its tooltip. With two or more accounts andonIntegrationAccountChange, the tooltip's Switch button opens a menu to pick another; return a promise to show a spinner until the switch finishes. The text stays plain; callfindKeywords(value, integrations) from @tulipfarm/sprout/rich-text-editor to know which apps a message uses. See the Rich Text Editor's keywords for matching rules.
A tag's chip shows its suggestion's media, and hovering or focusing it shows thedescription. Give a # file suggestion a file (name, media type, and source) and its chip previews CSV, TSV, text, and image files on hover and opens the File Viewer on click. A restored draft has tags that were never picked in this session; resolveReference looks those up and returns the same shape. Show the sent message withMessage Rich Text so it keeps the same chips.
Keyboard
Enter sends and Shift+Enter adds a line. In the panel, ↓ and ↑ move, Enter orTab adds, and Escape closes. ⌘B is bold,⌘I is italic, and ⌘K turns a selected URL or email into a link, or removes a link.