Commit Graph
15 Commits
Author SHA1 Message Date
yetone 17e5ef7457 all: load on OpenCode 2.x through a default {id, setup} (#657)
nbczw8750 (#657): trae 0.2.26 on OpenCode 2.2.5 fails with "Plugin
must export a default definition with an id and an effect or setup
function. (cause: SchemaError(Missing key at ["default"]))". 2.x
imports a package's exports["."] (a plugin dir and an npm install
alike) and has no V1 path at all, so every package here that serves
models failed the same way, not only trae.

Every one of the 32 model packages now has:
- opencode2.mjs, exports["."]: a copy of scripts/opencode2.mjs, an
  adapter that runs the package's V1 plugins inside 2.x's promise
  API. Config providers become 2.x providers (package pinned so the
  aisdk sdk hook runs), V1 auth methods become integration methods
  (oauth auto/code with forms; api without authorize as a key method),
  V1 credentials are kept in metadata.v1, the loader's baseURL,
  apiKey, headers and fetch are applied through the sdk hook, an
  auth.set renewal is stored per credential, and credential.switched
  /updated reload the account's own model list.
- opencode.mjs, main: re-exports the V1 plugin functions only.
  OpenCode 1.x and magpie's host.js take main. On 1.x, trae 0.2.26's
  main exported a non-plugin (_internal) and 1.19.5 refused it ("Plugin
  export is not a function"); the new main fixes that too.
- both files in "files"; patch version bumped. devin already had 2.x
  and is unchanged.

scripts/check.mjs fails a model package whose 2.x entry has no default
{id, setup}, whose opencode2.mjs differs from the canonical one, whose
entry is missing from files, or whose main exports a non-plugin.

Run at this head (mote):
- HOME=$(mktemp -d) bun test, as CI runs it: 4900 pass, 0 fail
  (4914 tests, 374 files). A first run set globalThis.fetch for the
  whole process from opencode2.test and failed 528 tests in other
  packages; the block is now set and put back around that file's tests.
- bun scripts/check.mjs: every package passes. With the network
  blocked cloudflare-workers-ai fails on its fetched catalog, the same
  on origin/main.
- Real OpenCode 2.2.5 (npm opencode-ai), sandbox HOME, packed trae
  0.2.27: loads with no error; /api/integration lists trae-cn "Trae CN"
  and trae-global "Trae Global" with their browser sign-ins; `auth
  login` starts the trae.cn authorization and waits (cancelled there);
  with a fake credential POSTed to /api/credential, `opencode models`
  lists trae-cn's six models.
- Real 2.2.5 with a fake V1 key plugin through the same adapter
  against a local fake server: `auth login` with a key, `models`,
  `opencode run` reached /real/v1/chat/completions with the loader's
  "Bearer loader-sk-fake" and header, and printed the fake's reply;
  with @ai-sdk/anthropic it reached /real/v1/messages with x-api-key
  from the loader. This run found the key method missing after 2.x's
  second integration transform (a once-only flag outside the
  transform); fixed, and opencode2.test checks a rebuild.
- Real OpenCode 1.19.5, sandbox HOME, trae 0.2.27: `opencode models`
  lists trae-cn and trae-global models; 0.2.26 failed there.

Broken by hand (scratch copy, bun test scripts/ and check.mjs):
- trae's exports back to "./index.mjs": the trae 2.x test fails
  (default.id undefined), check fails trae with "OpenCode 2.x:
  ./index.mjs has no default {id, setup} (plugins#657)".
- zed's opencode2.mjs changed: the copies test fails, check fails zed
  "differs from scripts/opencode2.mjs".
- the key flag back outside the transform: the 1.x plugin test fails
  on the rebuilt sign-ins (key missing).

Not tried: a real sign-in with a real account on 2.x; Windows (the
reporter's OS); chat.headers, chat.params, usage and tool hooks, which
the adapter doesn't carry to 2.x; the tools/pages packages (calc,
goanyapi, layerfs, search1api, aelios, agent-console, chat,
fingerprint, nowledge-mem, kimi-desktop), which still load only on 1.x.
2026-11-03 13:54:26 +08:00
yetone af4a0b365d mimo 0.1.9: an account with a Token Plan and no app membership gets answers (yetone: 2 个模型中有 2 个没有响应). The app's /route answers such an account 403 membership_required ("未开通会员或会员已到期,请订阅后使用") for every model. The plugin now reads the plan's tp- key and endpoint from the open platform with the same passToken (/tokenPlan/apiKey's openaiBaseUrl, /tokenPlan/apiKey/raw), sends the request there with Bearer <key> and no cookies, mimo-pro/mimo-flash asked as mimo-v2.6-pro/mimo-v2.6-flash, and goes straight to the plan for an hour after. A key the plan turns away (401) is read again next time; no plan or no key passes the app's 403 through as it was. The usage card's Token Plan window is the account's allowance, not an aside, when there is no app plan.
Tested on the owner's real account (Token Plan Lite, no app membership): mimo-pro, mimo-flash (streamed) and mimo-auto answered 200 through the loader's fetch; usage shows Token Plan Lite with the "Token Plan" window. bun test (990 pass) and scripts/check.mjs under a temp HOME; 3 of the new tests fail on 0.1.8.
2026-10-09 01:50:45 +08:00
yetone bf01ffc4d9 mimo 0.1.8: a Token Plan bought at the open platform shows on the card (yetone: 我明明已经订阅了啊为啥说我是 free 账号啊). The card read only the MiMo app's /user/xiaomi/subscription/self, which is empty for an account whose plan is the platform's Token Plan, so it said Free. The same passToken signs on at platform.xiaomimimo.com (401 loginUrl, sid api-platform, through /sts), whose /api/v1/tokenPlan/detail and /usage give the plan, its end (UTC), renewal and credits: the card's plan is the Token Plan when the app has none, and its credits are an aside window (they are spent by the tp- key, not this account's requests). A platform that can't be read leaves the card as it was. Tested against the reporter's real account (Token Plan Lite, 6.81M / 4.1B credits, the second read keeping the platform session); the new tests use its literal replies and 3 of them fail on 0.1.7. 2026-10-07 00:49:43 +08:00
yetone 7711a3714a mimo 0.1.7: the plugin gives its provider MiMo Code's logo (#14) — package.json's magpie.icon is the SVG mimo.mi.com serves (static/mimo-code.a1594b207bbc4bee.svg) as a data:image/svg+xml URI, so the host passes it on with nothing fetched, and OpenCode or a magpie showing the plugin's own picture shows Xiaomi MiMo's mark. Checked: the decoded URI renders as the black Xiaomi MiMo tile, host.js's iconOf test (data:image, under 1.5 MB) takes it, scripts/check.mjs mimo and bun test (20 pass) under a temp HOME. 2026-10-03 22:17:38 +08:00
yetone 7dd0b4e0b4 mimo 0.1.6: magpie renews the sign-in ahead of time through auth.refresh
auth.refresh with refreshLead 10 minutes before the day's session ends:
the account signs on again, once per account (the request path joins it),
and the new session (access, expires) is given. A passToken Xiaomi no
longer takes is signIn "expired"; any other failure throws and is retried.

The check before each request stays for OpenCode, which doesn't call the
hook (magpie 0.1.684+ does). refresh.test.mjs fails without the change;
HOME=$(mktemp -d) bun test passes (396 across the repo).
2026-10-03 12:07:22 +08:00
yetone 8f25b63718 publish from GitHub Actions with npm's trusted publishing, no one-time password [skip ci]
.github/workflows/publish.yml runs the tests (in a throwaway HOME) and
scripts/publish.sh on each package.json change pushed to main, or by hand;
npm's OIDC exchange stands in for a token and an OTP. Every package now
names magpie-community/plugins' publish.yml as its trusted publisher on
npmjs.com, and gets the repository field npm checks it against.
2026-10-03 00:00:23 +08:00
yetone 01aee5da28 all: a usage read says what it means for the sign-in, and a renewal clears the mark whatever follows, as the built-ins did (要保证插件跟内置的所有逻辑都要一模一样) — auth.usage returns signIn on every path: expired where the built-in's quota read marked the account (Zed's /users/me 401, Factory's and MiMo's refused renewals, Qoder's refused job refresh), renewed after a renewal, which took the mark off, kept everywhere else, so magpie no longer guesses from the words 'sign in again' (Kiro's, Devin's and ZCode's usage errors marked accounts their built-ins never did) nor clears on a clean read. A request after a renewal says renewed on any status; one without says kept, as the built-ins cleared only on renewal. Kiro, Cursor, Devin, Command Code, WorkBuddy, Grok and ZCode, whose built-ins never marked an account, say kept on every answer. New tests fail against 85d7dd0's index.mjs. 2026-10-01 04:53:29 +08:00
yetone 85d7dd0d0a all: each plugin fails with its built-in's status and marks the sign-in as it did, through X-Magpie-Sign-In (要保证插件跟内置的所有逻辑都要一模一样) — Factory's and MiMo's refused renewals are the built-ins' 502 marked expired, not 401s; Qoder's vendor 403 is the built-in's 401 kept, its model list's failure a 400, its job refresh refused marked expired; Zed's retried 401 is a 401 kept, not a 403; Kiro's unreachable refresh a 401 kept; Cursor's expired trial a 401 kept; a vendor 401 WorkBuddy, Grok, Devin, Command Code and ZCode passed on no longer marks the account, as their built-ins never did, and Grok and MiMo no longer retry what their built-ins sent once. Messages take the built-ins' words. New tests fail against the previous index.mjs. 2026-10-01 04:47:03 +08:00
yetone aac52c9ce4 mimo 0.1.4: a chat body handed over as bytes is read, so mimo-auto is still asked as mimo-pro; a sign-in Xiaomi no longer takes answers the request with a 401 in the built-in's words (<user>: the Xiaomi MiMo sign-in has expired — sign in again) instead of a thrown fetch 2026-10-01 03:13:34 +08:00
yetone fb82ecd4d2 mimo 0.1.3 2026-10-01 02:45:37 +08:00
yetone d28f9dfa09 mimo 0.1.3: two accounts signing on at once each keep their own session — one renewal was shared by every account, so an account could get another's session and show its plan and allowance 2026-10-01 02:45:10 +08:00
yetone c8f4d448df Parity with magpie's built-ins: a failed sign-in says why, CLI-backed Command Code and Devin accounts follow the CLI's key, Factory's refused renewal is a 401 in the caller's API shape
- every {type:"failed"} carries an error reason magpie shows
- commandcode/devin: accounts taken from the CLI are marked metadata.cli and re-read its credentials on each request, usage and models
- factory: a refused refresh answers 401 authentication_error (Anthropic shape on /llm/a/, OpenAI's elsewhere) instead of throwing; the whoami back-off is per account; 403 hints name the account to sign in again
- versions: factory/devin/commandcode/cursor/kiro/mimo/zed/zcode 0.1.2, workbuddy 0.1.3
2026-10-01 00:55:50 +08:00
yetone 3d1f24219a mimo 0.1.1: usage shows as magpie's built-in did — plan, period, windows and what they count, balancemimo 2026-09-30 23:03:09 +08:00
yetone 5a18bbdac4 Name the scope @magpie-community (the org's name, spelled right) 2026-09-30 17:04:47 +08:00
yetone fd05920836 mimo: Xiaomi MiMo (the MiMo app's Xiaomi account) — Xiaomi sign-in page or QR polled until done, regional servers, session cookies renewed every 24h and on a 401, MiMo Pro and Flash over chat completions 2026-09-30 17:00:13 +08:00