feat: 新增模型管理功能(供应商 + 模型 CRUD)

- 新增 providers/models 数据库表、迁移和数据访问层
- 新增 15 个后端 API 路由(供应商/模型 CRUD + 连通性测试)
- 新增 AI 服务层(registry.ts: buildProviderRegistry + testProviderConnection)
- 新增前端模型管理页面(Tabs: 供应商/模型,含表格、表单、工具栏)
- 新增前端 hooks(use-providers, use-models)
- 新增共享类型和 MODEL_CAPABILITIES 常量
- 新增 10 个测试文件(66 个测试用例,4 个因 bun test ESM 兼容问题待修复)
- 更新开发文档(architecture, backend, frontend)
- 附带 apply-review 修复:统一错误响应、提取共享常量、清理重复测试

注意:registry.test.ts 中 4 个测试因 bun test 无法解析
createProviderRegistry ESM 导出而失败,详情见 context.md
This commit is contained in:
2026-05-29 12:40:10 +08:00
parent 2ea4bd4410
commit 933c2133f0
56 changed files with 4706 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
import { sqliteTable, text } from "drizzle-orm/sqlite-core";
import { index, integer, sqliteTable, text, uniqueIndex } from "drizzle-orm/sqlite-core";
export const projects = sqliteTable("projects", {
archivedAt: text("archived_at"),
@@ -12,6 +12,41 @@ export const projects = sqliteTable("projects", {
updatedAt: text("updated_at").notNull(),
});
export const providers = sqliteTable("providers", {
apiKey: text("api_key").notNull(),
baseUrl: text("base_url").notNull(),
createdAt: text("created_at").notNull(),
enabled: integer("enabled", { mode: "boolean" }).notNull().default(true),
id: text("id").primaryKey(),
name: text("name").notNull().unique(),
type: text("type", { enum: ["anthropic", "openai", "openai-compatible"] })
.notNull()
.default("openai-compatible"),
updatedAt: text("updated_at").notNull(),
});
export const models = sqliteTable(
"models",
{
capabilities: text("capabilities").notNull(),
contextLength: integer("context_length"),
createdAt: text("created_at").notNull(),
enabled: integer("enabled", { mode: "boolean" }).notNull().default(true),
id: text("id").primaryKey(),
maxOutputTokens: integer("max_output_tokens"),
modelId: text("model_id").notNull(),
name: text("name").notNull(),
providerId: text("provider_id")
.notNull()
.references(() => providers.id),
updatedAt: text("updated_at").notNull(),
},
(table) => [
uniqueIndex("models_provider_id_model_id_unique").on(table.providerId, table.modelId),
index("models_provider_id_idx").on(table.providerId),
],
);
export const schemaMigrations = sqliteTable("schema_migrations", {
appliedAt: text("applied_at").notNull(),
checksum: text("checksum").notNull(),