On a signed-in agy, `agy models` takes about 4.4s and `agy acp`'s
session/new about 3s. provider.models() needed three calls before
claude-opus-5-5, claude-sonnet-5-5 and gpt-oss-120b showed up, and
OpenCode 2.x calls it once.
What changed:
- packages/agy-cli/index.mjs:
- The offered-model probe now starts in listAgyModels' .then, as soon as
a non-empty list arrives and a caller asked for probeOffered. It no
longer waits for the next models() call. A hung or failed `agy models`
still never spawns the probe.
- probeSignedIn reuses the `agy models` stdout it already has. The same
parser (parseAgyModels, split out of listAgyModels) fills
cachedModelCatalog, and the probe starts. Sign-in waits for the probe
for at most 3s.
- The offer (acpOfferedModels, acpOfferedKey, offeredProbeAt and any
in-flight probe) is forgotten when agyPath changes and after a new
sign-in finishes. A generation counter drops the answer of a probe
that started before the reset.
- provider.warming() returns a promise while a list or probe is still
running, and null when nothing is.
- scripts/opencode2.mjs, copied byte for byte to every
packages/*/opencode2.mjs: after the first background refresh, the
adapter awaits hooks.provider.warming() once, for at most 60s, and then
refreshes once more. It does not loop. Plugins without warming() behave
as before.
- Not done: the issue's on-disk catalog cache (point 3), skipped as asked.
Known gap: agy-cli has no `config` hook, so under OpenCode 2.x the adapter
lists no provider for it. refresh() returns before it calls
provider.models(), so the follow-up refresh can't add agy's models on 2.x
until agy-cli gets a config hook.
Tests: test/testkit.mjs's fake agy takes a sessionNewDelayMs. The new
tests in test/catalog.mjs set 1.5s on both `agy models` and session/new
and wait for state through warming(), with no fixed sleeps:
- On a slow cold start, the first models() after warming lists Claude and
GPT, from one probe spawn.
- authorize() on a signed-in agy fills the catalog, and the next models()
runs no second `agy models`.
- The sign-in wait is bounded: with a 6s session/new, sign-in returns in
about 4.5s.
- Changing agyPath probes again.
The hang test now awaits warming() before it counts acp spawns.
scripts/opencode2.test.mjs: the warming list is read a second time when
warming ends, and only once when nothing is warming.
Run on Linux (a separate test Mac was over its load limit):
- packages/agy-cli bun test: 17 pass, 0 fail.
- bun scripts/check.mjs agy-cli: ok.
- bun scripts/check.mjs (all packages): ok.
- Root bun test in a temp HOME: 8530 pass, 19 skip, 0 fail.
Broken by hand on Linux, each red, then restored green:
- No probe in the .then: the slow cold-start test.
- probeSignedIn drops the list: the authorize and bounded-wait tests.
- agyPath change keeps the old offer: the agyPath test.
- Unbounded sign-in wait: the bounded-wait test (7514ms).
- Probe also on a failed listing: the hang test.
- origin/main's index.mjs with the new tests: all four #1064 tests.
- Adapter reads the list once: the warming adapter test, and the
copy-identity check.
Not tried: a real agy (no Google sign-in, no network). The reset after
login.finish has no unit test of its own.
Reported-by: hiee3
@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 |