From d02bf9c243bb0d142469c71c2ca47640b6a1c107 Mon Sep 17 00:00:00 2001 From: Luis Pater Date: Wed, 17 Dec 2025 02:05:03 +0800 Subject: [PATCH] feat(diff): add support for model prefix changes in config diff logic Enhance the configuration diff logic to include detection and reporting of `prefix` changes for all model types. Update related struct naming for consistency across the watcher module. --- internal/watcher/diff/config_diff.go | 12 ++++++++++ internal/watcher/diff/oauth_excluded.go | 32 ++++++++++++------------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/internal/watcher/diff/config_diff.go b/internal/watcher/diff/config_diff.go index 892fc0b1..1f1a8b27 100644 --- a/internal/watcher/diff/config_diff.go +++ b/internal/watcher/diff/config_diff.go @@ -81,6 +81,9 @@ func BuildConfigChangeDetails(oldCfg, newCfg *config.Config) []string { if strings.TrimSpace(o.ProxyURL) != strings.TrimSpace(n.ProxyURL) { changes = append(changes, fmt.Sprintf("gemini[%d].proxy-url: %s -> %s", i, formatProxyURL(o.ProxyURL), formatProxyURL(n.ProxyURL))) } + if strings.TrimSpace(o.Prefix) != strings.TrimSpace(n.Prefix) { + changes = append(changes, fmt.Sprintf("gemini[%d].prefix: %s -> %s", i, formatProxyURL(o.Prefix), formatProxyURL(n.Prefix))) + } if strings.TrimSpace(o.APIKey) != strings.TrimSpace(n.APIKey) { changes = append(changes, fmt.Sprintf("gemini[%d].api-key: updated", i)) } @@ -108,6 +111,9 @@ func BuildConfigChangeDetails(oldCfg, newCfg *config.Config) []string { if strings.TrimSpace(o.ProxyURL) != strings.TrimSpace(n.ProxyURL) { changes = append(changes, fmt.Sprintf("claude[%d].proxy-url: %s -> %s", i, formatProxyURL(o.ProxyURL), formatProxyURL(n.ProxyURL))) } + if strings.TrimSpace(o.Prefix) != strings.TrimSpace(n.Prefix) { + changes = append(changes, fmt.Sprintf("claude[%d].prefix: %s -> %s", i, formatProxyURL(o.Prefix), formatProxyURL(n.Prefix))) + } if strings.TrimSpace(o.APIKey) != strings.TrimSpace(n.APIKey) { changes = append(changes, fmt.Sprintf("claude[%d].api-key: updated", i)) } @@ -135,6 +141,9 @@ func BuildConfigChangeDetails(oldCfg, newCfg *config.Config) []string { if strings.TrimSpace(o.ProxyURL) != strings.TrimSpace(n.ProxyURL) { changes = append(changes, fmt.Sprintf("codex[%d].proxy-url: %s -> %s", i, formatProxyURL(o.ProxyURL), formatProxyURL(n.ProxyURL))) } + if strings.TrimSpace(o.Prefix) != strings.TrimSpace(n.Prefix) { + changes = append(changes, fmt.Sprintf("codex[%d].prefix: %s -> %s", i, formatProxyURL(o.Prefix), formatProxyURL(n.Prefix))) + } if strings.TrimSpace(o.APIKey) != strings.TrimSpace(n.APIKey) { changes = append(changes, fmt.Sprintf("codex[%d].api-key: updated", i)) } @@ -225,6 +234,9 @@ func BuildConfigChangeDetails(oldCfg, newCfg *config.Config) []string { if strings.TrimSpace(o.ProxyURL) != strings.TrimSpace(n.ProxyURL) { changes = append(changes, fmt.Sprintf("vertex[%d].proxy-url: %s -> %s", i, formatProxyURL(o.ProxyURL), formatProxyURL(n.ProxyURL))) } + if strings.TrimSpace(o.Prefix) != strings.TrimSpace(n.Prefix) { + changes = append(changes, fmt.Sprintf("vertex[%d].prefix: %s -> %s", i, formatProxyURL(o.Prefix), formatProxyURL(n.Prefix))) + } if strings.TrimSpace(o.APIKey) != strings.TrimSpace(n.APIKey) { changes = append(changes, fmt.Sprintf("vertex[%d].api-key: updated", i)) } diff --git a/internal/watcher/diff/oauth_excluded.go b/internal/watcher/diff/oauth_excluded.go index 7fdfa9cb..4f08c4d6 100644 --- a/internal/watcher/diff/oauth_excluded.go +++ b/internal/watcher/diff/oauth_excluded.go @@ -10,15 +10,15 @@ import ( "github.com/router-for-me/CLIProxyAPI/v6/internal/config" ) -type excludedModelsSummary struct { +type ExcludedModelsSummary struct { hash string count int } // SummarizeExcludedModels normalizes and hashes an excluded-model list. -func SummarizeExcludedModels(list []string) excludedModelsSummary { +func SummarizeExcludedModels(list []string) ExcludedModelsSummary { if len(list) == 0 { - return excludedModelsSummary{} + return ExcludedModelsSummary{} } seen := make(map[string]struct{}, len(list)) normalized := make([]string, 0, len(list)) @@ -32,18 +32,18 @@ func SummarizeExcludedModels(list []string) excludedModelsSummary { } } sort.Strings(normalized) - return excludedModelsSummary{ + return ExcludedModelsSummary{ hash: ComputeExcludedModelsHash(normalized), count: len(normalized), } } // SummarizeOAuthExcludedModels summarizes OAuth excluded models per provider. -func SummarizeOAuthExcludedModels(entries map[string][]string) map[string]excludedModelsSummary { +func SummarizeOAuthExcludedModels(entries map[string][]string) map[string]ExcludedModelsSummary { if len(entries) == 0 { return nil } - out := make(map[string]excludedModelsSummary, len(entries)) + out := make(map[string]ExcludedModelsSummary, len(entries)) for k, v := range entries { key := strings.ToLower(strings.TrimSpace(k)) if key == "" { @@ -87,15 +87,15 @@ func DiffOAuthExcludedModelChanges(oldMap, newMap map[string][]string) ([]string return changes, affected } -type ampModelMappingsSummary struct { +type AmpModelMappingsSummary struct { hash string count int } // SummarizeAmpModelMappings hashes Amp model mappings for change detection. -func SummarizeAmpModelMappings(mappings []config.AmpModelMapping) ampModelMappingsSummary { +func SummarizeAmpModelMappings(mappings []config.AmpModelMapping) AmpModelMappingsSummary { if len(mappings) == 0 { - return ampModelMappingsSummary{} + return AmpModelMappingsSummary{} } entries := make([]string, 0, len(mappings)) for _, mapping := range mappings { @@ -107,25 +107,25 @@ func SummarizeAmpModelMappings(mappings []config.AmpModelMapping) ampModelMappin entries = append(entries, from+"->"+to) } if len(entries) == 0 { - return ampModelMappingsSummary{} + return AmpModelMappingsSummary{} } sort.Strings(entries) sum := sha256.Sum256([]byte(strings.Join(entries, "|"))) - return ampModelMappingsSummary{ + return AmpModelMappingsSummary{ hash: hex.EncodeToString(sum[:]), count: len(entries), } } -type vertexModelsSummary struct { +type VertexModelsSummary struct { hash string count int } // SummarizeVertexModels hashes vertex-compatible models for change detection. -func SummarizeVertexModels(models []config.VertexCompatModel) vertexModelsSummary { +func SummarizeVertexModels(models []config.VertexCompatModel) VertexModelsSummary { if len(models) == 0 { - return vertexModelsSummary{} + return VertexModelsSummary{} } names := make([]string, 0, len(models)) for _, m := range models { @@ -140,11 +140,11 @@ func SummarizeVertexModels(models []config.VertexCompatModel) vertexModelsSummar names = append(names, name) } if len(names) == 0 { - return vertexModelsSummary{} + return VertexModelsSummary{} } sort.Strings(names) sum := sha256.Sum256([]byte(strings.Join(names, "|"))) - return vertexModelsSummary{ + return VertexModelsSummary{ hash: hex.EncodeToString(sum[:]), count: len(names), }