| name | x-request |
| version | 2.8.1 |
| description | Focus on explaining the practical configuration and usage of XRequest, providing accurate configuration instructions based on official documentation |
๐ฏ Skill Positioning
This skill focuses on solving: How to correctly configure XRequest to adapt to various streaming interface requirements.
Table of Contents
๐ Quick Start
Dependency Management
๐ System Requirements
| Package | Version Requirement | Auto Install | Purpose |
|---|
| @ant-design/x-sdk | โฅ2.2.2 | โ
| Core SDK, includes XRequest tool |
๐ ๏ธ One-click Installation
tnpm install @ant-design/x-sdk
npm add @ant-design/x-sdk
npm ls @ant-design/x-sdk
Basic Configuration
Simplest Usage
import { XRequest } from '@ant-design/x-sdk';
const request = XRequest('https://api.example.com/chat');
const providerRequest = XRequest('https://api.example.com/chat', {
manual: true,
});
๐ก Tip: XRequest has built-in reasonable default configurations. In most cases, you only need to provide the API URL to use it.
๐ฆ Technology Stack Overview
๐๏ธ Technology Stack Architecture
graph TD
A[XRequest] --> B[Network Requests]
A --> C[Authentication Management]
A --> D[Error Handling]
A --> E[Streaming Processing]
B --> F[fetch Wrapper]
C --> G[Token Management]
D --> H[Retry Mechanism]
E --> I[Server-Sent Events]
๐ Core Concepts
| Concept | Role Positioning | Core Responsibilities | Usage Scenarios |
|---|
| XRequest | ๐ Request Tool | Handle all network communication, authentication, error handling | Unified request management |
| Global Config | โ๏ธ Config Center | Configure once, use everywhere | Reduce duplicate code |
| Streaming Config | ๐ Streaming Processing | Support SSE and JSON response formats | AI conversation scenarios |
๐ง Core Configuration Details
Core functionality reference content CORE.md
๐ก๏ธ Security Guide
Environment Security Configuration
๐ Security Strategies for Different Environments
| Runtime Environment | Security Level | Configuration Method | Risk Description |
|---|
| Browser Frontend | ๐ด High Risk | โ Prohibit key configuration | Keys will be directly exposed to users |
| Node.js Backend | ๐ข Safe | โ
Environment variable configuration | Keys stored on server side |
| Proxy Service | ๐ข Safe | โ
Same-origin proxy forwarding | Keys managed by proxy service |
๐ Authentication Methods Comparison
| Authentication Method | Applicable Environment | Configuration Example | Security |
|---|
| Bearer Token | Node.js | Bearer ${process.env.API_KEY} | โ
Safe |
| API Key Header | Node.js | X-API-Key: ${process.env.KEY} | โ
Safe |
| Proxy Forwarding | Browser | /api/proxy/service | โ
Safe |
| Direct Configuration | Browser | Bearer sk-xxx | โ Dangerous |
๐ Debugging and Testing
Debug Configuration
๐ ๏ธ Debug Templates
Node.js Debug Configuration:
const debugRequest = XRequest('https://your-api.com/chat', {
headers: {
Authorization: `Bearer ${process.env.DEBUG_API_KEY}`,
},
params: { query: 'test message' },
});
Frontend Debug Configuration:
const debugRequest = XRequest('/api/debug/chat', {
params: { query: 'test message' },
});
Configuration Validation
โ
Security Check Tools
const validateSecurity = (config: any) => {
const isBrowser = typeof window !== 'undefined';
const hasAuth = config.headers?.Authorization || config.headers?.authorization;
if (isBrowser && hasAuth) {
throw new Error(
'โ Frontend environment prohibits Authorization configuration, risk of key leakage!',
);
}
console.log('โ
Security configuration check passed');
return true;
};
validateSecurity({
headers: {
},
});
๐ Usage Scenarios
Standalone Usage
๐ฏ Direct Request Initiation
import { XRequest } from '@ant-design/x-sdk';
const testRequest = XRequest('https://httpbin.org/post', {
params: { test: 'data' },
});
const response = await testRequest();
console.log(response);
Integration with Other Skills
๐ Skill Collaboration Workflow
graph TD
A[x-request] -->|Configure Request| B[x-chat-provider]
A -->|Configure Request| C[use-x-chat]
B -->|Provide Provider| C
A --> D[Direct Request]
| Usage Method | Cooperating Skill | Purpose | Example |
|---|
| Standalone | None | Direct network request initiation | Test interface availability |
| With x-chat-provider | x-chat-provider | Configure requests for custom Provider | Configure private API |
| With use-x-chat | use-x-chat | Configure requests for built-in Provider | Configure OpenAI API |
| Complete AI Application | x-request โ x-chat-provider โ use-x-chat | Configure requests for entire system | Complete AI conversation application |
โ ๏ธ useXChat Integration Security Warning
Important Warning: useXChat is only for frontend environments, XRequest configuration must not contain Authorization!
โ Incorrect Configuration (Dangerous):
const unsafeRequest = XRequest('https://api.openai.com/v1/chat/completions', {
headers: {
Authorization: 'Bearer sk-xxxxxxxxxxxxxx',
},
manual: true,
});
โ
Correct Configuration (Safe):
const safeRequest = XRequest('/api/proxy/openai', {
params: {
model: 'gpt-3.5-turbo',
stream: true,
},
manual: true,
});
๐จ 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
โ
Configuration Checklist
Before using XRequest, please confirm the following configurations are correctly set:
๐ Configuration Checklist
| Check Item | Status | Description |
|---|
| API URL | โ
Must Configure | XRequest('https://api.xxx.com') |
| Auth Info | โ ๏ธ Environment Related | FrontendโProhibited, Node.jsโ
Available |
| manual Config | โ
Provider Scenario | In Provider needs to be set to true, other scenarios need to be set according to actual situation |
| Other Config | โ No Need to Configure | Built-in reasonable default values |
| Interface Availability | โ
Recommended Test | Verify with debug configuration |
๐ ๏ธ Quick Verification Script
const checkConfig = () => {
const checks = [
{
name: 'Global Configuration',
test: () => {
return true;
},
},
{
name: 'Security Configuration',
test: () => validateSecurity(globalConfig),
},
{
name: 'Type Check',
test: () => {
return true;
},
},
];
checks.forEach((check) => {
console.log(`${check.name}: ${check.test() ? 'โ
' : 'โ'}`);
});
};
๐ฏ Skill Collaboration
graph LR
A[x-request] -->|Configure Request| B[x-chat-provider]
A -->|Configure Request| C[use-x-chat]
B -->|Provide Provider| C
๐ Skill Usage Comparison Table
| Usage Scenario | Required Skills | Usage Order | Completion Time |
|---|
| Test Interface | x-request | Direct Use | 2 minutes |
| Private API Adaptation | x-request โ x-chat-provider | Configure request first, then create Provider | 10 minutes |
| Standard AI Application | x-request โ use-x-chat | Configure request first, then build interface | 15 minutes |
| Complete Customization | x-request โ x-chat-provider โ use-x-chat | Complete workflow | 30 minutes |
๐ Reference Resources
๐ Core Reference Documentation
๐ SDK Official Documentation
๐ป Example Code