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({
|
||||
|
||||
Reference in New Issue
Block a user