Commit Graph
8 Commits
Author SHA1 Message Date
yetone 37c1bc043b agent: a group whose members all serve Responses, one best there, is asked on Responses
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 on 49c9491b7, 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 on fcc0daa23: 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).
2026-11-06 19:07:15 +08:00
yetone 129578c3d9 agent: pi_api_test.go is gofmt'd
7474a86f1 left the map literal's keys aligned to a longer key it no
longer has, so `gofmt -l` named the file on main. gofmt -w only;
whitespace, no test changes.
2026-10-30 18:44:23 +08:00
yetone 7474a86f16 agent: TestPiModelsAskedOnTheirNativeAPI asks Gemini's API of OmO's folder, Pi's keeps Chat (2f5a3f1c0)
2f5a3f1c0 kept a Gemini model on Chat in Pi's models.json (Raft runs
Pi's SDK on it with a fetch pi-ai's Google adapter refuses) and was
pushed before its full suite ended. That suite went red on this test,
which still wanted google-generative-ai at /v1beta in Pi's file. It now
wants Chat there (no api, no baseUrl), and checks the same providers in
OmO's models.json, whose folder is its own: gem/ and hybrid/
gemini-3-flash on google-generative-ai at /v1beta, hybrid/gemini-2.5-pro
and the Gemini routing group on Chat.

Run (mote, at this tree on 2f5a3f1c0):
- Full suite at 2f5a3f1c0's tree (go test -tags nogui ./... -count=1
  -timeout 45m): every package ok but internal/agent, red on this test
  alone.
- go test -tags nogui ./internal/agent -count=1 -timeout 45m: ok (150s).
- Broken by hand (piAsked back to StepCode alone): this test red on Pi's
  two Gemini entries; OmO's part passes either way.
- gofmt -l: nothing.
2026-10-30 17:43:35 +08:00
yetoneandskygunner 7eb7fa5407 agent: Pi, OmO and Prime Agent ask a Gemini model on google-generative-ai at the gateway's /v1beta (#3282)
A model served on Google's Gemini API (a custom provider's gemini=, a
Google sign-in's Code Assist, a plugin model declaring @ai-sdk/google)
was written into Pi's models.json with no api, so it inherited the
provider's openai-completions and the gateway translated Chat to Gemini.
magpieModels now gives such a model the Gemini API when no Chat,
Responses or Messages API was chosen for it, and piModelJSON writes it as
api "google-generative-ai" with baseUrl <gateway>/v1beta. A model whose
user picked Chat for it, routing groups and Pencil stay as they were.
Sync rewrites magpie's own model list, so files written before get it.

The patch is skygunner's (279e9bd1 on fix/pi-google-api in their fork).
Changed here:
- StepCode keeps such a model on Chat. Step-Code at 90a57820 registers
  only anthropic-messages, openai-completions and openai-responses
  (packages/providers/src/compat.ts BUILTIN_APIS); its docs list
  google-generative-ai but nothing streams it, so the patch would have
  broken every Gemini model there.
- On google-generative-ai, pi-ai's resolveGoogleThinkingLevel maps a level
  through thinkingLevelMap and throws on anything but minimal, low,
  medium or high, so a level the model names otherwise (xhigh, max) is
  set to null there and Pi doesn't offer it.

Checked against each client's source: pi-ai 1.4.0 and OmO's senpi-ai
2026.10.27-1 set apiVersion "" when baseUrl is given ("baseUrl already
includes version path"); Prime Agent's pa-ai providers/google.rs takes a
model baseUrl in place of host and version, and pa-core models/custom.rs
reads a per-model api and baseUrl.

Run (mote, at this tree rebased on 96a703a59, then again on adc618bbf):
- go test -tags nogui ./internal/agent -count=1 -timeout 45m: ok (385s).
- go test -tags nogui ./internal/gateway -count=1 -timeout 45m: ok (744s,
  load ~20 from other sessions). A first run of both packages together
  exited 1 after agent's ok; its log was deleted from the shared
  scratchpad by another session before the red could be read, so it is
  unnamed. The rerun of gateway alone at the same tree passed.
- Rebased on adc618bbf (#3279's plugin text filter, fake plugin
  changes): internal/agent -timeout 45m ok (252s); internal/gateway
  -run 'TestPlugin|TestCustomGemini' ok (43s).
- Pushed on fa2332976: the three commits since adc618bbf (fc43c69e5,
  750bd1bb6, fa2332976) change gateway code this change doesn't touch;
  not run again on them.
- Red without the fix (origin/main with these tests): TestPiModelsAsked-
  OnTheirNativeAPI (gem/ and hybrid/gemini-3-flash api <nil>),
  TestPiGooglePluginModels for pi, omo, prime-agent, and
  TestPiGoogleThinkingLevelsAreGeminis. TestPluginProvider's new /v1beta
  part passes there too: it guards that the plugin's sign-in and fetch
  still serve the route, which already worked.
- Broken by hand: with the null-out of non-Gemini levels turned off and
  the StepCode exception removed, TestPiGoogleThinkingLevelsAreGeminis
  (xhigh, max kept) and TestPiGooglePluginModels/stepcode go red.
- Real Pi 1.4.0 (@earendil-works/pi-coding-agent) in a sandbox HOME on
  mote: a custom provider gemini=http://127.0.0.1:18761/v1beta (a local
  fake), magpie serve on 127.0.0.1:18762, `magpie pi
  magpie/gemfake/gemini-3-flash`. models.json had the model at
  google-generative-ai, <gw>/v1beta; `pi -p "say hi"` printed the fake's
  reply, its session recorded api google-generative-ai, and the fake got
  /v1beta/models/gemini-3-flash:streamGenerateContent?alt=sse.

Not tried: a real Google account or plugin sign-in, real OmO and Prime
Agent binaries (checked by their source only), Windows and Linux.

Co-authored-by: skygunner <84759+skygunner@users.noreply.github.com>
2026-10-29 18:34:21 +08:00
yetone 81a24cf8fe groups: a found group is listed as auto/<model id as the vendor spells it>
ZeroClover asked on X: Auto Group ids group/auto-<slug> can't be looked
up on models.dev. A found group is now listed and written as
auto/<model>, e.g. auto/claude-opus-5.5: /v1/models, the catalog, agent
configs, the GUI's Routing page and the CLI. Context and output limits
come from the model's metadata as before.

What stays the same:
- The internal id is still group/auto-<slug> (Group.Ref() gives the
  public one). Every old form is still accepted as input forever:
  provider.CanonicalRef turns auto/<model>[:level][[1m]] into it at the
  gateway (validateModel), keys, stats, affinity and usage, so both ids
  route to the same group and count as one.
- A key's model list allows a model by either id, group/* included
  (allows() in key_models.go).
- Hand-made groups stay group/<id>.
- A provider whose stored id is "auto" keeps its models: while one
  exists, found groups are listed by their old id (AutoRefsOn) and
  auto/<x> means that provider's model. Documented in
  docs/subsystems/gateway-routing.md.

Agent configs: SyncCatalog rewrites a field that holds a found group's
old id (renameFoundGroups), but only while the value is still what
applied.json says magpie wrote; a value the user set stays. A pick by
the old id written now is written as auto/<model> (Apply). Hidden,
picked and ordered model lists saved by the old id hold for the new one
(visible.go), and a bare model id still reaches its found group (bare.go).

Claude Code is given a dotted Claude version dashed (ClaudeSpelled), so
auto/claude-sonnet-4.5 sits in its settings as auto/claude-sonnet-4-5.
That routes to the same group, but with found groups off nothing reads
it back dotted, and Reseat took the field for changed and left the agent
on a group that was gone. Reseat now compares a group pick by its
canonical id (samePick). The old ids had no dots, so this is new with
auto/<model>.

Run at this tree (sandbox HOME, caches pinned):
- gofmt -l: clean. go vet ./...: clean on darwin, GOOS=linux -tags
  nogui, GOOS=windows.
- go test -p 4 -timeout 45m ./...: every package ok except agent and
  gateway, whose failures were the tests' expected ids (updated here)
  and two regressions now fixed (bare ids; desktop models hiding groups
  by prefix). Every failing test passes on rerun. Load average was
  ~210-290 from other sessions throughout.
- Reruns: provider, cli, codexcat ok. internal/gui: only
  TestSetAnswersWhileDevinAndProvidersHang fails (set slow/slow-1 took
  10.19s), and it fails the same in a git-archive export of 33dbdcc52.
- agent and gateway in full, -p 2 -timeout 120m: gateway ok (2996s).
  agent failed four tests that still expected the old ids
  (TestOmp/PiModelsAskedOnTheirNativeAPI, TestReseatFoundGroupsOff,
  TestReseatKeepsAFoundGroupWithAProviderOff); updating them showed the
  Reseat bug above. After the fix, go test -count=1 -timeout 120m
  ./internal/agent/: ok (1000s, load ~160-220).
- GUI files the change reaches, chromium and webkit: group-found-off and
  the routing files pass, except routing-bodies, routing-model-rest,
  routing-keys-fold and routing-request-metrics, which fail the same with
  33dbdcc52's JS.

Broken by hand and watched red, then restored: CanonicalRef in
validateModel (both-ids routing test), allows() (key tests both ways),
the Save refusal and AutoRefsOn checks in Ref/CanonicalRef (provider
named auto), catalog.Lists' preference (models.dev lookup of the part
after auto/), renameFoundGroups' applied.json check and its SyncCatalog
call (user values kept), PublicRef in visible.go, the codexcat prefix,
samePick in Reseat (TestReseatFoundGroupsOff: opus left on the gone
group).
TestBareModelIDsShared was red before the bare.go fix.

Not verified: no real agent, vendor or models.dev client run; no run on
the Windows box. Settings pickers (vision, title model) holding a saved
group/auto-... value may show it as saved. codexcat can't tell a stored
"auto" provider apart, so its models lose the "text only" hint. The
pre-existing reds above are not filed.
2026-10-20 00:18:51 +08:00
yetone d82985eee1 agent: a routing group whose members are all best on Responses is asked there by Pi, omp, droid and dsh, so its tool-call arguments stream (#1594, ObsidianArch02)
magpieModels gave a routing group no native API, since its members may
each want another. Pi, omp and droid then asked every group on Chat
Completions, and dsh put it on its Chat route, even a group of GPT
members all served on Responses. The gateway translated each answer from
Responses to Chat, and that translation holds a tool call's arguments
until the call ends (#613), so Pi's Code Mode saw no code until the whole
call had been generated.

A group now has APIs ["responses"] when every member, nested groups'
included, is served best on Responses (allResponses over the group's
members, by Provider.Native). Any other group keeps none: one with a Chat
member, and a Messages-only group too, as the gateway knows whether a
Claude thinks adaptively by its own model id, not the group's. dsh moves
a start on such a group to its Responses route (dshStartOnItsRoute); a
dsh session resumed on it asks for the model once, as for any model that
moved routes.

The rest of the request (a protocol picked per group, conversion shown
per request) is not in this commit.

Verified:
- TestPiModelsAskedOnTheirNativeAPI: auto-gpt-5-5, a GPT group and a
  group of that group get openai-responses; a group with a Chat member
  and one of Messages-only members get none. Without the route.go change
  it fails for the three Responses groups.
- TestOmpModelsAskedOnTheirNativeAPI: the same for omp.
- TestGroupOnResponsesRelaysArgumentDeltas (gateway): a group of two
  Responses-only members asked on /v1/responses relays each
  function_call_arguments.delta as the vendor sent it, on /responses.
  It guards what this change relies on, and passed before it too.
- go test ./internal/agent ./internal/provider, gofmt -l, GOOS=linux and
  windows go vet -tags nogui.
- Not tried with a real Pi against a real group.
2026-10-11 21:00:29 +08:00
yetone 8060650048 agent: Pi starts on the model magpie picks, and asks a Messages-only provider's models on Messages (#160 Aimer779; Cleary on Discord)
While Pi's ~/.pi/agent/settings.json has a non-empty enabledModels (its Ctrl+P / /scoped-models list), a new session starts on defaultProvider/defaultModel only when that list takes the model in, else on the list's first entry, so a model picked in magpie outside the list was written and never used. Setting Pi's model now adds it to enabledModels as provider/model, as Pi's own picker does, when nothing in the list takes it in already: the same reference with or without a :level after it, or a glob (*, ?, [..], without case) that the reference or its model id fits. The user's entries, their order and comments stay; no list is made where there is none, and an empty one is left as it is. Turning the model back to Pi's own takes magpie/… entries out with magpie's provider, removing the key rather than leaving it empty. The model field shows what a new session starts on: the list's first model when the saved default isn't in the list and that entry names one model outright. The list itself isn't editable in magpie yet; Field is single-valued, and an editor needs a multi-value field kind in the API, GUI (a multi-select, reorderable picker), TUI and CLI.

Pi's models.json now gives each magpie model the API its provider speaks natively, so the gateway passes the request through instead of translating Chat: Responses-native models keep openai-responses; a Messages-only provider's (a custom Anthropic-compatible endpoint, as Cleary's) get api anthropic-messages with baseUrl the gateway's root (Anthropic's SDK adds /v1/messages). A Claude from 4.6 on also gets compat.forceAdaptiveThinking, so Pi asks for adaptive thinking and an effort, not the budget such a Claude refuses (why these stayed on Chat before). Magpie's models stay under providers.magpie; other providers are untouched.

Why Chat→Messages could 400 where Pi's direct Messages didn't: with reasoning on, buildAnthropic raised max_tokens to budget+4096 (28096 for high) past the client's own max_completion_tokens, which Pi sets to the model's output limit, so an upstream capped below that refused it. The budget now fits under a cap the client gives (at most the cap less 1024; no thinking when the cap is 2048 or less); with no cap it still raises max_tokens as before.

Tested: go test -tags nogui ./... (new: TestPiTakes, TestPiModelJoinsEnabledModels, TestPiModelOffLeavesEnabledModels, TestThinkingBudgetFitsTheClientsCap; TestPiModelsAskedOnTheirNativeAPI extended), nogui builds for darwin, linux and windows. In a sandbox HOME: settings.json with enabledModels [xai/grok-4.6, openai-codex/gpt-5.6-sol, deepseek/deepseek-flash], magpie pi magpie/cleary/kimi-k3 appended the model and kept the rest, magpie pi default took it out again; models.json listed cleary's models on anthropic-messages, a Chat relay's on the provider's openai-completions, a Responses vendor's on openai-responses. Pi 0.87.1 loaded that models.json (--list-models) and, against a fake Messages endpoint standing in for the gateway (MAGPIE_ADDR on a spare port), posted to /v1/messages with the gateway key: kimi-k3 with a 15360-token budget under max_tokens 16384, claude-sonnet-5 with adaptive thinking and effort high.
2026-09-29 00:09:06 +08:00
yetone 761156a816 agent: Pi asks a Responses-native model on Responses (Leo: 同协议优先) — every magpie model in Pi's models.json went out as openai-completions, so a ChatGPT sign-in's models, a Responses-only provider's, and GPT on OpenAI's API or Copilot's were asked on Chat and translated to Responses by the gateway. Now each such model carries "api": "openai-responses" (Pi takes a model's own api over its provider's, and posts it to baseUrl/responses), so the gateway relays what Pi sent as it is: reasoning effort and summary, its encrypted reasoning, images, tools, prompt_cache_key; a ChatGPT sign-in's still made into Codex CLI's request. Which API is a model's is provider.Native — what the provider serves it on itself, Responses first for an OpenAI model where the gateway already put it first (ResponsesFirst, moved from the gateway). Chat providers, groups, Cursor/Devin/Kiro/Claude Code sign-ins and Anthropic-API models stay on openai-completions: Pi's anthropic-messages picks thinking by the Claude ids it knows and asks a newer Claude for a thinking budget it refuses, which magpie's translation doesn't. Tested with Pi 0.73.1 and @earendil-works/pi-coding-agent 0.87.1 against a sandbox gateway and a fake Responses upstream: /v1/responses relayed with effort high, xhigh, none (thinking off); a Chat model still on /v1/chat/completions 2026-09-28 20:18:37 +08:00