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.
@magpie-community/opencode-mimo-auth
Signs in to Xiaomi MiMo with a Xiaomi account, the way the MiMo desktop
app does, and makes its model requests. Provider id: mimo-app.
Sign-in
One way, Xiaomi account. The plugin opens Xiaomi's sign-in page (account.xiaomi.com's long-poll ticket). Sign in there, or scan its QR code with the Xiaomi phone app. The plugin waits on the ticket until Xiaomi says the account is in, so there's nothing to paste back.
Xiaomi's passToken then signs the account on at the MiMo server. The server
sends the browser through account.xiaomi.com and back through its /sts,
which sets the session cookies (serviceToken, userId, cUserId). An
account from Russia or India is moved to that region's server
(mimo-server-ru / mimo-server-in). Everyone else stays on
mimo-server-sgp.
Requests
Chat completions go to https://mimo-server-<region>.xiaomimimo.com/api/route/chat/completions
(@ai-sdk/openai-compatible). Each request carries:
- the session cookies, with no
Authorizationheader X-Mimo-Source: mimocode-cli-freeX-Client-Version: 26.929.292248- the app's User-Agent
mimo-auto, the app's default model, is requested as mimo-pro.
The session is renewed with the passToken a day after it was issued.
magpie (0.1.684 and later) does it ahead of time through auth.refresh, ten
minutes before that day is out (refreshLead), once for the account and
before its requests, models and usage ask for it; a passToken Xiaomi no
longer takes marks the account for a new sign-in. The check before each
request stays for OpenCode, which doesn't call auth.refresh, and one
sign-on at a time serves both. A model
request the server turns away (a 401) is answered as the server answered it,
as magpie's built-in MiMo account did; reading usage renews the session once
when the server turns it away. If the passToken no longer works, sign in
again.
An account with a Token Plan and no app membership
The app's server answers such an account's requests, every model, with
403 membership_required ("未开通会员或会员已到期,请订阅后使用"). The
plugin then asks the account's Token Plan instead. The passToken signs on
at the open platform (platform.xiaomimimo.com, sid api-platform), which
gives the plan's tp- key (/tokenPlan/apiKey/raw) and its endpoint
(openaiBaseUrl of /tokenPlan/apiKey, e.g.
https://token-plan-cn.xiaomimimo.com/v1). The request goes there with
Authorization: Bearer <tp- key> and no cookies, with mimo-pro asked as
mimo-v2.6-pro and mimo-flash as mimo-v2.6-flash. For an hour after,
the account's requests go straight to the plan; then the app is asked
first again, in case a membership was bought. A key reset at the platform
(the plan's 401) is read again on the next request. An account with no
Token Plan, or a plan with no key yet (the platform's Token Plan page
makes one), gets the app's 403 as it is.
Usage
magpie's Usage card shows the MiMo app's plan and its week's allowance.
A Token Plan bought at the open platform (platform.xiaomimimo.com) is a
plan of its own, spent by its tp- API key at
token-plan-<region>.xiaomimimo.com. The same passToken signs on at the
platform (sid api-platform), so the card shows the Token Plan too. With
an app plan, its credits are an aside beside the week's allowance: this
account's requests go to the app. With no app plan, the Token Plan is the
card's plan and its credits are the account's allowance, since its
requests go to the plan (above).
Where the sign-in is kept
In OpenCode's auth.json, or magpie's plugin-auth.json, as an OAuth sign-in:
refresh: the Xiaomi account as JSON (userId,cUserId,passToken,deviceId,region,base)access: the session cookies as JSONexpires: when the session is renewedaccountId: the Xiaomi user id
Models
| Model | Name | Context | Output | Input |
|---|---|---|---|---|
mimo-pro |
MiMo Pro | 1,000,000 | 128,000 | text, image |
mimo-flash |
MiMo Flash | 1,000,000 | 128,000 | text, image |