Skip to main content

veryfront/chat

Chat UI components and streaming hooks.

Import

import {
  Chat,
  useChat,
  useAgent,
  AgentCard,
  Message,
  AIErrorBoundary,
} from "veryfront/chat";

Examples

Basic chat (preset)

import { Chat, useChat } from "veryfront/chat";

export default function Page() {
  const chat = useChat({ api: "/api/chat" });
  return (
    <Chat
      messages={chat.messages}
      input={chat.input}
      onChange={chat.handleInputChange}
      onSubmit={chat.handleSubmit}
    />
  );
}

Custom layout (composition)

import { Chat, useChat } from "veryfront/chat";

export default function Page() {
  const chat = useChat({ api: "/api/chat" });
  return (
    <Chat.Root messages={chat.messages} input={chat.input}>
      <Chat.Empty title="Ask me anything" />
      <Chat.MessageList messages={chat.messages} />
      <Chat.Composer input={chat.input} onChange={chat.handleInputChange} onSubmit={chat.handleSubmit} />
    </Chat.Root>
  );
}

Per-message control (compound)

import { Message } from "veryfront/chat";

<Message.Root message={msg}>
  <Message.Avatar />
  <Message.Content />
  <Message.Actions />
</Message.Root>

Type Reference

UseChatOptions

useChat options
PropertyTypeDescription
apistringChat API endpoint URL
initialMessages?UIMessage[]Pre-populated messages
body?Record<string, unknown>Extra body fields sent with each request
headers?Record<string, string>Custom request headers
credentials?RequestCredentialsFetch credentials mode
model?stringOverride model at runtime (e.g. “openai/gpt-4o”, “anthropic/claude-sonnet-4-5-20250929”)
systemPrompt?stringSystem prompt for browser-side inference (server uses agent config)
browserFallback?booleanEnable/disable browser fallback when server can’t provide AI. Default: true
onResponse?(response: Response) => voidRaw response callback
onFinish?(message: UIMessage) => voidCompletion callback
onError?(error: Error) => voidError callback
onToolCall?(arg: OnToolCallArg) => void | Promise<void>Tool call handler for client-side execution

UseChatResult

useChat result
PropertyTypeDescription
messagesUIMessage[]All messages in the conversation
inputstringCurrent input value
isLoadingbooleanWhether a request is in flight
errorError | nullLast error (if any)
modelstring | undefinedCurrent model override (undefined = use agent default)
activeModelstring | undefinedThe actual model being used after auto-upgrade (e.g. “anthropic/claude-sonnet-4-20250514”)
inferenceModeInferenceModeWhere inference is currently happening
browserStatusBrowserInferenceStatus | nullBrowser-side model loading/inference status (null when not using browser fallback)
setInput(input: string) => voidSet input value
setModel(model: string | undefined) => voidChange the model for subsequent requests
sendMessage(message: { text: string }) => Promise<void>Send a message programmatically
editMessage(messageId: string, newText: string) => Promise<void>Edit a user message and resubmit — truncates history to that point
getBranches(messageId: string) => BranchInfoGet branch info for a message (returns ; total=1 if no branches)
switchBranch(messageId: string, branchIndex: number) => voidSwitch to a different branch at a given message
reload() => Promise<void>Re-send last user message
stop() => voidAbort current request
setMessages(messages: UIMessage[]) => voidReplace message history
addToolOutput(output: ToolOutput) => voidSubmit client-side tool result
data?unknownExtra data from server response
handleInputChange(e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => voidBind to input onChange
handleSubmit(e: React.FormEvent) => Promise<void>Submit current input
onChange(e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => voidAlias for handleInputChange — matches ChatProps.onChange for easy spreading
onSubmit(e: React.FormEvent) => Promise<void>Alias for handleSubmit — matches ChatProps.onSubmit for easy spreading
onModelChange(model: string | undefined) => voidAlias for setModel — matches ChatProps.onModelChange for easy spreading

UseAgentOptions

useAgent options
PropertyTypeDescription
agentstringAgent ID or endpoint
onToolCall?(toolCall: ToolCall) => voidCallback when tool is called
onToolResult?(toolCall: ToolCall, result: unknown) => voidCallback when tool result received
onError?(error: Error) => voidCallback when error occurs

UseAgentResult

useAgent result
PropertyTypeDescription
messagesAgentMessage[]Message history
toolCallsToolCall[]Active tool calls
statusAgentStatusAgent status
thinking?stringThinking/reasoning text
invoke(input: string) => Promise<void>Invoke the agent
stop() => voidStop agent execution
isLoadingbooleanLoading state
errorError | nullError state

Exports

Components

NameDescription
AgentCardAgent status, tool calls, and messages
AttachmentPill
BranchPicker
ChatFull chat UI (messages + input)
ChatComponentsCompound components for custom layouts
ChatComposer
ChatContextProvider
ChatEmpty
ChatIf
ChatMessageList
ChatRoot
ChatSidebar
ChatWithSidebar
ComposerContextProvider
ConversationEmptyState
ConversationScrollButton
DropZoneOverlay
ErrorBanner
FadeIn
InferenceBadge
InlineCitation
Loader
MessageChat message bubble
MessageActions
MessageContextProvider
MessageEditForm
MessageFeedback
ModelAvatar
ModelSelectorDropdown for switching models at runtime
QuickActions
ReasoningCard
RichCodeBlock
Shimmer
SkillBadge
Sources
StandaloneMessage
StepIndicator
StreamingMessageIncrementally rendered message
Suggestion
Suggestions
TabSwitcher
ThreadListContextProvider
ToolCallCardTool call card component - renders tool invocations with parameters and results
ToolStatusBadge
UpgradeCTA
UploadsPanel

Functions

NameDescription
downloadMarkdownDownload messages as a .md file.
exportAsMarkdownConvert chat messages to a markdown string.
extractSourcesFromPartsExtract sources from tool result parts.
getTextContentGet text content from UIMessage parts
groupPartsInOrderGroup consecutive parts for ordered rendering
isReasoningPartCheck if a part is a reasoning part
isSkillToolPartCheck if a tool part is a skill-related tool (load-skill, load-skill-reference, execute-skill-script)
isToolPartCheck if a part is a tool part
useAgentAgent interactions with tool call tracking
useAIErrorHandlerProgrammatic AI error handler
useChatuseChat hook for managing chat state with veryfront stream events.
useChatContext
useChatContextOptional
useCompletionuseCompletion hook for single text generation
useComposerContext
useComposerContextOptional
useMessageContext
useMessageContextOptional
useStreamingLow-level streaming hook
useThreadListContext
useThreadListContextOptional
useThreads
useVoiceInputVoice input (Web Speech API)

Classes

NameDescription
AIErrorBoundaryError boundary with retry

Types

NameDescription
AgentCardProps<AgentCard> props
AgentThemeAgent card theme config
AIErrorBoundaryProps<AIErrorBoundary> props
AttachmentInfo
AttachmentPillProps
BranchInfo
BranchPickerProps
BrowserInferenceStatusBrowser-side model loading and inference status
ChatComposerProps
ChatContextValue
ChatEmptyProps
ChatIfProps
ChatMessageListProps
ChatProps<Chat> props
ChatRootProps
ChatSidebarProps
ChatTab
ChatThemeTheme System for Styled Components
ChatWithSidebarAttachmentConfig
ChatWithSidebarChatController
ChatWithSidebarFeatureConfig
ChatWithSidebarGroupedProps
ChatWithSidebarMessageConfig
ChatWithSidebarModelConfig
ChatWithSidebarProps
ChatWithSidebarQuickActionsConfig
ChatWithSidebarSidebarConfig
ChatWithSidebarTabsConfig
ChatWithSidebarVoiceConfig
CodeBlockProps
ComposerContextValue
ConversationEmptyStateProps
ConversationScrollButtonProps
DropZoneOverlayProps
DynamicToolUIPartDynamic tool call UI part
ErrorBannerProps
FeedbackValue
InferenceBadgeProps
InferenceModeWhere inference is happening
InlineCitationProps
MessageActionsProps
MessageContextValue
MessageEditFormProps
MessageFeedbackProps
MessageProps<Message> props
MessageRootProps
ModelAvatarProps
ModelOptionA “provider/model” value and its display label.
ModelSelectorPropsProps for <ModelSelector>.
OnToolCallArgonToolCall callback argument
PartGroupPart group types for ordered rendering
QuickAction
QuickActionsProps
ReasoningUIPartChain-of-thought segment
SkillBadgeProps
Source
SourcesProps
StepIndicatorProps
StepUIPart
StreamingMessageProps<StreamingMessage> props
SuggestionProps
SuggestionsProps
TabSwitcherProps
TextUIPartText segment of a message
Thread
ThreadListContextValue
ToolOutputTool execution output
ToolResultUIPartTool result UI part
ToolStateTool state (pending, running, complete)
ToolUIPartTool invocation UI part
UIMessageNormalized UI message
UIMessagePartUI message segment (text, tool, reasoning)
UpgradeCTAProps
UploadedFile
UploadsPanelProps
UseAgentOptionsuseAgent options
UseAgentResultuseAgent result
UseChatOptionsuseChat options
UseChatResultuseChat result
UseCompletionOptionsuseCompletion options
UseCompletionResultuseCompletion result
UseStreamingOptionsuseStreaming options
UseStreamingResultuseStreaming result
UseThreadsOptions
UseThreadsResult
UseVoiceInputOptionsuseVoiceInput options
UseVoiceInputResultuseVoiceInput result