fix: add model display name

This commit is contained in:
wolfkill
2026-05-28 18:36:38 +08:00
committed by lyingbug
parent 4e58dd42cc
commit 43565c5d1b
21 changed files with 187 additions and 46 deletions
+15 -13
View File
@@ -15,18 +15,19 @@ import (
// stripped along with every other field that could leak how a particular
// tenant configured the upstream provider.
type ModelResponse struct {
ID string `json:"id"`
TenantID uint64 `json:"tenant_id"`
Name string `json:"name"`
Type types.ModelType `json:"type"`
Source types.ModelSource `json:"source"`
Description string `json:"description"`
Parameters ModelParametersDTO `json:"parameters"`
IsDefault bool `json:"is_default"`
IsBuiltin bool `json:"is_builtin"`
Status types.ModelStatus `json:"status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ID string `json:"id"`
TenantID uint64 `json:"tenant_id"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
Type types.ModelType `json:"type"`
Source types.ModelSource `json:"source"`
Description string `json:"description"`
Parameters ModelParametersDTO `json:"parameters"`
IsDefault bool `json:"is_default"`
IsBuiltin bool `json:"is_builtin"`
Status types.ModelStatus `json:"status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// Per-field "configured?" map. Omitted for builtin models (no
// per-tenant credentials). See MCPServiceResponse.Credentials.
Credentials map[string]CredentialFieldMetadata `json:"credentials,omitempty"`
@@ -44,7 +45,7 @@ type ModelParametersDTO struct {
Provider string `json:"provider"`
ExtraConfig map[string]string `json:"extra_config,omitempty"`
CustomHeaders map[string]string `json:"custom_headers,omitempty"`
SupportsVision bool `json:"supports_vision"`
SupportsVision bool `json:"supports_vision"`
AppID string `json:"app_id,omitempty"`
}
@@ -88,6 +89,7 @@ func NewModelResponse(m *types.Model) *ModelResponse {
ID: m.ID,
TenantID: m.TenantID,
Name: m.Name,
DisplayName: m.DisplayName,
Type: m.Type,
Source: m.Source,
Description: m.Description,
+4 -2
View File
@@ -11,8 +11,9 @@ import (
func TestModelResponse_OmitsSecrets(t *testing.T) {
m := &types.Model{
ID: "m-1",
Name: "gpt-x",
ID: "m-1",
Name: "gpt-x",
DisplayName: "Support QA",
Parameters: types.ModelParameters{
APIKey: "sk-real-api-key-do-not-leak",
AppSecret: "app-real-secret-do-not-leak",
@@ -39,6 +40,7 @@ func TestModelResponse_OmitsSecrets(t *testing.T) {
// Non-secret fields pass through.
assert.Contains(t, s, "appid-public-ok-to-show")
assert.Contains(t, s, "api.example.com")
assert.Contains(t, s, `"display_name":"Support QA"`)
}
func TestModelResponse_BuiltinStripsTenantConfig(t *testing.T) {
+6
View File
@@ -38,6 +38,7 @@ func NewModelHandler(service interfaces.ModelService) *ModelHandler {
// Contains all fields required to create a new model in the system
type CreateModelRequest struct {
Name string `json:"name" binding:"required"`
DisplayName string `json:"display_name"`
Type types.ModelType `json:"type" binding:"required"`
Source types.ModelSource `json:"source" binding:"required"`
Description string `json:"description"`
@@ -89,6 +90,7 @@ func (h *ModelHandler) CreateModel(c *gin.Context) {
model := &types.Model{
TenantID: tenantID,
Name: secutils.SanitizeForLog(req.Name),
DisplayName: secutils.SanitizeForLog(req.DisplayName),
Type: types.ModelType(secutils.SanitizeForLog(string(req.Type))),
Source: req.Source,
Description: secutils.SanitizeForLog(req.Description),
@@ -201,6 +203,7 @@ func (h *ModelHandler) ListModels(c *gin.Context) {
// Contains fields that can be updated for an existing model
type UpdateModelRequest struct {
Name string `json:"name"`
DisplayName *string `json:"display_name"`
Description string `json:"description"`
Parameters types.ModelParameters `json:"parameters"`
Source types.ModelSource `json:"source"`
@@ -256,6 +259,9 @@ func (h *ModelHandler) UpdateModel(c *gin.Context) {
if req.Name != "" {
model.Name = req.Name
}
if req.DisplayName != nil {
model.DisplayName = secutils.SanitizeForLog(*req.DisplayName)
}
model.Description = req.Description
// SSRF validation for updated model BaseURL
+20
View File
@@ -0,0 +1,20 @@
package handler
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestModelUpdateRequestDisplayNamePresence(t *testing.T) {
var omitted UpdateModelRequest
require.NoError(t, json.Unmarshal([]byte(`{"name":"gpt-4o"}`), &omitted))
assert.Nil(t, omitted.DisplayName)
var cleared UpdateModelRequest
require.NoError(t, json.Unmarshal([]byte(`{"display_name":""}`), &cleared))
require.NotNil(t, cleared.DisplayName)
assert.Equal(t, "", *cleared.DisplayName)
}