Commit Graph
2 Commits
Author SHA1 Message Date
yetone 2f5a3f1c0b agent: Pi's models.json keeps a Gemini model on Chat, as Raft runs Pi's SDK on it with a fetch of its own (yunfei9958 on X)
Since 7eb7fa540 (#3282, v0.1.2042) a model served on Gemini's API,
an Antigravity sign-in's gemini-3.8-flash among them, was written into
Pi's models.json as api "google-generative-ai" at the gateway's /v1beta.
Raft (slock, @botiverse/raft-daemon 1.0.17) runs Pi's SDK, pi-ai 0.83.0,
on Pi's own agent folder (PI_CODING_AGENT_DIR, else ~/.pi/agent:
ModelRuntime.create's modelsPath) and gives every request its own fetch
(installProviderHttpClient). pi-ai's Google adapter throws before
sending when a fetch is given ("Custom fetch is not supported by the
Google Generative AI adapter", api/google-generative-ai.js; the same in
pi-ai 1.4.0), so every Gemini model failed in Raft.

Per-request fetch is a feature of Pi's SDK, so the file Pi's folder holds
can't count on google-generative-ai. piAsked now drops the Gemini API for
"pi" as it did for StepCode, whose rule moves there from stepcodeProvider:
the model stays on the provider's openai-completions, which the gateway
translates, as before v0.1.2042. piOffered reads the same entry, so Pi
offers the levels Chat has. OmO's and Prime Agent's folders are their own
and keep google-generative-ai. A sync rewrites magpie's model list, so
files written since v0.1.2042 are corrected without the user editing them.

Run (mote, at this tree on origin/main 8f0d21a00):
- go test -tags nogui ./internal/agent -run
  'TestPiGoogle|TestPiFolder|TestPrimeAgent|TestStepcode|TestStepCode|TestAside'
  -count=1: ok.
- Broken by hand (piAsked back to StepCode alone):
  TestPiGooglePluginModels/pi and TestPiFolderKeepsGeminiOnChatForRaft red.
- Raft's pi-ai 0.83.0 from npm, a request with a fetch of its own (as
  Raft's daemon gives) against a local fake gateway: the old entry
  (google-generative-ai, /v1beta) ends "Custom fetch is not supported by
  the Google Generative AI adapter", the reporter's error; the new one
  (openai-completions, /v1) reaches /v1/chat/completions and gets the
  reply.
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./..., go build, GOOS=linux go build -tags nogui,
  GOOS=windows go build: ok.
- Full suite (go test -tags nogui ./... -timeout 45m): started on mote
  at this tree; pushed before it ends, per the owner's ship-at-once rule.
  Its result goes on the commit's thread when it ends.

Not tried: the real Raft app (it needs a slock account), and a real
Antigravity account through it. Aside also runs Pi's SDK, on a folder
of its own; its source isn't public, so whether it passes a fetch is
not known, and it keeps google-generative-ai.
2026-10-30 17:30:23 +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