zyh6036 on X: several subscriptions that all serve the Responses API were asked on Chat once they were put in a routing group. Pi, OmO, omp, StepCode, droid, dsh, Hermes, Grok CLI and the live agents ask each model on the one API catalog.Model.APIs names, and a group had Responses only when every member's Native was Responses (allResponses, #1594). A relay that serves Chat and Responses, best on Chat (no Base URL API given, not OpenAI's own host), counts as Chat there, so one such member put the whole group on Chat, and the gateway then translated Chat to Responses for the ChatGPT, Copilot GPT or Responses-relay members. Found groups (auto-<slug>) hit this without the user doing anything: a new relay that also lists gpt-5.5 moved auto/gpt-5.5 from openai-responses to Chat (pi_api_test shows it). provider.GroupAPI now gives Responses when one member is best on Responses and every other takes a Responses request as it is (Responses among the APIs it relays), or translates every request anyway (a Claude Code subscription). So no member is translated that Chat would have relayed, and the ones best on Responses are relayed, not translated from Chat. The gateway already relays a /v1/responses request to each member that serves it (usable), so nothing changes there. Mixed groups: a member that Responses doesn't reach (a Chat-only key, a Messages-only Claude) keeps the group on Chat, where that member is relayed; picking Responses there would translate it on every turn. A Messages-only group stays on Chat as before (#1594's reason: a Claude member's thinking is known by its own model id, not the group's). An agent plugin's connect is told a group's native_endpoints now (provider.GroupEndpoints: the APIs every member relays), where it had none. /v1/models still leaves them out for a group: TestRemoteMagpieNativeAPI holds that a remote magpie sends a group's request on in the client's API for the other side to pick per member. No setting added: the group's API follows from its members. Run (mote, through mote-run): - go test ./... -timeout 45m at 65780f04f on49c9491b7, under the shared lock: every package ok except three reds, all filed and not in this change's path: internal/gateway TestBurstTellsNoSpeed/ responses_from_chat_burst (passes 3 of 3 alone; #2719, commented), internal/gui TestMainWindowCorners/macOS_26_SDK (#3949), internal/provider TestRenewLoginsKeepsClaudeReading (red alone too; #5481, on main). - After rebasing onfcc0daa23: go test ./internal/agent ./internal/catalog, ./internal/provider -run 'TestGroupAPI|TestNative|Group', ./internal/gateway -run 'Group|RemoteMagpie'; go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...; gofmt -l empty. - Broken by hand: GroupAPI put back to "every member best on Responses": TestGroupAPI red (one best there plus one serving it too; the same second), TestPiModelsAskedOnTheirNativeAPI red (group/subs, and auto/gpt-5.5 once a Chat-first relay serves gpt-5.5). - New: TestGroupAPI (provider), TestGroupOfResponsesServersRelaysOnResponses (gateway: the Chat-first member is asked on /responses, relayed). Not tried: the reporter's own providers (not known: which subscriptions, which agent); a real Pi or dsh run against a real mixed-API group; the GUI (unchanged).
170 lines
6.3 KiB
Go
170 lines
6.3 KiB
Go
package agent
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// #597: Pi on a routing group of DeepSeek V4 Pro (TokenHub's, and the Token
|
|
// Plan's deepseek-v4-pro-202606 that nothing magpie reads knows) was
|
|
// written the group without reasoning, so its /thinking offered off alone,
|
|
// while magpie's thinking field offered every level and showed max — which
|
|
// Pi clamped to off, sending no reasoning_effort. The group now gets the
|
|
// levels verified for TokenHub's model, so Pi and magpie offer the same
|
|
// levels instead of borrowing DeepSeek's unverified off level.
|
|
func TestPiGroupThinkingIsWhatPiRuns(t *testing.T) {
|
|
home := syncHome(t)
|
|
if err := os.WriteFile(catalog.CachePath(), []byte(`{
|
|
"deepseek": {"models": {"deepseek-v4-pro": {"id":"deepseek-v4-pro","name":"DeepSeek V4 Pro","reasoning":true,
|
|
"reasoning_options":[{"type":"toggle"},{"type":"effort","values":["low","high","max"]}],"limit":{"context":1000000}}}}
|
|
}`), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
catalog.Reset()
|
|
for _, p := range []provider.Provider{
|
|
{ID: "th", Name: "TokenHub", Key: "k", Chat: "http://127.0.0.1:1/v1", Catalog: "tencent-tokenhub", Models: []string{"deepseek-v4-pro"}},
|
|
{ID: "tp", Name: "Token Plan", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"deepseek-v4-pro-202606"}},
|
|
} {
|
|
if err := provider.Save(p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if err := provider.SaveGroup(provider.Group{ID: "deepseek", Name: "腾讯DeepSeek", Members: []string{"tp/deepseek-v4-pro-202606", "th/deepseek-v4-pro"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := provider.SaveGroup(provider.Group{ID: "plan", Name: "Plan", Members: []string{"tp/deepseek-v4-pro-202606"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
a := pi(home)
|
|
if err := a.Field("model").Set("magpie/group/deepseek"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := a.Field("effort").Set("max"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
var file map[string]any
|
|
if err := json.Unmarshal([]byte(readFile(filepath.Join(home, ".pi", "agent", "models.json"))), &file); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var entry map[string]any
|
|
for _, raw := range file["providers"].(map[string]any)["magpie"].(map[string]any)["models"].([]any) {
|
|
if m := raw.(map[string]any); m["id"] == "group/deepseek" {
|
|
entry = m
|
|
}
|
|
}
|
|
if entry == nil || entry["reasoning"] != true {
|
|
t.Fatalf("group entry: %v", entry)
|
|
}
|
|
if got := piSupported(entry); !reflect.DeepEqual(got, []string{"low", "high", "max"}) {
|
|
t.Fatalf("Pi offers %v for the group: %v", got, entry["thinkingLevelMap"])
|
|
}
|
|
|
|
values := func(os []Option) []string {
|
|
var out []string
|
|
for _, o := range os {
|
|
out = append(out, o.Value)
|
|
}
|
|
return out
|
|
}
|
|
effort := a.Field("effort")
|
|
if got := values(effort.Options(map[string]string{"model": "magpie/group/deepseek"})); !reflect.DeepEqual(got, []string{"low", "high", "max"}) {
|
|
t.Fatalf("offered %v", got)
|
|
}
|
|
if got := effort.Get(); got != "max" {
|
|
t.Fatalf("shown %q, want max", got)
|
|
}
|
|
|
|
// on a group Pi can't reason with, max is shown as the off Pi runs at
|
|
if err := a.Field("model").Set("magpie/group/plan"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := values(effort.Options(map[string]string{"model": "magpie/group/plan"})); !reflect.DeepEqual(got, []string{"off"}) {
|
|
t.Fatalf("plan: offered %v", got)
|
|
}
|
|
if got := effort.Get(); got != "off" {
|
|
t.Fatalf("plan: shown %q, want off", got)
|
|
}
|
|
// a model of Pi's own keeps every level
|
|
if got := values(effort.Options(map[string]string{"model": "anthropic/claude-x"})); !reflect.DeepEqual(got, piLevels) {
|
|
t.Fatalf("own model: offered %v", got)
|
|
}
|
|
}
|
|
|
|
// #5037: a routing group has no api of its own — a Messages-only group
|
|
// stays on Chat (provider.GroupAPI) — so its entry went out with no promptCache
|
|
// and Pi's cacheWarming stopped with "cache lifetime unavailable". Whatever
|
|
// Claude member the group picks, the gateway's own translation marks the
|
|
// request ephemeral for five minutes, so the group declares that short
|
|
// lifetime; long stays out, the gateway marks an hour only where a
|
|
// session's turns are often far apart (addedMark), so it is not always true.
|
|
func TestPiGroupPromptCache(t *testing.T) {
|
|
syncHome(t)
|
|
if err := os.WriteFile(catalog.CachePath(), []byte(`{
|
|
"ap": {"models": {"claude-opus-5-5": {"id":"claude-opus-5-5","name":"Claude Opus 5.5","limit":{"context":200000}}}},
|
|
"zai": {"models": {"glm-4.6":{"id":"glm-4.6","name":"GLM-4.6","limit":{"context":204800}}}}
|
|
}`), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
catalog.Reset()
|
|
if err := provider.Save(provider.Provider{ID: "ap", Name: "Anthropic Plugin", Key: "k", Anthropic: "http://127.0.0.1:2", Models: []string{"claude-opus-5-5"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := provider.SaveGroup(provider.Group{ID: "auto", Name: "Auto", Members: []string{"ap/claude-opus-5-5", "relay/glm-4.6"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ms := magpieProviderJSON("pi").(map[string]any)["models"].([]map[string]any)
|
|
var group bool
|
|
for _, e := range ms {
|
|
switch e["id"] {
|
|
case "group/auto":
|
|
group = true
|
|
if _, set := e["api"]; set {
|
|
t.Errorf("group api %v, want none (Chat)", e["api"])
|
|
}
|
|
if !reflect.DeepEqual(e["promptCache"], map[string]any{"short": 300}) {
|
|
t.Errorf("group/auto: promptCache %v, want {short: 300}", e["promptCache"])
|
|
}
|
|
case "ap/claude-opus-5-5":
|
|
if e["api"] != "anthropic-messages" {
|
|
t.Fatalf("member on %v, want anthropic-messages", e["api"])
|
|
}
|
|
if !reflect.DeepEqual(e["promptCache"], map[string]any{"short": 300, "long": 3600}) {
|
|
t.Errorf("member: promptCache %v, want short and long", e["promptCache"])
|
|
}
|
|
case "relay/glm-4.6":
|
|
if _, set := e["promptCache"]; set {
|
|
t.Errorf("relay/glm-4.6: promptCache %v, want none", e["promptCache"])
|
|
}
|
|
}
|
|
}
|
|
if !group {
|
|
t.Fatalf("no group/auto entry among %d", len(ms))
|
|
}
|
|
}
|
|
|
|
// Pi's clamp: the level itself, else the nearest above, else below.
|
|
func TestPiClamp(t *testing.T) {
|
|
for _, c := range []struct {
|
|
level string
|
|
offered []string
|
|
want string
|
|
}{
|
|
{"max", []string{"off"}, "off"},
|
|
{"max", []string{"low", "high", "max"}, "max"},
|
|
{"medium", []string{"low", "high", "max"}, "high"},
|
|
{"xhigh", []string{"off", "low", "medium", "high"}, "high"},
|
|
{"minimal", []string{"low", "high"}, "low"},
|
|
} {
|
|
if got := piClamp(c.level, c.offered); got != c.want {
|
|
t.Errorf("%s of %v: %s, want %s", c.level, c.offered, got, c.want)
|
|
}
|
|
}
|
|
}
|