From df3a04070a722da99706fffb11f55769b86326aa Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 16 Oct 2026 02:57:51 +0800 Subject: [PATCH] README, registry: tools, pages and routing strategies, and how to write your own registry.json lists tools-calc (kind "tools"), page-usage (kind "page") and middleware-reserve (kind "middleware"), community, with en/zh summaries and no icon (magpie has none that fits). README: sections "Routing strategies" (under Gateway middleware), "Tools for every agent" and "Pages", each with a table and what a package of that kind is a folder with; "Write your own" pointing to usemagpie.ai/docs/plugins (#tools, #pages, #gateway-points, #middleware, #agents, #quick) and to a template package of each kind. The market section names the kinds. Run: registry.json parses (26 entries); HOME=$(mktemp -d) bun test 1554 pass, 0 fail; bun scripts/check.mjs ok. Known: magpie main's Plugins > Discover (plugins.js kindOf) treats any kind but middleware and agent as a provider, so the tools and page entries show with the provider chip until magpie learns those kinds. --- README.md | 91 ++++++++++++++++++++++++++++++++++++++++++++++++--- registry.json | 8 ++++- 2 files changed, 93 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index dbbd087..9989334 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,11 @@ # magpie-community plugins [OpenCode](https://opencode.ai) provider plugins for coding-plan -subscriptions, and [gateway middleware](#gateway-middleware) and [agents](#agents) for magpie, -maintained by the community. Each package signs in to one +subscriptions, and [gateway middleware](#gateway-middleware), +[routing strategies](#routing-strategies), [tools for every +agent](#tools-for-every-agent), [pages](#pages) and [agents](#agents) for +magpie, maintained by the community. To make one, see +[Write your own](#write-your-own). Each package signs in to one subscription and makes its requests. The packages work in OpenCode and in [magpie](https://usemagpie.ai), which runs OpenCode's provider plugins. @@ -53,6 +56,62 @@ A middleware package is a folder under `packages//` with: - **`.middleware.js`**: exports `onRequest`, `onEvent` and/or `onResponse` ([the hooks](https://usemagpie.ai/docs/plugins#middleware)). It runs in magpie's gateway on moejs, so it is one file and imports nothing. - **`cases.json`** and a test that runs them with `check()` from `scripts/middleware.mjs`, which calls the hooks the way the gateway does. +### Routing strategies + +A gateway plugin can also add routings: how one pool is ordered for a request, where the pool is a provider's accounts or keys, or a group's members. Each shows in every routing picker as `/`, beside magpie's own (smart, order, rotate, usage, pace, weight). + +| Package | Routings | +|---|---| +| [reserve](packages/reserve) | `reserve/ceiling`: fill accounts in order up to a share of their allowance (80% by default), then the next; `reserve/accounts-first`: subscriptions before API keys, keys by weight | + +```sh +magpie plugin add @magpie-community/middleware- +magpie group set routing=/ +``` + +A routing package is a folder under `packages//` with: + +- **`package.json`**: name `@magpie-community/middleware-`, `"magpie": {"gateway": "./.gateway.js", "options": {…}}`, no `main`. +- **`.gateway.js`**: exports `strategies`, `{: (pool, seats, options) => [indexes]}` ([the reference](https://usemagpie.ai/docs/plugins#gateway-points)). Each seat has `key`, `account`, `known`, `used`, `soon`, `pace`, `weight`, `resting` and `tokens`. A strategy has 20 ms. One that throws, or answers anything but a permutation of the seats, leaves them in their listed order. It runs on moejs, so it is one file and imports nothing. +- **`strategies.json`** and a test that runs them with `checkStrategies()` from `scripts/middleware.mjs`: seats in, the order of their keys wanted out. + +## Tools for every agent + +These give tools to every agent magpie connects. magpie serves them on its MCP server, `/mcp/magpie/tools`, named `_`. + +| Package | Tools | +|---|---| +| [calc](packages/calc) | `eval` exact arithmetic in fractions, `convert` units (data, time, length, mass, angle, temperature), `date` calendar date math across time zones and DST. No network, no key | + +```sh +magpie plugin add @magpie-community/tools- +magpie plugin # lists each plugin's tools +``` + +A tools package is a folder under `packages//` with: + +- **`package.json`**: name `@magpie-community/tools-`, `"type": "module"`, `"main": "./index.mjs"`. +- **`index.mjs`**: exports one async plugin function that returns a `tool` hook, `{tool: {: {description, args, execute(args)}}}` ([the reference](https://usemagpie.ai/docs/plugins#tools)). `args` is JSON Schema, and magpie passes the arguments on as they came, so `execute` checks them itself. A string it returns is sent as text, anything else as its JSON. Every function the module exports is taken as a plugin, so helpers go in another file. +- a test of each tool's `execute`. `bun scripts/check.mjs` loads the plugin and checks each tool's name, description and `args`. + +## Pages + +These add a page to magpie's window, in the app and in `magpie web`, under Plugins in the sidebar. + +| Package | Page | Reads | +|---|---|---| +| [usage](packages/usage) | Usage glance: calls, errors, tokens and cost for today, 7 or 30 days, and the models behind them | `usage:summary` | + +```sh +magpie plugin add @magpie-community/page- +``` + +A page package is a folder under `packages//` with: + +- **`package.json`**: name `@magpie-community/page-`, no `main`, and `"magpie": {"page": {"title", "file", "icon"}, "permissions": [...], "options": {…}}` ([the reference](https://usemagpie.ai/docs/plugins#pages)). `permissions` lists the reads the page makes, and magpie refuses any other. Declare only what it reads. +- **the page**: HTML, CSS and scripts in files. It runs in a sandboxed frame with no network (`connect-src 'none'`) and no inline scripts. It talks to magpie only through `_magpie/bridge.js`: `magpie.ready`, `magpie.read(name, params)`, `magpie.options.get/set` (at most once a second), and `magpie.theme` with `onTheme`, whose `--magpie-*` variables it styles itself by. +- a test that the page's scripts read only what `permissions` declares and reach no network, and of what it draws from a read. + ## Agents These add an agent magpie has no setup of its own for. Once added, the agent is @@ -156,6 +215,26 @@ built-in, the plugin's provider shows as `-plugin`. Once the built-in is gone, it takes over the same id, so an agent set to `/` keeps working. +## Write your own + +The reference is [usemagpie.ai/docs/plugins](https://usemagpie.ai/docs/plugins): [tools](https://usemagpie.ai/docs/plugins#tools), [pages](https://usemagpie.ai/docs/plugins#pages), [gateway points](https://usemagpie.ai/docs/plugins#gateway-points) (routing strategies among them), [middleware](https://usemagpie.ai/docs/plugins#middleware) and [agents](https://usemagpie.ai/docs/plugins#agents). [Quick start](https://usemagpie.ai/docs/plugins#quick) is the shortest way in. + +Start from the package of the same kind here and rename it: + +- a tool: [calc](packages/calc); +- a page: [usage](packages/usage); +- a routing: [reserve](packages/reserve); +- middleware: [think-tags](packages/think-tags); +- an agent: [aider](packages/aider); +- a subscription: [zen-free](packages/zen-free). + +Try it from its folder before publishing, in a sandbox HOME: + +```sh +magpie plugin add ./packages/ +magpie plugin +``` + ## Checking a package ```sh @@ -173,11 +252,13 @@ MIT ## The market `registry.json` is the list magpie's Plugins tab shows: the packages -here. A middleware's entry has `"kind": "middleware"` and no `providers`. magpie +here. An entry that signs in to nothing has a `"kind"` and no `providers`: +`"middleware"` for gateway middleware and routing strategies, `"tools"`, +`"page"` or `"agent"`. magpie fetches it every few hours and keeps a copy built into the app for when it can't. To list a plugin, add an entry with its npm `package`, a -`name`, `providers` (the provider ids it signs in to), an `icon` and a -`summary` in English and Chinese (`{"en": …, "zh": …}`), and open a pull +`name`, `providers` (the provider ids it signs in to), an `icon` (one +magpie has, or none) and a `summary` in English and Chinese (`{"en": …, "zh": …}`), and open a pull request. ## Publishing diff --git a/registry.json b/registry.json index ce3b7fd..0cd4fae 100644 --- a/registry.json +++ b/registry.json @@ -46,6 +46,12 @@ { "package": "@magpie-community/agent-aider", "name": "Aider", "kind": "agent", "community": true, "summary": { "en": "Aider (aider.chat) on magpie's Agents page: pick one of magpie's models for it, and switch it off to put its config back.", "zh": "把 Aider(aider.chat)加到 magpie 的 Agent 页:给它选 magpie 的模型,关掉即恢复它原来的配置。" } }, { "package": "@magpie-community/agent-type4me", "name": "Type4Me", "kind": "agent", "community": true, - "summary": { "en": "Type4Me (macOS voice input) on magpie's Agents page: pick one of magpie's models for its LLM post-processing, used from the next dictation.", "zh": "把 Type4Me(macOS 语音输入)加到 magpie 的 Agent 页:给它的 LLM 后处理选 magpie 的模型,下一次语音输入即生效。" } } + "summary": { "en": "Type4Me (macOS voice input) on magpie's Agents page: pick one of magpie's models for its LLM post-processing, used from the next dictation.", "zh": "把 Type4Me(macOS 语音输入)加到 magpie 的 Agent 页:给它的 LLM 后处理选 magpie 的模型,下一次语音输入即生效。" } }, + { "package": "@magpie-community/middleware-reserve", "name": "Reserve", "kind": "middleware", "community": true, + "summary": { "en": "Two routings that keep something in reserve: fill accounts up to a ceiling of their allowance, or use subscriptions before API keys.", "zh": "两种留余量的路由:账号用到额度上限就换下一个,或订阅账号优先于 API key。" } }, + { "package": "@magpie-community/tools-calc", "name": "Calc", "kind": "tools", "community": true, + "summary": { "en": "Exact arithmetic, unit conversion and calendar date math as tools for every agent: no network, no key.", "zh": "给每个 agent 的精确计算、单位换算和日历日期计算工具:不联网,不需要 key。" } }, + { "package": "@magpie-community/page-usage", "name": "Usage Glance", "kind": "page", "community": true, + "summary": { "en": "A page in magpie's window with calls, errors, tokens and cost for today, 7 or 30 days, and the models behind them. Reads only your usage summary.", "zh": "在 magpie 窗口里一眼看到今天、7 天或 30 天的调用、错误、token、费用和对应模型。只读取用量汇总。" } } ] }