refactor: 简化模型管理,移除启用/禁用,优化测试和布局
- 移除供应商/模型启用禁用能力,清理DB schema/migration/API/前端 - 供应商测试改为Base URL连通性+/models探测 - 新增POST /api/models/test模型连接测试 - 新增GET /api/providers/options专用供应商选项接口 - 统一工具栏为ModelsToolbar,参考项目管理布局 - 模型弹窗优化:默认能力、响应式3列标签、并排数值 - 前后端正整数校验、供应商下拉loading/error/empty状态 - 表格列宽统一,操作列/名称列固定宽度
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
|
||||
import type { CreateModelRequest, Model, ModelListResponse, ModelResponse, UpdateModelRequest } from "../../shared/api";
|
||||
import type {
|
||||
CreateModelRequest,
|
||||
Model,
|
||||
ModelListResponse,
|
||||
ModelResponse,
|
||||
ModelTestResponse,
|
||||
ModelTestResultResponse,
|
||||
TestModelRequest,
|
||||
UpdateModelRequest,
|
||||
} from "../../shared/api";
|
||||
|
||||
const MODELS_KEY = ["models"] as const;
|
||||
|
||||
@@ -21,16 +30,6 @@ export async function deleteModel(id: string): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function disableModel(id: string): Promise<Model> {
|
||||
const response = await fetch(`/api/models/${id}/disable`, { method: "POST" });
|
||||
return handleResponse(response);
|
||||
}
|
||||
|
||||
export async function enableModel(id: string): Promise<Model> {
|
||||
const response = await fetch(`/api/models/${id}/enable`, { method: "POST" });
|
||||
return handleResponse(response);
|
||||
}
|
||||
|
||||
export async function fetchModel(id: string): Promise<Model> {
|
||||
const response = await fetch(`/api/models/${id}`);
|
||||
return handleResponse(response);
|
||||
@@ -57,6 +56,20 @@ export async function fetchModelList(params: {
|
||||
return response.json() as Promise<ModelListResponse>;
|
||||
}
|
||||
|
||||
export async function testModelConnection(data: TestModelRequest): Promise<ModelTestResponse> {
|
||||
const response = await fetch("/api/models/test", {
|
||||
body: JSON.stringify(data),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
method: "POST",
|
||||
});
|
||||
if (!response.ok) {
|
||||
const body = (await response.json().catch(() => null)) as null | { error?: string };
|
||||
throw new Error(body?.error ?? `HTTP ${response.status}`);
|
||||
}
|
||||
const result = (await response.json()) as ModelTestResultResponse;
|
||||
return result.modelTestResponse;
|
||||
}
|
||||
|
||||
export async function updateModel(id: string, data: UpdateModelRequest): Promise<Model> {
|
||||
const response = await fetch(`/api/models/${id}`, {
|
||||
body: JSON.stringify(data),
|
||||
@@ -86,26 +99,6 @@ export function useDeleteModel() {
|
||||
});
|
||||
}
|
||||
|
||||
export function useDisableModel() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: disableModel,
|
||||
onSuccess: () => {
|
||||
void queryClient.invalidateQueries({ queryKey: MODELS_KEY });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useEnableModel() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: enableModel,
|
||||
onSuccess: () => {
|
||||
void queryClient.invalidateQueries({ queryKey: MODELS_KEY });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useModel(id: string) {
|
||||
return useQuery({
|
||||
enabled: !!id,
|
||||
@@ -121,6 +114,12 @@ export function useModelList(params: { keyword?: string; page?: number; pageSize
|
||||
});
|
||||
}
|
||||
|
||||
export function useTestModelConnection() {
|
||||
return useMutation({
|
||||
mutationFn: testModelConnection,
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateModel() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
|
||||
@@ -4,6 +4,7 @@ import type {
|
||||
CreateProviderRequest,
|
||||
Provider,
|
||||
ProviderListResponse,
|
||||
ProviderOptionsResponse,
|
||||
ProviderResponse,
|
||||
ProviderTestResponse,
|
||||
ProviderTestResultResponse,
|
||||
@@ -30,16 +31,6 @@ export async function deleteProvider(id: string): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function disableProvider(id: string): Promise<Provider> {
|
||||
const response = await fetch(`/api/providers/${id}/disable`, { method: "POST" });
|
||||
return handleResponse(response);
|
||||
}
|
||||
|
||||
export async function enableProvider(id: string): Promise<Provider> {
|
||||
const response = await fetch(`/api/providers/${id}/enable`, { method: "POST" });
|
||||
return handleResponse(response);
|
||||
}
|
||||
|
||||
export async function fetchProvider(id: string): Promise<Provider> {
|
||||
const response = await fetch(`/api/providers/${id}`);
|
||||
return handleResponse(response);
|
||||
@@ -64,6 +55,15 @@ export async function fetchProviderList(params: {
|
||||
return response.json() as Promise<ProviderListResponse>;
|
||||
}
|
||||
|
||||
export async function fetchProviderOptions(): Promise<ProviderOptionsResponse> {
|
||||
const response = await fetch("/api/providers/options");
|
||||
if (!response.ok) {
|
||||
const body = (await response.json().catch(() => null)) as null | { error?: string };
|
||||
throw new Error(body?.error ?? `HTTP ${response.status}`);
|
||||
}
|
||||
return response.json() as Promise<ProviderOptionsResponse>;
|
||||
}
|
||||
|
||||
export async function testProviderConfig(data: CreateProviderRequest): Promise<ProviderTestResponse> {
|
||||
const response = await fetch("/api/providers/test", {
|
||||
body: JSON.stringify(data),
|
||||
@@ -78,16 +78,6 @@ export async function testProviderConfig(data: CreateProviderRequest): Promise<P
|
||||
return result.providerTestResponse;
|
||||
}
|
||||
|
||||
export async function testProviderConnection(id: string): Promise<ProviderTestResponse> {
|
||||
const response = await fetch(`/api/providers/${id}/test`, { method: "POST" });
|
||||
if (!response.ok) {
|
||||
const body = (await response.json().catch(() => null)) as null | { error?: string };
|
||||
throw new Error(body?.error ?? `HTTP ${response.status}`);
|
||||
}
|
||||
const data = (await response.json()) as ProviderTestResultResponse;
|
||||
return data.providerTestResponse;
|
||||
}
|
||||
|
||||
export async function updateProvider(id: string, data: UpdateProviderRequest): Promise<Provider> {
|
||||
const response = await fetch(`/api/providers/${id}`, {
|
||||
body: JSON.stringify(data),
|
||||
@@ -118,26 +108,6 @@ export function useDeleteProvider() {
|
||||
});
|
||||
}
|
||||
|
||||
export function useDisableProvider() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: disableProvider,
|
||||
onSuccess: () => {
|
||||
void queryClient.invalidateQueries({ queryKey: PROVIDERS_KEY });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useEnableProvider() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: enableProvider,
|
||||
onSuccess: () => {
|
||||
void queryClient.invalidateQueries({ queryKey: PROVIDERS_KEY });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useProvider(id: string) {
|
||||
return useQuery({
|
||||
enabled: !!id,
|
||||
@@ -153,15 +123,16 @@ export function useProviderList(params: { keyword?: string; page?: number; pageS
|
||||
});
|
||||
}
|
||||
|
||||
export function useTestProviderConfig() {
|
||||
return useMutation({
|
||||
mutationFn: testProviderConfig,
|
||||
export function useProviderOptions() {
|
||||
return useQuery({
|
||||
queryFn: fetchProviderOptions,
|
||||
queryKey: [...PROVIDERS_KEY, "options"],
|
||||
});
|
||||
}
|
||||
|
||||
export function useTestProviderConnection() {
|
||||
export function useTestProviderConfig() {
|
||||
return useMutation({
|
||||
mutationFn: testProviderConnection,
|
||||
mutationFn: testProviderConfig,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user