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)
Since7eb7fa540(#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/main8f0d21a00): - 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.
This commit is contained in:
@@ -140,7 +140,7 @@ something else shows up as drift.
|
||||
- An agent is detected by its config file, its folder, or its command on magpie's PATH (`Detected`). That PATH is the login shell's plus the folders users' tools go in (`proc.UserPath`: `~/.local/bin`, npm's prefixes, the Node nvm's default alias resolves to (the highest installed when it names none), bun, Homebrew, ...; on Windows the registry's PATH plus the Node fnm's default alias names, `%APPDATA%\fnm\aliases\default` or under `FNM_DIR`, which fnm puts on a terminal's PATH from the shell profile and never in the registry, #2685), so a CLI a terminal doesn't find can still be found and listed: an npm install under a Node the terminal no longer uses. `/api/agents/cli` then gives where it is (`path`) and `offPath` when the login shell's PATH (`proc.LoginPath`) lacks its folder, and the Agents row says "Not on your terminal's PATH", its tip naming the file (悠悠哥 on Discord: Codex 0.162.1 listed with no codex on PATH and no `~/.codex`). An unknown login PATH says nothing. A folder another tool writes too doesn't count (`dirShared`): Pi's for omp, `~/.copilot` for the Copilot CLI, which GitHub Copilot's JetBrains and VS Code plugins also write, and Qoder's and Qoder CN's, which Qoder's JetBrains plugin fills, and `~/.cursor` for Cursor CLI, which the Cursor editor makes on its own (`TestCursorFolderFromTheEditorIsNotTheCLI`, @G_Z_Y on X); only `cli-config.json` or `cursor-agent` finds Cursor CLI. A command another app ships under the agent's name doesn't count either: VS Code forks put a `code` launcher in their own bin folder (Cursor; Qoder IDE beside `qoder`), which their Windows installers put on PATH, so a `code`, `code-insiders` or `codium` counts as VS Code, Insiders or VSCodium only when the `product.json` beside it names that build (`applicationName`), or names none (`vscodeCodeBinary`; ggbr on Discord: Qoder IDE listed as VS Code too, `TestVSCodeDetected`, `TestVSCodeBuildLauncher`). A config file another tool writes first counts only when `pathOwn` says it is the agent's: Qoder's `settings.json` holding `enabledPlugins` alone is the plugin's (`qoderPluginOnly`; #1495, `TestCopilotFolderFromAnIDEPluginIsNotTheCLI`, `TestQoderSettingsFromAnIDEPluginIsNotTheCLI`). The Qoder app (the desktop app, which runs Qoder's CLI as its agent with the same folder) is found by the `.qoder-app-status.json` it writes there (`sign`, `qoderApp`; #2138, `TestQoderAppIsQoder`), as its `settings.json` can be its bundled plugin's `enabledPlugins` alone. Only the GUI and `daemon install` widen the PATH so; `magpie serve`, `web`, `tui` and the CLI keep the one they were started with, so an agent's CLI (`cliBin`, which its version and `omp`'s max effort are read from) is looked for in those folders (`proc.FindTool`) on every system when it isn't on the PATH, not only on Windows (whqtian on Discord: omp under `~/.bun/bin` on Ubuntu read as no version and offered xhigh in place of max; `TestOmpVersionOffPath`).
|
||||
- Detection goes by an agent's folder, which an uninstall leaves behind, so an agent found by that alone is shown as gone (`CLIMissing`; #843, #2177, #2173): its CLI is on no PATH and in none of `proc.FindTool`'s folders nor where its own installer puts it (`~/.claude/local`, `~/.codex/packages/standalone`, `~/.opencode/bin`, Hermes' `hermes-agent` checkout), and nothing else that reads the folder is here (`cliHeld`): its desktop app (`HasApp`), an editor's extension (`~/.<editor>/extensions/<id>-*`: `anthropic.claude-code`, `openai.chatgpt`, `saoudrizwan.claude-dev`), Claude.app, OpenCode.app and Goose.app on a Mac, a JetBrains IDE's settings (its AI Assistant's agents and Cline's plugin) or Zed's `external_agents` (its Claude Code and Codex adapters). Where magpie can't tell (every shared folder, `cliShared`, on Windows, whose readers can be a Store app, a portable editor or a PATH only a shell profile sets, #1482, and there too one a desktop app of the agent's reads, `desktopApps`: DeepSeek Harness Desktop installs to any folder and puts its `dsh.cmd` in one the user picks, #2300, #2304; OpenCode and Goose off a Mac, Gemini, an agent detected its own way or by a command name other tools share, one with no install command but `cliOnly`'s Hermes), it is never gone. A gone row in the GUI shows "CLI not found" and none of its settings, nor Apply again; while connected it keeps its switch and Disconnect, and it folds under Not set up once not. Get started never offers it (`connectKind` is "no"). The TUI leaves it out and `magpie ls` says "CLI not found" (`TestCLIMissing*`, `agent-cli-missing.test.cjs`, `getting-started.test.cjs`).
|
||||
- Tests never touch the real machine. `TestMain` uses `testenv`, which points HOME, USERPROFILE, the XDG folders and APPDATA into a temporary folder, clears `agentenv.Vars` and puts failing stand-ins for keychain tools and agent CLIs on PATH. Agent-specific side effects (Aside, the Zed keychain, Codex's usage check) are also stubbed in `TestMain`.
|
||||
- Pi, OmO and Prime Agent write a Gemini-capable model as `google-generative-ai` at the gateway's `/v1beta` (`piModelJSON` in [`agents.go`](../../internal/agent/agents.go)); each one's Google client takes the version path from `baseUrl` (pi-ai's and senpi-ai's `apiVersion = ""`, Prime Agent's `pa-ai` `providers/google.rs`). StepCode keeps such a model on Chat (`stepcodeProvider`): it registers no `google-generative-ai` stream, only `anthropic-messages`, `openai-completions` and `openai-responses` (Step-Code `packages/providers/src/compat.ts`), though its docs list it. `magpieModels` in [`route.go`](../../internal/agent/route.go) includes Gemini and Code Assist capabilities when no native Chat, Responses or Messages API was selected; this includes a plugin model declaring `@ai-sdk/google`. Requests keep going through the gateway and the plugin's sign-in and fetch, with the gateway's usual translation where needed. A normal model sync updates existing entries. Routing groups retain their existing API choice, and Pencil remains on Chat. Pi resolves a level there to one of Gemini's four (minimal, low, medium, high) and throws on any other, so a level the model names otherwise is set to null in `thinkingLevelMap` (`TestPiGoogleThinkingLevelsAreGeminis`).
|
||||
- OmO and Prime Agent write a Gemini-capable model as `google-generative-ai` at the gateway's `/v1beta` (`piModelJSON` in [`agents.go`](../../internal/agent/agents.go)); each one's Google client takes the version path from `baseUrl` (senpi-ai's `apiVersion = ""`, Prime Agent's `pa-ai` `providers/google.rs`). Pi and StepCode keep such a model on Chat, which the gateway translates (`piAsked`). StepCode registers no `google-generative-ai` stream, only `anthropic-messages`, `openai-completions` and `openai-responses` (Step-Code `packages/providers/src/compat.ts`), though its docs list it. Pi's own agent folder is read by apps that run Pi's SDK on it too: Raft's daemon (`@botiverse/raft-daemon`, pi-ai 0.83.0) opens `~/.pi/agent/models.json` and hands every request its own fetch, which pi-ai's Google adapter refuses before sending ("Custom fetch is not supported by the Google Generative AI adapter", in pi-ai 1.4.0 too; yunfei9958 on X, `TestPiFolderKeepsGeminiOnChatForRaft`). `magpieModels` in [`route.go`](../../internal/agent/route.go) includes Gemini and Code Assist capabilities when no native Chat, Responses or Messages API was selected; this includes a plugin model declaring `@ai-sdk/google`. Requests keep going through the gateway and the plugin's sign-in and fetch, with the gateway's usual translation where needed. A normal model sync updates existing entries. Routing groups retain their existing API choice, and Pencil remains on Chat. Pi resolves a level there to one of Gemini's four (minimal, low, medium, high) and throws on any other, so a level the model names otherwise is set to null in `thinkingLevelMap` (`TestPiGoogleThinkingLevelsAreGeminis`).
|
||||
|
||||
## Verification
|
||||
|
||||
|
||||
@@ -512,7 +512,7 @@ func magpieProviderJSONAt(shape, catalog, gw string) any {
|
||||
case "pi":
|
||||
var ms []map[string]any
|
||||
for _, m := range models {
|
||||
ms = append(ms, piModelJSON(m, gw, true))
|
||||
ms = append(ms, piModelJSON(piAsked(catalog, m), gw, true))
|
||||
}
|
||||
if ms == nil {
|
||||
ms = []map[string]any{}
|
||||
@@ -615,6 +615,31 @@ func objectPairs(raw []byte) orderedJSON {
|
||||
return out
|
||||
}
|
||||
|
||||
// piAsked is m as agentID's models.json can ask it: without the Gemini API
|
||||
// where nothing that reads the file can be trusted to stream
|
||||
// google-generative-ai, so such a model stays on the provider's Chat,
|
||||
// which the gateway translates.
|
||||
//
|
||||
// - StepCode registers no google-generative-ai stream, only Pi's
|
||||
// anthropic-messages, openai-completions and openai-responses
|
||||
// (packages/providers/src/compat.ts BUILTIN_APIS, Step-Code at
|
||||
// 90a57820), though its docs list it (#3282).
|
||||
// - Pi's own agent folder is read by every app that runs Pi's SDK on it,
|
||||
// not by Pi alone. Raft (slock's raft-daemon, the Pi runtime of its
|
||||
// agents) opens ~/.pi/agent/models.json (or PI_CODING_AGENT_DIR's) and
|
||||
// hands every request its own fetch (installProviderHttpClient), which
|
||||
// pi-ai's Google adapter refuses before sending: "Custom fetch is not
|
||||
// supported by the Google Generative AI adapter" (pi-ai 0.83.0 and
|
||||
// 1.4.0, api/google-generative-ai.js; yunfei9958 on X). Per-request
|
||||
// fetch is a feature of Pi's SDK, so any other host of it can do the
|
||||
// same. OmO's and Prime Agent's folders are their own, and keep it.
|
||||
func piAsked(agentID string, m catalog.Model) catalog.Model {
|
||||
if agentID == "stepcode" || agentID == "pi" {
|
||||
m.APIs = slices.DeleteFunc(slices.Clone(m.APIs), func(a string) bool { return a == string(provider.Gemini) })
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// piModelJSON is one of magpie's models as an entry of Pi's models.json.
|
||||
// native selects the model's preferred gateway API (its own api and
|
||||
// baseUrl); without it the model is left on the provider's
|
||||
|
||||
@@ -119,7 +119,7 @@ func piOffered(agentID, model string) []string {
|
||||
}
|
||||
for _, m := range magpieModels(agentID) {
|
||||
if m.ID == ref {
|
||||
return piSupported(piModelJSON(m, "", true))
|
||||
return piSupported(piModelJSON(piAsked(agentID, m), "", true))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -53,10 +53,12 @@ func TestPiGooglePluginModels(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
found = true
|
||||
// StepCode has no google-generative-ai stream: Chat there
|
||||
if a.ID == "stepcode" {
|
||||
// StepCode has no google-generative-ai stream, and Pi's
|
||||
// folder is read by Raft, whose fetch pi-ai's Google
|
||||
// adapter refuses: Chat there (piAsked)
|
||||
if a.ID == "stepcode" || a.ID == "pi" {
|
||||
if m["api"] != nil || m["baseUrl"] != nil {
|
||||
t.Errorf("StepCode can't ask Gemini's API: %v", m)
|
||||
t.Errorf("%s can't ask Gemini's API: %v", a.ID, m)
|
||||
}
|
||||
} else if m["api"] != "google-generative-ai" || m["baseUrl"] != gw+"/v1beta" {
|
||||
t.Errorf("Google model still inherits Chat: %v", m)
|
||||
@@ -98,3 +100,26 @@ func TestPiGoogleThinkingLevelsAreGeminis(t *testing.T) {
|
||||
t.Errorf("a Chat model lost its levels: %v", l)
|
||||
}
|
||||
}
|
||||
|
||||
// Raft runs Pi's SDK on Pi's own agent folder and hands each request a
|
||||
// fetch of its own, which pi-ai's Google adapter refuses before sending
|
||||
// ("Custom fetch is not supported by the Google Generative AI adapter",
|
||||
// yunfei9958 on X), so a Gemini model in Pi's models.json stays on Chat,
|
||||
// and Pi offers it the levels Chat has; OmO and Prime Agent, whose
|
||||
// folders are their own, keep Gemini's API.
|
||||
func TestPiFolderKeepsGeminiOnChatForRaft(t *testing.T) {
|
||||
m := catalog.Model{ID: "gem/gemini-3.8-flash", Name: "Gemini 3.8 Flash", APIs: []string{"gemini"}, Efforts: []string{"low", "high", "xhigh"}}
|
||||
const gw = "http://127.0.0.1:1"
|
||||
for id, want := range map[string]any{"pi": nil, "stepcode": nil, "omo": "google-generative-ai", "prime-agent": "google-generative-ai"} {
|
||||
e := piModelJSON(piAsked(id, m), gw, true)
|
||||
if e["api"] != want {
|
||||
t.Errorf("%s: api %v, want %v", id, e["api"], want)
|
||||
}
|
||||
if want == nil && (e["baseUrl"] != nil || e["thinkingLevelMap"].(map[string]any)["xhigh"] != "xhigh") {
|
||||
t.Errorf("%s: not Chat's entry: %v", id, e)
|
||||
}
|
||||
}
|
||||
if !slices.Equal(m.APIs, []string{"gemini"}) {
|
||||
t.Errorf("the catalog's model changed: %v", m.APIs)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
"github.com/tidwall/jsonc"
|
||||
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
// StepCode keeps its configuration in ~/.stepcode/config.toml (or
|
||||
@@ -43,13 +42,7 @@ func stepcodeDir(at place) string {
|
||||
func stepcodeProvider(at place) any {
|
||||
ms := make([]map[string]any, 0)
|
||||
for _, m := range magpieModels("stepcode") {
|
||||
// StepCode registers no google-generative-ai stream, only Pi's
|
||||
// anthropic-messages, openai-completions and openai-responses
|
||||
// (packages/providers/src/compat.ts BUILTIN_APIS, Step-Code at
|
||||
// 90a57820), though its docs list it: a Gemini model stays on Chat
|
||||
// there, which the gateway translates (#3282)
|
||||
m.APIs = slices.DeleteFunc(slices.Clone(m.APIs), func(a string) bool { return a == string(provider.Gemini) })
|
||||
ms = append(ms, piModelJSON(m, at.gw(), true))
|
||||
ms = append(ms, piModelJSON(piAsked("stepcode", m), at.gw(), true))
|
||||
}
|
||||
return map[string]any{
|
||||
"name": "magpie",
|
||||
|
||||
Reference in New Issue
Block a user