diff --git a/internal/provider/base_probe_allocs_test.go b/internal/provider/base_probe_allocs_test.go new file mode 100644 index 000000000..2aa13644a --- /dev/null +++ b/internal/provider/base_probe_allocs_test.go @@ -0,0 +1,23 @@ +package provider + +import "testing" + +// The Providers page asks every provider whether it is a Tencent Token +// Plan or OpenCode's gateway; a base of another vendor's is told apart +// without parsing it. +func TestOtherVendorsBasesAreNotParsed(t *testing.T) { + p := Provider{ID: "x", Chat: "https://api.example.com/v1", Responses: "https://api.example.com/v1", Anthropic: "https://api.example.com/anthropic"} + if n := testing.AllocsPerRun(50, func() { tencentPlanRegion(p) }); n != 0 { + t.Errorf("tencentPlanRegion of another vendor's provider allocated %v times a call", n) + } + if n := testing.AllocsPerRun(50, func() { openCodeGateway(p.Chat) }); n != 0 { + t.Errorf("openCodeGateway of another vendor's base allocated %v times a call", n) + } + // and still what they are about, whatever its case + if r, ok := tencentPlanRegion(Provider{Chat: "https://TokenHub.TencentMaaS.com/plan/v3"}); !ok || r != "ap-guangzhou" { + t.Errorf("Tencent's plan base: %q %v", r, ok) + } + if g := openCodeGateway("https://OpenCode.ai/zen/go/v1"); g != "go" { + t.Errorf("OpenCode Go's base: %q", g) + } +} diff --git a/internal/provider/opencode_endpoints.go b/internal/provider/opencode_endpoints.go index f49cbf7d2..3e65c6a2d 100644 --- a/internal/provider/opencode_endpoints.go +++ b/internal/provider/opencode_endpoints.go @@ -36,6 +36,10 @@ func openCodeRoot(base string) (root, catalogID string) { // workspace's pay-as-you-go credits), "" for any other, a provider of the // user's own at …/inference/custom among them, which its vendor bills. func openCodeGateway(base string) string { + // every host openCodeHost takes holds it: another base isn't parsed + if !strings.Contains(strings.ToLower(base), "opencode.ai") { + return "" + } u, err := url.Parse(strings.TrimSpace(base)) if err != nil || !openCodeHost(u.Hostname()) { return "" diff --git a/internal/provider/tencent_usage.go b/internal/provider/tencent_usage.go index f7fb7e89a..0e3fc2bb1 100644 --- a/internal/provider/tencent_usage.go +++ b/internal/provider/tencent_usage.go @@ -95,6 +95,12 @@ func tencentPlanRegion(p Provider) (string, bool) { return "", false } for _, base := range []string{p.Chat, p.Responses, p.Anthropic} { + // both hosts below hold it: every other base, asked for each + // provider on each Providers page, isn't parsed (ToLower makes + // no copy of a base already lower-case) + if !strings.Contains(strings.ToLower(base), "tencentmaas.com") { + continue + } u, err := url.Parse(base) if err != nil || !strings.HasPrefix(strings.TrimSuffix(u.Path, "/")+"/", "/plan/") { continue