feat(config): add per-auth disable_cooling override support

- Introduced `disable_cooling` metadata field for fine-grained control over cooldown scheduling.
- Updated `Auth` object to include `Metadata` with conditional logic for handling empty states.
- Added YAML configuration support for `disable_cooling` in API key definitions across providers.
- Enhanced unit tests to validate `disable_cooling` behavior in various scenarios.
This commit is contained in:
Luis Pater
2026-05-09 10:51:27 +08:00
parent c67096b687
commit 0f0fcd2304
5 changed files with 108 additions and 17 deletions
+41
View File
@@ -60,6 +60,10 @@ func (s *ConfigSynthesizer) synthesizeGeminiKeys(ctx *SynthesisContext) []*corea
"source": fmt.Sprintf("config:gemini[%s]", token),
"api_key": key,
}
metadata := map[string]any{}
if entry.DisableCooling {
metadata["disable_cooling"] = true
}
if entry.Priority != 0 {
attrs["priority"] = strconv.Itoa(entry.Priority)
}
@@ -78,10 +82,14 @@ func (s *ConfigSynthesizer) synthesizeGeminiKeys(ctx *SynthesisContext) []*corea
Status: coreauth.StatusActive,
ProxyURL: proxyURL,
Attributes: attrs,
Metadata: metadata,
CreatedAt: now,
UpdatedAt: now,
}
ApplyAuthExcludedModelsMeta(a, cfg, entry.ExcludedModels, "apikey")
if len(a.Metadata) == 0 {
a.Metadata = nil
}
out = append(out, a)
}
return out
@@ -107,6 +115,10 @@ func (s *ConfigSynthesizer) synthesizeClaudeKeys(ctx *SynthesisContext) []*corea
"source": fmt.Sprintf("config:claude[%s]", token),
"api_key": key,
}
metadata := map[string]any{}
if ck.DisableCooling {
metadata["disable_cooling"] = true
}
if ck.Priority != 0 {
attrs["priority"] = strconv.Itoa(ck.Priority)
}
@@ -126,10 +138,14 @@ func (s *ConfigSynthesizer) synthesizeClaudeKeys(ctx *SynthesisContext) []*corea
Status: coreauth.StatusActive,
ProxyURL: proxyURL,
Attributes: attrs,
Metadata: metadata,
CreatedAt: now,
UpdatedAt: now,
}
ApplyAuthExcludedModelsMeta(a, cfg, ck.ExcludedModels, "apikey")
if len(a.Metadata) == 0 {
a.Metadata = nil
}
out = append(out, a)
}
return out
@@ -154,6 +170,10 @@ func (s *ConfigSynthesizer) synthesizeCodexKeys(ctx *SynthesisContext) []*coreau
"source": fmt.Sprintf("config:codex[%s]", token),
"api_key": key,
}
metadata := map[string]any{}
if ck.DisableCooling {
metadata["disable_cooling"] = true
}
if ck.Priority != 0 {
attrs["priority"] = strconv.Itoa(ck.Priority)
}
@@ -176,10 +196,14 @@ func (s *ConfigSynthesizer) synthesizeCodexKeys(ctx *SynthesisContext) []*coreau
Status: coreauth.StatusActive,
ProxyURL: proxyURL,
Attributes: attrs,
Metadata: metadata,
CreatedAt: now,
UpdatedAt: now,
}
ApplyAuthExcludedModelsMeta(a, cfg, ck.ExcludedModels, "apikey")
if len(a.Metadata) == 0 {
a.Metadata = nil
}
out = append(out, a)
}
return out
@@ -203,6 +227,7 @@ func (s *ConfigSynthesizer) synthesizeOpenAICompat(ctx *SynthesisContext) []*cor
providerName = "openai-compatibility"
}
base := strings.TrimSpace(compat.BaseURL)
disableCooling := compat.DisableCooling
// Handle new APIKeyEntries format (preferred)
createdEntries := 0
@@ -218,6 +243,10 @@ func (s *ConfigSynthesizer) synthesizeOpenAICompat(ctx *SynthesisContext) []*cor
"compat_name": compat.Name,
"provider_key": providerName,
}
metadata := map[string]any{}
if disableCooling {
metadata["disable_cooling"] = true
}
if compat.Priority != 0 {
attrs["priority"] = strconv.Itoa(compat.Priority)
}
@@ -236,9 +265,13 @@ func (s *ConfigSynthesizer) synthesizeOpenAICompat(ctx *SynthesisContext) []*cor
Status: coreauth.StatusActive,
ProxyURL: proxyURL,
Attributes: attrs,
Metadata: metadata,
CreatedAt: now,
UpdatedAt: now,
}
if len(a.Metadata) == 0 {
a.Metadata = nil
}
out = append(out, a)
createdEntries++
}
@@ -252,6 +285,10 @@ func (s *ConfigSynthesizer) synthesizeOpenAICompat(ctx *SynthesisContext) []*cor
"compat_name": compat.Name,
"provider_key": providerName,
}
metadata := map[string]any{}
if disableCooling {
metadata["disable_cooling"] = true
}
if compat.Priority != 0 {
attrs["priority"] = strconv.Itoa(compat.Priority)
}
@@ -266,9 +303,13 @@ func (s *ConfigSynthesizer) synthesizeOpenAICompat(ctx *SynthesisContext) []*cor
Prefix: prefix,
Status: coreauth.StatusActive,
Attributes: attrs,
Metadata: metadata,
CreatedAt: now,
UpdatedAt: now,
}
if len(a.Metadata) == 0 {
a.Metadata = nil
}
out = append(out, a)
}
}