fix(backend): 模型目录 - 空目录不再丢失集合字段导致刷新掉登录 (#502)

This commit is contained in:
zhuchiwangzhiqiang authored and GitHub committed 2026-09-14 22:39:18 +08:00
1 parent 73ec4a33b2
commit de6a642f6c
2 files changed
+84 -10

No files matched your search

+11 -10
View File
@@ -21,10 +21,11 @@ const (
// ModelCatalogResponse 是创作端模型选择的统一读模型。
// Source=frontend 时读取 Models;Source=system 时读取 Channels。
// 两个集合都始终序列化为数组:空目录必须发 [],缺字段会被前端判成畸形响应。
type ModelCatalogResponse struct {
Source ModelCatalogSource `json:"source"`
Models []PublicLogicalModel `json:"models,omitempty"`
Channels []PublicChannelCatalog `json:"channels,omitempty"`
Models []PublicLogicalModel `json:"models"`
Channels []PublicChannelCatalog `json:"channels"`
}
// PublicChannelCatalog 公开的渠道目录信息(脱敏)
@@ -74,25 +75,25 @@ func (s *Service) ModelCatalog(intent *ModelRequestIntent) (*ModelCatalogRespons
return nil, err
}
// 两个集合都初始化成非 nil 空切片:空目录要发 [],不能因为“没有模型”而丢掉字段。
response := &ModelCatalogResponse{Models: []PublicLogicalModel{}, Channels: []PublicChannelCatalog{}}
if frontendEnabled {
models, err := s.PublicLogicalModels(intent)
if err != nil {
return nil, err
}
return &ModelCatalogResponse{
Source: ModelCatalogSourceFrontend,
Models: models,
}, nil
response.Source = ModelCatalogSourceFrontend
response.Models = append(response.Models, models...)
return response, nil
}
channels, err := s.publicSystemChannelCatalog(intent)
if err != nil {
return nil, err
}
return &ModelCatalogResponse{
Source: ModelCatalogSourceSystem,
Channels: channels,
}, nil
response.Source = ModelCatalogSourceSystem
response.Channels = append(response.Channels, channels...)
return response, nil
}
// publicSystemChannelCatalog 组装普通用户可见的系统渠道读模型,不暴露密钥、Base URL 等执行凭证。