From d443c86620614e86a2e51559a406e91fde7f55bb Mon Sep 17 00:00:00 2001 From: hkfires <10558748+hkfires@users.noreply.github.com> Date: Tue, 30 Dec 2025 11:07:02 +0800 Subject: [PATCH] refactor(config): rename model mapping fields from from/to to name/alias --- config.example.yaml | 32 ++++++++++++------------ internal/config/config.go | 32 ++++++++++++------------ sdk/cliproxy/auth/model_name_mappings.go | 12 ++++----- sdk/cliproxy/service.go | 12 ++++----- 4 files changed, 44 insertions(+), 44 deletions(-) diff --git a/config.example.yaml b/config.example.yaml index db735250..73e2a8ac 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -201,29 +201,29 @@ ws-auth: false # NOTE: Mappings do not apply to gemini-api-key, codex-api-key, claude-api-key, openai-compatibility, vertex-api-key, or ampcode. # oauth-model-mappings: # gemini-cli: -# - from: "gemini-2.5-pro" # original model name under this channel -# to: "gpt-5" # client-visible alias +# - name: "gemini-2.5-pro" # original model name under this channel +# alias: "g2.5p" # client-visible alias # vertex: -# - from: "gemini-2.5-pro" -# to: "gpt-5" +# - name: "gemini-2.5-pro" +# alias: "g2.5p" # aistudio: -# - from: "gemini-2.5-pro" -# to: "gpt-5" +# - name: "gemini-2.5-pro" +# alias: "g2.5p" # antigravity: -# - from: "gemini-3-pro-preview" -# to: "gpt-5" +# - name: "gemini-3-pro-preview" +# alias: "g3p" # claude: -# - from: "claude-sonnet-4-5-20250929" -# to: "gpt-5" +# - name: "claude-sonnet-4-5-20250929" +# alias: "cs4.5" # codex: -# - from: "gpt-5" -# to: "gemini-2.5-pro" +# - name: "gpt-5" +# alias: "g5" # qwen: -# - from: "qwen3-coder-plus" -# to: "gpt-5" +# - name: "qwen3-coder-plus" +# alias: "qwen-plus" # iflow: -# - from: "glm-4.7" -# to: "gpt-5" +# - name: "glm-4.7" +# alias: "glm-god" # OAuth provider excluded models # oauth-excluded-models: diff --git a/internal/config/config.go b/internal/config/config.go index 517b836d..760be600 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -146,10 +146,10 @@ type RoutingConfig struct { } // ModelNameMapping defines a model ID rename mapping for a specific channel. -// It maps the original model name (From) to the client-visible alias (To). +// It maps the original model name (Name) to the client-visible alias (Alias). type ModelNameMapping struct { - From string `yaml:"from" json:"from"` - To string `yaml:"to" json:"to"` + Name string `yaml:"name" json:"name"` + Alias string `yaml:"alias" json:"alias"` } // AmpModelMapping defines a model name mapping for Amp CLI requests. @@ -508,29 +508,29 @@ func (cfg *Config) SanitizeOAuthModelMappings() { if channel == "" || len(mappings) == 0 { continue } - seenFrom := make(map[string]struct{}, len(mappings)) - seenTo := make(map[string]struct{}, len(mappings)) + seenName := make(map[string]struct{}, len(mappings)) + seenAlias := make(map[string]struct{}, len(mappings)) clean := make([]ModelNameMapping, 0, len(mappings)) for _, mapping := range mappings { - from := strings.TrimSpace(mapping.From) - to := strings.TrimSpace(mapping.To) - if from == "" || to == "" { + name := strings.TrimSpace(mapping.Name) + alias := strings.TrimSpace(mapping.Alias) + if name == "" || alias == "" { continue } - if strings.EqualFold(from, to) { + if strings.EqualFold(name, alias) { continue } - fromKey := strings.ToLower(from) - toKey := strings.ToLower(to) - if _, ok := seenFrom[fromKey]; ok { + nameKey := strings.ToLower(name) + aliasKey := strings.ToLower(alias) + if _, ok := seenName[nameKey]; ok { continue } - if _, ok := seenTo[toKey]; ok { + if _, ok := seenAlias[aliasKey]; ok { continue } - seenFrom[fromKey] = struct{}{} - seenTo[toKey] = struct{}{} - clean = append(clean, ModelNameMapping{From: from, To: to}) + seenName[nameKey] = struct{}{} + seenAlias[aliasKey] = struct{}{} + clean = append(clean, ModelNameMapping{Name: name, Alias: alias}) } if len(clean) > 0 { out[channel] = clean diff --git a/sdk/cliproxy/auth/model_name_mappings.go b/sdk/cliproxy/auth/model_name_mappings.go index e7238f67..483cb9c9 100644 --- a/sdk/cliproxy/auth/model_name_mappings.go +++ b/sdk/cliproxy/auth/model_name_mappings.go @@ -26,19 +26,19 @@ func compileModelNameMappingTable(mappings map[string][]internalconfig.ModelName } rev := make(map[string]string, len(entries)) for _, entry := range entries { - from := strings.TrimSpace(entry.From) - to := strings.TrimSpace(entry.To) - if from == "" || to == "" { + name := strings.TrimSpace(entry.Name) + alias := strings.TrimSpace(entry.Alias) + if name == "" || alias == "" { continue } - if strings.EqualFold(from, to) { + if strings.EqualFold(name, alias) { continue } - aliasKey := strings.ToLower(to) + aliasKey := strings.ToLower(alias) if _, exists := rev[aliasKey]; exists { continue } - rev[aliasKey] = from + rev[aliasKey] = name } if len(rev) > 0 { out.reverse[channel] = rev diff --git a/sdk/cliproxy/service.go b/sdk/cliproxy/service.go index 89f5b3c2..ae56e4b6 100644 --- a/sdk/cliproxy/service.go +++ b/sdk/cliproxy/service.go @@ -1191,19 +1191,19 @@ func applyOAuthModelMappings(cfg *config.Config, provider, authKind string, mode } forward := make(map[string]string, len(mappings)) for i := range mappings { - from := strings.TrimSpace(mappings[i].From) - to := strings.TrimSpace(mappings[i].To) - if from == "" || to == "" { + name := strings.TrimSpace(mappings[i].Name) + alias := strings.TrimSpace(mappings[i].Alias) + if name == "" || alias == "" { continue } - if strings.EqualFold(from, to) { + if strings.EqualFold(name, alias) { continue } - key := strings.ToLower(from) + key := strings.ToLower(name) if _, exists := forward[key]; exists { continue } - forward[key] = to + forward[key] = alias } if len(forward) == 0 { return models