Skip to main content

Import

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

Examples

Basic chat (preset)

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

export default function Page() {
  const chat = useChat();
  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();
  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

Options accepted by use chat.
PropertyTypeDescriptionSource
api?stringAG-UI endpoint. Defaults to “/api/ag-ui”.source
transport?"ag-ui"Streaming response protocol used by the endpoint. AG-UI is the default.source
initialMessages?ChatMessage[]Pre-populated messagessource
body?Record<string, unknown>Extra body fields sent with each requestsource
headers?Record<string, string>Custom request headerssource
credentials?RequestCredentialsFetch credentials modesource
model?stringOverride model at runtime (e.g. “openai/gpt-4o”, “Anthropic/claude-sonnet-4-5-20250929”)source
onResponse?(response: Response) => voidRaw response callbacksource
onFinish?(message: ChatMessage) => voidCompletion callbacksource
onError?(error: Error) => voidError callbacksource
onToolCall?(arg: OnToolCallArg) => void | Promise<void>Tool call handler for client-side executionsource

UseChatResult

Result returned from use chat.
PropertyTypeDescriptionSource
messagesChatMessage[]All messages in the conversationsource
inputstringCurrent input valuesource
isLoadingbooleanWhether a request is in flightsource
errorError | nullLast error (if any)source
modelstring | undefinedCurrent model override (undefined = use agent default)source
activeModelstring | undefinedThe actual model being used after auto-upgrade (e.g. “Anthropic/claude-sonnet-4-20250514”)source
inferenceModeInferenceModeWhere inference is currently happeningsource
setInput(input: string) => voidSet input valuesource
setModel(model: string | undefined) => voidChange the model for subsequent requestssource
sendMessage(message: { text: string }) => Promise<void>Send a message programmaticallysource
editMessage(messageId: string, newText: string) => Promise<void>Edit a user message and resubmit - truncates history to that pointsource
getBranches(messageId: string) => BranchInfoGet branch info for a message (returns ; total=1 if no branches)source
switchBranch(messageId: string, branchIndex: number) => voidSwitch to a different branch at a given messagesource
reload() => Promise<void>Re-send last user messagesource
stop() => voidAbort current requestsource
setMessages(messages: ChatMessage[]) => voidReplace message historysource
addToolOutput(output: ToolOutput) => voidSubmit client-side tool resultsource
data?unknownExtra data from server responsesource
handleInputChange(e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => voidBind to input onChangesource
handleSubmit(e?: React.FormEvent) => Promise<void>Submit current inputsource
onChange(e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => voidAlias for handleInputChange - matches ChatProps.onChange for easy spreadingsource
onSubmit(e?: React.FormEvent) => Promise<void>Alias for handleSubmit - matches ChatProps.onSubmit for easy spreadingsource
onModelChange(model: string | undefined) => voidAlias for setModel - matches ChatProps.onModelChange for easy spreadingsource

UseAgentOptions

Options accepted by use agent.
PropertyTypeDescriptionSource
agentstringAgent ID or endpointsource
onToolCall?(toolCall: ToolCall) => voidCallback when tool is calledsource
onToolResult?(toolCall: ToolCall, result: unknown) => voidCallback when tool result receivedsource
onError?(error: Error) => voidCallback when error occurssource

UseAgentResult

Result returned from use agent.
PropertyTypeDescriptionSource
messagesAgentMessage[]Message historysource
toolCallsToolCall[]Active tool callssource
statusAgentStatusAgent statussource
thinking?stringThinking/reasoning textsource
invoke(input: string) => Promise<void>Invoke the agentsource
stop() => voidStop agent executionsource
isLoadingbooleanLoading statesource
errorError | nullError statesource

Exports

Components

NameDescriptionSource
AgentCardRender agent card.source
AttachmentPillRender attachment pill.source
BranchPickerRender branch picker.source
ChatRender chat.source
ChatComponentsRender chat components.source
ChatComposerRender chat composer.source
ChatContextProviderRender chat context provider.source
ChatEmptyRender chat empty.source
ChatIfRender chat if.source
ChatMessageListRender chat message list.source
ChatRootRender chat root.source
ChatSidebarRender chat sidebar.source
ChatWithSidebarRender chat with sidebar.source
ComposerContextProviderRender composer context provider.source
ConversationEmptyStateState for conversation empty.source
ConversationScrollButtonRender conversation scroll button.source
DEFAULT_CHAT_STREAM_IDLE_TIMEOUT_MSDefault value for chat stream idle timeout ms.source
DEFAULT_CHAT_STREAM_TOOL_RUNNING_TIMEOUT_MSDefault value for chat stream tool running timeout ms.source
DropZoneOverlayRender drop zone overlay.source
ErrorBannerRender error banner.source
FadeInRender fade in.source
InferenceBadgeRender inference badge.source
InlineCitationRender inline citation.source
LoaderRender loader.source
MessageMessage shape for message.source
MessageActionsRender message actions.source
MessageContextProviderRender message context provider.source
MessageEditFormRender message edit form.source
MessageFeedbackRender message feedback.source
ModelAvatarRender model avatar.source
ModelSelectorRender model selector.source
QuickActionsRender quick actions.source
ReasoningCardRender reasoning card.source
RichCodeBlockRender rich code block.source
ShimmerRender shimmer.source
SkillBadgeRender skill badge.source
SourcesRender sources.source
StandaloneMessageRender a standalone chat message.source
StepIndicatorRender step indicator.source
StreamingMessageMessage shape for streaming.source
SuggestionRender suggestion.source
SuggestionsRender suggestions.source
TabSwitcherRender tab switcher.source
ThreadListContextProviderRender thread list context provider.source
ToolCallCardTool call card component - renders tool invocations with parameters and results Styled to match AI Elements (https://ai-sdk.dev/elements)source
ToolStatusBadgeRender tool status badge.source
UploadsPanelRender uploads panel.source

Functions

NameDescriptionSource
buildChatStreamChunkMessageMetadataBuilds chat stream chunk message metadata.source
createChatStreamWatchdogCreate chat stream watchdog.source
createChatStreamWatchdogStateState for create chat stream watchdog.source
dedupeChatUiMessageChunksDedupe chat UI message chunks.source
downloadMarkdownDownload messages as a .md file.source
exportAsMarkdownConvert chat messages to a markdown string.source
extractChatMessageMetadataExtract chat message metadata.source
extractSourcesFromPartsExtract sources from tool result parts. Looks for documents arrays in tool outputs and maps them to Source[].source
getNextChatStreamWatchdogStateState for get next chat stream watchdog.source
getTextContentGet text content from chat message partssource
groupPartsInOrderGroup consecutive parts for ordered rendering Returns an array of groups, each containing either consecutive text parts, a tool part, or a reasoning partsource
isHeartbeatOnlyMetadataChunkCheck whether a chunk only carries heartbeat metadata.source
isLongRunningToolRunningCheck whether a long-running tool is active.source
isReasoningPartCheck if a part is a reasoning partsource
isSkillToolPartCheck if a tool part is a skill-related tool.source
isToolPartCheck if a part is a tool partsource
mapHostedStreamPartToChatUiChunksMap hosted stream part to chat UI chunks.source
normalizeChatMessageMetadataNormalizes chat message metadata.source
normalizeChatUiMessageChunkNormalizes chat UI message chunk.source
normalizeChatUiMessageStreamNormalizes chat UI message stream.source
useAgentReact hook for agent.source
useChatsource
useChatContextContext for use chat.source
useChatContextOptionalReact hook for chat context optional.source
useChatErrorHandlerHandler for use chat error.source
useCompletionuseCompletion hook for single text generationsource
useComposerContextContext for use composer.source
useComposerContextOptionalReact hook for composer context optional.source
useMessageContextContext for use message.source
useMessageContextOptionalReact hook for message context optional.source
useStreamingReact hook for streaming.source
useThreadListContextContext for use thread list.source
useThreadListContextOptionalReact hook for thread list context optional.source
useThreadsReact hook for threads.source
useVoiceInputInput payload for use voice.source

Classes

NameDescriptionSource
ChatErrorBoundaryImplement chat error boundary.source
ChatStreamIdleTimeoutErrorError shape for chat stream idle timeout.source

Types

NameDescriptionSource
AgentCardPropsProps accepted by agent card.source
AgentThemePublic API contract for agent theme.source
AttachmentInfoPublic API contract for attachment info.source
AttachmentPillPropsProps accepted by attachment pill.source
BranchInfoPublic API contract for branch info.source
BranchPickerPropsProps accepted by branch picker.source
BuildChatStreamChunkMessageMetadataInputInput payload for build chat stream chunk message metadata.source
ChatComposerPropsProps accepted by chat composer.source
ChatContextValuePublic API contract for chat context value.source
ChatDynamicToolPartPublic API contract for chat dynamic tool part.source
ChatEmptyPropsProps accepted by chat empty.source
ChatErrorBoundaryPropsProps accepted by chat error boundary.source
ChatFinishReasonPublic API contract for chat finish reason.source
ChatIfPropsProps accepted by chat if.source
ChatMessageMessage shape for chat.source
ChatMessageListPropsProps accepted by chat message list.source
ChatMessageMetadataPublic API contract for chat message metadata.source
ChatMessageMetadataUsagePublic API contract for chat message metadata usage.source
ChatMessagePartPublic API contract for chat message part.source
ChatPropsProps accepted by chat.source
ChatReasoningPartChat message part that carries reasoning text.source
ChatRootPropsProps accepted by chat root.source
ChatSidebarPropsProps accepted by chat sidebar.source
ChatStepPartPublic API contract for chat step part.source
ChatStreamEventEvent emitted for chat stream.source
ChatStreamWatchdogOptionsOptions accepted by chat stream watchdog.source
ChatStreamWatchdogPhasePublic API contract for chat stream watchdog phase.source
ChatStreamWatchdogStateState for chat stream watchdog.source
ChatTabPublic API contract for chat tab.source
ChatTextPartChat message part that carries text.source
ChatThemePublic API contract for chat theme.source
ChatToolPartPublic API contract for chat tool part.source
ChatToolResultPartChat message part that carries a tool result.source
ChatToolStateState for chat tool.source
ChatUiMessageChunkPublic API contract for chat UI message chunk.source
ChatWithSidebarAttachmentConfigConfiguration used by chat with sidebar attachment.source
ChatWithSidebarChatControllerPublic API contract for chat with sidebar chat controller.source
ChatWithSidebarFeatureConfigConfiguration used by chat with sidebar feature.source
ChatWithSidebarGroupedPropsProps accepted by chat with sidebar grouped.source
ChatWithSidebarMessageConfigConfiguration used by chat with sidebar message.source
ChatWithSidebarModelConfigConfiguration used by chat with sidebar model.source
ChatWithSidebarPropsProps accepted by chat with sidebar.source
ChatWithSidebarQuickActionsConfigConfiguration used by chat with sidebar quick actions.source
ChatWithSidebarSidebarConfigConfiguration used by chat with sidebar sidebar.source
ChatWithSidebarTabsConfigConfiguration used by chat with sidebar tabs.source
ChatWithSidebarVoiceConfigConfiguration used by chat with sidebar voice.source
ChildRunAuditPublic API contract for child run audit.source
ChildRunAuditToolCallPublic API contract for child run audit tool call.source
ChildRunAuditToolResultResult returned from child run audit tool.source
CodeBlockPropsProps accepted by code block.source
ComposerContextValuePublic API contract for composer context value.source
ConversationEmptyStatePropsProps accepted by conversation empty state.source
ConversationScrollButtonPropsProps accepted by conversation scroll button.source
DropZoneOverlayPropsProps accepted by drop zone overlay.source
ErrorBannerPropsProps accepted by error banner.source
FeedbackValuePublic API contract for feedback value.source
HostedStreamPartForUiChunkMappingPublic API contract for hosted stream part for UI chunk mapping.source
HostedUiChunkMappingOptionsOptions accepted by hosted UI chunk mapping.source
InferenceBadgePropsProps accepted by inference badge.source
InferenceModeWhere inference is happening.source
InlineCitationPropsProps accepted by inline citation.source
MessageActionsPropsProps accepted by message actions.source
MessageContextValuePublic API contract for message context value.source
MessageEditFormPropsProps accepted by message edit form.source
MessageFeedbackPropsProps accepted by message feedback.source
MessagePropsProps accepted by message.source
MessageRootPropsProps accepted by message root.source
ModelAvatarPropsProps accepted by model avatar.source
ModelOptionA “provider/model” value and its display label.source
ModelSelectorPropsProps accepted by <ModelSelector>.source
OnToolCallArgPublic API contract for on tool call arg.source
PartGroupPart group types for ordered renderingsource
QuickActionPublic API contract for quick action.source
QuickActionsPropsProps accepted by quick actions.source
SkillBadgePropsProps accepted by skill badge.source
SourcePublic API contract for source.source
SourcesPropsProps accepted by sources.source
StepIndicatorPropsProps accepted by step indicator.source
StreamingMessagePropsProps accepted by streaming message.source
SuggestionPropsProps accepted by suggestion.source
SuggestionsPropsProps accepted by suggestions.source
TabSwitcherPropsProps accepted by tab switcher.source
ThreadPublic API contract for thread.source
ThreadListContextValuePublic API contract for thread list context value.source
ToolOutputOutput from tool.source
UploadedFilePublic API contract for uploaded file.source
UploadsPanelPropsProps accepted by uploads panel.source
UseAgentOptionsOptions accepted by use agent.source
UseAgentResultResult returned from use agent.source
UseChatOptionsOptions accepted by use chat.source
UseChatResultResult returned from use chat.source
UseCompletionOptionsOptions accepted by use completion.source
UseCompletionResultResult returned from use completion.source
UseStreamingOptionsOptions accepted by use streaming.source
UseStreamingResultResult returned from use streaming.source
UseThreadsOptionsOptions accepted by use threads.source
UseThreadsResultResult returned from use threads.source
UseVoiceInputOptionsOptions accepted by use voice input.source
UseVoiceInputResultResult returned from use voice input.source

Deep imports

These import paths group focused functionality under this module. Each is a separate barrel; import only what you need.

veryfront/chat/message-prep

import { compactForStep, compressTurn, dedupeToolHistory } from "veryfront/chat/message-prep";

Functions

NameDescriptionSource
compactForStepCompact for step.source
compressTurnCompress turn.source
dedupeToolHistoryDedupe tool history.source
enforceTokenBudgetEnforce token budget.source
enforceTokenBudgetWithTurnCompressionEnforce token budget with turn compression.source
ensureToolCallInputsEnsure tool call inputs helper.source
estimateOverheadEstimate overhead.source
estimateTokensEstimate tokens.source
isModelSupportedFileMediaTypeCheck whether the model supports the file media type.source
maskOldToolOutputsMask old tool outputs.source
normalizeMessageFilePartMediaTypesNormalizes message file part media types.source
prepareProviderModelMessagesFromUiMessagesPrepare provider model messages from UI messages.source
repairToolPairsRepair tool pairs.source
rewriteUnsupportedFilePartsAsAnnotationsRewrite unsupported file parts as annotations.source
sanitizeProviderModelMessagesSanitize provider model messages.source
stripPendingToolPartsStrip pending tool parts.source

Types

NameDescriptionSource
PrepareProviderModelMessagesFromUiMessagesOptionsOptions accepted by prepare provider model messages from UI messages.source

veryfront/chat/types

import { buildDataFileAnnotation, isImageFile, isTextPreviewFile } from "veryfront/chat/types";

Functions

NameDescriptionSource
buildDataFileAnnotationBuilds data file annotation.source
isImageFileCheck whether a file is an image.source
isTextPreviewFileCheck whether a file supports text preview.source
isValidImageFileCheck whether a file is a supported image upload.source
normalizeInlineAttachmentMediaTypeNormalizes inline attachment media type.source

Types

NameDescriptionSource
ChatAssistantContentPartPublic API contract for chat assistant content part.source
ChatAssistantMessageMessage shape for chat assistant.source
ChatDataUiPartChat UI part that carries custom data chunks.source
ChatDynamicToolUiPartTool UI part for a runtime-selected tool name.source
ChatFileUiPartPublic API contract for chat file UI part.source
ChatMessageMetadataPublic API contract for chat message metadata.source
ChatMessageMetadataUsagePublic API contract for chat message metadata usage.source
ChatModelFilePartPublic API contract for chat model file part.source
ChatModelReasoningPartProvider model message part that carries reasoning text.source
ChatModelTextPartProvider model message part that carries text.source
ChatNamedToolUiPartTool UI part keyed by a static tool type.source
ChatReasoningUiPartPublic API contract for chat reasoning UI part.source
ChatRequestContextContext for chat request.source
ChatRuntimeOverridesPublic API contract for chat runtime overrides.source
ChatSourceDocumentUiPartPublic API contract for chat source document UI part.source
ChatSourceUrlUiPartPublic API contract for chat source URL UI part.source
ChatStepStartUiPartPublic API contract for chat step start UI part.source
ChatSystemMessageMessage shape for chat system.source
ChatTextUiPartPublic API contract for chat text UI part.source
ChatToolCallPartProvider model message part that carries a tool call.source
ChatToolMessageMessage shape for chat tool.source
ChatToolPartStateState for chat tool part.source
ChatToolResultOutputOutput from chat tool result.source
ChatToolResultPartProvider model message part that carries a tool result.source
ChatUiMessageMessage shape for chat UI.source
ChatUiMessageChunkPublic API contract for chat UI message chunk.source
ChatUiMessagePartPublic API contract for chat UI message part.source
ChatUiMessageRolePublic API contract for chat UI message role.source
ChatUserContentPartPublic API contract for chat user content part.source
ChatUserMessageMessage shape for chat user.source
ChildRunAuditPublic API contract for child run audit.source
ChildRunAuditToolCallPublic API contract for child run audit tool call.source
ChildRunAuditToolResultResult returned from child run audit tool.source
DurableRootRunDescriptorPublic API contract for durable root run descriptor.source
FileUIPartWithUploadFile UI part enriched with upload metadata.source
MessageMetadataPublic API contract for chat message metadata.source
ProjectFilePublic API contract for project file.source
ProjectFileListItemPublic API contract for project file list item.source
ProviderModelMessageMessage shape for provider model.source
UploadedFileReferencePublic API contract for uploaded file reference.source

Constants

NameDescriptionSource
getChatRequestContextSchemaZod schema for get chat request context.source
getChatToolPartStateSchemaZod schema for get chat tool part state.source
getChatUiMessagePartSchemaZod schema for get chat UI message part.source
getChatUiMessageRoleSchemaZod schema for get chat UI message role.source
getChatUiMessageSchemaZod schema for get chat UI message.source
getChatUiMessagesSchemaZod schema for get chat UI messages.source
getMessageMetadataSchemaZod schema for get message metadata.source
imageFileTypesImage media types that chat uploads can display natively.source
textFileExtensionsFile extensions that chat uploads can inline as text.source