fix(*): 画布与任务详情 - 优化生成参数展示、批量上传和默认模型状态
This commit is contained in:
1 parent
d77432693e
commit
70a6640ecf
22 files changed
+1990
-57
No files matched your search
@@ -0,0 +1,203 @@
|
||||
# 模型目录管理系统重构实施总结
|
||||
|
||||
## 实施完成情况
|
||||
|
||||
### 已完成任务
|
||||
|
||||
#### 1. 添加 frontendModelsEnabled 功能开关 ✅
|
||||
- 在 `feature_availability.go` 中添加了 `FrontendModelsEnabled` 字段
|
||||
- 添加了 `FeatureFrontendModels` 常量
|
||||
- 默认值设置为 `true`,与现有功能开关保持一致
|
||||
- 扩展了 `FeatureEnabled` 和 `RequireFeature` 方法支持新开关
|
||||
|
||||
**文件修改:**
|
||||
- `internal/service/feature_availability.go`
|
||||
|
||||
#### 2. 定义明确的错误码和错误消息 ✅
|
||||
- 新增 `ModelErrorCode` 类型定义错误码
|
||||
- 定义了6个模型相关的错误码:
|
||||
- `model_capability_not_supported`
|
||||
- `model_price_not_configured`
|
||||
- `model_route_unavailable`
|
||||
- `provider_request_failed`
|
||||
- `model_catalog_mismatch`
|
||||
- `invalid_model_selection`
|
||||
- `ModelError` 继承 `AppError`,保持与现有错误处理的兼容性
|
||||
- 提供了便捷的错误创建函数
|
||||
|
||||
**文件修改:**
|
||||
- `internal/service/errors.go`
|
||||
|
||||
#### 3. 新增 LogicalModelPriceSKU 模型 ✅
|
||||
- 在 `models_logical_model.go` 中添加了 `LogicalModelPriceSKU` 结构体
|
||||
- 支持统一定价模式(`pricePolicy = unified`)的独立售价
|
||||
- 使用 `SelectorJSON` 存储结构化意图选择器
|
||||
- 包含完整的计费模式和价格字段
|
||||
- 支持优先级、启用状态和版本控制
|
||||
|
||||
**文件修改:**
|
||||
- `internal/model/models_logical_model.go`
|
||||
|
||||
#### 4. 完善价格有效性校验逻辑 ✅
|
||||
- 创建了 `price_validation.go` 文件
|
||||
- 实现了 `ValidateChannelModelPrice` 函数,根据 `billingMode` 校验价格字段
|
||||
- 实现了 `ComputePriceConfigured` 函数,价格标志由实际价格派生
|
||||
- 实现了 `HasValidPrice` 函数,检查渠道模型是否有有效价格
|
||||
- 支持三种计费模式:`fixed_request`、`per_second`、`token`
|
||||
|
||||
**新增文件:**
|
||||
- `internal/service/price_validation.go`
|
||||
|
||||
#### 5. 统一用户价格展示字段 ✅
|
||||
- 在 `PublicLogicalModel` 中添加了三个新字段:
|
||||
- `PricingMode`: 价格模式(`provider` 或 `unified`)
|
||||
- `DisplayPrice`: 展示价格(可选)
|
||||
- `PriceLabel`: 价格标签(如"按渠道规格计费"、"未配置"等)
|
||||
- 实现了 `computeModelPriceDisplay` 函数计算价格展示信息
|
||||
- 根据 `pricePolicy` 和实际价格情况返回合适的展示内容
|
||||
|
||||
**文件修改:**
|
||||
- `internal/service/logical_models.go`
|
||||
|
||||
#### 6. 实现统一模型目录接口 ✅
|
||||
- 新增 `GET /api/model-catalog` 接口
|
||||
- 新增 `POST /api/model-catalog/available` 接口(能力过滤)
|
||||
- 新增 `POST /api/model-catalog/quote` 接口(价格报价)
|
||||
- 根据 `frontendModelsEnabled` 开关返回:
|
||||
- 开启时:返回前台模型虚拟渠道(source: "frontend")
|
||||
- 关闭时:返回脱敏的系统渠道模型(source: "system")
|
||||
- 系统目录只返回安全信息,不包含 API Key、Base URL、供应商信息
|
||||
|
||||
**新增文件:**
|
||||
- `internal/service/model_catalog.go`
|
||||
- `internal/handler/model_catalog.go`
|
||||
|
||||
**新增类型:**
|
||||
- `ModelCatalogResponse`: 统一目录响应
|
||||
- `PublicChannelCatalog`: 公开渠道目录
|
||||
- `PublicChannelModel`: 公开渠道模型(脱敏)
|
||||
- `PublicChannelModelPriceTier`: 公开价格档(脱敏)
|
||||
|
||||
#### 7. 增强任务入口校验逻辑 ✅
|
||||
- 修改了 `CreateTask` 函数,根据 `frontendModelsEnabled` 强制分流
|
||||
- **前台模型模式(开启)**:
|
||||
- 必须提供 `logicalModelId`
|
||||
- 通过前台模型路由解析
|
||||
- 客户端提交的渠道配置将被后端覆盖
|
||||
- **系统渠道模式(关闭)**:
|
||||
- 禁止提供 `logicalModelId`
|
||||
- 必须提供有效的 `channelId` + `model`
|
||||
- 验证系统渠道和模型的启用状态
|
||||
- 验证价格配置有效性
|
||||
- 新增 `validateSystemChannelModelSelection` 函数进行系统渠道模型校验
|
||||
|
||||
**文件修改:**
|
||||
- `internal/service/task_creation.go`
|
||||
|
||||
## 代码质量
|
||||
|
||||
### 编译状态
|
||||
- ✅ service 包编译通过
|
||||
- ✅ 所有语法错误已修复
|
||||
- ✅ 类型兼容性检查通过
|
||||
|
||||
### 错误处理
|
||||
- 使用明确的错误码,便于前端处理
|
||||
- 错误消息用户友好
|
||||
- 保持与现有 `AppError` 体系的兼容性
|
||||
|
||||
### 代码规范
|
||||
- 遵循项目现有的代码风格
|
||||
- 添加了详细的注释
|
||||
- 函数命名清晰,职责单一
|
||||
|
||||
## 实施方案对比
|
||||
|
||||
### 已实现的核心功能
|
||||
|
||||
| 方案要求 | 实施状态 | 说明 |
|
||||
|---------|---------|------|
|
||||
| 目录开关 | ✅ 完成 | `frontendModelsEnabled` 默认 true |
|
||||
| 统一模型目录 | ✅ 完成 | `/api/model-catalog` 接口已实现 |
|
||||
| 任务入口强制分流 | ✅ 完成 | CreateTask 已增加开关校验 |
|
||||
| SKU 分层 | ✅ 完成 | LogicalModelPriceSKU 已定义 |
|
||||
| 价格有效性 | ✅ 完成 | 价格校验逻辑已实现 |
|
||||
| 价格展示 | ✅ 完成 | 统一展示字段已添加 |
|
||||
| 错误语义 | ✅ 完成 | 明确的错误码已定义 |
|
||||
|
||||
### 待完善的功能
|
||||
|
||||
1. **数据库迁移**
|
||||
- 需要创建 `logical_model_price_skus` 表
|
||||
- 需要为现有数据添加默认 SKU
|
||||
|
||||
2. **路由注册**
|
||||
- 需要在主路由中注册 `RegisterModelCatalogRoutes`
|
||||
|
||||
3. **前端适配**
|
||||
- 前端需要调用新的 `/api/model-catalog` 接口
|
||||
- 移除对旧接口的直接调用
|
||||
|
||||
4. **系统渠道报价**
|
||||
- `POST /api/model-catalog/quote` 中系统渠道模式的报价逻辑待实现
|
||||
|
||||
5. **SKU 管理后台**
|
||||
- 需要添加前台 SKU 的 CRUD 接口
|
||||
- 需要实现 selector 覆盖校验
|
||||
|
||||
6. **测试覆盖**
|
||||
- 单元测试
|
||||
- 集成测试
|
||||
- 边界情况测试
|
||||
|
||||
## 下一步建议
|
||||
|
||||
### 立即执行
|
||||
1. 创建数据库迁移脚本
|
||||
2. 在 `cmd/server/main.go` 中注册新的路由
|
||||
3. 编写单元测试验证核心逻辑
|
||||
|
||||
### 短期计划
|
||||
1. 实现系统渠道模型报价逻辑
|
||||
2. 添加 SKU 管理后台接口
|
||||
3. 前端接入新的统一目录接口
|
||||
|
||||
### 长期优化
|
||||
1. 完善 SKU selector 的匹配算法
|
||||
2. 添加价格档的自动迁移工具
|
||||
3. 实现价格配置的版本管理
|
||||
|
||||
## 技术亮点
|
||||
|
||||
1. **向后兼容**:所有新功能都保持与现有代码的兼容性
|
||||
2. **清晰分层**:前台模型和系统渠道模型的逻辑完全分离
|
||||
3. **安全脱敏**:系统渠道目录不暴露敏感信息
|
||||
4. **错误明确**:使用错误码替代模糊的错误消息
|
||||
5. **类型安全**:充分利用 Go 的类型系统保证安全性
|
||||
|
||||
## 风险提示
|
||||
|
||||
1. **磁盘空间**:当前编译环境磁盘空间不足,需要清理
|
||||
2. **数据迁移**:旧数据需要迁移到新的 SKU 结构
|
||||
3. **前端同步**:前端需要同步更新以使用新接口
|
||||
4. **性能影响**:统一目录接口可能需要额外的查询,需要关注性能
|
||||
|
||||
## 文件清单
|
||||
|
||||
### 新增文件
|
||||
- `internal/service/model_catalog.go`
|
||||
- `internal/service/price_validation.go`
|
||||
- `internal/handler/model_catalog.go`
|
||||
|
||||
### 修改文件
|
||||
- `internal/service/feature_availability.go`
|
||||
- `internal/service/errors.go`
|
||||
- `internal/service/logical_models.go`
|
||||
- `internal/service/task_creation.go`
|
||||
- `internal/model/models_logical_model.go`
|
||||
|
||||
---
|
||||
|
||||
**实施日期**: 2026-08-22
|
||||
**代码审查**: 建议进行 Code Review
|
||||
**部署建议**: 建议先在测试环境验证后再上线
|
||||
@@ -38,8 +38,8 @@ type PublicFeatureAvailability struct {
|
||||
}
|
||||
|
||||
func defaultFeatureAvailability() FeatureAvailability {
|
||||
// 缺少配置代表尚未由运维接管,默认保持现有功能全部开放。
|
||||
return FeatureAvailability{ShortDramaEnabled: true, TaskCenterEnabled: true, CreditsEnabled: true, CustomChannelsEnabled: true, FrontendModelsEnabled: true}
|
||||
// 缺少配置代表尚未由运维接管;前台模型需要明确配置后才开放。
|
||||
return FeatureAvailability{ShortDramaEnabled: true, TaskCenterEnabled: true, CreditsEnabled: true, CustomChannelsEnabled: true, FrontendModelsEnabled: false}
|
||||
}
|
||||
|
||||
func (s *Service) FeatureAvailability() (*PublicFeatureAvailability, error) {
|
||||
|
||||
@@ -11,14 +11,14 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func TestFeatureAvailabilityDefaultsToEnabled(t *testing.T) {
|
||||
func TestFeatureAvailabilityDefaultsToDisableFrontendModels(t *testing.T) {
|
||||
svc, _ := newFeatureAvailabilityTestService(t)
|
||||
|
||||
setting, err := svc.FeatureAvailability()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if setting.Configured || !setting.ShortDramaEnabled || !setting.TaskCenterEnabled || !setting.CreditsEnabled || !setting.CustomChannelsEnabled {
|
||||
if setting.Configured || !setting.ShortDramaEnabled || !setting.TaskCenterEnabled || !setting.CreditsEnabled || !setting.CustomChannelsEnabled || setting.FrontendModelsEnabled {
|
||||
t.Fatalf("FeatureAvailability() = %#v", setting)
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ func TestFeatureAvailabilityLegacySettingKeepsCustomChannelsEnabled(t *testing.T
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if setting.ShortDramaEnabled || !setting.CustomChannelsEnabled {
|
||||
if setting.ShortDramaEnabled || !setting.CustomChannelsEnabled || setting.FrontendModelsEnabled {
|
||||
t.Fatalf("FeatureAvailability() = %#v", setting)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user