Commit Graph
18 Commits
Author SHA1 Message Date
yetoneandClaude Opus 5.5 2b0b2d9401 ci: a pull request runs the tests and fails while a package in it isn't on npm yet (#52)
Trusted publishing can't create a package, so #39's block-patterns,
merged before its first version was on npm, left every publish run on
main red after it (8 runs, the last 37781353941), and a real refused
publish would have hidden behind it. pr.yml runs bun test and check.mjs
on each pull request, and scripts/new-to-npm.sh names any package npm
doesn't know, so its first version is published by hand and its Trusted
Publisher set before the merge. The README's market section says so.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 21:59:38 +08:00
yetone 96c5b0f992 skills: magpie-quota, an official skill that lets an agent check what is left of every subscription, plan and key balance magpie has (magpie quota --json, or GET /v1/magpie/quotas) and wait for allowance (magpie quota wait); it never spends a Codex reset (ttmouse on X: suggested an official skill to go with magpie quota) 2026-10-08 03:46:47 +08:00
xiaofei f5dc146c2c Add OpenCode Zen Free provider plugin (#31)
* Add OpenCode Zen Free provider and market listing

* Guard Zen tool calls and address provider review

* Preserve upstream SSE error frames in Zen tool guard

* Restore Zen Free package name and simplify README title
2026-10-07 08:24:54 +08:00
yetone c5c9d33e48 README: the auth hook's checkin(getAuth, provider) — a plugin can press its vendor's daily check-in itself, which magpie runs once a day per account and shows on the Usage card (Lemon on Discord); outcomes, captcha never solved, failed alone retried; links magpie's contract (yetone/magpie 87487c5e) 2026-10-06 18:45:32 +08:00
yetone d9236e976f middleware: param-override, model-map, system-prompt, word-guard and think-tags — gateway middleware that magpie runs on every agent's requests and replies, mostly New API's channel settings with the same JSON (the owner) — magpie can now run a plugin as gateway middleware (onRequest, onEvent, onResponse, in-process on moejs), and these are the first ones: param-override is New API's param_override (both forms, operations with gjson paths and conditions, return_error); model-map is model_mapping (chains, /regex/ keys with $1) and puts the asked-for name back into replies; system-prompt adds a prompt in each API's own place, keeping an agent's own unless override (New API's semantics), by agent or model; word-guard is the sensitive-word filter (reject or mask the user's text, optionally replies); think-tags strips a leading <think>…</think> from replies across stream chunks, or puts Chat reasoning_content into the text (thinking_to_content). Each is one file with no imports, named @magpie-community/middleware-<name>, with magpie.options as the example the app's editor starts from; registry.json lists them with "kind": "middleware" and no providers; check.mjs skips middleware-only packages. scripts/middleware.mjs calls the hooks as the gateway does (events split, [DONE] passed by) and runs each package's cases.json. Tested with a real DeepSeek account and real Claude Code through magpie's gateway: a mapped model named back in message_start, max_tokens capped, a system prompt appended for claude only, a word turned away as a 400 in Anthropic's shape, return_error as a 403 in Chat's, <think> stripped from Chat and Responses streams and an Anthropic whole reply, reasoning_content moved into the text. bun test (61 for these five) and bun scripts/check.mjs pass; packages/devin's two image tests fail on this machine only, as on main. Their first npm version has to be published by hand (trusted publishing can't create a package); until then magpie shows them as Coming soon. 2026-10-05 20:49:42 +08:00
如是andyetone 42783f0033 trae: one package, two realms — Trae Global folds into packages/trae (#23)
* trae: one package, two realms — Trae Global folds into packages/trae

The review asked for this and it is the right shape: the two deployments
share one implementation. 86 of the 89 top-level names were already the
same code; what differed was a table's worth of values (hosts, client,
versions, usage page, fallback models, error codes) and two realm-only
branches. A separate copy meant every request, stream and tool-call fix
had to be made twice, and it had already drifted (the 0.1.15 Max fix
came back as a bug there).

packages/trae now holds a SITES table with two entries — trae-cn and
trae-global — and makePlugin(site) builds a provider from one. Exported
as TraeCNAuthPlugin and TraeGlobalAuthPlugin. The CN values are moved
verbatim, not re-derived: same hosts, client id, app id, IDE/client
versions, plugin version, brand, functions, fallback models, credits
page, and its own check-in pages. The international entry carries what
only it has: the second (US) deployment and the region that selects it,
the dollar billing's entitlements page, its own model names, and its
extra lapse/quota codes (20101, 4011).

The CN plugin needs the stream fix too (the review's point), so the
AbortController the loader now builds per request, openai()'s abort, and
sse()'s finally are in this one implementation for both realms — as is
the wrong-function retry releasing the read it leaves behind.

fake.mjs takes a realm id, defaulting to CN so every test written before
the fold is unchanged. The global tests move to global.test.mjs, plus
new ones for what only the international realm does: the US/SG routing
of a request and of a saved sign-in, its own error codes and error name,
the dollar usage page, and its fallback model list. chatModel gains the
picker's invisible-entry filter (paygo/auto twins, search agents) and
the config hook names the realm's own provider.

The acceptance test: packages/trae/*.test.mjs' 48 CN tests are untouched
and green — that is the proof the refactor changed no CN behaviour, with
its constants verified line by line against HEAD. bun test: 63 pass
(48 CN + 15 global); bun scripts/check.mjs trae: ok.

registry.json: one entry, providers [trae-cn, trae-global]. README: both
realms, each realm's endpoints, usage page and codes; the verification
range stated honestly (CN never run live; Global on one Free SG account,
no Pro and no US account).

* trae: Trae CN's model lists stay whole; only Global hides is_invisible_to_user

The fold filtered is_invisible_to_user for both realms, which took 40 of
Trae CN's 76 models out of its list. CN is served as before; Global (a
site flag, hidesInvisible) keeps the filter. Also: the unsupported-request
error names the realm, and two duplicated/merged comments are tidied.

---------

Co-authored-by: yetone <yetoneful@gmail.com>
2026-10-05 17:18:12 +08:00
如是 228628689f Add Trae Global (trae.ai) plugin - trae-global provider (#22)
* Add Trae Global (trae.ai) plugin — trae-global provider

Trae international (trae.ai, ByteDance's AI IDE international build) as a
provider plugin: sign in with Trae's own browser flow, free tier included,
models served through the international llm_utils_chat gateway.

Same plugin contract and request/response machinery as the Trae CN
plugin (packages/trae), a separate deployment: different domains, OAuth
client, model catalog, plus a US region (coreva) routed by the account's
AIRegion. The usage card reads the dollar billing's entitlements
(basic+bonus allowance) from the pay host, with the Free plan's /month
allowance riding it.

bun test: 41 pass; bun scripts/check.mjs trae-global: ok

* trae-global: a stream the agent walks away from closes Trae's connection

The bug: an answer whose tool call the agent acts on is cancelled mid-read,
and the read to Trae was left hanging. A generator's return cannot break a
read that is already waiting on reader.read(), so the SSE reader kept its
half of the connection open, and the host the next ask reused was one Trae
had dropped — a stream that runs, then dies, exactly around tool calls.

The fix: the answer's fetch is what gets stopped. The loader builds one
AbortController per request, follows the caller's abort signal into it, and
openai() aborts it when the stream is cancelled. sse() also lets its reader
go in a finally, for the paths that end the generator rather than the fetch.

stream.test.mjs: the agent reads, then cancels with nothing more coming, so
only aborting Trae's fetch can release the read — red before, green after.
bun test (42 pass); bun scripts/check.mjs trae-global: ok

* trae-global: the review's three blockers — planLocked, the 0.1.15 Max, usage's error code

planLocked is gone. It read display_contact_config's identity_list and
assumed every account is Free (identity 0), so a paying account lost
exactly the models it pays for — gpt-5.5, the gpt-5.6 family, gpt-6,
glm-5.2 — and could never pick them. The plugin is never told the
account's own identity (not at sign-in, not in the entitlement answer),
so nothing is filtered on identity now: the list is the account's own,
the IDE greys out what the plan locks, and a locked model answers Trae's
own 1005 when asked. The picker's invisible entries (paygo/auto twins,
search agents) stay out, as before.

maxModel takes the 0.1.15 fix: a model's Max is found across every list
that names it, not just the one entry the model is listed through —
chat_v3 can name the __max model while the SOLO list names only __dev,
and the window can be another entry's again. Without it the same
"no -max model" bug the CN plugin fixed in 0.1.15 comes back here.
maxes holds each model's Max for the models hook, as CN's does.

usage: a 200 carrying an error code (e.code !== "0") now says Trae's own
message instead of "no entitlement pack in the answer", as CN's does.

README: the verification range is stated honestly — one Free account,
SG realm, no Pro and no US account tried; paid-account behaviour is
implemented from the interface's shape, not confirmed on a live one.
registry.json marks Trae Global experimental, as Trae CN is.

usage.test.mjs: the locked-model test now asserts the paying account's
list, and a new one asks a paid account's gpt-5.5 through the gateway.
stream.test.mjs: a Max split across lists is listed and asked where its
__max model is named. Each red before its fix, green after.
bun test (46 pass); bun scripts/check.mjs trae-global: ok
2026-10-05 16:10:35 +08:00
yetone 6c048c7fc2 trae 0.1.0: Trae CN (trae.cn) accounts, free tier included, with Trae's browser sign-in (experimental; Discord pdzebkbd0701)
Sign-in is trae.cn's authorization page back to a 127.0.0.1 /authorize
callback (userJwt + userInfo, or a refresh token exchanged), with a device
made at sign-in and kept for the account. ExchangeToken renews the JWT
through auth.refresh (refreshLead 10 min, one renewal per refresh token).
Requests go to the IDE agent's llm_utils_chat (chat_v3, then
solo_work_lite on 4001/4023/1005), its SSE events turned into OpenAI
chunks; tools named natively and as <tool_call> blocks. Usage is the
entitlement packs' credits. Worked out from wangqi233/trae2api and
autumnsentiment/Trae2api-cn; not run against a real account.
2026-10-03 14:34:31 +08:00
volcanic 8b4f759455 Cline: usage billing, ClinePass and the free models, with Cline's own device sign-in or an API key (#2)
* Cline: usage-billed models, ClinePass's and Cline's free ones, on your own Cline account — Cline's device sign-in (WorkOS device code, traded at /auth/register) or an API key; chat completions on api.cline.bot with Cline's own client-identity headers (pinned to the current CLI release — what the free models' gate reads), the non-stream data envelope unwrapped, the model list from Cline's recommended-models feed, usage from the account's balance (counted in millionths of a dollar). cline-pass answers 403 ENTITLEMENT_ERROR without the subscription and the message says so; so does an empty balance, with the top-up URL.

* cline 0.1.0: the pinned CLI version and the workos: prefix move to Cline's current client — apps/cli is at 3.0.68, and provider-auth-registry's formatProviderOAuthApiKey lowercases before it startsWith("workos:") so a token stored as WorkOS: is not double-prefixed here either; bearerOf's "once" test fails against 0.1.0.

* cline 0.1.0: the model list is Cline's whole catalog, not just the recommended feed — the title promised usage-billed models but the plugin read only recommended-models (6 paid models), while Cline's own clients also load /api/v1/ai/cline/models (loadCloudModels), so most usage-billed models were missing. The four feed arrays are now read by name instead of walking every value (a tag or description could become a model, and one in both recommended and free lost its "(free)"), clineCloud stays out as the client leaves it out, a raw-id name is prettified, and the bundled snapshot drops gemini-2.5-pro and minimax-m2.5 (not in cline-recommended.generated.ts) and gains the missing cline-pass/* entries; the parseFeed, snapshot and models-merge tests fail against 0.1.0.

* cline 0.1.0: a refresh failure no longer fails a request that still has a good token, and a rotated pair survives a failing auth.set — a 4-minute token plus a 500 from /auth/refresh answered the chat 502 and never sent it, and with auth.set throwing the next request re-spent the old refresh token, got invalid_grant and marked the account expired. fresh now keeps the current token on a transient failure while it is still good (Cline's getValidClineCredentials), failing only once it has expired, and the latest rotated pair is held in memory beside the save (kiro's held), used when getAuth still hands back the spent token; the still-good-token and rotated-pair tests fail against 0.1.0.

* cline 0.1.0: failure() keys on Cline's error codes and whole phrases, not loose substrings — a 403 whose text mentioned "tokens" (max_tokens exceeds…) became "the sign-in lapsed — sign in again" and lost the real message, and any message containing "credit" became a 429 usage limit. The 401/403 token check, the out-of-credits and entitlement checks and the 429 check now match what Cline's client matches (ENTITLEMENT_ERROR, insufficient_credits, SPEND_LIMIT_EXCEEDED, the not-subscribed wording), and a renewed token clears the lapse mark through the error path too as qoder's renewed() does; the codes-and-phrases and renewed-mark tests fail against 0.1.0.

* cline 0.1.0: device polling grows the interval for good and rides out a bad poll — slow_down raised it for one poll only (RFC 8628 and Cline's pollWorkOSTokens do interval += 1 permanently), the minimum was 0.25s where the client clamps to 1s, and a single 5xx, non-JSON reply or network error ended the sign-in with "the token answer had no access token". The poll now keeps polling through those; the slow_down, one-second and bad-poll tests fail against 0.1.0.

* cline 0.1.0: the held pair covers every refresh token this run has spent, not only the last — when auth.set goes on failing (which a store that failed once usually does) getAuth keeps handing back the first pair, and a second rotation overwrote held.from, so the third request refreshed the already-spent r1 again: /auth/refresh went r1, r2, r1 and the chat answered 401 expired. held.from is a Set every rotation adds to now, and the held pair is used whenever the refresh token getAuth hands back is in it; the two-rotation test fails against 0.1.0 (200, 200, 401).

* cline 0.1.0: X-CORE-VERSION moves to 0.0.90 with the CLI release — the header set pinned 3.0.68 beside 0.0.89, but cline@3.0.68 depends on @cline/core 0.0.90 (0.0.89 is what 3.0.67 shipped) and resolveProviderRequestHeaders sends X-CORE-VERSION from that dependency, so the number the comment calls the one that has to match was a release behind; the client-header test pins the pair now and fails against 0.1.0.

* cline 0.1.0: a poll reply that isn't JSON and isn't a 5xx fails the sign-in at once — a body that wouldn't parse was read as WorkOS having a moment, so an HTML 400 (a proxy's error page, say) kept the poll going to the deadline, ten minutes, before failing there anyway. Only a network error and a 5xx are a poll to try again now; a 4xx that isn't JSON is the poll refused. The refusal test fails against 0.1.0.

* cline 0.1.0: a renewal's mark survives a network error on the chat itself — the 502 the fetch throws after a renewal returned without signed(..., renewed(cred)), so the request that never left the machine dropped the mark while the request that came back refused kept it; it is wrapped the way the !res.ok path is. The network-error test fails against 0.1.0.

* cline 0.1.0: the held pair is kept per rotation chain, so no account is sent on another's token — magpie calls ClinePlugin once for the provider and hands every account its own getAuth, so the one `held` pair outlived them: with two accounts, a save failing every time and every token wanting renewal, A, B, A went out as A-jwt1, B-jwt1, B-jwt2 and A's third request refreshed with B's token, spending it and billing B (yetone's two-loader repro, page-for-page the same). A spent refresh token now maps to the newest pair its own chain reached — the token getAuth handed back and the one the refresh spent both point at that chain — so a request offering either finds its own account's pair; the per-chain test fails against 0.1.0 on the third request's Authorization, with the 51 before it passing.
2026-10-02 23:03:54 +08:00
yetone 7c859cc532 minimax 0.1.0: MiniMax Code (mcode) accounts' credits and M Plan, China (minimax-code) and international (minimax-code-global), with MiniMax Code's own device sign-in (Magic_zero on Discord)
A new package, @magpie-community/opencode-minimax-auth, written from MiniMax Code 0.6.2's bundle.

Sign-in: MiniMax Code's OAuth device flow, the same one mcode uses (account.minimax.cn / account.minimax.io, client mcode-public, scope agent.default, audience agent-backend, PKCE S256). It also handles MiniMax's own variant, where there is no device_code, the user_code is polled for, and expired_in may be an at-ms. The account is named from MiniMax's signed /v1/api/user/info. mcode's ~/.minimax sign-in is never read or written. Each account is a sign-in of its own, so magpie can hold several.

Refresh: two minutes before the token ends, or once on a 401. One refresh runs per account (keyed by the refresh token it spends), and its result answers for the old token for a minute, so a late reader doesn't spend a rotated token twice. Only invalid_grant with HTTP 400 signs the account out (signIn: expired); any other failure keeps it and uses the token in hand while it lasts.

Chats: Anthropic messages at <agent>/mavis/api/v1/llm/v1/messages, carrying:
- Authorization: Bearer <token>
- x-api-key sk-xxx (mcode's placeholder)
- User-Agent MiniMaxAgent
- X-Mavis-Agent-Id main
- X-Mavis-Timezone-Offset
- X-Mavis-Session-Id, from chat.headers' sessionID (otherwise a fixed id per run)

A 402, 403 or 429 whose body says credits or quota ran out goes on as a 429 "usage limit reached".

Models: the live config at GET /mavis/api/v1/models?region=&buildEnv=prod (asked again without auth on a 401/403), with mcode's built-in four as the fallback: MiniMax-M3.1-Flash-Preview, MiniMax-M3, MiniMax-M2.7 and MiniMax-M2.7-highspeed. Variants follow what mcode sends: adaptive thinking at an effort (output_config.effort), and none to turn thinking off.

Usage: mcode's signed account API: user info, the type-0 workspace from get_user_extra_info, then get_membership_info. The card shows credits left (op_credit_summary / opcredit_balance), Free or "M Plan <tier>" with its end, and, for an M Plan, coding_plan/remains with X-Group-Id. That is read as magpie's readMiniMaxPlan reads it. There is no check-in.

Tests: fakes only. nonet.mjs is imported first, so only 127.0.0.1 can be reached. They cover:
- sign-in, the variant, refused, and other errors
- refresh, a three-way race plus a late stale reader, per-account refreshes, invalid_grant, other failures, and 401 then refresh then retry
- request headers and chat.headers
- credits running out going on as a 429
- the live list, the retry without auth, and the fallback (the given object back)
- signing, against fixed vectors and the bundle's formula
- usage parsing (readMiniMaxPlan's own fixture), Free, M Plan, and a refused account

bun test packages/minimax (27 pass) and bun scripts/check.mjs pass.

End to end through magpie: origin/main b0486663, built with -tags nogui in a worktree since removed, under env -i with a sandbox HOME, a fake upstream on 127.0.0.1:47811, and a copy of the package with its hosts pointed there:
- plugin add
- plugin login minimax-code: the device flow and the account named; a second login of the same account merged into one
- the live list: 2 models
- provider test minimax-code: the chat went out with the headers above
- quota: M Plan Plus, 321.5 credits, 5 hours and 7 days windows
- an expired token refreshed and saved

No request was made to MiniMax.
2026-10-02 22:38:41 +08:00
yetone cc57432d16 zcode: Start Plan requests go as ZCode's own, with its headers and system prompt (0.1.7) (#5)
ARNO on Discord: the plugin's Start Plan requests were answered 405 / 3012
"blocked due to unusual activity" while his own plugin (Freeflow, provider
zcode-start) worked from the same machine. zcode.z.ai serves the plan only
to what looks like ZCode's own request: a Start Plan request now carries
ZCode's headers and its body is dressed as ZCode's (three cached system
blocks, the environment section, the date reminder as the first turn, one
cache mark on the last block, metadata.user_id naming the sign-in's
device). The prompt texts are magpie's (901fd87e), each matching ARNO's
plugin's hash. Coding Plan and team requests are unchanged. The Start Plan
is advertised again.
2026-10-02 19:28:42 +08:00
yetone 8c7e31911e qoder: Qoder CN (qoder.cn) as a second provider, qoder-cn (#1) (#4)
Hosts, client id and paths read from Qoder CN's own CLI (@qodercn-ai/qoderclicn 1.1.65): sign-in on qoder.cn, accounts on openapi.qoder.com.cn, models and chat on gateway.qoder.com.cn, client id e883ade2-…; signing unchanged. The same as magpie's built-in Qoder CN. When qoder.cn refuses a job token the account chats on its device token, renewed through /api/v1/deviceToken/refresh, as the CN CLI does. cn.test.mjs (12 tests, a local server standing in for every host) covers sign-in, polling, both tokens' refresh, a chat, models, usage and qoder.com unchanged; 6 fail with the CN chat host pointed back at api3.qoder.sh or the fallback off. Version 0.2.0.
2026-10-02 18:30:00 +08:00
yetone bd5e91ee00 zcode: stop advertising ZCode's free Start Plan — zcode.z.ai serves it only to requests carrying the official ZCode client's system prompt and answers others HTTP 405 'request has been blocked due to unusual activity'; the plugin, like magpie, never rewrites prompts or poses as the official client, so the plan can't be used through it. registry.json's summary (en/zh), the root README's table, the package's description and its README now name the GLM Coding Plan and team seats only, and the package README says why the Start Plan isn't usable. Text only; no code or version change. 2026-10-01 23:11:00 +08:00
yetone 03c948b6bb registry.json: the list magpie's Plugins tab shows, and how to add to it 2026-09-30 18:57:46 +08:00
yetone d7385c87c4 cursor: Cursor — cursor-agent's browser sign-in (PKCE poll), its existing sign-in or an API key; agent.v1 Run over HTTP/2 as magpie's gateway does it, with tool calls; tried with real requests. README lists every package so far 2026-09-30 17:17:06 +08:00
yetone 5a18bbdac4 Name the scope @magpie-community (the org's name, spelled right) 2026-09-30 17:04:47 +08:00
yetone 631b29b1c0 README: the packages so far 2026-09-30 17:01:55 +08:00
yetone 2578f471bb Scaffold: conventions for OpenCode provider plugins of coding-plan subscriptions, a hook checker and a sandboxed magpie runner 2026-09-30 16:55:58 +08:00