From aec6908c6df46c477d443a81875b95141e1e8cca Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 13 Oct 2026 16:57:55 +0800 Subject: [PATCH] agent: PI-Desktop's requests, sent as pi-desktop/, are its own and no longer Pi's (#1966, dgmico) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PI-Desktop (vastsa/PI-Desktop) runs Pi's own library, so by default it sends pi's User-Agent ("pi (darwin …)") and is counted as Pi. Its provider settings take a custom User-Agent ("pi-desktop/0.0.0" in its own tests), but that name started with Pi's "pi-" prefix, so it was still Pi. agents.go's others gains PI-Desktop (id pi-desktop, UA "pi-desktop", Pi's icon). AgentOf matches it by its exact name first and by the longer prefix, so pi-desktop/ and the key magpie-pi-desktop are PI-Desktop, while "pi (…)" and other "pi-" clients stay Pi. Run: TestPIDesktopIsNotPi (red without the agents.go entry: pi-desktop/0.1.0 went to pi), go test -tags nogui ./internal/agent ./internal/usage, gofmt, vet darwin/linux(nogui)/windows. A sandbox gateway (temp HOME, port 3561) given a /v1/chat/completions request with User-Agent pi-desktop/0.1.0 recorded agent "pi-desktop" in usage.jsonl. Not tried: the real PI-Desktop app; with its default User-Agent it still reads as Pi, which nothing in the request can tell apart. --- internal/agent/agents.go | 5 +++++ internal/agent/pi_test.go | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) 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") + } +}