fix: 模型管理审查修复与归档

- 修复 registry 测试 ai mock 缺失 createProviderRegistry 导出
- 新增 POST /api/providers/test 支持未保存供应商配置连通性测试
- 供应商表单新增测试连接按钮,新建默认 openai-compatible
- 连通性测试按 ok 展示成功/失败,不再统一 success 样式
- 模型表单新建时也可测试供应商连接
- 模型页使用独立 provider 列表避免分页/搜索影响
- 移除模型管理组件内联 style
- 新增 ProviderTestResultResponse 共享响应类型
- 新增 bun run format:check 脚本
- 补充关键测试覆盖(删除关联、连通性、默认类型、表单测试)
- 更新 docs/user/usage.md、docs/development/*、design.md、tasks.md
- 归档 change 至 openspec/changes/archive/2026-05-29-add-model-management
This commit is contained in:
2026-05-29 14:05:01 +08:00
parent 933c2133f0
commit 48c76e6180
23 changed files with 440 additions and 353 deletions

View File

@@ -1,7 +1,13 @@
import { App as AntApp, Form, Input, Modal, Select } from "antd";
import { useEffect } from "react";
import { App as AntApp, Button, Form, Input, Modal, Select, Space } from "antd";
import { useEffect, useState } from "react";
import type { CreateProviderRequest, Provider, ProviderType, UpdateProviderRequest } from "../../../../shared/api";
import type {
CreateProviderRequest,
Provider,
ProviderTestResponse,
ProviderType,
UpdateProviderRequest,
} from "../../../../shared/api";
interface FormValues {
apiKey: string;
@@ -15,6 +21,7 @@ interface ProviderFormModalProps {
onCancel: () => void;
onCreate: (data: CreateProviderRequest) => Promise<unknown>;
onOpenChange: (open: boolean) => void;
onTest: (data: CreateProviderRequest) => Promise<ProviderTestResponse>;
onUpdate: (args: { data: UpdateProviderRequest; id: string }) => Promise<unknown>;
open: boolean;
submitting: boolean;
@@ -31,12 +38,14 @@ export function ProviderFormModal({
onCancel,
onCreate,
onOpenChange,
onTest,
onUpdate,
open,
submitting,
}: ProviderFormModalProps) {
const { message } = AntApp.useApp();
const [form] = Form.useForm<FormValues>();
const [testing, setTesting] = useState(false);
useEffect(() => {
if (!open) return;
@@ -49,6 +58,7 @@ export function ProviderFormModal({
});
} else {
form.resetFields();
form.setFieldsValue({ type: "openai-compatible" });
}
}, [editingProvider, form, open]);
@@ -80,6 +90,30 @@ export function ProviderFormModal({
}
};
const handleTest = async () => {
try {
const values = await form.validateFields(["name", "type", "baseUrl", "apiKey"]);
setTesting(true);
const result = await onTest({
apiKey: values.apiKey,
baseUrl: values.baseUrl,
name: values.name,
type: values.type,
});
if (result.ok) {
message.success(result.message);
} else {
message.error(result.message);
}
} catch (err) {
if (err instanceof Error) {
message.error(err.message);
}
} finally {
setTesting(false);
}
};
return (
<Modal
confirmLoading={submitting}
@@ -107,6 +141,13 @@ export function ProviderFormModal({
<Form.Item label="API Key" name="apiKey" rules={[{ message: "请输入 API Key", required: true }]}>
<Input.Password placeholder="请输入 API Key" />
</Form.Item>
<Form.Item>
<Space>
<Button loading={testing} onClick={() => void handleTest()}>
</Button>
</Space>
</Form.Item>
</Form>
</Modal>
);