diff --git a/internal/gateway/history_gemini_test.go b/internal/gateway/history_gemini_test.go index 66ce06934..591fcb01c 100644 --- a/internal/gateway/history_gemini_test.go +++ b/internal/gateway/history_gemini_test.go @@ -34,3 +34,21 @@ func TestRouteKeptGrokServingNameNotSwapped(t *testing.T) { t.Fatalf("a real swap was cleared: %+v", r) } } + +// A route kept with a try marked swapped for ClinePass's +// cline-pass/deepseek-v4.1-flash-1017 answered as +// vmc/deepseek-v4p1-flash-1017 (its virtual model config's name, zRain on +// Discord) is read as not swapped; deepseek-v4-pro answered by +// vmc/deepseek-v4p1-flash stays swapped. +func TestRouteKeptClineServingNameNotSwapped(t *testing.T) { + r := &Route{Swapped: true, Served: "vmc/deepseek-v4p1-flash-1017", Tries: []Try{{Model: "cline-pass/deepseek-v4.1-flash-1017", Served: "vmc/deepseek-v4p1-flash-1017", Swapped: true, Upstream: "deepseek"}}} + r.routedAgain() + if r.Swapped || r.Tries[0].Swapped { + t.Fatalf("still swapped: %+v", r) + } + r = &Route{Swapped: true, Served: "vmc/deepseek-v4p1-flash", Tries: []Try{{Model: "cline-pass/deepseek-v4-pro", Served: "vmc/deepseek-v4p1-flash", Swapped: true}}} + r.routedAgain() + if !r.Swapped || !r.Tries[0].Swapped { + t.Fatalf("a real swap was cleared: %+v", r) + } +} diff --git a/internal/usage/served.go b/internal/usage/served.go index 39bfbc611..3130b530e 100644 --- a/internal/usage/served.go +++ b/internal/usage/served.go @@ -86,11 +86,35 @@ func RelayRenamed(sent, served string) bool { // ServingName reports whether served is the vendor's own name for the // deployment serving the model sent, which no request asks for by: Google's -// for a Gemini model (GeminiServing), xAI's for a Grok one (GrokServing). +// for a Gemini model (GeminiServing), xAI's for a Grok one (GrokServing), +// ClinePass's for one of its models (ClineServing). func ServingName(sent, served string) bool { - return GeminiServing(sent, served) || GrokServing(sent, served) + return GeminiServing(sent, served) || GrokServing(sent, served) || ClineServing(sent, served) } +// ClineServing reports whether served is ClinePass's name for the virtual +// model config ("vmc/") serving the cline-pass/ model sent: the model's +// own name, its version's dot written as "p". ClinePass answers +// cline-pass/deepseek-v4.1-flash-1017 as vmc/deepseek-v4p1-flash-1017 +// whichever upstream served it, DeepSeek's own API included +// (finalProvider "deepseek": hy125245 on X, 10-23), and the swap it was +// marked read as the request going to another provider (zRain on +// Discord, 10-24). It holds for ClinePass's models only, and for the same +// model: vmc/deepseek-v4p1-flash for cline-pass/deepseek-v4-pro is still +// a swap, as is a vmc/ name for a model not asked of ClinePass. +func ClineServing(sent, served string) bool { + s := strings.ToLower(strings.TrimSpace(served)) + if !strings.HasPrefix(s, "vmc/") || !strings.Contains(strings.ToLower(sent), "cline-pass/") { + return false + } + a := squash(bareModel(sent)) + return a != "" && squash(bareModel(vmcPoint.ReplaceAllString(s, "$1.$2"))) == a +} + +// vmcPoint is a version's dot as ClinePass's vmc/ names write it (v4p1 +// for v4.1), the part ClineServing reads past +var vmcPoint = regexp.MustCompile(`(\d)p(\d)`) + // GrokServing reports whether served is xAI's name for the build serving // the Grok model sent: the model's own name with "-build" after its // version. xAI answers grok-4.7 as grok-4.7-build, and grok-4.6 as diff --git a/internal/usage/served_cline_test.go b/internal/usage/served_cline_test.go new file mode 100644 index 000000000..0b24816d2 --- /dev/null +++ b/internal/usage/served_cline_test.go @@ -0,0 +1,49 @@ +package usage + +import "testing" + +// ClinePass answers a cline-pass/ model under its virtual model config's +// name, the version's dot written "p" (cline-pass/deepseek-v4.1-flash-1017 +// as vmc/deepseek-v4p1-flash-1017, hy125245 on X and zRain on Discord): +// the model asked for, whichever upstream served it. Another model under +// a vmc/ name, and a vmc/ name for a model not asked of ClinePass, are +// still swaps. +func TestSwappedClineServingName(t *testing.T) { + for _, c := range [][2]string{ + {"cline-pass/deepseek-v4.1-flash-1017", "vmc/deepseek-v4p1-flash-1017"}, + {"cline/cline-pass/deepseek-v4.1-flash-1017", "vmc/deepseek-v4p1-flash-1017"}, + {"cline-pass/deepseek-v4.1-flash", "vmc/deepseek-v4p1-flash"}, + {"cline-pass/deepseek-v4.1-flash", "VMC/DeepSeek-V4p1-Flash"}, + {"cline-pass/glm-5.3", "vmc/glm-5p3"}, + {"cline-pass/deepseek-v4-pro", "vmc/deepseek-v4-pro"}, + } { + if Swapped(c[0], c[1]) { + t.Errorf("%s answered as %s is the model asked for", c[0], c[1]) + } + } + for _, c := range [][2]string{ + {"cline-pass/deepseek-v4-pro", "vmc/deepseek-v4p1-flash"}, + {"cline-pass/deepseek-v4.1-flash", "vmc/deepseek-v4p1-pro"}, + {"cline-pass/deepseek-v4.1-flash", "vmc/deepseek-v4p2-flash"}, + {"cline-pass/glm-5.3", "vmc/glm-5p3-flash"}, + {"deepseek/deepseek-v4.1-flash", "vmc/deepseek-v4p1-flash"}, + {"cline-pass/deepseek-v4.1-flash", "other/deepseek-v4p1-flash"}, + } { + if !Swapped(c[0], c[1]) { + t.Errorf("%s answered as %s is another model", c[0], c[1]) + } + } +} + +// A row kept marked swapped before is read back as not swapped when +// ClinePass named its vmc/ config for the model; a real swap stays one. +func TestKeptRowClineServingNameNotSwapped(t *testing.T) { + c := &rowChunk{} + c.add(Row{Record: Record{Model: "cline-pass/deepseek-v4.1-flash-1017", Served: "vmc/deepseek-v4p1-flash-1017"}, Swapped: true}, "", 0, false) + c.add(Row{Record: Record{Model: "cline-pass/deepseek-v4-pro", Served: "vmc/deepseek-v4p1-flash"}, Swapped: true}, "", 1, false) + for _, chunk := range []*rowChunk{c, c.pack().unpack()} { + if chunk.row(0).Swapped || !chunk.row(1).Swapped { + t.Fatalf("serving name %v, another model %v", chunk.row(0).Swapped, chunk.row(1).Swapped) + } + } +}