agent: PI-Desktop's requests, sent as pi-desktop/<ver>, are its own and no longer Pi's (#1966, dgmico)
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/<ver> 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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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/<version>, 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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user