docs: the management API's routing groups and the app's switch for it (#6307)

docs/reference.md's Management API lists the routing-groups routes
(list, get, create, update and the Routing page's actions), says they are
checked as the app checks them and that found/skip are not served, names
the key menu's Advanced switch beside `magpie gateway-key admin`, and
drops "this first part leaves out Routing Groups": what is left out on
purpose is the export of sign-ins, which would hand out every account's
secrets. docs/subsystems/gateway-routing.md says how the routes reach
/api/groups (adminGroupActions, adminGroupWrite over provider.SaveGroup)
and names the tests. The site's remote page says the same in en, zh and
ja, and public/llms-full.txt is built again from it (node llms-full.mjs,
on mica).

Run: site's worker.test.mjs (llms-full current) in the full run before
the push; no code changes here.

Run for the three #6307 commits (mica, at 4eafd9963 on 90efddaba's
successor, then the touched tests again after rebasing onto 221c91fae):
- gofmt -l: clean. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok. Builds (darwin, linux nogui, windows): ok.
- site worker.test.mjs: 41/41 (llms-full.txt current).
- go test -tags nogui -count=1 -timeout 45m ./...: every package ok but
  two, both red on origin/main and filed: internal/cli
  TestEveryRouteHasACommandOrIsNamed (POST /api/providers/delete, #6677)
  and internal/tui TestEveryWordHasZh ("permission mode", #6686).
- At 221c91fae + these: go test -run 'Admin|Group' ./internal/gui ok;
  gateway-card, gateway-key-admin, gateway-chat-page in both engines
  62/62; i18n-keys, i18n-en-no-cjk 8/8.
This commit is contained in:
yetone
2026-11-15 00:16:11 +08:00
parent 1cfa53b678
commit 3ffac60480
6 changed files with 31 additions and 15 deletions
+13 -5
View File
@@ -1144,14 +1144,22 @@ can't drift:
| `POST signin` `{"agent": …}`, `GET signin/{id}`, `POST signin/{id}/cancel`, `POST signin/{id}/callback` | OAuth sign-in: the answer holds the vendor's page and the code to type there. Nothing is opened on this computer and no password is taken |
| `GET gateway-keys[/models\|/mcp]`, `POST gateway-keys/{action}` | gateway keys: `add-key`, `rename-key`, `rotate-key`, `limit-key`, `models-key`, `accounts-key`, `mcp-key`, `access-key`, `on-key`, `off-key`, `remove-key`, … |
| `GET account-groups`, `POST account-groups/{action}` | named account groups |
| `GET routing-groups`, `GET routing-groups/{id}` | the Routing page's groups and combos, as the app shows them; one by its id or `group/<id>` |
| `POST routing-groups/create`, `POST routing-groups/update` | a group or combo made, or changed: `create` takes the editor's body (`name`, `members`, …) and is 409 for an id in use; `update` takes `id` and only the fields to change, the rest kept (`from` and a new `id` rename it, and the combos naming it follow) |
| `POST routing-groups/{action}` | the Routing page's own: `save`, `delete` (`id` or `ids`; refused while a combo names it), `copy`, `switch`, `arrange`, `pick`, `defaults`, `template`, `share`, `import`, `show` |
Bodies are the app's own JSON. A route or action not listed is a 404. Never
Bodies are the app's own JSON, and each is checked as the app checks it (a
member a provider doesn't serve, an account it doesn't have, a combo of
itself are 400). A member may name one account, `provider/model#<account>`.
A route or action not listed is a 404: Routing's `found` and `skip`, which
set this computer's agents, are not served. Never
served: a provider's saved key, a gateway key's secret after its `add-key` or
`rotate-key` answer, exporting sign-ins, and what changes this computer's
other apps (moving, showing, restarting).
Who may call it: a gateway key set with `magpie gateway-key admin <id>
local|any`. `local` is from this computer only; `any` also from the network
local|any`, or in the app from the key's menu, Advanced (Off, From this
computer, From any computer); such a key says Manages magpie in its row. `local` is from this computer only; `any` also from the network
when sharing is on. Only a key the user made can have it: a read-only,
Magpie Browser, issued or expiring key, and the default sharing key, can't,
and the API can't set the level on any key, so it can't raise its own
@@ -1160,9 +1168,9 @@ caller. A request with no key is 401, a key without the level 403
any request with `Origin` (`null`, a foreign page, a listed page or
`*.localhost` among them) or `Sec-Fetch-*` is 403, and so is one that
reached loopback under another name (a rebound page's GET has neither).
Answers are `Cache-Control: no-store`. This first part leaves out Routing
Groups (the Routing page) and the import and export of sign-ins; they are
tracked in [#6307](https://github.com/yetone/magpie/issues/6307).
Answers are `Cache-Control: no-store`. The import and export of sign-ins
is left out on purpose: it would hand a script every account's secrets
([#6307](https://github.com/yetone/magpie/issues/6307)).
### Embeddings and rerank
+10 -2
View File
@@ -1463,7 +1463,7 @@ told its own calls and limit alone:
| `GET /v1/magpie/concurrency` | requests in flight per account |
| `POST`/`GET /v1/magpie/keys`, `DELETE /v1/magpie/keys/{id}` | short-lived keys, above |
| `POST /v1/magpie/keys/oidc` | an OIDC token traded for a short-lived key, above |
| `/v1/magpie/admin/…` | the management API: the app's provider, account, gateway-key and account-group handlers for a key with `Key.Admin`, below |
| `/v1/magpie/admin/…` | the management API: the app's provider, account, gateway-key, account-group and routing-group handlers for a key with `Key.Admin`, below |
### The management API
@@ -1485,7 +1485,15 @@ key. A key action through the API on another key that has `Admin`
secret, or set one the caller chose, so a `local` key would get an `any`
one or take over a peer's. The caller's own key is its to change. The route is in `readOnlyRefused`, so a read-only key never reaches
it. The handlers are built with no window, so a sign-in opens no browser.
Routing Groups and sign-in export are not in it yet (#6307).
Routing Groups go to `/api/groups` (`adminGroupActions`; `found` and `skip`
are left out, as they set this computer's agents), with
`routing-groups/{id...}` (an id may be `group/<id>`), `create` and `update`
of the API's own in front: `update` reads the stored group, lays the body's
fields over it and hands that to the same `save` (`adminGroupWrite`), so
`provider.SaveGroup` checks every write the page's does
(`TestAdminAPIRoutingGroups`, `TestAdminAPIRoutingGroupsGuarded`). The app
sets `Key.Admin` from a key's menu, Advanced (`gatewayAdminPick`,
`gateway-key-admin.test.cjs`). Sign-in export is left out (#6307).
### Route events for a display
+2 -2
View File
@@ -247,7 +247,7 @@ steps:
<p>キーはルールのゲートウェイキーの下で発行され、他の発行済みキーと同じくそのキーに縛られ、ルールの期間より長くは有効になりません。名前はリポジトリ、ブランチ、実行番号です。別のリポジトリやブランチのトークン、期限切れ、交換済みのトークンには理由付きの <code>401</code> が返ります。他のコンピューターから使えるのは magpie を共有している間だけで、断られたトークンは認証失敗の回数に数えられます。ルールがなければ何も交換されません。</p>
<h2 id="admin"><a class="anchor" href="#admin">管理 API</a></h2>
<p>プロバイダー、アカウント、ゲートウェイキー、アカウントグループは、許可したキーがあれば設定ファイルを手で編集せずに管理できます。許可はコマンドラインで行います(API 経由ではできません。キーは自分以上の権限を別のキーに与えられません)。</p>
<p>プロバイダー、アカウント、ゲートウェイキー、アカウントグループ、ルーティンググループは、許可したキーがあれば設定ファイルを手で編集せずに管理できます。許可はアプリでそのキーのメニュー → 詳細設定から、またはコマンドラインで行います(API 経由ではできません。キーは自分以上の権限を別のキーに与えられません)。</p>
<div class="code">
<span class="lang">Shell</span>
<button class="copy" data-copy="ex-admin">Copy</button>
@@ -258,7 +258,7 @@ curl -s http://127.0.0.1:3425/v1/magpie/admin/providers -H "Authorization: Beare
curl -s -X POST http://127.0.0.1:3425/v1/magpie/admin/gateway-keys/add-key \
-H "Authorization: Bearer $KEY" -d '{"name":"ci"}'</pre>
</div>
<p>アプリ自身のページと同じ処理が <code>/v1/magpie/admin/</code> の下にあります。<code>GET providers</code>、<code>POST provider/{save,delete,on,off,name,…}</code>、<code>POST keys/…</code>(プロバイダーのキー)、<code>GET</code>/<code>POST gateway-keys[/{add-key,rename-key,limit-key,models-key,remove-key,…}]</code>、<code>GET</code>/<code>POST account-groups[/…]</code>、そして <code>POST signin</code>(<code>{"agent":…}</code>)は、ベンダーのページと入力するコードを返し、パスワードは受け取りません。ブラウザーのあるコンピューターで開いてください。保存済みのキーとゲートウェイキーの秘密は再び返されず、このコンピューターのほかのアプリを変更する操作も提供しません。</p>
<p>アプリ自身のページと同じ処理が <code>/v1/magpie/admin/</code> の下にあります。<code>GET providers</code>、<code>POST provider/{save,delete,on,off,name,…}</code>、<code>POST keys/…</code>(プロバイダーのキー)、<code>GET</code>/<code>POST gateway-keys[/{add-key,rename-key,limit-key,models-key,remove-key,…}]</code>、<code>GET</code>/<code>POST account-groups[/…]</code>、<code>GET routing-groups[/{id}]</code> と <code>POST routing-groups/{create,update,delete,switch,…}</code>(ルーティングページのグループと組み合わせ。検証はアプリと同じで、<code>update</code> は送ったフィールドだけを変えます)、そして <code>POST signin</code>(<code>{"agent":…}</code>)は、ベンダーのページと入力するコードを返し、パスワードは受け取りません。ブラウザーのあるコンピューターで開いてください。保存済みのキーとゲートウェイキーの秘密は再び返されず、このコンピューターのほかのアプリを変更する操作も提供しません。サインインはエクスポートしません。すべてのアカウントの秘密を渡すことになるからです。</p>
<p>読み取り専用キー、拡張機能のキー、発行されたキーや短期キー、共有キーは使えません。キーの有無にかかわらず Web ページからは呼べません(<code>Origin</code> や <code>Sec-Fetch-*</code> を持つリクエストはすべて拒否)。このコンピューターの別名で届いたリクエストも拒否されます。ネットワーク越しに共有している場合、<code>any</code> のキーだけが通ります。</p>
<h2 id="api"><a class="anchor" href="#api">統計 API</a></h2>
+2 -2
View File
@@ -247,7 +247,7 @@ steps:
<p>The key is issued under the rule’s gateway key and held to it like any other issued key, lives no longer than the rule says, and is named after the repository, branch and run. A token from another repository or branch, an expired one, or one already traded gets <code>401</code> and why. The route answers another computer only while magpie is shared, and refused tokens count against the failed sign-ins it allows. Without a rule nothing is traded.</p>
<h2 id="admin"><a class="anchor" href="#admin">Management API</a></h2>
<p>Providers, accounts, gateway keys and account groups can be managed with no hand-edited file, by a key you allow to. Allow it from the command line (not through the API: a key can't give another more than it has):</p>
<p>Providers, accounts, gateway keys, account groups and routing groups can be managed with no hand-edited file, by a key you allow to. Allow it from the key’s menu in the app, under Advanced, or from the command line (not through the API: a key can't give another more than it has):</p>
<div class="code">
<span class="lang">Shell</span>
<button class="copy" data-copy="ex-admin">Copy</button>
@@ -258,7 +258,7 @@ curl -s http://127.0.0.1:3425/v1/magpie/admin/providers -H "Authorization: Beare
curl -s -X POST http://127.0.0.1:3425/v1/magpie/admin/gateway-keys/add-key \
-H "Authorization: Bearer $KEY" -d '{"name":"ci"}'</pre>
</div>
<p>It answers the same as the app’s own pages do, under <code>/v1/magpie/admin/</code>: <code>GET providers</code>, <code>POST provider/{save,delete,on,off,name,…}</code>, <code>POST keys/…</code> (a provider’s keys), <code>GET</code>/<code>POST gateway-keys[/{add-key,rename-key,limit-key,models-key,remove-key,…}]</code>, <code>GET</code>/<code>POST account-groups[/…]</code>, and <code>POST signin</code> with <code>{"agent":…}</code>, which answers the vendor’s page and the code to type there, never a password; open it on a computer with a browser. A saved key and a gateway key’s secret are never told again, and what changes this computer’s apps is not served.</p>
<p>It answers the same as the app’s own pages do, under <code>/v1/magpie/admin/</code>: <code>GET providers</code>, <code>POST provider/{save,delete,on,off,name,…}</code>, <code>POST keys/…</code> (a provider’s keys), <code>GET</code>/<code>POST gateway-keys[/{add-key,rename-key,limit-key,models-key,remove-key,…}]</code>, <code>GET</code>/<code>POST account-groups[/…]</code>, <code>GET routing-groups[/{id}]</code> and <code>POST routing-groups/{create,update,delete,switch,…}</code> (the Routing page’s groups and combos, checked as the app checks them; <code>update</code> changes only the fields you send), and <code>POST signin</code> with <code>{"agent":…}</code>, which answers the vendor’s page and the code to type there, never a password; open it on a computer with a browser. A saved key and a gateway key’s secret are never told again, and what changes this computer’s apps is not served. Sign-ins are not exported: that would hand out every account’s secrets.</p>
<p>A key that is read-only, the extension’s, issued or short-lived, or the sharing key, can’t have it. A web page can’t call it, with a key or without (any request with <code>Origin</code> or <code>Sec-Fetch-*</code> is refused), and nor can a request under another name for this computer. Shared over the network, only a key set to <code>any</code> gets in.</p>
<h2 id="api"><a class="anchor" href="#api">Stats API</a></h2>
+2 -2
View File
@@ -247,7 +247,7 @@ steps:
<p>换到的密钥由规则里的网关密钥签发,和其他签发的密钥一样受它约束,有效期不超过规则所写,名字是仓库、分支和运行编号。其他仓库或分支的 token、过期的 token、已经换过的 token 会收到 <code>401</code> 和原因。只有 magpie 共享时其他电脑才能调用这个接口,被拒的 token 计入失败认证次数。没有规则就什么都换不到。</p>
<h2 id="admin"><a class="anchor" href="#admin">管理 API</a></h2>
<p>提供商、账号、网关密钥和账号组都可以不改任何配置文件来管理,用你允许的密钥即可。在命令行里允许(不能通过 API:密钥给不了别的密钥比自己更多的权限):</p>
<p>提供商、账号、网关密钥、账号组和路由组都可以不改任何配置文件来管理,用你允许的密钥即可。在应用里该密钥的菜单 → 高级中允许,或在命令行里允许(不能通过 API:密钥给不了别的密钥比自己更多的权限):</p>
<div class="code">
<span class="lang">Shell</span>
<button class="copy" data-copy="ex-admin">Copy</button>
@@ -258,7 +258,7 @@ curl -s http://127.0.0.1:3425/v1/magpie/admin/providers -H "Authorization: Beare
curl -s -X POST http://127.0.0.1:3425/v1/magpie/admin/gateway-keys/add-key \
-H "Authorization: Bearer $KEY" -d '{"name":"ci"}'</pre>
</div>
<p>它和应用自己的页面答得一样,路径在 <code>/v1/magpie/admin/</code> 下:<code>GET providers</code>、<code>POST provider/{save,delete,on,off,name,…}</code>、<code>POST keys/…</code>(提供商的密钥)、<code>GET</code>/<code>POST gateway-keys[/{add-key,rename-key,limit-key,models-key,remove-key,…}]</code>、<code>GET</code>/<code>POST account-groups[/…]</code>,以及 <code>POST signin</code>(<code>{"agent":…}</code>),它返回厂商的网页和要输入的代码,从不收密码;请在有浏览器的电脑上打开。已保存的密钥和网关密钥的明文不会再被告知,会改动这台电脑上其他应用的操作也不提供。</p>
<p>它和应用自己的页面答得一样,路径在 <code>/v1/magpie/admin/</code> 下:<code>GET providers</code>、<code>POST provider/{save,delete,on,off,name,…}</code>、<code>POST keys/…</code>(提供商的密钥)、<code>GET</code>/<code>POST gateway-keys[/{add-key,rename-key,limit-key,models-key,remove-key,…}]</code>、<code>GET</code>/<code>POST account-groups[/…]</code>、<code>GET routing-groups[/{id}]</code> 和 <code>POST routing-groups/{create,update,delete,switch,…}</code>(路由页的路由组和组合,校验和应用里一样;<code>update</code> 只改你发送的字段),以及 <code>POST signin</code>(<code>{"agent":…}</code>),它返回厂商的网页和要输入的代码,从不收密码;请在有浏览器的电脑上打开。已保存的密钥和网关密钥的明文不会再被告知,会改动这台电脑上其他应用的操作也不提供。登录不会被导出:那会交出每个账号的密钥。</p>
<p>只读密钥、浏览器扩展的密钥、签发的或短期的密钥以及共享密钥,都不能拥有它。网页不能调用它,带不带密钥都一样(带 <code>Origin</code> 或 <code>Sec-Fetch-*</code> 的请求一律拒绝),用别的名字指向本机的请求也不行。通过网络共享时,只有设为 <code>any</code> 的密钥能进来。</p>
<h2 id="api"><a class="anchor" href="#api">统计 API</a></h2>
+2 -2
View File
@@ -10648,7 +10648,7 @@ The key is issued under the rule’s gateway key and held to it like any other i
## Management API
Providers, accounts, gateway keys and account groups can be managed with no hand-edited file, by a key you allow to. Allow it from the command line (not through the API: a key can't give another more than it has):
Providers, accounts, gateway keys, account groups and routing groups can be managed with no hand-edited file, by a key you allow to. Allow it from the key’s menu in the app, under Advanced, or from the command line (not through the API: a key can't give another more than it has):
```
magpie gateway-key add automation
@@ -10659,7 +10659,7 @@ curl -s -X POST http://127.0.0.1:3425/v1/magpie/admin/gateway-keys/add-key \
-H "Authorization: Bearer $KEY" -d '{"name":"ci"}'
```
It answers the same as the app’s own pages do, under `/v1/magpie/admin/`: `GET providers`, `POST provider/{save,delete,on,off,name,…}`, `POST keys/…` (a provider’s keys), `GET`/`POST gateway-keys[/{add-key,rename-key,limit-key,models-key,remove-key,…}]`, `GET`/`POST account-groups[/…]`, and `POST signin` with `{"agent":…}`, which answers the vendor’s page and the code to type there, never a password; open it on a computer with a browser. A saved key and a gateway key’s secret are never told again, and what changes this computer’s apps is not served.
It answers the same as the app’s own pages do, under `/v1/magpie/admin/`: `GET providers`, `POST provider/{save,delete,on,off,name,…}`, `POST keys/…` (a provider’s keys), `GET`/`POST gateway-keys[/{add-key,rename-key,limit-key,models-key,remove-key,…}]`, `GET`/`POST account-groups[/…]`, `GET routing-groups[/{id}]` and `POST routing-groups/{create,update,delete,switch,…}` (the Routing page’s groups and combos, checked as the app checks them; `update` changes only the fields you send), and `POST signin` with `{"agent":…}`, which answers the vendor’s page and the code to type there, never a password; open it on a computer with a browser. A saved key and a gateway key’s secret are never told again, and what changes this computer’s apps is not served. Sign-ins are not exported: that would hand out every account’s secrets.
A key that is read-only, the extension’s, issued or short-lived, or the sharing key, can’t have it. A web page can’t call it, with a key or without (any request with `Origin` or `Sec-Fetch-*` is refused), and nor can a request under another name for this computer. Shared over the network, only a key set to `any` gets in.