| name | x-chat-provider |
| version | 0.0.1 |
| description | Focus on implementing custom Chat Provider, helping to adapt any streaming interface to Antdv Next X standard format |
๐ฏ Skill Positioning
This skill focuses on solving one problem: How to quickly adapt your streaming interface to Antdv Next X's Chat Provider.
Not involved: useXChat usage tutorial (that's another skill).
Table of Contents
๐ฆ Technology Stack Overview
๐๏ธ Antdv Next X Ecosystem Architecture
| Layer | Package Name | Core Purpose | Typical Usage Scenarios |
|---|
| UI Layer | @antdv-next/x | Vue 3 UI component library | Build chat interfaces, bubbles, input boxes |
| Logic Layer | @antdv-next/x-sdk | Development toolkit | Data flow management, Provider, Hook |
| Render Layer | @antdv-next/x-markdown | Markdown renderer | Content display, code highlighting |
โ ๏ธ Important Reminder: These three packages have different functional positioning, please import required features from the correct package
import { Bubble } from "@antdv-next/x";
import { AbstractChatProvider } from "@antdv-next/x-sdk";
import { XRequest } from "@antdv-next/x-sdk";
๐ Core Concept Analysis
graph LR
A[Original API Interface] -->|Adapt| B[Chat Provider]
B -->|Provide Data| C[useXChat Hook]
C -->|Render| D[Antdv Next X UI]
E[XRequest] -->|Network Request| B
| Concept | Role Positioning | Core Responsibility | Usage Scenario |
|---|
| Chat Provider | ๐ Data Adapter | Convert any interface format to Antdv Next X standard format | Private API adaptation, format conversion |
| useXChat | ๐งฉ Vue 3 Composable | Manage conversation state, message flow, request control | Build AI conversation interface |
| XRequest | ๐ Request Tool | Handle all network communication, authentication, error handling | Unified request management |
๐ Quick Start
๐ Environment Preparation
System Requirements
| Package | Version Requirement | Auto Install | Purpose |
|---|
| @antdv-next/x-sdk | โฅ0.0.1 | โ
| Core SDK, includes Provider and Hook |
| @antdv-next/x | Latest version | โ
| UI component library, build chat interface |
๐ ๏ธ One-click Environment Check
npm ls @antdv-next/x-sdk
npm install @antdv-next/x-sdk@latest
๐ Version Compatibility Matrix
| SDK Version | Supported Features | Compatibility |
|---|
| โฅ0.0.1 | Full Provider functionality | โ
Recommended |
๐ฏ Provider Selection Decision Tree
graph TD
A[Start] --> B{Use Standard API?}
B -->|Yes| C[Use Built-in Provider]
B -->|No| D{Private API?}
D -->|Yes| E[Custom Provider]
D -->|No| F{Special Format?}
F -->|Yes| E
F -->|No| C
C --> G[OpenAI/DeepSeek Provider]
E --> H[Four Steps to Create Custom Provider]
๐ญ Built-in Provider Overview
Out-of-the-box Providers
| Provider Type | Applicable Scenario | Usage Method |
|---|
| OpenAI Provider | Standard OpenAI API | Direct import use |
| DeepSeek Provider | Standard DeepSeek API | Direct import use |
Quick Decision Guide
| Scenario | Recommended Solution | Example |
|---|
| Call official OpenAI | Built-in OpenAI Provider | new OpenAIProvider() |
| Call official DeepSeek | Built-in DeepSeek Provider | new DeepSeekProvider() |
| Company internal API | Custom Provider | See four-step implementation |
| Third-party non-standard API | Custom Provider | See four-step implementation |
๐ Four Steps to Implement Custom Provider
๐ฏ Implementation Path Overview
journey
title Custom Provider Implementation Path
section Analysis Phase
Interface Analysis: 2: User
section Development Phase
Create Class: 5: User
Check Validation: 1: User
section Integration Phase
Configure Usage: 1: User
Step1: Analyze Interface Format โฑ๏ธ 2 minutes
๐ Interface Information Collection Table
| Information Type | Example Value | Your Interface |
|---|
| Interface URL | https://your-api.com/chat | _____________ |
| Request Method | POST | _____________ |
| Request Format | JSON | _____________ |
| Response Format | Server-Sent Events | _____________ |
| Authentication Method | Bearer Token | _____________ |
๐ Interface Format Template
โ
Request Format Example
interface MyAPIRequest {
query: string;
context?: string;
model?: string;
stream?: boolean;
}
โ
Response Format Example
interface MyAPIResponse {
content: string;
finish_reason?: string;
}
Step2: Create Provider Class โฑ๏ธ 5 minutes
๐๏ธ Code Template (Copy and Use)
import { AbstractChatProvider } from "@antdv-next/x-sdk";
interface MyInput {
query: string;
context?: string;
model?: string;
stream?: boolean;
}
interface MyOutput {
content: string;
finish_reason?: string;
}
interface MyMessage {
content: string;
role: "user" | "assistant";
timestamp: number;
}
export class MyChatProvider extends AbstractChatProvider<
MyMessage,
MyInput,
MyOutput
> {
transformParams(
requestParams: Partial<MyInput>,
options: XRequestOptions<MyInput, MyOutput, MyMessage>,
): MyInput {
if (typeof requestParams !== "object") {
throw new Error("requestParams must be an object");
}
return {
query: requestParams.query || "",
context: requestParams.context,
model: "gpt-3.5-turbo",
stream: true,
...(options?.params || {}),
};
}
transformLocalMessage(requestParams: Partial<MyInput>): MyMessage {
return {
content: requestParams.query || "",
role: "user",
timestamp: Date.now(),
};
}
transformMessage(info: {
originMessage: MyMessage;
chunk: MyOutput;
}): MyMessage {
const { originMessage, chunk } = info;
if (!chunk?.content || chunk.content === "[DONE]") {
return { ...originMessage, status: "success" as const };
}
return {
...originMessage,
content: `${originMessage.content || ""}${chunk.content || ""}`,
role: "assistant" as const,
status: "loading" as const,
};
}
}
๐จ Development Notes
- โ
Only change 3 places: interface types, class name, response conversion logic
- โ
Prohibit implementing request method: Network requests handled by XRequest
- โ
Maintain type safety: Use TypeScript strict mode
Step3: Check Validation โฑ๏ธ 1 minute
โ
Quick Checklist
| Check Item | Status | Description |
|---|
| Correct class name | โณ | MyChatProvider โ Your class name |
| Type matching | โณ | Interface types match actual API |
| Complete methods | โณ | All 3 methods implemented |
| No request method | โณ | Confirm no request method implemented |
| Type check passed | โณ | tsc --noEmit no errors |
๐ Validation Code
npx tsc --noEmit MyChatProvider.ts
Step4: Configure Usage โฑ๏ธ 1 minute
๐ง Complete Integration Example
import { MyChatProvider } from "./MyChatProvider";
import { XRequest } from "@antdv-next/x-sdk";
const request = XRequest("https://your-api.com/chat", {
headers: {
Authorization: "Bearer your-token-here",
"Content-Type": "application/json",
},
params: {
model: "gpt-3.5-turbo",
max_tokens: 1000,
temperature: 0.7,
},
manual: true,
});
const provider = new MyChatProvider({
request,
});
export { provider };
๐ Usage Advantages
- Zero network code: XRequest handles all network details
- Type safety: Complete TypeScript support
- Easy testing: Can mock XRequest for unit testing
- Unified configuration: Authentication, parameters, error handling centralized management
๐ง Common Scenario Adaptation
๐ Scenario Adaptation Guide
๐ Complete Examples: EXAMPLES.md contains complete code for all actual scenarios
๐ Joint Skill Usage Guide
๐ฏ Skill Relationship Diagram
graph TD
User[Developer] --> A{Choose Solution}
A -->|Standard API| B[Built-in Provider]
A -->|Private API| C[Custom Provider]
B --> D[use-x-chat]
C --> E[x-chat-provider]
E --> D
D --> F[x-request]
F --> G[Final Application]
๐ Skill Comparison Table
| Skill Role | Skill Name | Prerequisites | Core Responsibility | Usage Scenario |
|---|
| ๐๏ธ Creator | x-chat-provider | None | Create custom Provider | Adapt private/non-standard APIs |
| ๐งฉ User | use-x-chat | Needs Provider | Build AI conversation interface | Vue 3 component development |
| ๐ง Configurer | x-request | None | Configure request parameters authentication | Unified network request management |
๐ฏ Combined Usage Scenarios
๐ Scenario1: Complete AI Conversation Application
Applicable: Build complete AI conversation product from scratch
sequenceDiagram
participant Dev as Developer
participant CP as x-chat-provider
participant UX as use-x-chat
participant XR as x-request
Dev->>CP: 1. Create custom Provider
CP->>Dev: Return adapted Provider
Dev->>XR: 2. Configure XRequest parameters
XR->>Dev: Return configured request
Dev->>UX: 3. Use Provider to build interface
UX->>Dev: Complete AI conversation application
Implementation Steps:
- x-chat-provider โ Create custom Provider (four-step implementation)
- x-request โ Configure authentication, parameters, error handling
- use-x-chat โ Build Vue 3 chat interface
๐ฏ Scenario2: Only Create Provider
Applicable: Provide Provider for other frameworks or teams
graph LR
A[Private API] -->|Adapt| B[Custom Provider]
B -->|Export| C[Other Framework Usage]
B -->|Publish| D[NPM Package]
Core Value:
- ๐ง Decoupling: Provider separated from UI framework
- ๐ฆ Reusability: Can be used by multiple projects
- ๐ Efficiency: Develop once, use everywhere
โก Scenario3: Use Built-in Provider
Applicable: Quick prototype development or standard API calls
graph LR
A[Standard API] -->|Built-in| B[OpenAI/DeepSeek Provider]
B -->|Direct Use| C[use-x-chat]
C -->|Configure| D[x-request]
D --> E[Quick Launch]
Advantages:
- โก Zero Development: No need for custom Provider
- ๐ฏ Zero Configuration: Built-in best practices
- ๐ Ultra-fast Launch: Complete in 5 minutes
โ ๏ธ Important Reminders
๐จ Mandatory Rule: Prohibit Writing request Method!
Mandatory Requirements:
- ๐ซ Absolutely prohibit implementing
request method in Provider
- โ
Must use XRequest to handle all network requests
- โ
Only focus on data conversion logic (transformParams, transformLocalMessage, transformMessage)
โ Serious Error (Absolutely Prohibited):
class MyProvider extends AbstractChatProvider {
async request(params: any) {
const response = await fetch(this.url, { ... });
return response;
}
}
โ
Mandatory Requirement (Only Correct Way):
class MyProvider extends AbstractChatProvider {
transformParams(params) {
}
transformLocalMessage(params) {
}
transformMessage(info) {
}
}
const provider = new MyProvider({
request: XRequest("https://your-api.com/chat"),
});
โก Quick Checklist
Before creating Provider, confirm:
After completion:
๐จ Development Rules
Test Case Rules
- If the user does not explicitly need test cases, do not add test files
- Only create test cases when the user explicitly requests them
Code Quality Rules
- After completion, must check types: Run
tsc --noEmit to ensure no type errors
- Keep code clean: Remove all unused variables and imports
๐ Reference Resources
๐ Core Reference Documentation
๐ SDK Official Documentation
๐ป Example Code