agent: OpenBot, magpie's models in its model picker (jiezhengj)
OpenBot (nightly-labs/openbot, openbot.run, v0.58.0) is a new row on the
Agents page. jiezhengj on Discord asked for it: today they type magpie's
address into OpenBot by hand and add each model one at a time.
OpenBot lists the user's own OpenAI-compatible endpoints from
openbot-custom-providers-v1.json in its userData folder:
~/Library/Application Support/OpenBot, %APPDATA%\OpenBot, or
~/.config/OpenBot. Connecting adds an entry with id "magpie" pointing at
the gateway's /v1 and holding the models picked for OpenBot, with
secret null. OpenBot seals an entry's key in safeStorage, which magpie
doesn't open, so the entry has no key. OpenBot hands it to OpenCode
keyless, and the gateway accepts it as a request from this computer.
What the entry keeps to:
- OpenBot's decoders drop the whole list over one bad entry. So the entry
has at most 64 models, only ids OpenBot accepts as magpie/<id>, and a
context window only inside 1,024 to 100,000,000.
- The user's other entries stay. The name, harness and secret they give
magpie's entry in OpenBot stay too.
- A sync with nothing to change doesn't write.
- A file whose version isn't the number 1, or whose providers isn't a
list, is one OpenBot refuses itself, so magpie leaves it alone.
- Disconnect takes out magpie's entry, and the file too when only the
version and an empty list are left.
OpenBot reads the file at start, so while it runs, a notice says to
restart it. The notice is in every language.
OpenBot is detected by its userData folder, OpenBot.app
(app.openbot.desktop), or OpenBot.exe under %LOCALAPPDATA%\Programs or
%ProgramFiles%. Docs updated: agent-wiring.md, reference.md, and both
READMEs.
Run at the pushed head, on mote:
- gofmt -l: clean.
- go vet -tags nogui for internal/agent and internal/gui, and for ./...
with GOOS=linux and GOOS=windows: ok.
- go test -tags nogui -count=1 -timeout 45m on internal/agent and every
package that imports it (., backup, cli, davsync, gui, library,
profile, stats, tui, uninstall, plugins/...): ok.
- GUI: agent-notice-lang, i18n-keys, header-relang and about-notices in
Chromium and WebKit: 58 of 58 pass.
After rebasing on d20caffae (appdir, i18n.js and gui changed on main), these were run again: gofmt; linux and windows vet of agent, gui and appdir; go test of the same three: ok. The four GUI files plus checkin-now-account: 80 of 80 pass.
Real OpenBot 0.58.0: the arm64 zip, sha512 checked against
latest-mac.yml, notarized by Akudama GmbH. It ran on mote under a
sandbox HOME with --user-data-dir and --use-mock-keychain, on a file
that magpie's own openBotWire wrote.
- OpenBot started without setting the file aside.
- Asked over CDP, window.openbot.customProviders.list() returned magpie's
entry with all three models and harness opencode.
- Saving another endpoint in OpenBot wrote magpie's entry back unchanged.
- The notice's pgrep pattern matched the running OpenBot.
Broken by hand, each red:
- the 64 cap
- the id filter
- the version check
- keeping the user's name, secret and harness
- writing version 1 into a new file
- the notice's Running check
One break stayed green: dropping openBotWire's own no-change check.
edit.SetJSON already skips a write that changes nothing, so the test
holds at that layer.
Not tried:
- a chat through OpenBot to the gateway. OpenBot's onboarding and its
OpenCode download were not gone through, so no request reached magpie.
- OpenBot's MCP servers. They live in its SQLite database, which magpie
doesn't write; magpie's /mcp/magpie/... servers are added by hand.
- Windows. Its install folder is read from electron-builder's defaults,
not from a real install.
- Linux and the AppImage.
- A request from OpenBot is counted under OpenCode's name, since
OpenCode sends it.
This commit is contained in:
@@ -80,7 +80,7 @@ magpie finds the subscriptions your agents are signed in to by reading their sig
|
||||
<table>
|
||||
<tr><td>
|
||||
|
||||
Claude Code · Claude Desktop · Claude Science · Codex · Gemini CLI · Antigravity CLI · OpenCode · OpenChamber · MiMo Code · DevEco Code · Pi · oh-my-pi · StepCode · MothX · PenguinHarness · Aside · OmO · Prime Agent · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · Zoo Code · JetBrains Air · Copilot (JetBrains) · Copilot CLI · Crush · DeepSeek Harness · Reasonix Studio · Command Code · fx · Devin · Hermes Agent · Mister Morph · Kimi Code · jcode · Qwen Code · Muse Code · Empryo · MiniMax Code · Droid · Cline · Qoder · Qoder CN · Grok Build · Grok App · ZCode · WorkBuddy · WorkBuddy AI · CodeBuddy · Pencil · OpenPencil · NewMax · Raycast · Kiro Crew · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Cindy · Lody · AionUi · Ante · AstrBot · QwenPaw · OpenClaw
|
||||
Claude Code · Claude Desktop · Claude Science · Codex · Gemini CLI · Antigravity CLI · OpenCode · OpenChamber · MiMo Code · DevEco Code · Pi · oh-my-pi · StepCode · MothX · PenguinHarness · Aside · OmO · Prime Agent · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · Zoo Code · JetBrains Air · Copilot (JetBrains) · Copilot CLI · Crush · DeepSeek Harness · Reasonix Studio · Command Code · fx · Devin · Hermes Agent · Mister Morph · Kimi Code · jcode · Qwen Code · Muse Code · Empryo · MiniMax Code · Droid · Cline · Qoder · Qoder CN · Grok Build · Grok App · ZCode · WorkBuddy · WorkBuddy AI · CodeBuddy · Pencil · OpenPencil · OpenBot · NewMax · Raycast · Kiro Crew · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Cindy · Lody · AionUi · Ante · AstrBot · QwenPaw · OpenClaw
|
||||
|
||||
</td></tr>
|
||||
</table>
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ magpie 通过读取智能体的登录信息(Claude Code 和 Codex 的文件、
|
||||
<table>
|
||||
<tr><td>
|
||||
|
||||
Claude Code · Claude Desktop · Claude Science · Codex · Gemini CLI · Antigravity CLI · OpenCode · OpenChamber · MiMo Code · DevEco Code · Pi · oh-my-pi · StepCode · MothX · PenguinHarness · Aside · OmO · Prime Agent · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · Zoo Code · JetBrains Air · Copilot (JetBrains) · Copilot CLI · Crush · DeepSeek Harness · Reasonix Studio · Command Code · fx · Devin · Hermes Agent · Mister Morph · Kimi Code · jcode · Qwen Code · Muse Code · Empryo · MiniMax Code · Droid · Cline · Qoder · Qoder CN · Grok Build · Grok App · ZCode · WorkBuddy · WorkBuddy AI · CodeBuddy · Pencil · OpenPencil · NewMax · Raycast · Kiro Crew · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Cindy · Lody · AionUi · Ante · AstrBot · QwenPaw · OpenClaw
|
||||
Claude Code · Claude Desktop · Claude Science · Codex · Gemini CLI · Antigravity CLI · OpenCode · OpenChamber · MiMo Code · DevEco Code · Pi · oh-my-pi · StepCode · MothX · PenguinHarness · Aside · OmO · Prime Agent · Goose · Cursor CLI · Cursor Private Inference · Zed · VS Code Chat · VS Code Insiders · VSCodium Chat · Zoo Code · JetBrains Air · Copilot (JetBrains) · Copilot CLI · Crush · DeepSeek Harness · Reasonix Studio · Command Code · fx · Devin · Hermes Agent · Mister Morph · Kimi Code · jcode · Qwen Code · Muse Code · Empryo · MiniMax Code · Droid · Cline · Qoder · Qoder CN · Grok Build · Grok App · ZCode · WorkBuddy · WorkBuddy AI · CodeBuddy · Pencil · OpenPencil · OpenBot · NewMax · Raycast · Kiro Crew · T3 Code · OpenHanako · AtomCode · Snow CLI · Alma · Cindy · Lody · AionUi · Ante · AstrBot · QwenPaw · OpenClaw
|
||||
|
||||
</td></tr>
|
||||
</table>
|
||||
|
||||
@@ -146,6 +146,7 @@ line; agents connected to magpie lose it when it quits.
|
||||
| Raycast | `~/.config/raycast/ai/providers.yaml` in the user's folder, on Mac and Windows | provider (a `magpie` entry in Raycast AI's Custom Providers, magpie's models in its model picker; Raycast Pro; the user's providers, `tools` and comments kept) |
|
||||
| Kiro Crew | `~/.kiro/crew/config.json` (`$KIROCREW_HOME`; `config.local.json` over it is left alone) | provider, harness (`agent.acp_backend`, and `agent.member_acp_backend` for a harness that can dispatch: an agent connected to magpie, so its models are magpie's: the one Crew is set to is connected along with it when it isn't yet, and disconnected with it again; the user's value is put back on Disconnect) |
|
||||
| OpenPencil | `openpencil/settings.json` in the config folder: `~/Library/Application Support` (macOS), `$XDG_CONFIG_HOME` or `~/.config` (Linux), `%APPDATA%` (Windows) | provider (a `magpie` entry in its `builtin_agents`, magpie's models in its chat's model picker; the user's entries and settings kept; refused while OpenPencil runs, as it writes the file back when it quits) |
|
||||
| OpenBot | `OpenBot/openbot-custom-providers-v1.json` in the app data folder: `~/Library/Application Support` (macOS), `%APPDATA%` (Windows), `$XDG_CONFIG_HOME` or `~/.config` (Linux) | provider (a keyless `magpie` endpoint, magpie's models in its model picker; the user's endpoints kept; OpenBot reads it at start, so restart it) |
|
||||
| NewMax | `newmax.db` (SQLite, the row `app` of its `settings` table) in `$NEWMAX_USER_DATA_DIR`, else `~/.newmax` (every OS) | provider (a `magpie-gateway` entry in its `providers` and `providerOrder`, magpie's models in its model picker; the rest of the row kept byte for byte; refused while NewMax runs, as it writes its settings back whenever one changes) |
|
||||
| T3 Code | `~/.t3/userdata/settings.json` (`$T3CODE_HOME/userdata`) | provider (a `magpie` provider instance on Claude Code, magpie's models as its custom models; a `magpie-codex` instance on Codex, whose `launchArgs` are Codex's own `-c` overrides to magpie and a `magpie-codex-models.json` catalog beside the settings. The harness is picked in T3's model picker) |
|
||||
| OpenHanako | `~/.hanako/provider-catalog.json` + `agents/<id>/config.yaml` (`$HANA_HOME`; its local API while it runs) | model (the primary agent's; magpie's models as a provider) |
|
||||
|
||||
@@ -86,6 +86,7 @@ something else shows up as drift.
|
||||
- Raycast AI reads Custom Providers from `~/.config/raycast/ai/providers.yaml` in the user's folder, on Mac and Windows alike (`raycast` in [`raycast.go`](../../internal/agent/raycast.go); manual.raycast.com/ai/custom-providers). magpie adds one entry to its `providers` list, `id: magpie`, at the gateway's `/v1` with an `api_keys` alias holding a key that names Raycast (its User-Agent isn't known), and one model per catalog model with `context` and all five `abilities` said, since Raycast assumes tools and vision off when one isn't. The list is edited as a node (`EditYAMLNode`), so the user's other entries, the `tools` block (anchors too) and comments stay. A key the user adds to magpie's entry or to one of its models (`include_user_email`, a `description`) is kept on a sync (`mergeYAMLKept`), and a sync with nothing to change doesn't write. Disconnect takes the entry out, the list when it was the only one, and a file left with nothing in it. Raycast watches the file, so there is no restart notice. The model is picked in Raycast, so the field is whether magpie is in its picker (`ListsModels`). Detected by `Raycast.app` on a Mac or the `~/.config/raycast` folder.
|
||||
- Kiro Crew (AWS's persistent agent: KiroCrew.app, the `kirocrew` CLI, its Gateway on :5476) has no model setting of its own: it runs every session on a harness over ACP, chosen by `agent.acp_backend` in `$KIROCREW_HOME/config.json` (default `~/.kiro/crew`; `""` is kiro-cli), and dispatched members by `agent.member_acp_backend` (`kirocrew` in [`kirocrew.go`](../../internal/agent/kirocrew.go); github.com/kirodotdev/KiroCrew v0.9.0, `src/kiro_crew/` `config/paths.py`, `config/loader.py`, `config/sections.py`, `agent_sdk/backends.py`). Connecting it sets both to an agent already connected to magpie (Codex, Claude Code, OpenCode, Pi or Goose; Pi can't take dispatch, so only the first key for it), preferring the one whose ACP adapter is installed (codex-acp, claude-agent-acp, pi-acp; looked for, never installed, and named in the notice when missing). When `agent.acp_backend` already names one of those five and that agent is installed but not connected, connecting Kiro Crew connects that agent too, in the same action, and runs Crew on it (wuping9525 on Windows: Crew on Claude Code, Claude Code not connected); the stash's `kirocrew.joined` records it, and Kiro Crew's Disconnect disconnects it again, unless the user disconnected it themselves since (`kiroCrewUserLeft` in `Agent.Disconnect`), and a disconnect the user had made before stays theirs. Otherwise, with none connected it refuses and says which to connect. On Windows the app is found by `~\.kirocrew-app\.venv\Scripts\kirocrew.exe` and an adapter also by npm's `.cmd`/`.exe` shim names. `config.local.json` is merged over `config.json` and wins, so a harness set there is the user's: magpie neither writes nor reads past it, and the row says so. The previous values are stashed and put back on Disconnect, only while each key still holds what magpie wrote; a file magpie made is removed when it is left empty. The row reads as connected only while the harness it names is still wired to magpie. Open sessions keep their harness; new ones take it.
|
||||
- OpenPencil (ZSeven-W/openpencil, the `openpencil-desktop` app) keeps the builtin agents its chat runs on in `settings.json` in Rust's `dirs::config_dir()` joined with `openpencil`: `~/Library/Application Support/openpencil` on a Mac, `$XDG_CONFIG_HOME` or `~/.config` on Linux, `%APPDATA%` on Windows (`openPencil` in [`openpencil.go`](../../internal/agent/openpencil.go); its `settings_io.rs` and `settings_payload.rs`). magpie adds one entry to `builtin_agents`, `id: magpie`, `kind: openai-compat` at the gateway's `/v1` with a key naming OpenPencil (its User-Agent isn't known), `preset: custom`, the picked models as OpenPencil writes a list: the first as `model`, `models` only for two or more, at most 64 (v0.8.4 reads `model` alone). The user's other entries and settings stay, and so do the `display_name` and `enabled` they give magpie's entry; a sync with nothing to change doesn't write. OpenPencil needs `"version": 1` (a file without it is set aside as corrupt and saving stops), so magpie writes it in a file it makes and leaves a file with any other version, or none, alone. Disconnect takes the entry out, and the file when only the version and an empty list are left. OpenPencil reads the file once at start and writes it back whole when it quits, so a change is refused while `openpencil-desktop` runs (Windows can't be asked, so the notice says to quit it first). The model is picked in OpenPencil's chat, so the field is whether magpie is in its picker (`ListsModels`). Detected by its settings folder, `~/.openpencil` (its CLI's), `OpenPencil.app` (`com.zseven-w.openpencil`), or `%ProgramFiles%\OpenPencil`. open-pencil/open-pencil, the other app of the name, keeps its providers in its webview's localStorage, so it is not a row: it reaches magpie through Pi or an ACP agent magpie wires.
|
||||
- OpenBot (nightly-labs/openbot, openbot.run; jiezhengj on Discord) keeps the OpenAI-compatible endpoints its model picker lists in `openbot-custom-providers-v1.json` in Electron's userData folder, app data joined with `OpenBot`: `~/Library/Application Support/OpenBot` on a Mac, `%APPDATA%\OpenBot` on Windows, `$XDG_CONFIG_HOME/OpenBot` or `~/.config/OpenBot` on Linux (`openBot` in [`openbot.go`](../../internal/agent/openbot.go); its `custom-provider-store.ts` and `opencode-config.ts`, v0.58.0). magpie adds one entry to `providers`, `id: magpie` at the gateway's `/v1` with `secret: null`: an entry's key and headers are one safeStorage ciphertext (the Keychain, DPAPI) that magpie doesn't open, so OpenBot hands the entry to OpenCode keyless, the gateway takes it as a request from this computer, and it counts as OpenCode's. OpenBot's list decoders fail closed (one entry or model it wouldn't take empties the list), so the models are the picked ones whose `magpie/<id>` OpenBot accepts (ASCII letters, digits and `._:/[],=-`, at most 160), at most 64, with a context window only inside 1,024 to 100,000,000. The user's other entries stay, and so do the `name`, `harness` and `secret` they give magpie's entry; a sync with nothing to change doesn't write. A file whose `version` isn't the number 1, or whose `providers` isn't a list, is one OpenBot itself refuses, so magpie leaves it alone. Disconnect takes the entry out, and the file when only the version and an empty list are left. OpenBot reads the file once at start and writes it whole only when an endpoint is saved, edited or removed there, so the notice (while it runs) says to restart it before doing that. The model is picked in OpenBot's picker (`ListsModels`). Detected by its userData folder, `OpenBot.app` (`app.openbot.desktop`), or `OpenBot.exe` under `%LOCALAPPDATA%\Programs` or `%ProgramFiles%`. Its MCP servers live in its SQLite database, which magpie doesn't write: magpie's `/mcp/magpie/…` servers are added there by hand as HTTP servers.
|
||||
- Antigravity, Google's desktop app (not Antigravity IDE, `com.google.antigravity-ide`), takes a gateway from `~/.antigravity/settings.json` from 2.15 on: Google's Antigravity Enterprise Gateway (docs.cloud.google.com/gemini/enterprise/docs/ai-developer-tools/connect-enterprise-gateway; `antigravity` in [`antigravity.go`](../../internal/agent/antigravity.go), ryougi_hachi on X). magpie writes `gateway` as `{enabled: true, url: <gateway>, apiKey: <key naming Antigravity>, wireProtocol: openai}` and the model it starts on as `models.defaultModelId`, and takes out `models.list`, which would narrow the picker to the user's own. On the openai protocol the app's backend (2.28.2) asks `<url>/v1/models` for its picker, labelled by id (`NoNames`, `ListsModels`), and streams `<url>/v1/chat/completions` with the key as a bearer token and a User-Agent of `antigravity/hub/<version>`. The user's gateway, default model and list are stashed and put back on disconnect, or when a model of their own is picked; `caCertPath` and the rest of the file are never touched, and a `Sync` keeps what the user added to magpie's block (`customHeaders`). On a gateway the app uses no Google sign-in. An organisation's `admin_settings.json` and the `AGY_LLM_GATEWAY_*` variables win over the file, so `Check` says when either sets a gateway. agy reads the same file below its own settings: an agy connected on its own row keeps its route, one that isn't follows the app's gateway, as the notice says. `~/.antigravity` is Antigravity IDE's and agy's too, so the app is found by its bundle at 2.15 or later (`desktopApps`) or `~/.gemini/antigravity/agyhub_summaries_proto.pb`, which only its backend writes. The app reads the file at start, so the notice asks for a restart. The Antigravity accounts magpie signs in (provider `antigravity`) are a separate thing: those send magpie's requests to Google.
|
||||
- NewMax (newmax.cc, an Electron app on the Claude Agent SDK) keeps its settings as JSON in the row `app` of the `settings` table of `newmax.db`, a SQLite database in WAL mode in `$NEWMAX_USER_DATA_DIR`, else `~/.newmax` on every system (`newMax` in [`newmax.go`](../../internal/agent/newmax.go); its main bundle's `configureAppDataPaths`, `loadPersistedAppSettings` and the renderer's `mergeProviders`, v1.1.22). magpie adds one entry to `providers` in the shape NewMax's own import writes, `id: magpie-gateway` (its own preset is `magpie`, its import's ids hold `%3A`), `apiFormat: anthropic` at the gateway's root (NewMax appends `/v1/messages`) with `ANTHROPIC_AUTH_TOKEN` and a key naming NewMax, at most 20 models (`MAX_MODELS`) as `models` and `enabledModels` with their context windows, and its id at the end of `providerOrder`. The row is edited in place in one immediate transaction, so every other byte stays; the user's `name` and `enabled` for magpie's entry and the fields NewMax adds to it stay through a sync, and a sync with nothing to change doesn't write. A row that isn't a JSON object, or whose `providers` or `providerOrder` isn't a list, is left alone. With no row (NewMax at its defaults), magpie writes one with its entry alone, as NewMax lays its defaults and presets under the row; with no database yet, it asks to open NewMax once. Disconnect takes the entry and the id out, sets a pick of it back to `default`, and takes the row out when only what magpie made is left. NewMax holds its settings in memory and writes the whole row back whenever one changes, so a change is refused while `NewMax` (`newmax` on Linux) runs (Windows can't be asked, so the notice says to quit it first). The model is picked in NewMax's model picker, so the field is whether magpie is in it (`ListsModels`). Detected by its data folder or `NewMax.app` (`cc.newmax.desktop`).
|
||||
- DevEco Code (Huawei's OpenCode fork, #1885) is wired as OpenCode is (`deveco` in [`agents.go`](../../internal/agent/agents.go)): magpie's provider goes into the first of `deveco.jsonc`, `deveco.json` and `config.json` in `~/.config/deveco` (the one DevEco merges last, so the one that wins), or in `$DEVECO_CONFIG_DIR` when that is absolute, read after them. 0.2.3 sends `deveco/0.2.3 ai-sdk/…` to a provider of its config, but much of the OpenCode code it keeps still sends OpenCode's own User-Agent (`opencode/<version>`), so its provider's key is `magpie-deveco` (`openCodeKeyAt`), not the plain `magpie` OpenCode and MiMo Code send, and Check asks for that key. Its npm package has no Linux binary, so no install command is offered there (`cliSpec.only`).
|
||||
@@ -187,6 +188,7 @@ go test -tags nogui ./internal/agent -run '^TestOpenClaw'
|
||||
go test -tags nogui ./internal/agent -run '^TestRaycast'
|
||||
go test -tags nogui ./internal/agent -run '^TestKiroCrew'
|
||||
go test -tags nogui ./internal/agent -run '^TestOpenPencil'
|
||||
go test -tags nogui ./internal/agent -run '^TestOpenBot'
|
||||
go test -tags nogui ./internal/agent -run '^TestAntigravity'
|
||||
go test -tags nogui ./internal/agent -run '^TestNewMax'
|
||||
go test -tags nogui ./internal/agent -run '^TestGrokApp'
|
||||
|
||||
@@ -274,6 +274,7 @@ func onMachine(home, cfg string) []*Agent {
|
||||
codebuddy(home),
|
||||
pencil(home),
|
||||
openPencil(home, cfg),
|
||||
openBot(home, cfg),
|
||||
newMax(home),
|
||||
raycast(home),
|
||||
kiroCrew(home),
|
||||
|
||||
@@ -61,7 +61,7 @@ func TestEveryPickerOfMagpiesModelsCanBeNarrowed(t *testing.T) {
|
||||
if len(bare) > 0 {
|
||||
t.Errorf("magpie's models are put in these agents' pickers with no way to pick which: %v", bare)
|
||||
}
|
||||
for _, id := range []string{"zcode", "pencil", "openpencil", "newmax", "t3code", "workbuddy", "workbuddy-ai", copilotJBID, CursorLocalID} {
|
||||
for _, id := range []string{"zcode", "pencil", "openpencil", "openbot", "newmax", "t3code", "workbuddy", "workbuddy-ai", copilotJBID, CursorLocalID} {
|
||||
if !slices.Contains(menus, id) {
|
||||
t.Errorf("%s's row has no model list to pick in (ListsModels): %v", id, menus)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,311 @@
|
||||
package agent
|
||||
|
||||
// OpenBot (nightly-labs/openbot, openbot.run; jiezhengj on Discord) is an
|
||||
// Electron workspace that runs Codex, Claude, OpenCode and other agents,
|
||||
// and lists the user's own OpenAI-compatible endpoints in its model picker.
|
||||
// It keeps them in openbot-custom-providers-v1.json in Electron's userData
|
||||
// folder, app data joined with its product name: ~/Library/Application
|
||||
// Support/OpenBot on a Mac, %APPDATA%\OpenBot on Windows, ~/.config/OpenBot
|
||||
// on Linux (src/main/index.ts, application-services.ts; v0.58.0). The file
|
||||
// (custom-provider-store.ts, its zod fileSchema):
|
||||
//
|
||||
// {"version":1,"providers":[{"id":"magpie","name":"magpie",
|
||||
// "baseUrl":"http://127.0.0.1:3425/v1",
|
||||
// "models":[{"id":"<model>","name":"<name>","contextWindow":<n>},…],
|
||||
// "secret":null}]}
|
||||
//
|
||||
// version must be 1: a file OpenBot can't parse leaves it with no endpoints
|
||||
// and refuses every save, so magpie leaves alone a file it can't read the
|
||||
// same way. An entry's key and headers are one ciphertext, secret, sealed
|
||||
// with Electron's safeStorage (the Keychain, DPAPI), which magpie doesn't
|
||||
// open, so magpie's entry has none: OpenBot hands it to OpenCode keyless
|
||||
// (opencode-config.ts, providerEntry), and the gateway takes a request with
|
||||
// no key from this computer. OpenCode sends it, so its requests count as
|
||||
// OpenCode's. A secret the user gave magpie's entry in OpenBot stays.
|
||||
//
|
||||
// OpenBot's list decoders fail closed: one entry or model it wouldn't accept
|
||||
// empties the whole list. So the models are the ones picked for it, at most
|
||||
// 64 (CUSTOM_PROVIDER_LIMITS.models), each with an id OpenBot takes as
|
||||
// magpie/<id> (isAgentModel: ASCII letters, digits and ._:/[],=-, at most
|
||||
// 160), and a context window only inside its 1,024 to 100,000,000.
|
||||
//
|
||||
// OpenBot reads the file once, when it starts, and writes it whole from
|
||||
// what it holds only when an endpoint is saved, edited or removed there.
|
||||
// So a change shows after a restart, and an endpoint saved in OpenBot
|
||||
// before that writes magpie's entry out again: the notice says both. The
|
||||
// model is picked in OpenBot's own picker, so what magpie sets is whether
|
||||
// its models are in it. The user's other entries stay as written, and so
|
||||
// do the name and harness they give magpie's.
|
||||
//
|
||||
// MCP servers live in OpenBot's SQLite database (McpServerStore), which
|
||||
// magpie doesn't write; magpie's own (/mcp/magpie/…) are added there by
|
||||
// hand as HTTP servers.
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
)
|
||||
|
||||
// openBotFile is the file of OpenBot's custom endpoints in its userData.
|
||||
const openBotFile = "openbot-custom-providers-v1.json"
|
||||
|
||||
// openBotApp is OpenBot's macOS bundle (electron-builder.yml: appId
|
||||
// app.openbot.desktop, productName OpenBot).
|
||||
var openBotApp = desktopApp{id: "app.openbot.desktop", names: []string{"OpenBot.app"}}
|
||||
|
||||
// openBotMaxModels is how many models OpenBot takes for one endpoint
|
||||
// (CUSTOM_PROVIDER_LIMITS.models); a list longer than that hides them all.
|
||||
const openBotMaxModels = 64
|
||||
|
||||
// openBotModelID is a model id OpenBot lists as magpie/<id>
|
||||
// (isAgentModel, ipc-agent-identity.ts).
|
||||
var openBotModelID = regexp.MustCompile(`^[A-Za-z0-9._:/\[\],=-]+$`)
|
||||
|
||||
// openBotProc is OpenBot's process: the .app's and the .exe's OpenBot, the
|
||||
// AppImage's openbot.
|
||||
var openBotProc = []string{`(^|/)(OpenBot|openbot)( |$)`}
|
||||
|
||||
var noticeOpenBot = newNotice("OpenBot reads its custom endpoints at start-up — restart OpenBot to see magpie's models in its model picker, before adding or editing an endpoint there.")
|
||||
|
||||
func openBot(home, cfg string) *Agent {
|
||||
dir := openBotDir(home, cfg)
|
||||
path := filepath.Join(dir, openBotFile)
|
||||
write := func(on bool) error {
|
||||
if !on {
|
||||
return openBotUnwire(path)
|
||||
}
|
||||
return openBotWire(path, openBotEntry(gateway.URL()))
|
||||
}
|
||||
return atomic(&Agent{
|
||||
ID: "openbot", Name: "OpenBot", Icon: "generic", Aliases: []string{"open-bot"},
|
||||
Dir: dir, Path: path,
|
||||
// its userData folder once it has run, else its app
|
||||
detect: func() bool {
|
||||
return isDir(dir) || macBundle(openBotApp) || openBotWindowsApp()
|
||||
},
|
||||
Notice: func() string {
|
||||
if openBotWired(path) && Running(openBotProc...) {
|
||||
return noticeOpenBot.String()
|
||||
}
|
||||
return ""
|
||||
},
|
||||
Sync: func() error {
|
||||
if !openBotWired(path) {
|
||||
return nil
|
||||
}
|
||||
return write(true)
|
||||
},
|
||||
// its picker lists the models picked for it (#1508)
|
||||
ListsModels: true,
|
||||
Fields: []Field{{
|
||||
Key: "provider", Label: "provider",
|
||||
Get: func() string {
|
||||
if openBotWired(path) {
|
||||
return magpieID
|
||||
}
|
||||
return ""
|
||||
},
|
||||
Set: func(v string) error { return write(v != "") },
|
||||
Options: func(map[string]string) []Option {
|
||||
return []Option{{Value: magpieID, Label: "magpie", Icon: "magpie", Note: "every magpie model in OpenBot's model picker"}}
|
||||
},
|
||||
}},
|
||||
}, path)
|
||||
}
|
||||
|
||||
// openBotDir is OpenBot's userData folder, as Electron finds it.
|
||||
func openBotDir(home, cfg string) string {
|
||||
return openBotDirOn(runtime.GOOS, home, cfg, appdir.Getenv("APPDATA"))
|
||||
}
|
||||
|
||||
// openBotDirOn is openBotDir on the system goos, with the XDG_CONFIG_HOME
|
||||
// folder cfg and %APPDATA% appData.
|
||||
func openBotDirOn(goos, home, cfg, appData string) string {
|
||||
switch goos {
|
||||
case "darwin":
|
||||
return filepath.Join(home, "Library", "Application Support", "OpenBot")
|
||||
case "windows":
|
||||
d := appData
|
||||
if d == "" {
|
||||
d = filepath.Join(home, "AppData", "Roaming")
|
||||
}
|
||||
return filepath.Join(d, "OpenBot")
|
||||
}
|
||||
return filepath.Join(cfg, "OpenBot")
|
||||
}
|
||||
|
||||
// openBotWindowsApp says OpenBot's installer has put it where it installs
|
||||
// it for one user, %LOCALAPPDATA%\Programs\<its name>, or for all of them.
|
||||
func openBotWindowsApp() bool {
|
||||
if runtime.GOOS != "windows" {
|
||||
return false
|
||||
}
|
||||
var dirs []string
|
||||
if d := appdir.Getenv("LOCALAPPDATA"); d != "" {
|
||||
dirs = append(dirs, filepath.Join(d, "Programs"))
|
||||
}
|
||||
for _, v := range []string{"ProgramW6432", "ProgramFiles"} {
|
||||
if d := appdir.Getenv(v); d != "" {
|
||||
dirs = append(dirs, d)
|
||||
}
|
||||
}
|
||||
for _, d := range dirs {
|
||||
for _, name := range []string{"OpenBot", "openbot"} {
|
||||
if isFile(filepath.Join(d, name, "OpenBot.exe")) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// openBotModel is a model of an entry, as OpenBot writes one.
|
||||
type openBotModel struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
ContextWindow int `json:"contextWindow,omitempty"`
|
||||
}
|
||||
|
||||
// openBotProvider is an entry of providers in the order OpenBot writes one.
|
||||
type openBotProvider struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
BaseURL string `json:"baseUrl"`
|
||||
Models []openBotModel `json:"models"`
|
||||
Secret json.RawMessage `json:"secret"`
|
||||
Harness string `json:"harness,omitempty"`
|
||||
}
|
||||
|
||||
// openBotEntry is magpie's entry for a gateway at gw: its Chat Completions,
|
||||
// no key, and the models picked for it that OpenBot would list, at most 64.
|
||||
func openBotEntry(gw string) openBotProvider {
|
||||
ms := []openBotModel{}
|
||||
seen := map[string]bool{}
|
||||
for _, m := range sharedModels("openbot") {
|
||||
if m.ID == "" || seen[m.ID] || len(m.ID) > 128 || len(magpieID)+1+len(m.ID) > 160 || !openBotModelID.MatchString(m.ID) {
|
||||
continue
|
||||
}
|
||||
seen[m.ID] = true
|
||||
name := m.Name
|
||||
if name == "" || len([]rune(name)) > 160 {
|
||||
name = m.ID
|
||||
}
|
||||
e := openBotModel{ID: m.ID, Name: name}
|
||||
if m.Context >= 1024 && m.Context <= 100_000_000 {
|
||||
e.ContextWindow = m.Context
|
||||
}
|
||||
ms = append(ms, e)
|
||||
if len(ms) == openBotMaxModels {
|
||||
break
|
||||
}
|
||||
}
|
||||
return openBotProvider{ID: magpieID, Name: "magpie", BaseURL: gw + "/v1", Models: ms, Secret: json.RawMessage("null")}
|
||||
}
|
||||
|
||||
// openBotWired says the file has magpie's entry.
|
||||
func openBotWired(path string) bool {
|
||||
_, i, _ := openBotProviders(path)
|
||||
return i >= 0
|
||||
}
|
||||
|
||||
// openBotProviders are the entries of the file's providers as written, and
|
||||
// the place of magpie's among them (-1 for none). A file that isn't there or
|
||||
// holds nothing has none; one OpenBot wouldn't read is an error, so magpie
|
||||
// leaves it alone.
|
||||
func openBotProviders(path string) (list []json.RawMessage, i int, err error) {
|
||||
i = -1
|
||||
b, err := edit.Read(path)
|
||||
if err != nil {
|
||||
return nil, i, err
|
||||
}
|
||||
if len(bytes.TrimSpace(b)) == 0 {
|
||||
return nil, i, nil
|
||||
}
|
||||
if !json.Valid(b) || !gjson.ParseBytes(b).IsObject() {
|
||||
return nil, i, fmt.Errorf("%s isn't JSON OpenBot reads", path)
|
||||
}
|
||||
if v := gjson.GetBytes(b, "version"); v.Type != gjson.Number || v.Raw != "1" {
|
||||
return nil, i, fmt.Errorf("%s says version %s, not the 1 OpenBot reads, so magpie leaves it alone", path, v.Raw)
|
||||
}
|
||||
raw := gjson.GetBytes(b, "providers")
|
||||
if !raw.IsArray() || json.Unmarshal([]byte(raw.Raw), &list) != nil {
|
||||
return nil, i, fmt.Errorf("%s: providers is not a list", path)
|
||||
}
|
||||
for j, e := range list {
|
||||
if gjson.GetBytes(e, "id").String() == magpieID {
|
||||
return list, j, nil
|
||||
}
|
||||
}
|
||||
return list, i, nil
|
||||
}
|
||||
|
||||
// openBotWire puts magpie's entry into the file, made when there is none;
|
||||
// an entry there already keeps the name, harness and secret the user gave
|
||||
// it in OpenBot. The file is written only when the entry says something
|
||||
// else.
|
||||
func openBotWire(path string, want openBotProvider) error {
|
||||
list, i, err := openBotProviders(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if i >= 0 {
|
||||
if n := gjson.GetBytes(list[i], "name"); n.Type == gjson.String && n.String() != "" {
|
||||
want.Name = n.String()
|
||||
}
|
||||
if h := gjson.GetBytes(list[i], "harness"); h.Type == gjson.String {
|
||||
want.Harness = h.String()
|
||||
}
|
||||
if s := gjson.GetBytes(list[i], "secret"); s.Type == gjson.String {
|
||||
want.Secret = json.RawMessage(s.Raw)
|
||||
}
|
||||
}
|
||||
w, err := json.Marshal(want)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if i >= 0 && sameJSON(string(list[i]), want) {
|
||||
return nil
|
||||
}
|
||||
if i >= 0 {
|
||||
list[i] = w
|
||||
} else {
|
||||
list = append(list, w)
|
||||
}
|
||||
if _, has := edit.GetJSON(path, "version"); !has {
|
||||
return edit.SetJSON(path, edit.KV{Path: "version", Value: 1}, edit.KV{Path: "providers", Value: list})
|
||||
}
|
||||
return edit.SetJSON(path, edit.KV{Path: "providers", Value: list})
|
||||
}
|
||||
|
||||
// openBotUnwire takes magpie's entry out of the file, and the file when
|
||||
// nothing else is left in it: the version and an empty list are what OpenBot
|
||||
// starts without a file on too.
|
||||
func openBotUnwire(path string) error {
|
||||
list, i, err := openBotProviders(path)
|
||||
if err != nil || i < 0 {
|
||||
return err
|
||||
}
|
||||
list = append(list[:i], list[i+1:]...)
|
||||
if len(list) == 0 {
|
||||
var rest map[string]json.RawMessage
|
||||
if b, err := edit.Read(path); err == nil && json.Unmarshal(b, &rest) == nil {
|
||||
delete(rest, "version")
|
||||
delete(rest, "providers")
|
||||
if len(rest) == 0 {
|
||||
return os.Remove(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
return edit.SetJSON(path, edit.KV{Path: "providers", Value: list})
|
||||
}
|
||||
@@ -0,0 +1,363 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
// openBotUser is openbot-custom-providers-v1.json as OpenBot saves it
|
||||
// (CustomProviderStore, v0.58.0): an LM Studio endpoint with no key, and
|
||||
// one with a key sealed in secret that runs on Pi.
|
||||
const openBotUser = `{
|
||||
"version": 1,
|
||||
"providers": [
|
||||
{
|
||||
"id": "lm-studio",
|
||||
"name": "LM Studio",
|
||||
"baseUrl": "http://127.0.0.1:1234/v1",
|
||||
"models": [{"id": "qwen3-coder-30b", "name": "Qwen3 Coder 30B", "contextWindow": 262144}],
|
||||
"secret": null
|
||||
},
|
||||
{
|
||||
"id": "work",
|
||||
"name": "Work proxy",
|
||||
"baseUrl": "https://llm.example.com/v1",
|
||||
"models": [{"id": "gpt-5", "name": "gpt-5"}],
|
||||
"secret": "djEwAAAAsealedbyelectronsafestorage==",
|
||||
"harness": "pi"
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
|
||||
// openBotEntryDoc is a providers entry with OpenBot's fields alone
|
||||
// (entrySchema), so a field of magpie's own fails to decode.
|
||||
type openBotEntryDoc struct {
|
||||
ID *string `json:"id"`
|
||||
Name *string `json:"name"`
|
||||
BaseURL *string `json:"baseUrl"`
|
||||
Models *[]struct {
|
||||
ID *string `json:"id"`
|
||||
Name *string `json:"name"`
|
||||
ContextWindow *int `json:"contextWindow"`
|
||||
} `json:"models"`
|
||||
Secret *string `json:"secret"`
|
||||
Harness *string `json:"harness"`
|
||||
}
|
||||
|
||||
// openBotAgentModel is isAgentModel (ipc-agent-identity.ts): what a
|
||||
// composed provider/model id must be, or OpenBot drops the whole list.
|
||||
var openBotAgentModel = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._:/\[\],=-]*$`)
|
||||
|
||||
// openBotRead is the file's magpie entry, checked as OpenBot reads one
|
||||
// (fileSchema, then isCustomProviderSummary, which fails closed on the
|
||||
// whole list): version 1, the required fields there and nothing else, at
|
||||
// most 64 models with ids and names it takes and windows in its range;
|
||||
// and the user's entries, as written.
|
||||
func openBotRead(t *testing.T, path string) (magpie openBotEntryDoc, others []json.RawMessage) {
|
||||
t.Helper()
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var doc struct {
|
||||
Version *int `json:"version"`
|
||||
Providers []json.RawMessage `json:"providers"`
|
||||
}
|
||||
if err := json.Unmarshal(b, &doc); err != nil || doc.Version == nil || *doc.Version != 1 || doc.Providers == nil {
|
||||
t.Fatalf("not a file OpenBot reads (version 1 and providers required): %v\n%s", err, b)
|
||||
}
|
||||
found := false
|
||||
for _, raw := range doc.Providers {
|
||||
var e openBotEntryDoc
|
||||
d := json.NewDecoder(bytes.NewReader(raw))
|
||||
d.DisallowUnknownFields()
|
||||
if err := d.Decode(&e); err != nil {
|
||||
t.Fatalf("not OpenBot's entry: %v\n%s", err, raw)
|
||||
}
|
||||
if e.ID == nil || e.Name == nil || e.BaseURL == nil || e.Models == nil {
|
||||
t.Fatalf("entry without a required field: %s", raw)
|
||||
}
|
||||
if *e.ID != magpieID {
|
||||
others = append(others, raw)
|
||||
continue
|
||||
}
|
||||
if found {
|
||||
t.Fatalf("two entries of magpie's: %s", b)
|
||||
}
|
||||
found, magpie = true, e
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("no entry of magpie's: %s", b)
|
||||
}
|
||||
if len(*magpie.Name) > 80 {
|
||||
t.Errorf("name %q", *magpie.Name)
|
||||
}
|
||||
if n := len(*magpie.Models); n > 64 {
|
||||
t.Errorf("%d models, OpenBot takes 64", n)
|
||||
}
|
||||
for _, m := range *magpie.Models {
|
||||
if m.ID == nil || m.Name == nil {
|
||||
t.Fatalf("model without id or name: %s", b)
|
||||
}
|
||||
if id := magpieID + "/" + *m.ID; len(*m.ID) > 128 || len(id) > 160 || !openBotAgentModel.MatchString(id) {
|
||||
t.Errorf("model id %q OpenBot refuses", *m.ID)
|
||||
}
|
||||
if len([]rune(*m.Name)) > 160 {
|
||||
t.Errorf("model name %q", *m.Name)
|
||||
}
|
||||
if w := m.ContextWindow; w != nil && (*w < 1024 || *w > 100_000_000) {
|
||||
t.Errorf("%s: window %d", *m.ID, *w)
|
||||
}
|
||||
}
|
||||
return magpie, others
|
||||
}
|
||||
|
||||
// OpenBot (nightly-labs/openbot) lists the user's own endpoints in its
|
||||
// model picker, from openbot-custom-providers-v1.json in its userData
|
||||
// folder. magpie adds itself as the endpoint "magpie" on the gateway's
|
||||
// Chat Completions, keyless, keeps the user's entries as they were and the
|
||||
// name, harness and key they give its entry, writes nothing when nothing
|
||||
// changed, and off takes only its own entry out.
|
||||
func TestOpenBotProvider(t *testing.T) {
|
||||
home := syncHome(t)
|
||||
cfg := filepath.Join(home, ".config")
|
||||
if err := provider.Save(provider.Provider{ID: "deepseek", Name: "DeepSeek", Chat: "https://api.deepseek.com/v1", Key: "k", Models: []string{"pro", "flash"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a := openBot(home, cfg)
|
||||
if !slices.ContainsFunc(All(), func(x *Agent) bool { return x.ID == "openbot" && x.Name == "OpenBot" }) {
|
||||
t.Fatal("OpenBot is not among the agents")
|
||||
}
|
||||
if a.Detected() {
|
||||
t.Fatal("found with nothing of it here")
|
||||
}
|
||||
os.MkdirAll(a.Dir, 0o755)
|
||||
if !a.Detected() {
|
||||
t.Fatal("not found with its userData folder")
|
||||
}
|
||||
path := a.Path
|
||||
if filepath.Base(path) != "openbot-custom-providers-v1.json" || filepath.Dir(path) != a.Dir {
|
||||
t.Fatalf("path %s", path)
|
||||
}
|
||||
os.WriteFile(path, []byte(openBotUser), 0o600)
|
||||
f := a.Field("provider")
|
||||
if f.Get() != "" {
|
||||
t.Fatalf("get: %q", f.Get())
|
||||
}
|
||||
if err := f.Set(magpieID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if f.Get() != magpieID {
|
||||
t.Fatalf("get after set: %q", f.Get())
|
||||
}
|
||||
// the restart it needs, said while it runs
|
||||
running := Running
|
||||
t.Cleanup(func() { Running = running })
|
||||
Running = func(...string) bool { return true }
|
||||
if a.Notice() != noticeOpenBot.String() {
|
||||
t.Errorf("notice while it runs: %q", a.Notice())
|
||||
}
|
||||
Running = func(...string) bool { return false }
|
||||
if a.Notice() != "" {
|
||||
t.Errorf("notice while it doesn't: %q", a.Notice())
|
||||
}
|
||||
|
||||
gw := gateway.URL()
|
||||
e, others := openBotRead(t, path)
|
||||
if *e.BaseURL != gw+"/v1" || *e.Name != "magpie" || e.Secret != nil || e.Harness != nil {
|
||||
t.Errorf("entry: base %q name %q secret %v harness %v", *e.BaseURL, *e.Name, e.Secret, e.Harness)
|
||||
}
|
||||
var got, want []string
|
||||
for _, m := range *e.Models {
|
||||
got = append(got, *m.ID)
|
||||
}
|
||||
for _, m := range magpieModels("openbot") {
|
||||
want = append(want, m.ID)
|
||||
}
|
||||
if len(want) < 2 || !slices.Equal(got, want) {
|
||||
t.Errorf("models %v, want %v", got, want)
|
||||
}
|
||||
var user struct {
|
||||
Providers []json.RawMessage `json:"providers"`
|
||||
}
|
||||
json.Unmarshal([]byte(openBotUser), &user)
|
||||
if len(others) != 2 || !sameJSON(string(others[0]), user.Providers[0]) || !sameJSON(string(others[1]), user.Providers[1]) {
|
||||
t.Errorf("the user's entries: %s", others)
|
||||
}
|
||||
|
||||
// nothing changed: nothing written
|
||||
b, _ := os.ReadFile(path)
|
||||
st, _ := os.Stat(path)
|
||||
if err := a.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := f.Set(magpieID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if b2, _ := os.ReadFile(path); !bytes.Equal(b, b2) {
|
||||
t.Errorf("rewritten with nothing changed:\n%s\n%s", b, b2)
|
||||
}
|
||||
if st2, _ := os.Stat(path); !st2.ModTime().Equal(st.ModTime()) {
|
||||
t.Error("written with nothing changed")
|
||||
}
|
||||
|
||||
// renamed, given a key and put on Pi in OpenBot, and a model gone: a
|
||||
// sync keeps the three and puts the model back
|
||||
var doc map[string]any
|
||||
json.Unmarshal(b, &doc)
|
||||
for _, x := range doc["providers"].([]any) {
|
||||
if m := x.(map[string]any); m["id"] == magpieID {
|
||||
m["name"], m["secret"], m["harness"] = "My magpie", "c2VhbGVk", "pi"
|
||||
m["models"] = m["models"].([]any)[:1]
|
||||
}
|
||||
}
|
||||
edited, _ := json.MarshalIndent(doc, "", " ")
|
||||
os.WriteFile(path, edited, 0o600)
|
||||
if err := a.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
e, _ = openBotRead(t, path)
|
||||
if *e.Name != "My magpie" || e.Secret == nil || *e.Secret != "c2VhbGVk" || e.Harness == nil || *e.Harness != "pi" {
|
||||
t.Errorf("the user's name, key and harness not kept: %+v", e)
|
||||
}
|
||||
if len(*e.Models) != len(want) {
|
||||
t.Errorf("models after sync: %d, want %d", len(*e.Models), len(want))
|
||||
}
|
||||
|
||||
// off: only magpie's entry goes, the file stays
|
||||
if err := f.Set(""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if f.Get() != "" {
|
||||
t.Fatalf("get after off: %q", f.Get())
|
||||
}
|
||||
b, _ = os.ReadFile(path)
|
||||
var after struct {
|
||||
Version int `json:"version"`
|
||||
Providers []json.RawMessage `json:"providers"`
|
||||
}
|
||||
json.Unmarshal(b, &after)
|
||||
if after.Version != 1 || len(after.Providers) != 2 || !sameJSON(string(after.Providers[0]), user.Providers[0]) || !sameJSON(string(after.Providers[1]), user.Providers[1]) {
|
||||
t.Errorf("after off: %s", b)
|
||||
}
|
||||
// a sync of an entry that isn't there writes none
|
||||
if err := a.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if b2, _ := os.ReadFile(path); !bytes.Equal(b, b2) {
|
||||
t.Errorf("a sync off wrote:\n%s", b2)
|
||||
}
|
||||
}
|
||||
|
||||
// OpenBot not run yet: magpie makes the file with the version 1 OpenBot
|
||||
// needs, and off takes the file away again.
|
||||
func TestOpenBotMakesItsFile(t *testing.T) {
|
||||
home := syncHome(t)
|
||||
a := openBot(home, filepath.Join(home, ".config"))
|
||||
if err := a.Field("provider").Set(magpieID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, others := openBotRead(t, a.Path)
|
||||
if len(others) != 0 {
|
||||
t.Errorf("others: %s", others)
|
||||
}
|
||||
b, _ := os.ReadFile(a.Path)
|
||||
var top map[string]json.RawMessage
|
||||
json.Unmarshal(b, &top)
|
||||
if len(top) != 2 || string(top["version"]) != "1" {
|
||||
t.Errorf("made: %s", b)
|
||||
}
|
||||
if err := a.Field("provider").Set(""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := os.Stat(a.Path); !os.IsNotExist(err) {
|
||||
t.Errorf("magpie's own file left behind: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// A file OpenBot can't read leaves it with no endpoints and every save
|
||||
// refused, so it may be a newer OpenBot's: magpie leaves it as it is.
|
||||
func TestOpenBotLeavesAlone(t *testing.T) {
|
||||
home := syncHome(t)
|
||||
a := openBot(home, filepath.Join(home, ".config"))
|
||||
os.MkdirAll(a.Dir, 0o755)
|
||||
for _, s := range []string{
|
||||
`{"version": 2, "providers": []}`,
|
||||
`{"providers": []}`,
|
||||
`{"version": "1", "providers": []}`,
|
||||
`{"version": 1}`,
|
||||
`{"version": 1, "providers": {}}`,
|
||||
`[]`,
|
||||
`{"version": 1,`,
|
||||
} {
|
||||
os.WriteFile(a.Path, []byte(s), 0o600)
|
||||
if err := a.Field("provider").Set(magpieID); err == nil {
|
||||
t.Errorf("%s: set", s)
|
||||
}
|
||||
if b, _ := os.ReadFile(a.Path); string(b) != s {
|
||||
t.Errorf("%s: written: %s", s, b)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// OpenBot drops every model of an endpoint when one would not do: more than
|
||||
// 64, an id it won't compose as magpie/<id>, a window out of its range. So
|
||||
// magpie writes the first 64 it takes, and a window only inside the range.
|
||||
func TestOpenBotModelsItTakes(t *testing.T) {
|
||||
syncHome(t)
|
||||
ms := []string{"has space", "ünï"}
|
||||
for i := range 70 {
|
||||
ms = append(ms, fmt.Sprintf("m%02d", i))
|
||||
}
|
||||
if err := provider.Save(provider.Provider{ID: "many", Name: "Many", Chat: "https://api.example/v1", Key: "k", Models: ms}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
all := magpieModels("openbot")
|
||||
if len(all) <= openBotMaxModels || !slices.ContainsFunc(all, func(m catalog.Model) bool { return m.ID == "has space" || m.ID == "many/has space" }) {
|
||||
t.Fatalf("fixture: %d models", len(all))
|
||||
}
|
||||
e := openBotEntry(gateway.URL())
|
||||
if len(e.Models) != openBotMaxModels {
|
||||
t.Errorf("%d models", len(e.Models))
|
||||
}
|
||||
for _, m := range e.Models {
|
||||
if !openBotAgentModel.MatchString(magpieID + "/" + m.ID) {
|
||||
t.Errorf("model %q OpenBot refuses", m.ID)
|
||||
}
|
||||
if m.ContextWindow != 0 && (m.ContextWindow < 1024 || m.ContextWindow > 100_000_000) {
|
||||
t.Errorf("%s: window %d", m.ID, m.ContextWindow)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The file is where Electron puts OpenBot's userData on each system: app
|
||||
// data joined with its product name.
|
||||
func TestOpenBotDirPerOS(t *testing.T) {
|
||||
home := filepath.Join("h", "me")
|
||||
cfg := filepath.Join(home, ".cfg")
|
||||
for _, c := range []struct{ goos, appData, want string }{
|
||||
{"darwin", "", filepath.Join(home, "Library", "Application Support", "OpenBot")},
|
||||
{"linux", "", filepath.Join(cfg, "OpenBot")},
|
||||
{"windows", filepath.Join("R", "Roaming"), filepath.Join("R", "Roaming", "OpenBot")},
|
||||
{"windows", "", filepath.Join(home, "AppData", "Roaming", "OpenBot")},
|
||||
} {
|
||||
if got := openBotDirOn(c.goos, home, cfg, c.appData); got != c.want {
|
||||
t.Errorf("%s (APPDATA %q): %s, want %s", c.goos, c.appData, got, c.want)
|
||||
}
|
||||
}
|
||||
if got := openBotDir(home, cfg); got != openBotDirOn(runtime.GOOS, home, cfg, os.Getenv("APPDATA")) {
|
||||
t.Errorf("here: %s", got)
|
||||
}
|
||||
}
|
||||
@@ -4166,6 +4166,7 @@ const I18N = {
|
||||
"Muse Code reads its settings at start-up — restart open muse sessions to use this.": "Muse Code 启动时读取设置,需重启已打开的 muse 会话才会生效。",
|
||||
"New dsh sessions start on this. A session made before keeps its model, open now or reopened later, until you pick another in it with /model or the model button by its message box. A dsh started with -p or in a terminal reads it at start-up.": "新的 dsh 会话会使用这项设置。之前建的会话,无论现在开着还是以后再打开,都保留原来的模型,直到你在其中用 /model 或输入框旁的模型按钮另选一个。用 -p 或在终端里启动的 dsh 在启动时读取它。",
|
||||
"DeepSeek Harness Desktop hasn't been opened yet: it starts on this the first time it opens.": "DeepSeek Harness 桌面版还没打开过:第一次打开时就会使用这项设置。",
|
||||
"OpenBot reads its custom endpoints at start-up — restart OpenBot to see magpie's models in its model picker, before adding or editing an endpoint there.": "OpenBot 启动时读取自定义端点,需重启 OpenBot 才能在它的模型选择器中看到 magpie 的模型;在此之前请不要在 OpenBot 里添加或编辑端点。",
|
||||
"OpenChamber takes the new model for new sessions; sessions already open keep theirs.": "OpenChamber 的新会话会使用新模型;已打开的会话保留原来的模型。",
|
||||
"Kiro Crew takes the new harness for new sessions; sessions already open keep theirs.": "Kiro Crew 的新会话会使用新的 harness;已打开的会话保留原来的。",
|
||||
"Kiro Crew runs on {harness}, so magpie connected {harness} too; turning Kiro Crew off disconnects it again.": "Kiro Crew 运行在 {harness} 上,所以 magpie 也一并接入了 {harness};关闭 Kiro Crew 时会把它一起断开。",
|
||||
@@ -8533,6 +8534,7 @@ const I18N = {
|
||||
"Muse Code reads its settings at start-up — restart open muse sessions to use this.": "Muse Code 啟動時讀取設定,需重啟已打開的 muse 會話才會生效。",
|
||||
"New dsh sessions start on this. A session made before keeps its model, open now or reopened later, until you pick another in it with /model or the model button by its message box. A dsh started with -p or in a terminal reads it at start-up.": "新的 dsh 會話會使用這項設定。之前建立的會話,無論現在開著還是以後再打開,都保留原來的模型,直到你在其中用 /model 或輸入框旁的模型按鈕另選一個。用 -p 或在終端裡啟動的 dsh 在啟動時讀取它。",
|
||||
"DeepSeek Harness Desktop hasn't been opened yet: it starts on this the first time it opens.": "DeepSeek Harness 桌面版還沒開啟過:第一次開啟時就會使用這項設定。",
|
||||
"OpenBot reads its custom endpoints at start-up — restart OpenBot to see magpie's models in its model picker, before adding or editing an endpoint there.": "OpenBot 啟動時讀取自訂端點,需重新啟動 OpenBot 才能在它的模型選擇器中看到 magpie 的模型;在此之前請不要在 OpenBot 裡新增或編輯端點。",
|
||||
"OpenChamber takes the new model for new sessions; sessions already open keep theirs.": "OpenChamber 的新會話會使用新模型;已打開的會話保留原來的模型。",
|
||||
"Kiro Crew takes the new harness for new sessions; sessions already open keep theirs.": "Kiro Crew 的新工作階段會使用新的 harness;已開啟的工作階段保留原本的。",
|
||||
"Kiro Crew runs on {harness}, so magpie connected {harness} too; turning Kiro Crew off disconnects it again.": "Kiro Crew 執行在 {harness} 上,所以 magpie 也一併接入了 {harness};關閉 Kiro Crew 時會把它一起中斷。",
|
||||
@@ -12902,6 +12904,7 @@ const I18N = {
|
||||
"Muse Code reads its settings at start-up — restart open muse sessions to use this.": "Muse Code は起動時に設定を読み込みます。反映するには開いている muse セッションを再起動してください。",
|
||||
"New dsh sessions start on this. A session made before keeps its model, open now or reopened later, until you pick another in it with /model or the model button by its message box. A dsh started with -p or in a terminal reads it at start-up.": "新しい dsh セッションはこれで始まります。以前に作ったセッションは、今開いていても後で開き直しても、その中で /model か入力欄の横のモデルボタンで別のモデルを選ぶまで今のモデルのままです。-p 付きやターミナルで起動した dsh は起動時に読み込みます。",
|
||||
"DeepSeek Harness Desktop hasn't been opened yet: it starts on this the first time it opens.": "DeepSeek Harness デスクトップ版はまだ一度も開かれていません。初めて開いたときからこの設定で始まります。",
|
||||
"OpenBot reads its custom endpoints at start-up — restart OpenBot to see magpie's models in its model picker, before adding or editing an endpoint there.": "OpenBot は起動時にカスタムエンドポイントを読み込みます。モデル選択に magpie のモデルを表示するには OpenBot を再起動してください。それまでは OpenBot でエンドポイントを追加・編集しないでください。",
|
||||
"OpenChamber takes the new model for new sessions; sessions already open keep theirs.": "OpenChamber は新しいセッションで新しいモデルを使います。開いているセッションは今のモデルのままです。",
|
||||
"Kiro Crew takes the new harness for new sessions; sessions already open keep theirs.": "Kiro Crew は新しいセッションから新しいハーネスを使います。開いているセッションは元のままです。",
|
||||
"Kiro Crew runs on {harness}, so magpie connected {harness} too; turning Kiro Crew off disconnects it again.": "Kiro Crew は {harness} 上で動くため、magpie は {harness} も接続しました。Kiro Crew をオフにすると、こちらも切断します。",
|
||||
@@ -17271,6 +17274,7 @@ const I18N = {
|
||||
"Muse Code reads its settings at start-up — restart open muse sessions to use this.": "Muse Code liest seine Einstellungen beim Start – offene muse-Sitzungen neu starten, damit es gilt.",
|
||||
"New dsh sessions start on this. A session made before keeps its model, open now or reopened later, until you pick another in it with /model or the model button by its message box. A dsh started with -p or in a terminal reads it at start-up.": "Neue dsh-Sitzungen starten damit. Eine vorher angelegte Sitzung behält ihr Modell, ob jetzt offen oder später wieder geöffnet, bis Sie darin mit /model oder der Modell-Schaltfläche neben dem Eingabefeld ein anderes wählen. Ein mit -p oder im Terminal gestartetes dsh liest es beim Start.",
|
||||
"DeepSeek Harness Desktop hasn't been opened yet: it starts on this the first time it opens.": "DeepSeek Harness Desktop wurde noch nie geöffnet: Beim ersten Öffnen startet es mit dieser Einstellung.",
|
||||
"OpenBot reads its custom endpoints at start-up — restart OpenBot to see magpie's models in its model picker, before adding or editing an endpoint there.": "OpenBot liest seine eigenen Endpunkte beim Start – OpenBot neu starten, um magpies Modelle in seiner Modellauswahl zu sehen, bevor dort ein Endpunkt hinzugefügt oder bearbeitet wird.",
|
||||
"OpenChamber takes the new model for new sessions; sessions already open keep theirs.": "OpenChamber nimmt das neue Modell für neue Sitzungen; bereits offene behalten ihres.",
|
||||
"Kiro Crew takes the new harness for new sessions; sessions already open keep theirs.": "Kiro Crew nutzt den neuen Harness für neue Sitzungen; bereits offene Sitzungen behalten ihren.",
|
||||
"Kiro Crew runs on {harness}, so magpie connected {harness} too; turning Kiro Crew off disconnects it again.": "Kiro Crew läuft auf {harness}, daher hat magpie {harness} gleich mit verbunden; schaltest du Kiro Crew aus, wird es wieder getrennt.",
|
||||
@@ -17536,6 +17540,7 @@ const NOTICES = [
|
||||
"Muse Code reads its settings at start-up — restart open muse sessions to use this.",
|
||||
"New dsh sessions start on this. A session made before keeps its model, open now or reopened later, until you pick another in it with /model or the model button by its message box. A dsh started with -p or in a terminal reads it at start-up.",
|
||||
"DeepSeek Harness Desktop hasn't been opened yet: it starts on this the first time it opens.",
|
||||
"OpenBot reads its custom endpoints at start-up — restart OpenBot to see magpie's models in its model picker, before adding or editing an endpoint there.",
|
||||
"OpenChamber takes the new model for new sessions; sessions already open keep theirs.",
|
||||
"Kiro Crew takes the new harness for new sessions; sessions already open keep theirs.",
|
||||
"Kiro Crew runs on {harness}, so magpie connected {harness} too; turning Kiro Crew off disconnects it again.",
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
// genericIcon are the clients magpie has no logo for yet, drawn with the
|
||||
// generic cube on purpose (#4487). Each leaves this list when its real
|
||||
// logo, from the app or its vendor, is added.
|
||||
var genericIcon = map[string]bool{"ante": true, "pencil": true, "openpencil": true, "newmax": true, "kirocrew": true, "raft": true}
|
||||
var genericIcon = map[string]bool{"ante": true, "pencil": true, "openpencil": true, "openbot": true, "newmax": true, "kirocrew": true, "raft": true}
|
||||
|
||||
// Every client a request can be recorded as is drawn by its own name and
|
||||
// icon in the Routing page's request list, Usage and Sessions, which all
|
||||
|
||||
Reference in New Issue
Block a user