1
0

feat: 前端适配后端新接口

适配后端统一模型 ID、协议字段、UUID 自动生成和结构化错误响应:

- 类型定义:Provider 新增 protocol 字段,Model 新增 unifiedId,CreateModelInput 移除 id
- API 客户端:提取结构化错误响应中的错误码
- 供应商管理:添加协议选择下拉框和表格列
- 模型管理:移除 ID 输入,显示统一模型 ID(只读)
- Hooks:错误码映射为友好中文消息
- 测试:所有组件测试通过,mock 数据适配新字段
- 文档:更新 README 说明协议字段和统一模型 ID
This commit is contained in:
2026-04-21 20:49:37 +08:00
parent 24f03595a7
commit feff97acbd
28 changed files with 547 additions and 78 deletions

View File

@@ -9,6 +9,7 @@ const mockProviders = [
name: 'OpenAI',
api_key: 'sk-xxx',
base_url: 'https://api.openai.com',
protocol: 'openai',
enabled: true,
created_at: '2025-01-01T00:00:00Z',
updated_at: '2025-01-01T00:00:00Z',
@@ -18,6 +19,7 @@ const mockProviders = [
name: 'Anthropic',
api_key: 'sk-yyy',
base_url: 'https://api.anthropic.com',
protocol: 'anthropic',
enabled: false,
created_at: '2025-01-02T00:00:00Z',
updated_at: '2025-01-02T00:00:00Z',
@@ -34,7 +36,7 @@ describe('providers API', () => {
describe('listProviders', () => {
it('returns array of Provider objects with camelCase keys', async () => {
server.use(
http.get('/api/providers', () => {
http.get('http://localhost:3000/api/providers', () => {
return HttpResponse.json(mockProviders);
}),
);
@@ -47,6 +49,7 @@ describe('providers API', () => {
name: 'OpenAI',
apiKey: 'sk-xxx',
baseUrl: 'https://api.openai.com',
protocol: 'openai',
enabled: true,
createdAt: '2025-01-01T00:00:00Z',
updatedAt: '2025-01-01T00:00:00Z',
@@ -56,6 +59,7 @@ describe('providers API', () => {
name: 'Anthropic',
apiKey: 'sk-yyy',
baseUrl: 'https://api.anthropic.com',
protocol: 'anthropic',
enabled: false,
createdAt: '2025-01-02T00:00:00Z',
updatedAt: '2025-01-02T00:00:00Z',
@@ -70,7 +74,7 @@ describe('providers API', () => {
let receivedBody: Record<string, unknown> | null = null;
server.use(
http.post('/api/providers', async ({ request }) => {
http.post('http://localhost:3000/api/providers', async ({ request }) => {
receivedMethod = request.method;
receivedBody = (await request.json()) as Record<string, unknown>;
return HttpResponse.json(mockProviders[0]);
@@ -100,6 +104,7 @@ describe('providers API', () => {
name: 'OpenAI',
apiKey: 'sk-xxx',
baseUrl: 'https://api.openai.com',
protocol: 'openai',
enabled: true,
createdAt: '2025-01-01T00:00:00Z',
updatedAt: '2025-01-01T00:00:00Z',
@@ -114,7 +119,7 @@ describe('providers API', () => {
let receivedBody: Record<string, unknown> | null = null;
server.use(
http.put('/api/providers/:id', async ({ request, params }) => {
http.put('http://localhost:3000/api/providers/:id', async ({ request, params }) => {
receivedMethod = request.method;
receivedUrl = new URL(request.url).pathname;
receivedBody = (await request.json()) as Record<string, unknown>;
@@ -148,7 +153,7 @@ describe('providers API', () => {
let receivedUrl: string | null = null;
server.use(
http.delete('/api/providers/:id', ({ request, params }) => {
http.delete('http://localhost:3000/api/providers/:id', ({ request, params }) => {
receivedMethod = request.method;
receivedUrl = new URL(request.url).pathname;
return new HttpResponse(null, { status: 204 });