@ai-chat-ui/react
v0.0.32
Published
React components for AI Chat UI
Readme
@ai-chat-ui/react
React components for AI Chat UI, built with shadcn/ui and the AG-UI protocol.
Installation
npm install @ai-chat-ui/react
# or
pnpm add @ai-chat-ui/react
# or
yarn add @ai-chat-ui/reactUsage
Basic Setup
Import the styles in your app:
import "@ai-chat-ui/react/styles.css";ResizableChatLayout
The main layout component that provides a resizable split view between your client content and a chat panel.
import {
ResizableChatLayout,
ChatPanel,
AgentClient,
useAgentChat,
} from "@ai-chat-ui/react";
function App() {
const { messages, sendMessage, isLoading } = useAgentChat({
agentId: "my-agent",
});
return (
<ResizableChatLayout
clientPanel={<AgentClient />}
chatPanel={
<ChatPanel
messages={messages}
onSendMessage={sendMessage}
isLoading={isLoading}
/>
}
defaultClientSize={60}
defaultChatSize={40}
/>
);
}Components
ResizableChatLayout
Main layout component with resizable panels.
Props:
clientPanel: React.ReactNode - Content for the main/client panelchatPanel: React.ReactNode - Content for the chat paneldefaultClientSize?: number- Default size percentage for client panel (default: 60)defaultChatSize?: number- Default size percentage for chat panel (default: 40)minClientSize?: number- Minimum size percentage for client panel (default: 30)minChatSize?: number- Minimum size percentage for chat panel (default: 20)direction?: "horizontal" | "vertical"- Layout direction (default: "horizontal")className?: string- Additional CSS classes
ChatPanel
Chat interface component with messages and input.
Props:
messages: Message[] - Array of chat messagesonSendMessage: (content: string) => void - Callback for sending messagesisLoading?: boolean- Loading stateclassName?: string- Additional CSS classesplaceholder?: string- Input placeholder text
ChatInput
Message input component with auto-resize textarea.
Props:
onSend: (message: string) => void - Callback for sending messagesdisabled?: boolean- Disabled stateplaceholder?: string- Placeholder textclassName?: string- Additional CSS classes
AgentClient
Placeholder component for the main client/content area.
Props:
children?: React.ReactNode- Custom contentclassName?: string- Additional CSS classes
Hooks
useAgentChat
Hook for managing chat with an AG-UI agent.
Basic Usage:
const { messages, sendMessage, isLoading, error, clearMessages, abort } =
useAgentChat({
agentId: "my-agent",
onEvent: (event) => console.log(event),
onError: (error) => console.error(error),
});With Agent Configuration:
const { messages, sendMessage, isLoading } = useAgentChat({
agentId: "my-agent",
agentUrl: "http://localhost:3000/api/agent",
agentHeaders: {
Authorization: "Bearer your-token",
},
onEvent: (event) => console.log(event),
onError: (error) => console.error(error),
});Options:
agentId?: string- Agent identifieragentUrl?: string- URL of the AG-UI compatible agent endpointagentHeaders?: Record<string, string>- Optional HTTP headers (e.g., for authentication)initialMessages?: Message[]- Initial messagesonEvent?: (event: Event) => void- Event handler for AG-UI protocol eventsonError?: (error: Error) => void- Error handler
Returns:
messages: Message[] - Current messagesisLoading: boolean - Loading stateerror: Error | null - Current errorsendMessage: (content: string) => Promise - Send a messageclearMessages: () => void - Clear all messagesabort: () => void - Abort current request
Styling
This package uses Tailwind CSS. Make sure Tailwind is configured in your project and includes the package in your content paths:
// tailwind.config.js
module.exports = {
content: [
"./src/**/*.{js,ts,jsx,tsx}",
"./node_modules/@ai-chat-ui/react/dist/**/*.{js,mjs}",
],
// ... rest of config
};License
MIT
