Token导航 LogoToken导航

Agent Skill · 前端设计

ai-ui-patterns(ai ui 模式)

用于辅助界面设计、视觉规范、排版、配色、布局和交互体验优化。它适合让 Agent 根据产品场景整理页面结构、生成 UI 方案、检查视觉一致性或改进组件层级。使用时需要结合现有品牌、设计系统和用户任务,不应只堆装饰元素;涉及真实页面改动时,应通过截图或浏览器预览检查文本溢出、对齐和响应式表现。

ai-ui-patterns 是前端设计类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为接触敏感数据;许可证信息还不明确,第三方扫描已通过,按安装量在前端设计类的 10,216 个 Skill 里排第 1,054。

总安装 8,008周安装 344GitHub Stars 173下载 2,807核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:ai-ui-patterns(ai ui 模式)
来源仓库:https://github.com/patternsdev/skills
仓库路径:skills/ai-ui-patterns
安装命令:
npx skills add https://github.com/patternsdev/skills --skill ai-ui-patterns
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/patternsdev/skills --skill ai-ui-patterns

这个 Skill 是做什么的

前端设计类 Skill 关注页面结构、视觉规范和组件写法,输出通常是可运行的界面代码。

用于辅助界面设计、视觉规范、排版、配色、布局和交互体验优化。适合整理页面结构、生成 UI 方案或检查视觉一致性。使用时需结合品牌和设计系统,避免仅堆砌装饰元素。涉及真实页面改动时,应通过截图或浏览器预览检查文本溢出和对齐问题。ai-ui-patterns 属于前端设计类 Skill,可作为该场景下的辅助能力补充。

来源仓库内路径:skills/ai-ui-patterns

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/patternsdev/skills --skill ai-ui-patterns;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要接触敏感数据,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

ai-ui-patterns 怎么安装?

在终端执行 npx skills add https://github.com/patternsdev/skills --skill ai-ui-patterns。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

ai-ui-patterns 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

ai-ui-patterns 需要什么权限?

权限级别是接触敏感数据。该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

ai-ui-patterns 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

ai-ui-patterns 用的人多吗?

公开数据是累计安装 8,008 次,近一周安装 344 次,下载 2,807 次,GitHub 173 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

ai-ui-patterns 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 需要接触敏感数据,装到常用环境前要先评估影响面。
  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理前端设计类任务、又不想每次都手写提示词的人。

不太适合

  • 环境里有大量密钥、凭证,不方便给第三方 Skill 读取的人。
  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

前端设计类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
frontend-design

前端设计 · Codex、Claude

8,823,360126,072只读MIT通过
vercel-composition-patterns

Vercel 组合模式 · Codex、Claude

3,858,81625,893需要联网MIT通过
vercel-react-native-skills

Vercel React native skills 前端 · Codex、Claude

2,468,66425,878只读MIT通过
adapt

adapt 搜索 · Codex、Claude

2,027,04023,125操作浏览器未明确通过
bolder

bolder 分析 · Codex、Claude

2,004,28823,130只读未明确通过
ai-ui-patterns

ai ui 模式 · 本页

8,008173接触敏感数据未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

AI UI Patterns

Table of Contents

Building AI-powered interfaces – from chatbots to intelligent assistants – requires careful integration of backend AI services with reactive UI components. In this chapter, we explore design patterns in React for such interfaces, focusing on two implementations: a plain React app (using Vite) and a Next.js app. We'll use OpenAI's API (via the Vercel AI SDK) as our AI engine, and TailwindCSS for styling. Key topics include prompt management, streaming responses, input debouncing, error handling, and how these patterns differ between Vite and Next.js. We also highlight reusable component patterns and Vercel's AI UI components (AI Elements) for building polished chat UIs.

When to Use

  • Use this when building conversational AI interfaces that stream responses from LLMs
  • This is helpful for integrating OpenAI, Anthropic, or other AI providers into React applications
  • Use this when you need patterns for prompt management, streaming, error handling, and AI-specific UI

Instructions

  • Use the Vercel AI SDK's useChat hook for managing conversation state and streaming responses
  • Keep API keys on the server — use Next.js API routes or a separate backend for AI calls
  • Enable streaming (stream: true) for responsive real-time output in chat interfaces
  • Debounce input for autocomplete features; disable input during response streaming for chat
  • Build reusable components (ChatMessage, InputBox) decoupled from data-fetching logic

Details

Note: While this article uses OpenAI as an example, the Vercel AI SDK supports multiple model providers including Gemini, OpenAI, and Anthropic. You can easily swap between providers through the SDK's unified interface – we're just choosing one option for demonstration purposes.

Introduction: AI Interfaces in React

AI-driven user interfaces (UIs) have become popular with the rise of LLMs like ChatGPT. Unlike traditional UIs, AI interfaces often involve conversational interactions, dynamic content streaming, and asynchronous backend calls. This introduces unique challenges and patterns for React developers. A typical AI chat interface consists of a frontend (for user input and displaying responses) and a backend (to call the AI model). The backend is essential to keep API keys and heavy processing off the client for security and performance. Tools like Vercel's AI SDK make it easier to connect to providers (OpenAI, HuggingFace, etc.) and stream responses in real-time. We'll explore how to set up both a Next.js app and a Vite (React) app to handle these concerns, and discuss best practices that apply to both.

Key patterns covered:

  • Structuring AI prompt data and managing conversation state
  • Streaming AI responses to the UI for real-time feedback
  • Debouncing user input to avoid spamming the API
  • Error handling and fallbacks in the UX
  • Reusable UI components for messages, inputs, and more (with TailwindCSS)
  • Architectural differences: Next.js route handlers vs. Vite with a Node backend

By the end, you'll be equipped to build a responsive, robust AI-powered UI in React, whether you prefer Next.js or a Vite toolchain.

Project Setup and Tools

Before diving into code, ensure you have the necessary packages and configurations:

  • React & Vite: Initialize a Vite + React project (e.g. npm create vite@latest my-ai-app -- --template react). For Next.js, you can use npx create-next-app or the Next 13 App Router templates. Both will work – we'll highlight differences as we go.
  • TailwindCSS: Set up Tailwind in your project for quick styling.
  • OpenAI API & Vercel AI SDK: Install OpenAI's library or the Vercel AI SDK. We will use Vercel's AI SDK (npm i ai) which provides helpful React hooks (useChat, useCompletion) and server utilities. This SDK is framework-agnostic, working with Next.js, vanilla React, Svelte, and more. It simplifies streaming and state management, and is free/open-source.
  • API Keys: Get your OpenAI API key from the OpenAI dashboard and store it safely. In Next.js, put it in .env.local (e.g. OPENAI_API_KEY=sk-...) and never commit it. In a Vite app, do not expose the key in client code – instead, use a backend proxy or environment variable on the server.

Setting Up AI Endpoints (Next.js vs. Vite)

Next.js Implementation: Next.js allows us to create route handlers as serverless functions. We can define an API route that the React front-end will call for AI responses:

// app/api/chat/route.ts (Next.js)
import { Configuration, OpenAIApi } from 'openai-edge';
import { OpenAIStream, StreamingTextResponse } from 'ai';

export const runtime = 'edge';

const config = new Configuration({ apiKey: process.env.OPENAI_API_KEY });
const openai = new OpenAIApi(config);

export async function POST(req: Request) {
  const { messages } = await req.json();
  const response = await openai.createChatCompletion({
    model: 'gpt-3.5-turbo',
    stream: true,
    messages: messages.map((m: any) => ({ role: m.role, content: m.content }))
  });
  const stream = OpenAIStream(response);
  return new StreamingTextResponse(stream);
}

In this handler, we receive a JSON body containing an array of messages (chat history). We call OpenAI's chat completion with stream: true to get a streaming response. We then wrap the response in a StreamingTextResponse provided by the AI SDK to pipe it back to the client in chunks. The Next.js API route keeps our API key on the server and streams data efficiently.

Vite (React) Implementation: In a Vite app, there's no built-in server, so we need to create our own backend for the OpenAI calls. This can be a simple Node/Express server:

// backend/server.js (Node/Express for Vite app)
import express from 'express';
import { Configuration, OpenAIApi } from 'openai';

const app = express();
app.use(express.json());

const config = new Configuration({ apiKey: process.env.OPENAI_API_KEY });
const openai = new OpenAIApi(config);

app.post('/api/chat', async (req, res) => {
  try {
    const { messages = [] } = req.body;
    const systemMsg = { role: 'system', content: 'You are a helpful assistant.' };
    const inputMessages = [systemMsg, ...messages];
    const response = await openai.createChatCompletion({
      model: 'gpt-3.5-turbo',
      stream: false,
      messages: inputMessages
    });
    const content = response.data.choices[0].message?.content;
    res.json({ content });
  } catch (err) {
    console.error(err);
    res.status(500).json({ error: 'Internal Server Error' });
  }
});

app.listen(6000, () => console.log('API server listening on http://localhost:6000'));

During development, you can configure the Vite dev server to proxy /api calls to this backend (e.g. in vite.config.js, set server.proxy['/api'] = 'http://localhost:6000'). The key is that the React app calls a relative /api/chat endpoint, which the proxy/hosting will route to your server code. This keeps the OpenAI key hidden.

Enabling Streaming in Node: The above Express example returns the full response after completion (stream: false for simplicity). To stream in Node, you can use OpenAI's HTTP stream: set stream: true and handle the response as a stream of data. This involves reading the response.data stream and flushing chunks to the client with res.write(). If you choose to stick with full responses (no streaming), the UI patterns still largely apply – but streaming greatly improves UX.

Prompt Handling and Conversation State

At the heart of any AI interface is prompt management – assembling user input (and context) into a prompt or message sequence for the AI model. In a chat scenario, we maintain a list of messages, each with a role and content. OpenAI's Chat API expects messages in the format {role: 'user' | 'assistant' | 'system', content: string}. We typically start with a system message (to set the assistant's behavior or context), followed by alternating user and assistant messages as the conversation progresses.

State management in React: We can store the conversation in component state. Using the Vercel SDK's React hook:

import { useChat } from 'ai/react';

function ChatInterface() {
  const { messages, input, handleInputChange, handleSubmit } = useChat();
  // ...
}

The useChat hook handles a lot for us: it manages the messages state (an array of message objects), an input state for the current text input, and provides handleInputChange and handleSubmit helpers. By default, useChat() will POST to /api/chat when you submit.

Manual state handling: If you aren't using useChat, you can manage state with useState or context. On form submit, call your API and then update the messages array by appending the user query and the assistant's response.

System prompts and context: A common pattern is including an initial system message describing the assistant's role or knowledge base. For example, if building a docs helper, system content might be "You are a documentation assistant. Answer with examples from the docs."

Single-turn vs multi-turn: If your interface is a single question answering (no conversation memory), you could use the useCompletion hook from the Vercel SDK instead. For chatbots and multi-turn dialogs, useChat is the go-to pattern, since it retains and sends the message history on each request.

Streaming AI Responses to the UI

One hallmark of modern AI UI is streaming output: as the AI generates tokens, the user sees the reply appearing in real-time. This is crucial for better UX because model-generated answers can be lengthy or slow. Instead of waiting many seconds in silence, streaming lets us display partial results immediately.

How streaming works: When we enabled stream: true on the OpenAI API, the response is sent as a sequence of chunks (data events) rather than one JSON blob. The Vercel AI SDK simplifies consumption of these chunks. On the server, we turned the response into a text stream (StreamingTextResponse). On the client side, the useChat hook handles reading this stream and updating the messages state incrementally as new text arrives.

If you implement streaming manually in React (without the SDK), you would do something like:

const res = await fetch('/api/chat', { method: 'POST', body: JSON.stringify({ messages }) });
const reader = res.body.getReader();
const decoder = new TextDecoder();
let partial = "";
while(true) {
  const { value, done } = await reader.read();
  if (done) break;
  partial += decoder.decode(value);
  setAssistantMessage(partial);
}

Auto-scrolling: One UX detail when streaming is ensuring the latest message is visible. A pattern to handle this is auto-scrolling the message container on update with a useEffect watching the messages array length.

Partial rendering and completion: Show a visual indicator during streaming – for example, a blinking cursor or "AI is typing…" message. Once the stream finishes, finalize the message display.

Input Handling and Debouncing

For chat interactions, you usually send the query when the user submits the form. In some AI applications, however, you might want to react to input continuously – for example, autocomplete suggestions or real-time validation by AI. In such cases, debouncing is important.

Why debounce? Calling the OpenAI API on every keystroke would be extremely inefficient and costly. Debouncing delays the API call until the user has stopped typing for a short period.

const [draft, setDraft] = useState("");

useEffect(() => {
  if (!draft) return;
  const timeout = setTimeout(() => {
    getSuggestion(draft);
  }, 500);
  return () => clearTimeout(timeout);
}, [draft]);

For a simple chatbot with explicit "send" action, debouncing is usually not needed – you send when the user hits Enter. However, it's still useful to disable the input or prevent multiple submissions while an AI response is in progress.

Error Handling and Resilience

Robust error handling is vital in AI applications:

  • Try/Catch around API calls: On the server, wrap the OpenAI call in try/catch. Return a proper error response if something fails.
  • Client-side error state: Handle cases where the response indicates an error.
try {
  await sendMessage({ text: input });
} catch (error) {
  console.error("Failed to send message:", error);
}
  • User feedback: Always inform the user when something goes wrong. Display the error inline in the chat – e.g., as a special "system" message saying "*Sorry, something went wrong. Please try again.*"
  • Retry mechanism: Consider allowing the user to retry with a "Try again" button.
  • Validation errors: Validate on the client before calling the API. Disable send on empty input, or truncate inputs that exceed some length.

Building the UI: Components and Styling Patterns

Chat message components: Create a ChatMessage component that renders a single message bubble. Based on role, style it differently:

function ChatMessage({ role, content }) {
  const isUser = role === 'user';
  return (
    <div className={`flex ${isUser ? 'justify-end' : 'justify-start'} mb-2`}>
      <div className={`max-w-xl px-4 py-2 rounded-lg ${
        isUser ? 'bg-blue-500 text-white' : 'bg-gray-200 text-gray-900'
      }`}>
        {content}
      </div>
    </div>
  );
}

Input component:

function InputBox({ value, onChange, onSubmit, disabled }) {
  return (
    <form onSubmit={onSubmit} className="flex gap-2">
      <input
        type="text"
        value={value}
        onChange={onChange}
        disabled={disabled}
        className="flex-1 border rounded px-3 py-2"
        placeholder="Type your message..."
      />
      <button type="submit" disabled={disabled} className="bg-blue-500 text-white px-4 py-2 rounded">
        Send
      </button>
    </form>
  );
}

Composition:

function ChatInterface() {
  const { messages, input, handleInputChange, handleSubmit, isLoading } = useChat();

  return (
    <div className="flex flex-col h-screen max-w-2xl mx-auto p-4">
      <div className="flex-1 overflow-y-auto">
        {messages.map((msg, i) => (
          <ChatMessage key={i} role={msg.role} content={msg.content} />
        ))}
      </div>
      <InputBox
        value={input}
        onChange={handleInputChange}
        onSubmit={handleSubmit}
        disabled={isLoading}
      />
    </div>
  );
}

This separation of concerns makes it easy to test and swap UI parts. The logic (useChat) is decoupled from the display components.

Vercel AI Elements (Pre-Built Chat UI Components)

Vercel's AI Elements library offers a set of ready-made React components specifically designed for AI chat interfaces:

  • Conversation: A container that renders a list of messages with auto-scrolling.
  • Prompt: An input component optimized for chat prompts.
  • TypingIndicator: Shows when the AI is "thinking" or streaming a response.
  • ErrorBoundary/ErrorMessage: Handle and display errors gracefully.
import { Conversation, Prompt, TypingIndicator } from '@vercel/ai-elements';

function ChatApp() {
  const { messages, input, handleInputChange, handleSubmit, isLoading } = useChat();

  return (
    <div className="h-screen flex flex-col">
      <Conversation messages={messages} />
      {isLoading && <TypingIndicator />}
      <Prompt
        value={input}
        onChange={handleInputChange}
        onSubmit={handleSubmit}
      />
    </div>
  );
}

Putting It All Together

  1. Backend API Route: Whether using Next.js route handlers or a separate Express server, create an endpoint that receives messages, calls the AI model, and streams the response back.
  2. State Management: Use the Vercel AI SDK's useChat hook (or roll your own with useState) to manage the conversation state.
  3. Streaming: Enable streaming on both server and client for responsive UX.
  4. Debouncing & Rate Limiting: For features like autocomplete, debounce API calls. For chat, disable input during response streaming.
  5. Error Handling: Wrap API calls in try/catch, provide user feedback on errors, and consider retry mechanisms.
  6. Reusable Components: Build presentational components (ChatMessage, InputBox) that are decoupled from data-fetching logic. Consider using AI Elements for production-ready components.
  7. Styling: Use TailwindCSS (or your preferred styling solution) to create a clean, responsive chat interface.

Architectural Comparison: Next.js vs. Vite

AspectNext.jsVite + Node Backend
API RoutesBuilt-in (pages/api/ or app/api/)Separate Express/Node server required
StreamingNative support with Edge RuntimeManual implementation with res.write()
DeploymentVercel (optimized) or self-hostDeploy frontend (static) + backend separately
ComplexityLower (all-in-one)Higher (two codebases)
FlexibilityFramework conventionsFull control

For most AI chat applications, Next.js provides a simpler developer experience with its integrated API routes and streaming support. However, if you have an existing Vite/React app or prefer more control, the patterns described here work well with a separate backend.

Source

References

平台分布

Codex

36.92%
按下载量换算1,036

Claude

33.41%
按下载量换算938

Cursor

17.98%
按下载量换算505

Gemini CLI

9.01%
按下载量换算253

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

接触敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills