diff --git a/internal/agent/agents.go b/internal/agent/agents.go index 946a7b1e0..8a1a531f9 100644 --- a/internal/agent/agents.go +++ b/internal/agent/agents.go @@ -47,6 +47,11 @@ func init() { var others = []*Agent{ {ID: "magpie", Name: "magpie", Icon: "magpie", UA: []string{"magpie"}}, {ID: "curl", Name: "curl", Icon: "curl", UA: []string{"curl"}}, + // PI-Desktop (vastsa/PI-Desktop) runs Pi's own library, which says + // "pi (…)"; given a User-Agent of its own in its provider's settings + // ("pi-desktop/0.1.0"), it is told apart from Pi by that name, which + // Pi's "pi-" would take otherwise (#1966, dgmico) + {ID: "pi-desktop", Name: "PI-Desktop", Icon: "pi", UA: []string{"pi-desktop"}}, } // Clients is everyone whose requests the gateway knows by name: every diff --git a/internal/agent/pi_test.go b/internal/agent/pi_test.go index d947e5aa6..1740f430c 100644 --- a/internal/agent/pi_test.go +++ b/internal/agent/pi_test.go @@ -2,9 +2,11 @@ package agent import ( "reflect" + "slices" "testing" "github.com/yetone/magpie/internal/catalog" + "github.com/yetone/magpie/internal/usage" ) // Every one of Pi's levels is in the map, the model's own mapped and the @@ -105,3 +107,24 @@ func TestPiCostAndPromptCache(t *testing.T) { } } } + +// dgmico's report (#1966): PI-Desktop's requests, sent with a User-Agent +// of pi-desktop/, were counted as Pi's, since Pi's requests are +// known by "pi-". Pi's own and other pi- names stay Pi's. +func TestPIDesktopIsNotPi(t *testing.T) { + for ua, want := range map[string]string{ + "pi-desktop/0.1.0": "pi-desktop", + "PI-Desktop/0.1.0": "pi-desktop", + "pi-desktop": "pi-desktop", + "pi (darwin 25.6.0; arm64)": "pi", + "pi-bridge/1.0": "pi", + "pidesktop/1.0": "pidesktop", + } { + if got := usage.AgentOf(ua); got != want { + t.Errorf("%q: %q, want %q", ua, got, want) + } + } + if !slices.ContainsFunc(Clients(), func(a *Agent) bool { return a.ID == "pi-desktop" && a.Name == "PI-Desktop" && a.Icon == "pi" }) { + t.Error("PI-Desktop isn't a client the Usage and Routing views draw") + } +}