mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-18 12:20:52 +08:00
refactor(watcher): extract model summary functions to dedicated file
This commit is contained in:
@@ -125,6 +125,11 @@ func BuildConfigChangeDetails(oldCfg, newCfg *config.Config) []string {
|
|||||||
if !equalStringMap(o.Headers, n.Headers) {
|
if !equalStringMap(o.Headers, n.Headers) {
|
||||||
changes = append(changes, fmt.Sprintf("claude[%d].headers: updated", i))
|
changes = append(changes, fmt.Sprintf("claude[%d].headers: updated", i))
|
||||||
}
|
}
|
||||||
|
oldModels := SummarizeClaudeModels(o.Models)
|
||||||
|
newModels := SummarizeClaudeModels(n.Models)
|
||||||
|
if oldModels.hash != newModels.hash {
|
||||||
|
changes = append(changes, fmt.Sprintf("claude[%d].models: updated (%d -> %d entries)", i, oldModels.count, newModels.count))
|
||||||
|
}
|
||||||
oldExcluded := SummarizeExcludedModels(o.ExcludedModels)
|
oldExcluded := SummarizeExcludedModels(o.ExcludedModels)
|
||||||
newExcluded := SummarizeExcludedModels(n.ExcludedModels)
|
newExcluded := SummarizeExcludedModels(n.ExcludedModels)
|
||||||
if oldExcluded.hash != newExcluded.hash {
|
if oldExcluded.hash != newExcluded.hash {
|
||||||
@@ -155,6 +160,11 @@ func BuildConfigChangeDetails(oldCfg, newCfg *config.Config) []string {
|
|||||||
if !equalStringMap(o.Headers, n.Headers) {
|
if !equalStringMap(o.Headers, n.Headers) {
|
||||||
changes = append(changes, fmt.Sprintf("codex[%d].headers: updated", i))
|
changes = append(changes, fmt.Sprintf("codex[%d].headers: updated", i))
|
||||||
}
|
}
|
||||||
|
oldModels := SummarizeCodexModels(o.Models)
|
||||||
|
newModels := SummarizeCodexModels(n.Models)
|
||||||
|
if oldModels.hash != newModels.hash {
|
||||||
|
changes = append(changes, fmt.Sprintf("codex[%d].models: updated (%d -> %d entries)", i, oldModels.count, newModels.count))
|
||||||
|
}
|
||||||
oldExcluded := SummarizeExcludedModels(o.ExcludedModels)
|
oldExcluded := SummarizeExcludedModels(o.ExcludedModels)
|
||||||
newExcluded := SummarizeExcludedModels(n.ExcludedModels)
|
newExcluded := SummarizeExcludedModels(n.ExcludedModels)
|
||||||
if oldExcluded.hash != newExcluded.hash {
|
if oldExcluded.hash != newExcluded.hash {
|
||||||
|
|||||||
121
internal/watcher/diff/models_summary.go
Normal file
121
internal/watcher/diff/models_summary.go
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
package diff
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
|
"encoding/hex"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GeminiModelsSummary struct {
|
||||||
|
hash string
|
||||||
|
count int
|
||||||
|
}
|
||||||
|
|
||||||
|
type ClaudeModelsSummary struct {
|
||||||
|
hash string
|
||||||
|
count int
|
||||||
|
}
|
||||||
|
|
||||||
|
type CodexModelsSummary struct {
|
||||||
|
hash string
|
||||||
|
count int
|
||||||
|
}
|
||||||
|
|
||||||
|
type VertexModelsSummary struct {
|
||||||
|
hash string
|
||||||
|
count int
|
||||||
|
}
|
||||||
|
|
||||||
|
// SummarizeGeminiModels hashes Gemini model aliases for change detection.
|
||||||
|
func SummarizeGeminiModels(models []config.GeminiModel) GeminiModelsSummary {
|
||||||
|
if len(models) == 0 {
|
||||||
|
return GeminiModelsSummary{}
|
||||||
|
}
|
||||||
|
keys := normalizeModelPairs(func(out func(key string)) {
|
||||||
|
for _, model := range models {
|
||||||
|
name := strings.TrimSpace(model.Name)
|
||||||
|
alias := strings.TrimSpace(model.Alias)
|
||||||
|
if name == "" && alias == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
out(strings.ToLower(name) + "|" + strings.ToLower(alias))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return GeminiModelsSummary{
|
||||||
|
hash: hashJoined(keys),
|
||||||
|
count: len(keys),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SummarizeClaudeModels hashes Claude model aliases for change detection.
|
||||||
|
func SummarizeClaudeModels(models []config.ClaudeModel) ClaudeModelsSummary {
|
||||||
|
if len(models) == 0 {
|
||||||
|
return ClaudeModelsSummary{}
|
||||||
|
}
|
||||||
|
keys := normalizeModelPairs(func(out func(key string)) {
|
||||||
|
for _, model := range models {
|
||||||
|
name := strings.TrimSpace(model.Name)
|
||||||
|
alias := strings.TrimSpace(model.Alias)
|
||||||
|
if name == "" && alias == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
out(strings.ToLower(name) + "|" + strings.ToLower(alias))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return ClaudeModelsSummary{
|
||||||
|
hash: hashJoined(keys),
|
||||||
|
count: len(keys),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SummarizeCodexModels hashes Codex model aliases for change detection.
|
||||||
|
func SummarizeCodexModels(models []config.CodexModel) CodexModelsSummary {
|
||||||
|
if len(models) == 0 {
|
||||||
|
return CodexModelsSummary{}
|
||||||
|
}
|
||||||
|
keys := normalizeModelPairs(func(out func(key string)) {
|
||||||
|
for _, model := range models {
|
||||||
|
name := strings.TrimSpace(model.Name)
|
||||||
|
alias := strings.TrimSpace(model.Alias)
|
||||||
|
if name == "" && alias == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
out(strings.ToLower(name) + "|" + strings.ToLower(alias))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return CodexModelsSummary{
|
||||||
|
hash: hashJoined(keys),
|
||||||
|
count: len(keys),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SummarizeVertexModels hashes Vertex-compatible model aliases for change detection.
|
||||||
|
func SummarizeVertexModels(models []config.VertexCompatModel) VertexModelsSummary {
|
||||||
|
if len(models) == 0 {
|
||||||
|
return VertexModelsSummary{}
|
||||||
|
}
|
||||||
|
names := make([]string, 0, len(models))
|
||||||
|
for _, model := range models {
|
||||||
|
name := strings.TrimSpace(model.Name)
|
||||||
|
alias := strings.TrimSpace(model.Alias)
|
||||||
|
if name == "" && alias == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if alias != "" {
|
||||||
|
name = alias
|
||||||
|
}
|
||||||
|
names = append(names, name)
|
||||||
|
}
|
||||||
|
if len(names) == 0 {
|
||||||
|
return VertexModelsSummary{}
|
||||||
|
}
|
||||||
|
sort.Strings(names)
|
||||||
|
sum := sha256.Sum256([]byte(strings.Join(names, "|")))
|
||||||
|
return VertexModelsSummary{
|
||||||
|
hash: hex.EncodeToString(sum[:]),
|
||||||
|
count: len(names),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -116,62 +116,3 @@ func SummarizeAmpModelMappings(mappings []config.AmpModelMapping) AmpModelMappin
|
|||||||
count: len(entries),
|
count: len(entries),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type VertexModelsSummary struct {
|
|
||||||
hash string
|
|
||||||
count int
|
|
||||||
}
|
|
||||||
|
|
||||||
type GeminiModelsSummary struct {
|
|
||||||
hash string
|
|
||||||
count int
|
|
||||||
}
|
|
||||||
|
|
||||||
// SummarizeVertexModels hashes vertex-compatible models for change detection.
|
|
||||||
func SummarizeVertexModels(models []config.VertexCompatModel) VertexModelsSummary {
|
|
||||||
if len(models) == 0 {
|
|
||||||
return VertexModelsSummary{}
|
|
||||||
}
|
|
||||||
names := make([]string, 0, len(models))
|
|
||||||
for _, m := range models {
|
|
||||||
name := strings.TrimSpace(m.Name)
|
|
||||||
alias := strings.TrimSpace(m.Alias)
|
|
||||||
if name == "" && alias == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if alias != "" {
|
|
||||||
name = alias
|
|
||||||
}
|
|
||||||
names = append(names, name)
|
|
||||||
}
|
|
||||||
if len(names) == 0 {
|
|
||||||
return VertexModelsSummary{}
|
|
||||||
}
|
|
||||||
sort.Strings(names)
|
|
||||||
sum := sha256.Sum256([]byte(strings.Join(names, "|")))
|
|
||||||
return VertexModelsSummary{
|
|
||||||
hash: hex.EncodeToString(sum[:]),
|
|
||||||
count: len(names),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SummarizeGeminiModels hashes Gemini model aliases for change detection.
|
|
||||||
func SummarizeGeminiModels(models []config.GeminiModel) GeminiModelsSummary {
|
|
||||||
if len(models) == 0 {
|
|
||||||
return GeminiModelsSummary{}
|
|
||||||
}
|
|
||||||
keys := normalizeModelPairs(func(out func(key string)) {
|
|
||||||
for _, model := range models {
|
|
||||||
name := strings.TrimSpace(model.Name)
|
|
||||||
alias := strings.TrimSpace(model.Alias)
|
|
||||||
if name == "" && alias == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
out(strings.ToLower(name) + "|" + strings.ToLower(alias))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return GeminiModelsSummary{
|
|
||||||
hash: hashJoined(keys),
|
|
||||||
count: len(keys),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user