Agent skill

Use X Chat

by kqcoxn in kqcoxn/MaaPipelineEditor

专注讲解如何使用 useXChat Hook,包括自定义 Provider 的集成、消息管理、错误处理、多会话管理等. An agent skill from kqcoxn/MaaPipelineEditor.

MITAuto-check passed

Install Use X Chat

skills CLI
$ npx skills add kqcoxn/MaaPipelineEditor --skill use-x-chat -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install kqcoxn/MaaPipelineEditor use-x-chat --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/kqcoxn/MaaPipelineEditor.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/ant-design-x/skills/use-x-chat .claude/skills/use-x-chat && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
use-x-chat
GitHub stars
408
Token cost
~3k tokens
SKILL.md length
305 words
Files
4
Skills in repo
12
Repo updated
First seen
Licence
MIT

At a glance

专注讲解如何使用 useXChat Hook,包括自定义 Provider 的集成、消息管理、错误处理、多会话管理等. An agent skill from kqcoxn/MaaPipelineEditor.

  • Works in 2 steps: 依赖管理 → 三步集成
  • SKILL.md covers 目录导航, 1. 依赖管理, 2. 三步集成 and 数据模型, plus 5 more sections
  • Calls npm and tsc

What it does

Use X Chat is an agent skill from kqcoxn/MaaPipelineEditor. 专注讲解如何使用 useXChat Hook,包括自定义 Provider 的集成、消息管理、错误处理、多会话管理等

Its SKILL.md is about 3k tokens, which your agent loads only when the skill is triggered. The skill folder holds 4 other files (for example `reference/API.md`, `reference/CORE.md` and `reference/EXAMPLES.md`).

The repository describes itself as: ✨ 可视化构建 MaaFramework Pipeline 的下一代工作流 审阅&编辑&调试 工具,你的工程师牛牛! ✨. The licence is MIT.

Example prompts

  • “/use-x-chat”

Requirements

  • Node.js

Workflow steps

2 steps, taken from the step headings in SKILL.md.

  1. 依赖管理
  2. 三步集成

What it can do on your machine

Read from SKILL.md and the folder at commit bbfe0d0. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • npm
    • tsc

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • github.com

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Use X Chat loads about 3k tokens when it runs. Until then it costs about 17 tokens; SKILL.md has 305 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~17
When it runs · the whole SKILL.md, loaded when a task matches
~3k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from kqcoxn/MaaPipelineEditor at commit bbfe0d0, republished under its MIT licence (© kqcoxn). 305 words, ~3,008 tokens.

Download SKILL.mdSave it as .claude/skills/use-x-chat/SKILL.md (or your agent's skills folder). This skill also uses 3 other files; get the full folder from GitHub.
name
use-x-chat
description
专注讲解如何使用 useXChat Hook,包括自定义 Provider 的集成、消息管理、错误处理、多会话管理等
version
2.9.0

🎯 技能定位

核心定位:使用 useXChat Hook 构建专业级 AI 对话应用 前置要求:已具备自定义 Chat Provider(参考 x-chat-provider 技能)

目录导航

🚀 快速开始

1. 依赖管理

  • @ant-design/x-sdk: 2.2.2+
  • @ant-design/x: 最新版(UI 组件)
bash
npm install @ant-design/x-sdk@latest @ant-design/x@latest

2. 三步集成

步骤1:准备 Provider

由 x-chat-provider 技能负责。注意 XRequest 必须传 manual: true:

ts
import { MyChatProvider } from './MyChatProvider';
import { XRequest } from '@ant-design/x-sdk';

// ⚠️ manual: true 是必须的
const provider = new MyChatProvider({
  request: XRequest('https://your-api.com/chat', { manual: true }),
});
步骤2:基础使用
tsx
import { useXChat } from '@ant-design/x-sdk';

const ChatComponent = () => {
  const { messages, onRequest, isRequesting } = useXChat({
    provider,
    requestPlaceholder: (_, { messages }) => ({
      content: '正在思考中...',
      role: 'assistant',
    }),
    requestFallback: (_, { error, messageInfo }) => {
      if (error.name === 'AbortError') {
        return { content: messageInfo?.message?.content || '已取消回复', role: 'assistant' };
      }
      return { content: '网络异常,请稍后重试', role: 'assistant' };
    },
  });

  return (
    <div>
      {messages.map((msg) => (
        <div key={msg.id}>
          {msg.message.role}: {msg.message.content}
        </div>
      ))}
      <button onClick={() => onRequest({ query: '你好' })}>发送</button>
    </div>
  );
};
步骤3:UI 集成

⚠️ messages 是 MessageInfo<ChatMessage>[],不能直接传给 Bubble.List。需要映射为 { key, role, content, loading } 格式。 Bubble.List 使用 role 属性(不是 roles)配置角色样式。

tsx
import { Bubble, Sender } from '@ant-design/x';

const ChatUI = () => {
  const { messages, onRequest, isRequesting, abort } = useXChat({ provider });

  return (
    <div style={{ height: 600 }}>
      <Bubble.List
        // ✅ 正确:使用 role(不是 roles)
        role={{
          user: { placement: 'end' },
          assistant: { placement: 'start' },
        }}
        items={messages.map(({ id, message, status }) => ({
          key: id,
          role: message.role, // 用于匹配 role 配置
          content: message.content, // 消息内容
          loading: status === 'loading', // 加载动画
        }))}
      />
      <Sender
        loading={isRequesting}
        onSubmit={(content) => onRequest({ query: content })}
        onCancel={abort}
      />
    </div>
  );
};
当 ChatMessage 是对象类型时(非字符串)

当 ChatMessage 是复杂对象(如有 content、attachments 等字段),需用 contentRender 渲染:

tsx
<Bubble.List
  role={{
    assistant: {
      placement: 'start',
      // contentRender 接收 content 参数,就是 message 字段本身
      contentRender(content: MyMessage) {
        return (
          <div>
            <div>{content.content}</div>
            {content.attachments?.map((a) => (
              <FileCard key={a.url} name={a.name} />
            ))}
          </div>
        );
      },
    },
    user: {
      placement: 'end',
      contentRender(content: MyMessage) {
        return content.content;
      },
    },
  }}
  items={messages.map(({ id, message, status }) => ({
    key: id,
    role: message.role,
    content: message, // ⚠️ 传整个 message 对象,contentRender 会处理渲染
    loading: status === 'loading',
  }))}
/>

🧩 核心概念

数据模型

⚠️ 重要:messages 类型是 MessageInfo<ChatMessage>[],消息内容在 msg.message 中

ts
interface MessageInfo<ChatMessage> {
  id: number | string; // 消息唯一标识
  message: ChatMessage; // 实际消息内容(你的 ChatMessage 类型)
  status: MessageStatus; // 消息状态
  extraInfo?: AnyObject; // 扩展信息(注意:是 extraInfo,不是 extra)
}

type MessageStatus = 'local' | 'loading' | 'updating' | 'success' | 'error' | 'abort';
// local: 用户发送的本地消息
// loading: AI 回复占位中(requestPlaceholder 对应此状态)
// updating: AI 正在流式输出
// success: AI 回复完成
// error: 请求失败
// abort: 用户主动取消

useXChat 配置项

配置项类型说明
providerAbstractChatProvider<ChatMessage, Input, Output>必填,Provider 实例
conversationKeystring会话唯一标识,多会话必填
defaultMessagesDefaultMessageInfo[] | () => ... | async () => ...默认展示消息,支持异步加载
requestPlaceholderChatMessage | (requestParams, { messages }) => ChatMessage请求中的占位消息
requestFallbackChatMessage | (requestParams, { error, errorInfo, messages, messageInfo }) => ChatMessage | Promise<ChatMessage>请求失败/中止时的兜底消息
parser(message: ChatMessage) => BubbleMessage | BubbleMessage[]将 ChatMessage 转为组件消费格式,支持一转多

requestFallback 中 messageInfo 类型为 MessageInfo<ChatMessage>,是请求失败时正在更新的那条消息。 requestFallback 同时处理网络错误(error)和主动取消(error.name === 'AbortError')。

useXChat 返回值

返回值类型说明
messagesMessageInfo<ChatMessage>[]消息列表,需映射后传给 Bubble.List
parsedMessagesMessageInfo<ParsedMessage>[]经过 parser 转译后的消息列表(有 parser 时用这个)
onRequest(params: Partial<Input>, opts?: { extraInfo: AnyObject }) => void添加消息并触发请求
isRequestingboolean是否正在请求
abort() => void中止当前请求
setMessages(messages: Partial<MessageInfo<ChatMessage>>[]) => void直接修改消息列表,不触发请求
setMessage(id: string | number, info: Partial<MessageInfo<ChatMessage>>) => void修改单条消息,不触发请求
removeMessage(id: string | number) => boolean删除某条消息,返回是否删除成功
onReload(id: string | number, params: Partial<Input>, opts?: { extraInfo: AnyObject }) => void重新生成某条 AI 回复
queueRequest(conversationKey: string | symbol, params: Partial<Input>, opts?: { extraInfo: AnyObject }) => void队列化请求,等待会话初始化后发送
isDefaultMessagesRequestingboolean默认消息是否在异步加载中

🔧 核心功能详解

核心功能参考 CORE.md

🗂️ 多会话管理

useXConversations Hook

useXConversations 是 @ant-design/x-sdk 提供的会话列表管理 Hook,与 useXChat 配合实现多会话:

ts
import { useXConversations } from '@ant-design/x-sdk';
import type { ConversationData } from '@ant-design/x-sdk';

const {
  conversations, // ConversationData[]:会话列表
  activeConversationKey, // string:当前激活会话的 key
  setActiveConversationKey, // (key: string) => void:切换会话
  addConversation, // ( ConversationData, placement?) => boolean
  removeConversation, // (key: string) => boolean
  setConversation, // (key: string, data: ConversationData) => boolean
  getConversation, // (key: string) => ConversationData | undefined
  setConversations, // (list: ConversationData[]) => void
  getMessages, // (key: string) => MessageInfo[] | undefined(跨组件读取消息)
} = useXConversations({
  defaultConversations: [
    { key: 'conv-1', label: '会话 1' },
    { key: 'conv-2', label: '会话 2' },
  ],
  defaultActiveConversationKey: 'conv-1',
});
多会话完整模式
tsx
import { useXChat, useXConversations } from '@ant-design/x-sdk';
import { OpenAIChatProvider, XRequest } from '@ant-design/x-sdk';
import { Bubble, Conversations, Sender } from '@ant-design/x';
import React, { useEffect, useRef } from 'react';

// ⚠️ 每个会话必须有独立的 Provider 实例,否则状态会混用
const providerCache = new Map<string, OpenAIChatProvider>();

function getProvider(key: string): OpenAIChatProvider {
  if (!providerCache.has(key)) {
    providerCache.set(
      key,
      new OpenAIChatProvider({
        request: XRequest(BASE_URL, { manual: true, params: { model: 'gpt-4o', stream: true } }),
      }),
    );
  }
  return providerCache.get(key)!;
}

const App = () => {
  const senderRef = useRef<any>(null);

  const { conversations, activeConversationKey, setActiveConversationKey, addConversation } =
    useXConversations({
      defaultConversations: [{ key: 'conv-1', label: '新对话' }],
      defaultActiveConversationKey: 'conv-1',
    });

  const { messages, onRequest, isRequesting, abort, queueRequest } = useXChat({
    provider: getProvider(activeConversationKey),
    conversationKey: activeConversationKey,
    // 异步加载默认消息
    defaultMessages: async ({ conversationKey }) => {
      // 根据 conversationKey 从服务器加载历史消息
      return [];
    },
    requestFallback: (_, { error, messageInfo }) => {
      if (error.name === 'AbortError') {
        return { content: messageInfo?.message?.content || '已取消', role: 'assistant' };
      }
      return { content: '请求失败', role: 'assistant' };
    },
  });

  // 切换会话时清空输入框
  useEffect(() => {
    senderRef.current?.clear?.();
  }, [activeConversationKey]);

  const handleNewConversation = () => {
    const newKey = `conv-${Date.now()}`;
    addConversation({ key: newKey, label: `新对话 ${conversations.length + 1}` });
    setActiveConversationKey(newKey);
  };

  return (
    <div style={{ display: 'flex', height: '100vh' }}>
      <Conversations
        items={conversations}
        activeKey={activeConversationKey}
        onActiveChange={setActiveConversationKey}
        creation={{ onClick: handleNewConversation }}
      />
      <div style={{ flex: 1, display: 'flex', flexDirection: 'column' }}>
        <Bubble.List
          role={{ assistant: { placement: 'start' }, user: { placement: 'end' } }}
          items={messages.map(({ id, message, status }) => ({
            key: id,
            role: message.role,
            content: message.content,
            loading: status === 'loading',
          }))}
        />
        <Sender
          ref={senderRef}
          loading={isRequesting}
          onCancel={abort}
          onSubmit={(val) => {
            onRequest({ messages: [{ role: 'user', content: val }] });
          }}
        />
      </div>
    </div>
  );
};
queueRequest:会话切换后延迟发送
tsx
// 场景:用户切换到新会话,同时触发一条初始消息
// queueRequest 会等 defaultMessages 异步加载完成后,再发送请求

const handleNewConversationWithFirstMessage = () => {
  const newKey = `conv-${Date.now()}`;
  addConversation({ key: newKey, label: '新对话' });
  setActiveConversationKey(newKey);

  // 把消息加入队列,等 newKey 会话的 defaultMessages 加载完后自动发送
  queueRequest(newKey, {
    messages: [{ role: 'user', content: '你好!请自我介绍' }],
  });
};

📋 使用前提和依赖

使用场景需要的技能/Provider使用顺序
私有API适配x-chat-provider → use-x-chat先创建 Provider
标准API内置 Provider + use-x-chat直接使用
多会话Provider 工厂 + useXConversations + useXChat配合使用

🚨 开发规则

使用 use-x-chat 前必须确认:

  • 已有 Provider(自定义或内置 Provider)
  • Provider 中的 XRequest 已配置 manual: true
  • 已了解 MessageInfo 数据结构(消息内容在 msg.message 中)
  • Bubble.List 使用 role 属性(不是 roles)
  • 多会话场景:每个会话有独立的 Provider 实例
测试用例规则
  • 如果用户没有明确需要测试用例,则不要添加测试文件
代码质量规则
  • 完成编写后必须检查类型:运行 tsc --noEmit 确保无类型错误
  • 保持代码整洁:移除所有未使用的变量和导入

🔗 参考资源

📚 核心参考文档

🌐 SDK 官方文档

💻 示例代码

© kqcoxn, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 3 other files in .agents/skills/ant-design-x/skills/use-x-chat of kqcoxn/MaaPipelineEditor.

  • SKILL.md
  • reference/API.md
  • reference/CORE.md
  • reference/EXAMPLES.md

Open the folder on GitHubat commit bbfe0d0

Compare with similar skills

Use X Chat next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Use X Chat compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Use X Chat this skillkqcoxn/MaaPipelineEditor408—~3kAutomated safety check: PassMIT
Agent Runtime Lifecycle Hookslobehub/lobehub83k—~2.8kAutomated safety check: PassCustom licence
Agentmemory Capture Hooksrohitg00/agentmemory29k—~444Automated safety check: PassApache-2.0
Crush Hook Writercharmbracelet/crush29k—~1.8kAutomated safety check: PassCustom licence
Add Model Provideropenclaw/openclaw392k—~1.1kAutomated safety check: PassMIT
Hook Development for Claude Code Pluginsanthropics/claude-plugins-official38k10 repos~4.1kAutomated safety check: NotesApache-2.0

Similar skills

  • Registers lifecycle hooks on an agent run to observe, mock or intervene at each step, dispatching them in the order they were registered.

    83k GitHub stars~2.8k tokensUpdated today
    Agent WorkflowsAuto-check passed
  • Agentmemory Capture Hooks

    rohitg00/agentmemory

    Describes the lifecycle hooks in the agentmemory Claude Code plugin that record observations automatically, and what to check when observations go missing.

    29k GitHub stars~444 tokensUpdated today
    Agent WorkflowsAuto-check passed
  • Crush Hook Writer

    charmbracelet/crush

    Helps write, debug and configure Crush hooks in crush.json that block, approve or rewrite tool calls before they run.

    29k GitHub stars~1.8k tokensUpdated today
    Agent WorkflowsAuto-check passed
  • Add Model Provider

    openclaw/openclaw

    Add and live-prove a model provider with non-interactive config one-liners, without exposing credentials.

    392k GitHub stars~1.1k tokensUpdated today
    Auto-check passed
  • Hook Development for Claude Code Plugins

    anthropics/claude-plugins-official

    Official

    Explains how to write Claude Code plugin hooks, both prompt-based checks and bash commands, for events such as PreToolUse, Stop and SessionStart.

    38k GitHub starsUsed in 10 repos~4.1k tokens
    Agent WorkflowsAuto-check: notes
  • OmniRoute Provider Management

    diegosouzapw/OmniRoute

    Manages AI provider connections, API keys, OAuth flows and connection tests through OmniRoute's REST API across its 327-provider catalog.

    75k GitHub stars~2.4k tokensUpdated today
    Backend & APIsAuto-check passed

More from kqcoxn/MaaPipelineEditor

All 12 skills in this repo
  • Ant Design

    kqcoxn/MaaPipelineEditor

    Decision guide for antd 6.x, Ant Design Pro 5/ProComponents, Ant Design X v2, and the offline @ant-design/cli.

    408 GitHub starsUsed in 1 repo~1.1k tokens
    Auto-check passed
  • Maafw

    kqcoxn/MaaPipelineEditor

    MaaFramework 开发与集成指南。当任务涉及 MaaFramework 项目结构、Pipeline 协议、ProjectInterface V2 协议、自定义识别/动作(Custom/Agent)、Python/NodeJS/CSharp 等语言 Binding 集成、控制器配置、回调协议或运行时行为时使用。

    408 GitHub stars~1.1k tokensUpdated today
    Auto-check passed
  • Mpe Background Art

    kqcoxn/MaaPipelineEditor

    为 MPE 桌面端策划、生成或修改版本主题背景图,复用机械动力牛牛与章鱼猫的定稿形象;也用于维护这两个角色的设定与三视图。不用于普通界面样式修改或无关插画。

    408 GitHub stars~410 tokensUpdated today
    Auto-check passed
  • X Card

    kqcoxn/MaaPipelineEditor

    当需要用 @ant-design/x-card 让 AI Agent 动态渲染富交互 UI 时使用——涵盖 XCard.Box、XCard.Card、A2UI v0.9 命令、数据绑定、Catalog、Actions 和流式渲染模式。

    408 GitHub stars~2.1k tokensUpdated today
    Auto-check passed
  • X Chat Provider

    kqcoxn/MaaPipelineEditor

    专注于自定义 Chat Provider 的实现,帮助将任意流式接口适配为 Ant Design X 标准格式. An agent skill from kqcoxn/MaaPipelineEditor.

    408 GitHub stars~3.1k tokensUpdated today
    Auto-check passed
  • X Components

    kqcoxn/MaaPipelineEditor

    使用 @ant-design/x 组件库构建 AI 对话 UI 时使用 —— 涵盖 Bubble、Sender、Conversations、Prompts、ThoughtChain、Actions、Welcome、Attachments、Sources、Suggestion、Think、FileCard、CodeHighlighter、Mermaid、Folder、XProvider 和…

    408 GitHub stars~1.6k tokensUpdated today
    Auto-check passed

Questions about Use X Chat

What does Use X Chat do?

专注讲解如何使用 useXChat Hook,包括自定义 Provider 的集成、消息管理、错误处理、多会话管理等. An agent skill from kqcoxn/MaaPipelineEditor. Use X Chat is an agent skill from kqcoxn/MaaPipelineEditor.

How do I install Use X Chat in Claude Code?

Run `npx skills add kqcoxn/MaaPipelineEditor --skill use-x-chat -a claude-code`. Or copy the skill folder (.agents/skills/ant-design-x/skills/use-x-chat in kqcoxn/MaaPipelineEditor) into .claude/skills/use-x-chat in your project. Claude Code loads it when a task matches its description.

How do I install Use X Chat in Codex?

Run `npx skills add kqcoxn/MaaPipelineEditor --skill use-x-chat -a codex`. Or copy the skill folder (.agents/skills/ant-design-x/skills/use-x-chat in kqcoxn/MaaPipelineEditor) into .agents/skills/use-x-chat in your project. Codex loads it when a task matches its description.

Can I use Use X Chat in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add kqcoxn/MaaPipelineEditor --skill use-x-chat -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/use-x-chat, .gemini/skills/use-x-chat, .github/skills/use-x-chat and .opencode/skills/use-x-chat in your project.

What does Use X Chat need to run?

Going by SKILL.md and its folder, Use X Chat needs the command-line tools its instructions call (npm and tsc). Our summary lists: Node.js.

Does Use X Chat access the network?

SKILL.md names 1 domain. As links in the text: github.com. This is read from the text; nothing was executed.

Is Use X Chat safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Use X Chat use?

Use X Chat is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Use X Chat use?

About 3k tokens (SKILL.md is roughly 12k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Use X Chat?

Skills that share tags, products or a category with Use X Chat: Agent Runtime Lifecycle Hooks (lobehub/lobehub, 83k stars), Agentmemory Capture Hooks (rohitg00/agentmemory, 29k stars), Crush Hook Writer (charmbracelet/crush, 29k stars) and Add Model Provider (openclaw/openclaw, 392k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Use X Chat?

kqcoxn (a GitHub user) maintains it in kqcoxn/MaaPipelineEditor, which has 408 GitHub stars. The repository holds 12 skills in this directory. The repository was last updated on October 9, 2026.

Source: kqcoxn/MaaPipelineEditor on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.