SuperAPI AI 工具集

chat-ui

前端与建站

查看项目

更新于 10-16 10:13

技能介绍

用途

chat-ui 提供来自 ui.inference.sh 的聊天界面构建块,面向 React / Next.js 项目,用于快速搭建聊天 / 对话式界面。

主要能力

提供的组件包括:

  • container(聊天容器 ChatContainer)
  • messages(消息 ChatMessage)
  • input(输入框 ChatInput)
  • typing indicators(打字指示器 TypingIndicator)
  • avatars(头像)

消息组件支持三种角色:

  • user:用户消息(右对齐)
  • assistant:AI 回复(左对齐)
  • system:系统消息(居中)

使用方式

安装 belt CLI skill:

npx skills add belt-sh/cli

安装聊天组件:

npx shadcn@latest add https://ui.inference.sh/r/chat.json

组件导入与基本用法:

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"
/>

相关技能

# 完整 agent 组件(推荐)
npx skills add inference-sh/skills@agent-ui

# 声明式 widgets
npx skills add inference-sh/skills@widgets-ui

# Markdown 渲染
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
  • 组件文档:ui.inference.sh/blocks/chat

适用场景

需要在 React / Next.js 项目中构建对话式聊天界面、智能体聊天交互界面时使用。

限制

关于收费、价格、平台支持范围、实际效果等信息暂未提供。