feat(group): 添加分组级别模型路由配置功能
支持为分组配置模型路由规则,可以指定特定模型模式优先使用的账号列表。 - 新增 model_routing 字段存储路由配置(JSONB格式,支持通配符匹配) - 新增 model_routing_enabled 字段控制是否启用路由 - 更新后端 handler/service/repository 支持路由配置的增删改查 - 更新前端 GroupsView 添加路由配置界面 - 添加数据库迁移脚本 040/041
This commit is contained in:
@@ -3864,6 +3864,8 @@ type GroupMutation struct {
|
||||
claude_code_only *bool
|
||||
fallback_group_id *int64
|
||||
addfallback_group_id *int64
|
||||
model_routing *map[string][]int64
|
||||
model_routing_enabled *bool
|
||||
clearedFields map[string]struct{}
|
||||
api_keys map[int64]struct{}
|
||||
removedapi_keys map[int64]struct{}
|
||||
@@ -4974,6 +4976,91 @@ func (m *GroupMutation) ResetFallbackGroupID() {
|
||||
delete(m.clearedFields, group.FieldFallbackGroupID)
|
||||
}
|
||||
|
||||
// SetModelRouting sets the "model_routing" field.
|
||||
func (m *GroupMutation) SetModelRouting(value map[string][]int64) {
|
||||
m.model_routing = &value
|
||||
}
|
||||
|
||||
// ModelRouting returns the value of the "model_routing" field in the mutation.
|
||||
func (m *GroupMutation) ModelRouting() (r map[string][]int64, exists bool) {
|
||||
v := m.model_routing
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldModelRouting returns the old "model_routing" field's value of the Group entity.
|
||||
// If the Group object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *GroupMutation) OldModelRouting(ctx context.Context) (v map[string][]int64, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldModelRouting is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldModelRouting requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldModelRouting: %w", err)
|
||||
}
|
||||
return oldValue.ModelRouting, nil
|
||||
}
|
||||
|
||||
// ClearModelRouting clears the value of the "model_routing" field.
|
||||
func (m *GroupMutation) ClearModelRouting() {
|
||||
m.model_routing = nil
|
||||
m.clearedFields[group.FieldModelRouting] = struct{}{}
|
||||
}
|
||||
|
||||
// ModelRoutingCleared returns if the "model_routing" field was cleared in this mutation.
|
||||
func (m *GroupMutation) ModelRoutingCleared() bool {
|
||||
_, ok := m.clearedFields[group.FieldModelRouting]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetModelRouting resets all changes to the "model_routing" field.
|
||||
func (m *GroupMutation) ResetModelRouting() {
|
||||
m.model_routing = nil
|
||||
delete(m.clearedFields, group.FieldModelRouting)
|
||||
}
|
||||
|
||||
// SetModelRoutingEnabled sets the "model_routing_enabled" field.
|
||||
func (m *GroupMutation) SetModelRoutingEnabled(b bool) {
|
||||
m.model_routing_enabled = &b
|
||||
}
|
||||
|
||||
// ModelRoutingEnabled returns the value of the "model_routing_enabled" field in the mutation.
|
||||
func (m *GroupMutation) ModelRoutingEnabled() (r bool, exists bool) {
|
||||
v := m.model_routing_enabled
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldModelRoutingEnabled returns the old "model_routing_enabled" field's value of the Group entity.
|
||||
// If the Group object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *GroupMutation) OldModelRoutingEnabled(ctx context.Context) (v bool, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldModelRoutingEnabled is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldModelRoutingEnabled requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldModelRoutingEnabled: %w", err)
|
||||
}
|
||||
return oldValue.ModelRoutingEnabled, nil
|
||||
}
|
||||
|
||||
// ResetModelRoutingEnabled resets all changes to the "model_routing_enabled" field.
|
||||
func (m *GroupMutation) ResetModelRoutingEnabled() {
|
||||
m.model_routing_enabled = nil
|
||||
}
|
||||
|
||||
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by ids.
|
||||
func (m *GroupMutation) AddAPIKeyIDs(ids ...int64) {
|
||||
if m.api_keys == nil {
|
||||
@@ -5332,7 +5419,7 @@ func (m *GroupMutation) Type() string {
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *GroupMutation) Fields() []string {
|
||||
fields := make([]string, 0, 19)
|
||||
fields := make([]string, 0, 21)
|
||||
if m.created_at != nil {
|
||||
fields = append(fields, group.FieldCreatedAt)
|
||||
}
|
||||
@@ -5390,6 +5477,12 @@ func (m *GroupMutation) Fields() []string {
|
||||
if m.fallback_group_id != nil {
|
||||
fields = append(fields, group.FieldFallbackGroupID)
|
||||
}
|
||||
if m.model_routing != nil {
|
||||
fields = append(fields, group.FieldModelRouting)
|
||||
}
|
||||
if m.model_routing_enabled != nil {
|
||||
fields = append(fields, group.FieldModelRoutingEnabled)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
@@ -5436,6 +5529,10 @@ func (m *GroupMutation) Field(name string) (ent.Value, bool) {
|
||||
return m.ClaudeCodeOnly()
|
||||
case group.FieldFallbackGroupID:
|
||||
return m.FallbackGroupID()
|
||||
case group.FieldModelRouting:
|
||||
return m.ModelRouting()
|
||||
case group.FieldModelRoutingEnabled:
|
||||
return m.ModelRoutingEnabled()
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
@@ -5483,6 +5580,10 @@ func (m *GroupMutation) OldField(ctx context.Context, name string) (ent.Value, e
|
||||
return m.OldClaudeCodeOnly(ctx)
|
||||
case group.FieldFallbackGroupID:
|
||||
return m.OldFallbackGroupID(ctx)
|
||||
case group.FieldModelRouting:
|
||||
return m.OldModelRouting(ctx)
|
||||
case group.FieldModelRoutingEnabled:
|
||||
return m.OldModelRoutingEnabled(ctx)
|
||||
}
|
||||
return nil, fmt.Errorf("unknown Group field %s", name)
|
||||
}
|
||||
@@ -5625,6 +5726,20 @@ func (m *GroupMutation) SetField(name string, value ent.Value) error {
|
||||
}
|
||||
m.SetFallbackGroupID(v)
|
||||
return nil
|
||||
case group.FieldModelRouting:
|
||||
v, ok := value.(map[string][]int64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetModelRouting(v)
|
||||
return nil
|
||||
case group.FieldModelRoutingEnabled:
|
||||
v, ok := value.(bool)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetModelRoutingEnabled(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Group field %s", name)
|
||||
}
|
||||
@@ -5793,6 +5908,9 @@ func (m *GroupMutation) ClearedFields() []string {
|
||||
if m.FieldCleared(group.FieldFallbackGroupID) {
|
||||
fields = append(fields, group.FieldFallbackGroupID)
|
||||
}
|
||||
if m.FieldCleared(group.FieldModelRouting) {
|
||||
fields = append(fields, group.FieldModelRouting)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
@@ -5834,6 +5952,9 @@ func (m *GroupMutation) ClearField(name string) error {
|
||||
case group.FieldFallbackGroupID:
|
||||
m.ClearFallbackGroupID()
|
||||
return nil
|
||||
case group.FieldModelRouting:
|
||||
m.ClearModelRouting()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Group nullable field %s", name)
|
||||
}
|
||||
@@ -5899,6 +6020,12 @@ func (m *GroupMutation) ResetField(name string) error {
|
||||
case group.FieldFallbackGroupID:
|
||||
m.ResetFallbackGroupID()
|
||||
return nil
|
||||
case group.FieldModelRouting:
|
||||
m.ResetModelRouting()
|
||||
return nil
|
||||
case group.FieldModelRoutingEnabled:
|
||||
m.ResetModelRoutingEnabled()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Group field %s", name)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user