mirror of
https://github.com/Finesssee/ProxyPilot.git
synced 2026-11-19 02:17:46 +00:00
Upstream changes: - Codex responses compaction payload compatibility - Codex usage_limit_reached retry-after, deterministic parsing - Codex refresh_token_reused non-retryable fix - Qwen rate limiting and quota error handling - Context management compatibility simplification - Antigravity tool_result image fix, model list backfill, deep copy cache - Auth auto-refresh interval/concurrency limiting - Auth hook OnResult refactor (replaces MarkResult) - Gemini-3.1-flash-image support - Registry cleanup of outdated model definitions Fork resolution: - Accept upstream's consolidated conductor.go (auto-refresh, round-tripper) - Delete stale conductor_oauth.go, conductor_token.go (upstream reversed split) - Delete stale provider_rotation_test.go (references removed method)
89 lines
2.6 KiB
Go
89 lines
2.6 KiB
Go
package util
|
|
|
|
import (
|
|
"strings"
|
|
"unicode"
|
|
)
|
|
|
|
// NormalizeDroidCustomModel attempts to convert Factory Droid "custom:*" model ids
|
|
// into the underlying model id that this proxy understands.
|
|
//
|
|
// Examples:
|
|
//
|
|
// custom:CLIProxy-(local):-gemini-claude-opus-4-5-thinking-12 -> gemini-claude-opus-4-5-thinking
|
|
// custom:CLIProxy-(local):-gpt-5.2-(reasoning:-medium)-2 -> gpt-5.2(medium)
|
|
func NormalizeDroidCustomModel(model string) string {
|
|
model = strings.TrimSpace(model)
|
|
if !strings.HasPrefix(strings.ToLower(model), "custom:") {
|
|
return model
|
|
}
|
|
raw := strings.TrimPrefix(model, "custom:")
|
|
|
|
// Prefer well-known ":-<family>" markers so we don't get confused by "reasoning:-low".
|
|
candidate := ""
|
|
lower := strings.ToLower(raw)
|
|
for _, marker := range []string{":-antigravity-", ":-gemini-", ":-gpt-", ":-claude-", ":-qwen", ":-deepseek", ":-kimi", ":-glm-", ":-minimax", ":-tstars"} {
|
|
if idx := strings.LastIndex(lower, marker); idx >= 0 {
|
|
candidate = raw[idx+2:] // drop the leading ":-"
|
|
break
|
|
}
|
|
}
|
|
if candidate == "" {
|
|
// Fallback: take the substring after the last ":-" if present.
|
|
if idx := strings.LastIndex(raw, ":-"); idx >= 0 && idx+2 < len(raw) {
|
|
candidate = raw[idx+2:]
|
|
} else {
|
|
candidate = raw
|
|
}
|
|
}
|
|
candidate = strings.TrimSpace(candidate)
|
|
|
|
// Strip trailing "-<digits>" index suffix (Droid custom model numbering).
|
|
candidate = stripTrailingDashDigits(candidate)
|
|
|
|
// Map Droid's "(reasoning:-level)" encoding to our "(level)" suffix.
|
|
// Example: gpt-5.2-(reasoning:-medium) -> gpt-5.2(medium)
|
|
if strings.Contains(strings.ToLower(candidate), "-(reasoning:-") {
|
|
lc := strings.ToLower(candidate)
|
|
idx := strings.Index(lc, "-(reasoning:-")
|
|
if idx >= 0 {
|
|
base := strings.TrimSpace(candidate[:idx])
|
|
rest := candidate[idx+len("-(reasoning:-"):]
|
|
// rest should look like: medium) or medium)-something
|
|
level := rest
|
|
if end := strings.Index(level, ")"); end >= 0 {
|
|
level = level[:end]
|
|
}
|
|
level = strings.TrimSpace(strings.Trim(level, "-"))
|
|
levelLower := strings.ToLower(level)
|
|
if base != "" && (levelLower == "low" || levelLower == "medium" || levelLower == "high" || levelLower == "xhigh" || levelLower == "minimal" || levelLower == "none") {
|
|
return base + "(" + levelLower + ")"
|
|
}
|
|
}
|
|
}
|
|
|
|
return candidate
|
|
}
|
|
|
|
func stripTrailingDashDigits(s string) string {
|
|
s = strings.TrimSpace(s)
|
|
if s == "" {
|
|
return s
|
|
}
|
|
// Find final "-<digits>" segment.
|
|
lastDash := strings.LastIndex(s, "-")
|
|
if lastDash < 0 || lastDash == len(s)-1 {
|
|
return s
|
|
}
|
|
suffix := s[lastDash+1:]
|
|
if suffix == "" {
|
|
return s
|
|
}
|
|
for _, r := range suffix {
|
|
if !unicode.IsDigit(r) {
|
|
return s
|
|
}
|
|
}
|
|
return strings.TrimSpace(s[:lastDash])
|
|
}
|