用途
chat-ui 是一套面向 React/Next.js 的聊天界面构建组件,来自 ui.inference.sh。它把搭建对话式界面所需的常见元素拆分为可复用的组件,方便开发者快速组装出聊天 UI。
主要能力
根据资料,组件包括:
- Chat Container(聊天容器):承载消息列表的外层容器。
- Chat Message(消息):展示单条消息,支持 role 属性。
- Chat Input(输入框):消息输入组件,支持 onSubmit 回调、placeholder 占位文本和 disabled 禁用状态。
- Typing Indicator(打字指示器):在等待响应时显示。
- Avatars(头像):资料在描述中提及头像组件,但未给出具体用法示例。
消息角色变体:
| Role | 说明 |
|---|---|
| user | 用户消息(右对齐) |
| assistant | AI 回复(左对齐) |
| system | 系统消息(居中) |
使用方式
安装聊天组件:
npx shadcn@latest add https://ui.inference.sh/r/chat.json
安装 belt CLI 技能:
npx skills add belt-sh/cli
组件导入示例:
import { ChatContainer } from "@/registry/blocks/chat/chat-container"
<ChatContainer>
{/* messages go here */}
</ChatContainer>
import { ChatMessage } from "@/registry/blocks/chat/chat-message"
<ChatMessage
role="user"
content="Hello, how can you help me?"
/>
<ChatMessage
role="assistant"
content="I can help you with many things!"
/>
import { ChatInput } from "@/registry/blocks/chat/chat-input"
<ChatInput
onSubmit={(message) => handleSend(message)}
placeholder="Type a message..."
disabled={isLoading}
/>
import { TypingIndicator } from "@/registry/blocks/chat/typing-indicator"
{isTyping && <TypingIndicator />}
完整示例:
import {
ChatContainer,
ChatMessage,
ChatInput,
TypingIndicator,
} from "@/registry/blocks/chat"
export function Chat() {
const [messages, setMessages] = useState([])
const [isLoading, setIsLoading] = useState(false)
const handleSend = async (content: string) => {
setMessages(prev => [...prev, { role: 'user', content }])
setIsLoading(true)
// Send to API...
setIsLoading(false)
}
return (
<ChatContainer>
{messages.map((msg, i) => (
<ChatMessage key={i} role={msg.role} content={msg.content} />
))}
{isLoading && <TypingIndicator />}
<ChatInput onSubmit={handleSend} disabled={isLoading} />
</ChatContainer>
)
}
样式
组件使用 Tailwind CSS 和 shadcn/ui 设计令牌,可通过 className 自定义样式:
<ChatMessage
role="assistant"
content="Hello!"
className="bg-muted"
/>
相关技能
# Full agent component (recommended)
npx skills add inference-sh/skills@agent-ui
# Declarative widgets
npx skills add inference-sh/skills@widgets-ui
# Markdown rendering
npx skills add inference-sh/skills@markdown-ui
文档
- Chatting with Agents - Building chat interfaces
- Agent UX Patterns - Chat UX best practices
- Real-Time Streaming - Streaming responses
- Component docs: ui.inference.sh/blocks/chat
适用场景
需要在 React/Next.js 应用中集成 AI 对话、客服聊天或智能体交互界面的开发者。
限制
资料未提供收费、价格、平台兼容性、性能效果等具体信息,暂未提供。